← Back to Pull requests

feat(gateway-api): add ReferenceGrant CRD and cross-namespace authorization #9953

Open
unknown opened this pull request with 464 lines diff across 5 files
View on GitHub
unknown unknown commented on Dec 03, 2026 07:52 UTC
Author

Stacked on #9950

Description

Problem

Phase 1 of smg-gateway-api rejected all cross-namespace backendRefs and certificateRefs unconditionally (RefNotPermitted). Real multi-tenant Kubernetes deployments require ReferenceGrant (gateway.networking.k8s.io/v1beta1) so target namespaces can explicitly authorize cross-namespace references from Gateway to Secret (listener certificates and GEP-3155 backend client certificates) and from HTTPRoute to Service or InferencePool, while remaining fail-closed whenever no matching grant exists.

Solution

  • Add ReferenceGrant (gateway.networking.k8s.io/v1beta1) custom resource definitions under crates/gateway_api/src/crds/reference_grant.rs.

  • Add ReferenceGrantIndex under crates/gateway_api/src/compiler/reference_grants.rs and wire it into Gateway listener/client Secret resolution and HTTPRoute backend resolution (Service and InferencePool).

  • Keep cross-namespace references fail-closed (ResolvedRefs: False / RefNotPermitted) unless a ReferenceGrant in the target namespace matches both (from.group, from.kind, from.namespace) and (to.group, to.kind, to.name) (empty/omitted to.name matching any object of (group, kind) in that namespace).

  • Add a ReferenceGrant reflector watch to GatewayController (included in the initial InitDone barrier) and hash ReferenceGrant specs in inputs_fingerprint so spec changes trigger recompilation even though Kubernetes does not bump metadata.generation on status-less CRDs.
  • Refs: #8616

    Changes

  • crates/gateway_api/src/crds/reference_grant.rs, mod.rs, tests.rs: ReferenceGrant, ReferenceGrantSpec, ReferenceGrantFrom, ReferenceGrantTo + deserialization and CRD schema tests.

  • crates/gateway_api/src/compiler/reference_grants.rs: ReferenceGrantIndex.

  • crates/gateway_api/src/compiler/{mod.rs, listeners.rs, routes.rs, tests.rs}: wire ReferenceGrant into GatewayInputs and cross-namespace Secret / Service / InferencePool authorization with fail-closed and allowed unit tests.

  • crates/gateway_api/src/controller.rs: ReferenceGrant reflector watch, InitDone barrier inclusion, and spec-based inputs_fingerprint hashing + unit test.

  • crates/gateway_api/src/matcher/{backend.rs, mod.rs}: update doc comments for ReferenceGrant-authorized cross-namespace namespaces.
  • Test Plan

    Ran on branch feat/gateway-api-reference-grant (f15332376327b29c596ad6d0f9078aaf83e77651):

    cargo +nightly fmt --all -- --check
    # exit 0
    
    python3 scripts/check_unit_test_layout.py
    # exit 0
    
    cargo clippy -p smg-gateway-api --all-targets --no-default-features -- -D warnings
    # Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.67s
    
    cargo clippy -p smg-gateway-api --all-targets --all-features -- -D warnings
    # Finished `dev` profile [unoptimized + debuginfo] target(s) in 3.09s (0 crate warnings)
    
    cargo test -p smg-gateway-api --no-default-features
    # test result: ok. 64 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.03s
    
    cargo test -p smg-gateway-api --all-features
    # test result: ok. 67 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.03s
    
    cargo check -p smg
    # Finished `dev` profile [unoptimized + debuginfo] target(s) in 2.01s
    

    Release note

    none (internal foundation crate for Gateway API support, not yet wired into the smg binary)

    <details>
    <summary>Checklist</summary>

  • cargo +nightly fmt passes

  • cargo clippy --all-targets --all-features -- -D warnings passes

  • (Optional) Documentation updated

  • (Optional) Please join us on Slack #sig-smg to discuss, review, and merge PRs
  • </details>

    Diff: 464 lines (+348 / -116) across 5 files Reviewer: claude[bot] Review duration: 9m
    All Vouch review confidence checks passed
    Residual risk 0.40 = Change Risk (0.69) × (1 − Review Confidence (0.41)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.69 · 464 lines diff across 5 files
    0.69
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 78% · Reviewer familiarity: 35%
    41%
    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.367
    Shallow Review Depth shallow_review_depth
    0.344
    Sensitive Paths sensitive_paths
    0.069
    Real PR Conversation Timeline
    1 comments
    "Review active on #9953"
    general weight: 0.35
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: medium confidence: 41.2% 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: 68.8% (HIGH) · Higher = larger blast radius
    68.8%
    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: 41.2% · Lower = rushed or shallow review
    41.2%
    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: 40.4% · Moderate risk
    40.4%