-
Notifications
You must be signed in to change notification settings - Fork 1.6k
rule id / metadata processing follow-ups #8613
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
596c8ea
runtime: process metadata annotations by default
srenatus f008263
ast: remove 'parse if id key is in metadata' heuristic
srenatus a022a7d
runtime: copy over `custom` rule metadata into `custom` decision logs
srenatus 1a874c8
runtime+config: drive annotation parsing from new configurable
srenatus 80ce61f
config: move default TLS settings
srenatus 6502e0e
initload+pathwatcher: use `ast.ParserOptions` argument
srenatus f4cf189
fix e2e tests, pass ProcessAnnotation in bundle downloaders
srenatus 9576398
pivot: go from "custom" to a new "labels" MD/DL field
srenatus 2ec12bb
ast: update aux methods for labels
srenatus 2b46aac
pivot: remove `id`, rely on `labels` only. enable annotations by default
srenatus da9fbcc
topdown: deduplicate aggregated rule label sets
srenatus 3d90dee
topdown: pin down document-scope labels behaviour
srenatus d02a5c7
docs: update policy-language
srenatus 1da18f7
sdk: fix parser options
srenatus File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| # Verify that labels from evaluated rule annotations appear as a top-level | ||
| # field in decision logs when policies are loaded from disk (no bundle server). | ||
|
|
||
| exec $OPA run --server --addr unix://opa.sock --log-format json --log-level info --set decision_logs.console=true ./policy/ &opa& | ||
| retry curl -sf --unix-socket opa.sock 'http://localhost/health' | ||
|
|
||
| # Evaluate allow — triggers rule with labels. | ||
| exec curl -sf --unix-socket opa.sock -H 'Content-Type: application/json' -d '{"input": {"role": "admin"}}' http://localhost/v1/data/authz/allow | ||
| jq stdout '.result == true' | ||
|
|
||
| # Evaluate with no match — no labels expected. | ||
| exec curl -sf --unix-socket opa.sock -H 'Content-Type: application/json' -d '{"input": {"role": "guest"}}' http://localhost/v1/data/authz/allow | ||
| jq stdout '.result == false' | ||
|
|
||
| kill -INT opa | ||
| wait opa | ||
|
|
||
| # Decision log for the admin request should have rule_labels. | ||
| jq -s stderr '[.[] | select(.msg == "Decision Log" and .result == true)] | .[0].rule_labels == [{"severity": "low", "team": "platform"}]' | ||
|
|
||
| # Decision log for the guest request should have no rule_labels. | ||
| jq -s stderr '[.[] | select(.msg == "Decision Log" and .result == false)] | .[0] | has("rule_labels") | not' | ||
|
|
||
| -- policy/authz.rego -- | ||
| package authz | ||
|
|
||
| default allow := false | ||
|
|
||
| # METADATA | ||
| # labels: | ||
| # severity: low | ||
| # team: platform | ||
| allow if input.role == "admin" |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| # Verify that rule labels appear in decision logs written via the | ||
| # file_logger plugin (slog-based path). | ||
|
|
||
| exec $OPA build -o bundles/bundle.tar.gz --bundle policy/ | ||
|
|
||
| http_server bundles | ||
|
|
||
| exec $OPA run --server --addr unix://opa.sock --log-format json --log-level info --config-file config.yaml &opa& | ||
| retry curl -sf --unix-socket opa.sock 'http://localhost/health?bundles' | ||
|
|
||
| # POST to v1/data — rule with labels should be evaluated. | ||
| exec curl -sf --unix-socket opa.sock -H 'Content-Type: application/json' -d '{"input": {"role": "admin"}}' http://localhost/v1/data/authz/allow | ||
| jq stdout '.result == true' | ||
|
|
||
| # POST to v1/data — no rules match. | ||
| exec curl -sf --unix-socket opa.sock -H 'Content-Type: application/json' -d '{"input": {"role": "guest"}}' http://localhost/v1/data/authz/allow | ||
| jq stdout '.result == false' | ||
|
|
||
| kill -INT opa | ||
| wait opa | ||
|
|
||
| # Decision log file should contain rule_labels for the admin request. | ||
| jq -s decisions.log '[.[] | select(.rule_labels == [{"severity": "low"}])] | length == 1' | ||
|
|
||
| # Decision log file should have an entry without rule_labels for the guest request. | ||
| jq -s decisions.log '[.[] | select(.path == "authz/allow" and (.rule_labels == null))] | length == 1' | ||
|
|
||
| -- config.yaml -- | ||
| services: | ||
| bundle-server: | ||
| url: "http://${HTTP_ADDR}" | ||
| bundles: | ||
| test: | ||
| service: bundle-server | ||
| resource: bundle.tar.gz | ||
| polling: | ||
| min_delay_seconds: 300 | ||
| max_delay_seconds: 300 | ||
| plugins: | ||
| file_logger: | ||
| path: decisions.log | ||
| decision_logs: | ||
| plugin: file_logger | ||
|
|
||
| -- policy/authz.rego -- | ||
| package authz | ||
|
|
||
| default allow := false | ||
|
|
||
| # METADATA | ||
| # labels: | ||
| # severity: low | ||
| allow if input.role == "admin" | ||
|
|
||
| # METADATA | ||
| # labels: | ||
| # severity: low | ||
| allow if input.role == "editor" | ||
|
|
||
| -- bundles/.gitkeep -- |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| # Verify that labels from evaluated rule annotations appear as a top-level | ||
| # field in decision logs. | ||
|
|
||
| exec $OPA build -o bundles/bundle.tar.gz --bundle policy/ | ||
|
|
||
| http_server bundles | ||
|
|
||
| exec $OPA run --server --addr unix://opa.sock --log-format json --log-level info --config-file config.yaml &opa& | ||
| retry curl -sf --unix-socket opa.sock 'http://localhost/health?bundles' | ||
|
|
||
| # Evaluate allow — triggers allow-admin rule. | ||
| exec curl -sf --unix-socket opa.sock -H 'Content-Type: application/json' -d '{"input": {"role": "admin"}}' http://localhost/v1/data/authz/allow | ||
| jq stdout '.result == true' | ||
|
|
||
| # Evaluate violations — triggers both violation rules; labels collected per-rule. | ||
| exec curl -sf --unix-socket opa.sock -H 'Content-Type: application/json' -d '{"input": {"role": "admin", "dept": "eng"}}' http://localhost/v1/data/authz/violations | ||
| jq stdout '.result | length == 2' | ||
|
|
||
| kill -INT opa | ||
| wait opa | ||
|
|
||
| # Decision log for allow should have rule_labels with the single matching rule's labels. | ||
| jq -s stderr '[.[] | select(.msg == "Decision Log" and .path == "authz/allow")] | .[0].rule_labels == [{"severity": "low"}]' | ||
|
|
||
| # Decision log for violations should have one entry per evaluated rule, preserving per-rule grouping. | ||
| jq -s stderr '[.[] | select(.msg == "Decision Log" and .path == "authz/violations")] | .[0].rule_labels | sort_by(.category) == [{"severity": "high", "category": "compliance"}, {"severity": "critical", "category": "org-policy"}]' | ||
|
|
||
| -- config.yaml -- | ||
| services: | ||
| bundle-server: | ||
| url: "http://${HTTP_ADDR}" | ||
| bundles: | ||
| test: | ||
| service: bundle-server | ||
| resource: bundle.tar.gz | ||
| polling: | ||
| min_delay_seconds: 300 | ||
| max_delay_seconds: 300 | ||
| decision_logs: | ||
| console: true | ||
|
|
||
| -- policy/authz.rego -- | ||
| package authz | ||
|
|
||
| default allow := false | ||
|
|
||
| # METADATA | ||
| # labels: | ||
| # severity: low | ||
| allow if input.role == "admin" | ||
|
|
||
| # METADATA | ||
| # labels: | ||
| # severity: low | ||
| allow if input.role == "editor" | ||
|
|
||
| # METADATA | ||
| # labels: | ||
| # severity: high | ||
| # category: compliance | ||
| violations contains "admin role is restricted" if input.role == "admin" | ||
|
|
||
| # METADATA | ||
| # labels: | ||
| # severity: critical | ||
| # category: org-policy | ||
| violations contains "admin not allowed in eng" if { | ||
| input.role == "admin" | ||
| input.dept == "eng" | ||
| } | ||
|
|
||
| -- bundles/.gitkeep -- |
Oops, something went wrong.
Oops, something went wrong.
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This struck me as an acceptable compromise. It's a limitation we can deal with if it really is something blocking people.