← Back to Pull requests

feat(builtins)!: add a Kubernetes SubjectAccessReview PDP #389

Closed
unknown closed this pull request without merging on Nov 30, 2026 18:26 UTC
View on GitHub
unknown unknown commented on Nov 26, 2026 16:02 UTC
Author

Closes #214.

This adds kubernetes-sar, a decision point that defers an access decision to the Kubernetes API server. A pdp(kubernetes-sar): step sends a SubjectAccessReview describing the caller and the action, and allows only when the cluster's authorizer chain (RBAC, Node, or a webhook) allows. Paired with identity/kubernetes-token-review, an operator can grant agents access to tools with ordinary RBAC objects.

No PDP could make an HTTP call before this. PdpFactory lived in praxis-policy-apl-core, which does not depend on praxis-policy-core and so cannot name the host's transport. The first commit fixes that by moving PdpFactory to the runtime and passing it the host services; the second adds the PDP.

Configuration

global:
  pdp:
    - kind: kubernetes-sar
      api_server:
        url: https://kubernetes.default.svc
        reviewer_token:
          kind: file
          path: /var/run/secrets/kubernetes.io/serviceaccount/token
      on_error: deny

routes:
  - tool: search_issues
    authorization:
      pre_invocation:
        - "require(authenticated)"
        - pdp(kubernetes-sar):
            non_resource_attributes:
              path: "'/tools/' + meta.entity_name"
              verb: "'post'"
  - tool: deploy_service
    authorization:
      pre_invocation:
        - pdp(kubernetes-sar):
            resource_attributes:
              group: "'mcp.example.com'"
              resource: "'tools'"
              name: meta.entity_name
              namespace: args.environment
              verb: "args.dry_run == true ? 'get' : 'invoke'"

Both review shapes from the issue are supported: resource_attributes ("may the subject verb this object?") and non_resource_attributes ("may the subject verb this path?"). A step sets exactly one. Every field, including the subject's user, groups, uid and extra, is a CEL expression over the attribute bag, using the cel PDP's bag mapping, so a SAR step reads the same names a cel: step does. Only the values the expressions produce are sent; tool arguments stay in PPE unless an expression names one. user defaults to subject.id and groups to subject.roles; the global.pdp block can change the defaults and a step can override them.

The API server connection and reviewer token are the same block identity/kubernetes-token-review uses. Both now live in a crate-private module that the TokenReview plugin re-exports, so its public paths are unchanged. The reviewer token's identity needs create on subjectaccessreviews; system:auth-delegator grants it with tokenreviews.

Behaviour

| Situation | Decision |
|---|---|
| An authorizer allows | Allow |
| An authorizer denies, or none has an opinion | Deny, as the API server itself does |
| An expression fails, yields the wrong type, or user is empty | Deny, without calling the API server, whatever on_error says |
| The groups include system:masters | Deny, without calling the API server |
| The API server is unreachable, refuses the reviewer credential (401, 403), answers non-2xx, or answers something that is not a review | on_error, deny by default |

reason and evaluationError from the answer go to the decision's diagnostics, not the client-facing denial. Expression failures deny unconditionally because they mean the policy could not say who or what to review; on_error: allow is for an authorizer that is down, not for a broken policy.

system:masters is the one group the API server lets skip authorization, and the review takes PPE's groups on trust. No ServiceAccount token carries it, so a review naming it has groups from somewhere else. It is a single hardcoded name, not a list: every other group's effect is visible in the cluster's own bindings.

The default groups is right for a TokenReview identity, whose groups are the cluster's own answer. For a JWT or API key identity the roles are names an identity provider chose, and the cluster would match them against its bindings as if they were Kubernetes groups. The docs say to set groups explicitly in that case, to [] or with an oidc: prefix the way the API server's --oidc-groups-prefix does. Making the default depend on where the identity came from needs the subject's attestor in the bag, which it is not today; that is a follow-up issue (link once filed).

Host transport

PdpFactory::build now takes &PdpHostServices, a non-exhaustive struct whose http field is the transport the host installed with set_http_transport, read through a new PolicyEngine::http_transport(). Cedar, CEL and OPA ignore it. kubernetes-sar fails the config load without one, with a message saying to call set_http_transport first. The transport is taken when the global.pdp entry is built, so the host sets it before load_config_yaml; Praxis already does. TLS trust for the API server is the transport's, as for TokenReview.

PDPs have no perform_http capability. Capabilities limit what plugin code can reach from a request; a PDP is compiled in by the host and configured only in global.pdp, so declaring kind: kubernetes-sar is the operator's opt in, as for the Vault secret provider. The API server URL is static config, so request data cannot steer where the review goes.

Differential harness

The facade test from #25 requires every builtin PDP to be in the Cedar/CEL/OPA differential harness. kubernetes-sar holds no policy of its own to express in the other dialects, so the test now exempts it by name, and the builtins reference says so.

Breaking changes

  • PdpFactory moves from praxis_policy_apl_core::step to praxis_policy_apl_runtime, and build takes a second argument, &PdpHostServices. Out-of-tree implementors update the import and add the argument. The praxis_policy::PdpFactory facade path is unchanged.

  • The cedar, cel and opa builtin features now compile praxis-policy-apl-runtime, and so need a crypto backend selected, like every other engine-backed feature. A builtins build with only cel and no backend used to compile and no longer does.

  • A host that loads a policy declaring kind: kubernetes-sar must call set_http_transport before load_config_yaml. Nothing changes for a policy without one.
  • Testing

  • Unit tests on reading the answer: allowed, explicit deny, no opinion, both flags set, evaluationError beside allowed, malformed bodies, and the request JSON omitting unset fields.

  • Integration tests through the engine against a scripted API server: an allow checking the exact JSON sent and the reviewer bearer; a no-opinion deny; resource attributes built from tool arguments, including the dry-run verb; a step reviewing a different subject with extra; on_error both ways on 503 and 403; no subject and system:masters each denying without a call under on_error: allow; and load failures for both shapes set, invalid CEL, an unknown key, and a missing transport.

  • A visitor test that the factory receives the engine's transport and that a factory needing one fails the load without it.

  • The TokenReview tests pass unchanged after the config moved.

  • make check, make lint, make doc, and a FIPS build with cedar, cel, opa and kubernetes-sar pass.
  • Not tested against a live API server. The answer shapes (201 for every outcome, allowed and denied omitted when false, both absent for no opinion) match what TokenReview showed on kind and the API documentation, but this PR has no SAR fixtures captured from a real cluster.

    Not done: a review cache keyed on the evaluated review. The generic cache: option on a global.pdp entry works but keys on the whole bag, so it rarely hits; while an answer is cached, an RBAC change waits out its TTL. The cel crate's string extensions, such as split(), are not available, the same as in cel: steps.

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

    New Features
    Added Kubernetes authorization checks for resource and non-resource requests, with configurable subject and attribute mapping and fallback behavior when the API server does not respond.
    Added shared Kubernetes API-server and reviewer-token configuration, and support for using the host’s HTTP transport.
    Decision caches now store only results marked cacheable; Kubernetes outage-fallback allows are not cached.
    Added OPA-enabled builtins to applicable Makefile targets.
    Breaking Changes
    Custom policy decision point factories must accept host services. Cedar, CEL, and OPA builtin features require a crypto backend.
    Documentation
    * Added Kubernetes authorization configuration and usage guidance, including caching behavior.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: guicassolato Review duration: 5903m
    All Vouch review confidence checks passed
    Residual risk 0.30 = Change Risk (0.75) × (1 − Review Confidence (0.60)). 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%
    60%
    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 #389"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 60.5% 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: 60.5% · Lower = rushed or shallow review
    60.5%
    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: 29.7% · Safe to merge
    29.7%