feat: added reference grant mode#14209
Merged
davidjumani merged 7 commits intoJun 11, 2026
Merged
Conversation
Signed-off-by: Andy Fong <[email protected]>
Contributor
There was a problem hiding this comment.
Pull request overview
Adds a configurable ReferenceGrant enforcement mode to kgateway to control how strictly cross-namespace references are validated, preserving current behavior by default while enabling stricter (or disabled) enforcement when desired.
Changes:
- Introduces
ReferenceGrantMode(OFF,PERMISSIVEdefault,STRICT) inapi/settings, including env var parsing and settings tests. - Wires the mode into
RefGrantIndexto globally short-circuit ReferenceGrant checks whenOFF. - Enforces ReferenceGrants for cross-namespace
TrafficPolicy -> GatewayExtensionextensionRefonly inSTRICT, with new translator golden tests and documentation.
Reviewed changes
Copilot reviewed 22 out of 22 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/pluginsdk/collections/collections.go | Passes Settings.ReferenceGrantMode into NewRefGrantIndex during common collection setup. |
| pkg/krtcollections/policy.go | Extends RefGrantIndex to store mode and bypass checks when mode is OFF; updates constructor signature. |
| pkg/krtcollections/secrets_test.go | Updates test to construct RefGrantIndex with an explicit mode. |
| pkg/krtcollections/policy_test.go | Updates test to construct RefGrantIndex with an explicit mode. |
| pkg/krtcollections/policy_backendtls_test.go | Updates tests to construct RefGrantIndex with an explicit mode. |
| pkg/krtcollections/grpc_route_test.go | Updates test to construct RefGrantIndex with an explicit mode. |
| pkg/kgateway/query/query_test.go | Updates test to construct RefGrantIndex with an explicit mode. |
| pkg/kgateway/proxy_syncer/gateway_backend_variants_test.go | Updates test to construct RefGrantIndex with an explicit mode. |
| pkg/kgateway/proxy_syncer/backendtls_synthetic_test.go | Updates test to construct RefGrantIndex with an explicit mode. |
| pkg/kgateway/extensions2/plugins/trafficpolicy/constructor.go | Adds strict-mode ReferenceGrant validation for cross-namespace extensionRef resolution. |
| pkg/kgateway/translator/gateway/gateway_translator_test.go | Adds translator test cases covering OFF / PERMISSIVE / STRICT behaviors. |
| pkg/kgateway/translator/gateway/testutils/inputs/reference-grant-mode/off-backendref-no-grant.yaml | New input fixture for OFF mode backend ref behavior. |
| pkg/kgateway/translator/gateway/testutils/inputs/reference-grant-mode/permissive-extensionref-no-grant.yaml | New input fixture for PERMISSIVE mode extensionRef behavior. |
| pkg/kgateway/translator/gateway/testutils/inputs/reference-grant-mode/strict-extensionref-no-grant.yaml | New input fixture for STRICT mode missing grant behavior. |
| pkg/kgateway/translator/gateway/testutils/inputs/reference-grant-mode/strict-extensionref-with-grant.yaml | New input fixture for STRICT mode allowed-with-grant behavior. |
| pkg/kgateway/translator/gateway/testutils/outputs/reference-grant-mode/off-backendref-no-grant.yaml | New golden output for OFF mode backend ref behavior. |
| pkg/kgateway/translator/gateway/testutils/outputs/reference-grant-mode/permissive-extensionref-no-grant.yaml | New golden output for PERMISSIVE mode extensionRef behavior. |
| pkg/kgateway/translator/gateway/testutils/outputs/reference-grant-mode/strict-extensionref-no-grant.yaml | New golden output for STRICT mode missing grant behavior. |
| pkg/kgateway/translator/gateway/testutils/outputs/reference-grant-mode/strict-extensionref-with-grant.yaml | New golden output for STRICT mode allowed-with-grant behavior. |
| devel/reference_grant/reference-grant-mode.md | Adds detailed developer documentation for modes, semantics, and test workflows. |
| api/settings/settings.go | Adds ReferenceGrantMode type/decoder and Settings.ReferenceGrantMode field (default PERMISSIVE). |
| api/settings/settings_test.go | Extends settings tests to cover new env var and invalid-mode error case. |
Signed-off-by: Andy Fong <[email protected]>
Signed-off-by: Andy Fong <[email protected]>
Signed-off-by: Andy Fong <[email protected]>
davidjumani
reviewed
Jun 10, 2026
| } | ||
|
|
||
| // In Strict mode, cross-namespace ExtensionRef requires a ReferenceGrant. | ||
| if c.commoncol.Settings.ReferenceGrantMode == apisettings.ReferenceGrantStrict { |
Contributor
There was a problem hiding this comment.
It doesn't look nice to have this explicit chek in the traffic policy constructor but its better than keeping it in ReferenceAllowed
| } | ||
|
|
||
| func NewRefGrantIndex(refgrants krt.Collection[*gwv1b1.ReferenceGrant]) *RefGrantIndex { | ||
| func NewRefGrantIndex(refgrants krt.Collection[*gwv1b1.ReferenceGrant], mode apisettings.ReferenceGrantMode) *RefGrantIndex { |
Contributor
There was a problem hiding this comment.
Thinking of this from a future perspective, where users could turn off reference grants for specific Kinds, would passing the settings object itself be a better idea ?
davidjumani
approved these changes
Jun 10, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Jun 10, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Jun 10, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Jun 11, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Jun 11, 2026
github-merge-queue
Bot
removed this pull request from the merge queue due to failed status checks
Jun 11, 2026
Signed-off-by: Andy Fong <[email protected]>
Signed-off-by: Andy Fong <[email protected]>
… dyanmic module Signed-off-by: Andy Fong <[email protected]>
davidjumani
approved these changes
Jun 11, 2026
This was referenced Jun 11, 2026
chandler-solo
pushed a commit
to chandler-solo/kgateway
that referenced
this pull request
Jun 15, 2026
…-dev#14239) Signed-off-by: Andy Fong <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Added 3 modes:
see devel/reference_grant/reference-grant-mode.md for details.
Change Type
/kind feature
Changelog