End-to-end walkthroughs of the five key interactions in this PoC, showing how Keycloak, Kong, OPA, and banking-api-service collaborate on each request.
Flow 1: Demo User Setup
You run the demo script once before any login. It calls identity-bootstrap-service, which provisions repeatable demo users in Keycloak.
Steps:
- The demo script calls
POST /demo/usersonidentity-bootstrap-service. identity-bootstrap-serviceauthenticates toKeycloakusing an admin credential.identity-bootstrap-servicecreates or reconciles the demo user.- It assigns the user’s role (
customerorops-admin) and custom claims (e.g.,account_ids). Keycloakconfirms the user is ready;identity-bootstrap-servicereturns201.
For details on how identity-bootstrap-service works, see 10 — Identity Bootstrap Service.
Flow 2: User Login
You exchange credentials for a JWT. The token carries identity and claims used in every subsequent request.
Steps:
- The client posts
username+passwordtoKeycloak’s token endpoint. Keycloakvalidates the credentials.Keycloakreturns a signed JWT access token.
For Keycloak token endpoint details and JWT claim structure, see 06 — Keycloak IdP.
Flow 3: Allowed Account Access
alice reads one of her own accounts. Kong (PEP) verifies the token is live, OPA (PDP) confirms alice owns that account, and banking-api-service re-validates before serving the data.
Example: alice requests GET /api/accounts/A-1001 where A-1001 belongs to alice.
Steps:
- The client sends the JWT as a bearer token to
Kong. Kongintrospects the token withKeycloak— confirms it is active.Kongsends the decoded claims and requestedaccount_idtoOPA.OPAevaluates the policy and returnsallow(the account is inalice’saccount_idsclaim).Kongforwards the request tobanking-api-service.banking-api-servicere-validates the JWT signature, issuer, and audience.banking-api-serviceverifiesaliceownsA-1001.banking-api-servicereturns200with the account data.
For introspection details, see 11 — JWT Signature Validation. For OPA policy logic, see 08 — OPA. For wire-level payloads, see 14 — Request-Response Reference.
Flow 4: Forbidden Account Access
alice attempts to read an account she does not own. OPA denies it at the gateway — banking-api-service is never reached.
Example: alice requests GET /api/accounts/A-2001 where A-2001 belongs to a different customer.
For contrast: ops-admin making the same request would receive allow from OPA, because the ops-admin role grants access to any account.
Steps:
- The client sends the JWT to
Kong. Kongintrospects the token — confirms it is active.Kongsends the decoded claims andaccount_id=A-2001toOPA.OPAreturnsdeny(A-2001is not inalice’saccount_idsclaim and she lacks theops-adminrole).Kongreturns403 Forbidden. The request never reachesbanking-api-service.
For OPA policy logic, see 08 — OPA. For wire-level payloads, see 14 — Request-Response Reference.
Flow 5: Missing Or Tampered Token
Requests without a valid token are rejected by Kong before any policy check.
Missing token:
- The client calls
Kongwithout a bearer token. Kongrejects immediately with401 Unauthorized.
Tampered token:
- The client sends a modified JWT.
Kongintrospects the token withKeycloak.Keycloakreports the token as inactive (signature mismatch or unknown).Kongreturns401 Unauthorized.
For introspection details, see 11 — JWT Signature Validation.
Why These Flows Matter
Each flow illustrates the clean separation between components (defined in 01 — Concepts):
Keycloakauthenticates and signs tokens.Kongenforces edge access and drives the policy check.OPAdecides allow or deny from policy rules alone.banking-api-servicere-validates and provides business data.
No component over-reaches into another’s responsibility.
📚 返回专栏目录

410

被折叠的 条评论
为什么被折叠?



