5.3 Describe REST API security
ENCOR 350-401 v1.2 · 5.0 Security
APIs open the network to automation, and to attackers if they are careless. REST API security covers who may call (authentication), what they may do (authorization), protecting the data in transit (TLS), and protecting the API itself (rate limits, input validation, secrets handling).
What you must know
- Compare API authentication: basic, API keys, tokens (bearer, JWT), OAuth 2.0, certificates.
- Explain why HTTPS (TLS) is mandatory and what certificate validation protects.
- Describe authorization: roles and scopes, least privilege.
- List good practice: no secrets in code or URLs, token expiry, rate limiting, input validation, logging.
Authentication and transport
| Method | How | Notes |
|---|---|---|
| Basic | Username:password in Base64 in a header | Only over HTTPS; often used once to get a token |
| API key | A static secret in a header | Simple; rotate and scope it |
| Token (bearer, JWT) | Short-lived token from an auth endpoint, sent with each request | Catalyst Center uses X-Auth-Token; expires |
| OAuth 2.0 | An authorization server issues scoped tokens | Delegated access without sharing passwords |
| Mutual TLS | Client certificate | Strong machine-to-machine identity |
Every call must use HTTPS: Base64 is encoding, not encryption. Clients must validate the server certificate; disabling verification (verify=False) invites man-in-the-middle attacks.
The script authenticates once (1) and then uses the token, limited by its role, for each call (2).
Good practice
- Least privilege: read-only roles for monitoring scripts, write roles only where needed.
- Keep secrets in a vault or environment variables, never in code, Git or URLs (URLs end up in logs).
- Short token lifetimes and revocation.
- Rate limiting and quotas against abuse; input validation against injection.
- Log and audit API calls like CLI changes.
Commands
curl -H 'X-Auth-Token: …' https://… | A token-authenticated call. |
openssl s_client -connect host:443 | Inspect the API's TLS certificate. |
Exam traps
- Basic authentication over HTTP sends the password in readable Base64.
- Never disable certificate verification in production scripts.
- Tokens expire; scripts must handle 401 and re-authenticate.
- 401 = not authenticated; 403 = authenticated but not authorized.
Check yourself
- Why is basic authentication acceptable only over HTTPS?
- Base64 is reversible; TLS is what protects the credentials.
- Where should an automation script keep its API secret?
- In a secrets vault or environment variable, not in the code or repository.
- A call returns 403. Is the token wrong?
- Not necessarily: the caller is authenticated but its role does not allow that action.