Skip to content

feat: added reference grant mode#14209

Merged
davidjumani merged 7 commits into
kgateway-dev:mainfrom
andy-fong:af-reference-grant-mode
Jun 11, 2026
Merged

feat: added reference grant mode#14209
davidjumani merged 7 commits into
kgateway-dev:mainfrom
andy-fong:af-reference-grant-mode

Conversation

@andy-fong

@andy-fong andy-fong commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Description

Added 3 modes:

  • STRICT
  • PERMISSIVE (default)
  • OFF

see devel/reference_grant/reference-grant-mode.md for details.

Change Type

/kind feature

Changelog

added reference grant mode

Copilot AI review requested due to automatic review settings June 9, 2026 00:57
@andy-fong
andy-fong requested a review from a team as a code owner June 9, 2026 00:57
@gateway-bot gateway-bot added kind/feature Categorizes issue or PR as related to a new feature. release-note labels Jun 9, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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, PERMISSIVE default, STRICT) in api/settings, including env var parsing and settings tests.
  • Wires the mode into RefGrantIndex to globally short-circuit ReferenceGrant checks when OFF.
  • Enforces ReferenceGrants for cross-namespace TrafficPolicy -> GatewayExtension extensionRef only in STRICT, 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.

Comment thread pkg/krtcollections/policy.go
andy-fong added 3 commits June 9, 2026 10:24
Signed-off-by: Andy Fong <[email protected]>
Signed-off-by: Andy Fong <[email protected]>
Signed-off-by: Andy Fong <[email protected]>
@andy-fong andy-fong changed the title added reference grant mode feat: added reference grant mode Jun 9, 2026
}

// In Strict mode, cross-namespace ExtensionRef requires a ReferenceGrant.
if c.commoncol.Settings.ReferenceGrantMode == apisettings.ReferenceGrantStrict {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
davidjumani added this pull request to the merge queue Jun 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 10, 2026
@davidjumani
davidjumani added this pull request to the merge queue Jun 10, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 10, 2026
@davidjumani
davidjumani added this pull request to the merge queue Jun 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 11, 2026
@davidjumani
davidjumani added this pull request to the merge queue Jun 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 11, 2026
@andy-fong
andy-fong added this pull request to the merge queue Jun 11, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 11, 2026
@davidjumani
davidjumani added this pull request to the merge queue Jun 11, 2026
Merged via the queue into kgateway-dev:main with commit 1560573 Jun 11, 2026
32 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

kind/feature Categorizes issue or PR as related to a new feature. release-note

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants