← Back to Pull requests

feat(identity): resolve identity through Kubernetes TokenReview #361

Closed
unknown closed this pull request without merging on Nov 24, 2026 02:18 UTC
View on GitHub
unknown unknown commented on Nov 21, 2026 21:12 UTC
Author

Closes: #213

This PR adds identity/kubernetes-token-review, which sends the presented token to the API server's TokenReview API and maps the user the cluster names onto the identity slots. For a ServiceAccount JWT that only needs its signature checked, identity/jwt against the cluster issuer is still the cheaper option, and Recipe 12 says so.

Two commits

1. refactor(builtins) moves the parts of identity/api-key that are not specific to API keys into a crate-private token_lookup module: the KeyDirectory trait, the cache, credential hashing and the identity.resolve handler. A small LookupProfile holds what differs between plugins (the unknown and expired denial codes, and the cache's hashing labels). identity_api_key re-exports cache, directory and its codes, so every public path is unchanged and the API key tests pass without edits. The module doc states the rule that keeps it small: a mechanism that needs a branch in the shared resolver gets its own plugin.
2. feat(identity) adds the plugin as a KeyDirectory backend on that core, behind the kubernetes-token-review feature, also in the facade's builtins.

Configuration

plugins:
  - name: k8s-identity
    kind: identity/kubernetes-token-review
    hooks: [identity.resolve]
    capabilities: [perform_http]
    config:
      credential: { kind: header, name: Authorization }
      prefix: "Bearer "
      api_server:
        url: https://kubernetes.default.svc
        reviewer_token:
          kind: file
          path: /var/run/secrets/kubernetes.io/serviceaccount/token
      audiences: [praxis-gateway]
      record_map:
        subject: { id: username, roles: groups }
      cache: { ttl_secs: 30, negative_ttl_secs: 5 }

  • PPE's own token comes from a file, re-read once reread_secs has passed (default 60) so a projected token rotates, or from an environment variable read once. Its identity needs create on tokenreviews, which system:auth-delegator grants. A failed re-read keeps the last token. The secrets: block is not used because plugins cannot read the secret store today.

  • TLS trust belongs to the host's transport, as for the API key HTTP backend, so there is no CA setting here. api_server.url must be https://, because the reviewer token travels on it.

  • Audiences are sent as spec.audiences and also checked against status.audiences. With none set, any token the cluster accepts for its own API signs a caller in, and the plugin warns at load. Legacy Secret tokens authenticate only for the API server's audience, so a deployment serving them leaves audiences unset.

  • The record is status.user as the API server returns it: username, uid, groups, extra.

  • The cache is the shared one. Its TTL is the revocation window, except that an answer for a JWT never outlives the token's exp, read without verification from a token the API server just authenticated.

  • perform_http is required at load, not discovered on the first request.
  • | Outcome | Code |
    |---|---|
    | Not authenticated, or not for a configured audience | auth.token_unauthenticated |
    | A cached answer outlived the JWT's exp | auth.token_expired |
    | 401 or 403 (PPE's own token was refused), 5xx, timeout, unreadable answer | auth.directory_unavailable |

    The API server answers 201 for both outcomes and omits authenticated when it is false, so the verdict is read from the body and a missing field is a refusal.

    Testing

    The plugin has 21 tests. The API server's answers in tests/token_review/fixtures/ were captured from Kubernetes 1.35 (kind), with the echoed spec.token redacted: a projected token, a legacy token with and without a custom audience, a legacy token after its Secret was deleted, an unknown token, and a reviewer without RBAC. One test builds Recipe 12's exact config: block from the docs.

    End to end, Praxis upstream/main built against this branch, with SSL_CERT_FILE pointing at the cluster CA, reviewed every request against kind: a team-a token reached the backend, a team-b token was denied by the role check, and default-audience, custom-audience legacy, unknown and revoked legacy tokens were refused. Praxis compiled against 0.7.0 with no source changes.

    One finding from that run is in the docs: the API server caches successful authentications for about 10 seconds, so a token whose Secret was just deleted keeps passing for that long, on top of PPE's cache TTL.

    make check, lint, doc, check-features, test (both passes) and test-fips-no-provider are clean.

    Breaking changes

    None. Public paths and codes of identity/api-key are unchanged. The only behaviour change is one log message from the shared resolver, which now says "credential directory could not answer" instead of "api key directory could not answer".

    Not in this PR

  • Choosing what to do when a token is unauthenticated (fall through to the next resolver instead of denying). As in the #154 review, that belongs at the chain level.

  • A secret: source for the reviewer token, once plugins can read the secret store.

  • Custom CA roots for the bundled HyperTransport, which today trusts only the public roots and so cannot reach a cluster API server. Praxis is unaffected. To be filed separately.

  • SubjectAccessReview (#214), which can reuse api_server.
  • <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    Added Kubernetes TokenReview identity resolution, mapping authenticated Kubernetes user details to identity attributes, including tokens that cannot be verified locally.
    Added configurable audiences, reviewer credentials from environment variables or refreshed files, HTTPS API-server configuration, request timeouts, and optional caching. Cached results do not outlive parseable JWT expiration.
    Added the feature to bundled plugin options and documented setup and configuration.
    Bug Fixes
    Unauthenticated reviews and Kubernetes API authorization failures deny access; API 401 and 403 responses report the directory as unavailable.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: guicassolato Review duration: 3185m
    All Vouch review confidence checks passed
    Residual risk 0.32 = Change Risk (0.75) × (1 − Review Confidence (0.58)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.75 · 650 lines diff across 8 files
    0.75
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    57%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Sensitive Paths sensitive_paths
    0.075
    Real PR Conversation Timeline
    1 comments
    "Review active on #361"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 58.0% reviewed sensitive_module
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 75.2% (HIGH) · Higher = larger blast radius
    75.2%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 58.0% · Lower = rushed or shallow review
    58.0%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 31.6% · Safe to merge
    31.6%