Skip to content

feat: add namespace support to Rego driver via input.review.namespaceObject#646

Merged
JaydipGabani merged 7 commits intoopen-policy-agent:masterfrom
JaydipGabani:fix#3777
Dec 17, 2025
Merged

feat: add namespace support to Rego driver via input.review.namespaceObject#646
JaydipGabani merged 7 commits intoopen-policy-agent:masterfrom
JaydipGabani:fix#3777

Conversation

@JaydipGabani
Copy link
Copy Markdown
Contributor

  • Add Namespace field to ReviewCfg for passing namespace data to drivers
  • Add reviews.Namespace() option function for callers to pass namespace
  • Update Rego driver to accept namespace in toParsedInput and pass to Query
  • Update hookModuleRego to include input.namespace for Rego policy access
  • Add TemplateCheckNamespace for testing namespace-based policies
  • Add WantEnvironment constraint argument for namespace tests
  • Add TestClient_Review_Namespace e2e test for Rego namespace support

This enables Rego policies to access namespace metadata via input.namespace for namespace-scoped policy decisions.

Copilot AI review requested due to automatic review settings December 5, 2025 06:05
- Add Namespace field to ReviewCfg for passing namespace data to drivers
- Add reviews.Namespace() option function for callers to pass namespace
- Update Rego driver to accept namespace in toParsedInput and pass to Query
- Update hookModuleRego to include input.namespace for Rego policy access
- Add TemplateCheckNamespace for testing namespace-based policies
- Add WantEnvironment constraint argument for namespace tests
- Add TestClient_Review_Namespace e2e test for Rego namespace support

This enables Rego policies to access namespace metadata via input.namespace
for namespace-scoped policy decisions.

Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR adds namespace support to the Rego driver, enabling Rego policies to access namespace metadata via input.namespace for namespace-scoped policy decisions.

  • Adds Namespace field to ReviewCfg and a reviews.Namespace() option function for passing namespace data to drivers
  • Updates Rego driver to include namespace in the input passed to policies via object.get(input, "namespace", null)
  • Adds comprehensive test coverage with TemplateCheckNamespace and TestClient_Review_Namespace

Reviewed changes

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
constraint/pkg/client/template_client_test.go Minor comment punctuation fix
constraint/pkg/client/template_client.go Minor comment punctuation fix
constraint/pkg/client/reviews/review_opts.go Adds Namespace field to ReviewCfg and Namespace() option function
constraint/pkg/client/e2e_test.go Adds end-to-end test for namespace support with multiple test cases
constraint/pkg/client/drivers/rego/rego.go Updates hook module to include namespace in input using object.get()
constraint/pkg/client/drivers/rego/driver.go Updates toParsedInput() to accept and pass namespace parameter
constraint/pkg/client/clienttest/templates.go Adds TemplateCheckNamespace for testing namespace-based policies
constraint/pkg/client/clienttest/cts/constraints.go Adds WantEnvironment() constraint argument helper
constraint/pkg/client/client.go Reorders imports to follow Go conventions (alphabetical within groups)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov-commenter
Copy link
Copy Markdown

codecov-commenter commented Dec 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 43.33%. Comparing base (76869f8) to head (8e4f824).
⚠️ Report is 148 commits behind head on master.

Additional details and impacted files
@@             Coverage Diff             @@
##           master     #646       +/-   ##
===========================================
- Coverage   54.68%   43.33%   -11.35%     
===========================================
  Files          71       97       +26     
  Lines        5241     5411      +170     
===========================================
- Hits         2866     2345      -521     
- Misses       2073     2763      +690     
- Partials      302      303        +1     
Flag Coverage Δ
unittests 43.33% <ø> (-11.35%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Copy link
Copy Markdown
Member

@sozercan sozercan left a comment

Choose a reason for hiding this comment

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

a few minor comments, otherwise lgtm


violation[{"msg": msg}] {
# Check if namespace is provided and has the expected label
ns := input.review.namespaceObject
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do we need the guard if object doesn't have namespace?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added the check, if its nil then the variable results in undefined. So it should be alright, but added the check regardless.

}{
{
name: "no namespace provided - expects violation for missing namespace",
namespace: nil,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you add a case for empty namespace too

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added a test for this.

name: "no namespace provided - expects violation for missing namespace",
namespace: nil,
wantEnv: "production",
wantResults: 1,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

do we want this to be 0 or 1?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Not really, the test policy is written so that it will result in violation when namespace is nil or empty.

Signed-off-by: Jaydip Gabani <gabanijaydip@gmail.com>
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 9 out of 9 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@JaydipGabani JaydipGabani changed the title feat: add namespace support to Rego driver via input.namespace feat: add namespace support to Rego driver via input.review.namespaceObject Dec 17, 2025
Copy link
Copy Markdown
Member

@sozercan sozercan left a comment

Choose a reason for hiding this comment

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

LGTM, thanks

@JaydipGabani JaydipGabani merged commit e3880ce into open-policy-agent:master Dec 17, 2025
8 checks passed
@JaydipGabani JaydipGabani deleted the fix#3777 branch December 17, 2025 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants