Skip to content

Access Control, OIDC, and Session Management ​

Authentication identifies a user or service; access control decides which resource may be accessed under which conditions. OAuth2/OIDC tokens are inputs to that decision, but authorization must be enforced by the resource-owning backend.

Quick Decision ​

NeedApproachWatch out
Simple role matrixRBACWatch role explosion
Resource/tenant/device contextABAC or policy enginePolicies must be testable
Federated user loginOIDCDo not use an ID token as an API access token
Enterprise SSOSAML or OIDC federationRotate metadata and certificates
Stateless APIShort-lived access tokenDesign revocation and refresh
Stateful browser sessionSecure cookie + distributed sessionCSRF and session fixation

Production Checklist ​

  • Problem: Are identity, authorization, resource ownership, and tenant boundaries separate?
  • Solution: Are token claims, scopes, policies, session storage, revocation, and audit flows clear?
  • Trade-off: Central policy improves consistency but makes the auth service critical.
  • Failure mode: Handle expired/revoked tokens, privilege escalation, session theft, and confused deputy.
  • Measurement: Track authorization denies, token refreshes, session anomalies, policy latency, and SSO failures.
  • Security/cost: Apply least privilege, short token lifetimes, secret rotation, and policy-cache invalidation.

OIDC and OAuth2 Roles ​

OIDC adds an identity layer on top of OAuth2. Use authorization code + PKCE for user login and client credentials for service-to-service access. An ID token carries identity to the client; an API must validate an access token's audience and scopes.

For JWTs, validate issuer, audience, signing algorithm, expiry, not-before, key ID, and clock skew. Design refresh-token rotation, reuse detection, and revocation separately; a valid JWT signature does not solve logout or emergency revocation.

RBAC and ABAC ​

RBAC maps role -> permission and is simple to audit. Hierarchical roles help initially but can create role explosion in large organizations.

ABAC evaluates attributes such as subject, resource, action, tenant, device, location, or time:

text
allow if subject.tenant == resource.tenant
       and action in subject.permissions
       and resource.classification <= subject.clearance

Policy evaluation should fail closed. Record policy version, decision reason, cache lifetime, and object-level authorization tests. A coarse gateway check never replaces resource-ownership checks in the service.

Session Management ​

For stateful sessions, use a random opaque session ID. Protect cookies with Secure, HttpOnly, suitable SameSite, narrow Domain/Path, and idle/absolute timeouts. Rotate the session ID after login to prevent fixation.

Across instances, store sessions in a shared Redis or database store. Sticky sessions do not remove the need to design failover, expiry, revocation, serialization, and store-outage behavior. Revoke related sessions and refresh tokens on logout, password change, or a risky device change.

SSO and Identity Federation ​

Map a SAML assertion or OIDC identity-provider identity to a local account and tenant policy. Do not use a mutable email as the permanent identity; prefer the provider subject and verified claims.

Test redirect-URI allowlists, state, nonce, PKCE, certificate/signing-key rotation, clock skew, and account-linking rules. Decide explicitly how long existing sessions survive an identity-provider outage.

Zero-Trust Service Access ​

Zero trust means a service is not automatically trusted because it is on a private network:

  • Use verifiable service identity and short-lived credentials per workload.
  • Enforce authentication, authorization, audience, and policy on every request.
  • Use mTLS, network policy, and least-privilege service accounts.
  • Use just-in-time human access, audit, and regular access reviews.

Service-mesh policies are a defense layer; business authorization remains in the application and resource-owning service. Policy bypass, default allow, and shared admin credentials are red flags.

Audit and Investigation ​

Auth events should include actor, subject, resource, action, decision, policy version, request/trace ID, and timestamp. Never log tokens or passwords. Sudden deny-rate increases, impossible session geography, and failed SSO flows can be alert signals.

See Authentication vs Authorization, API Security, and TLS/mTLS for OAuth2/JWT, request security, and service-identity details.

Created by Eren Demir.