Skip to content

fix(observability): name the policy that decided each inspected request - #6244

Merged
krishicks merged 1 commit into
mainfrom
fix/5922-attribute-request-policy/krishicks
Dec 5, 2026
Merged

krishicks merged 1 commit into
mainfrom
fix/5922-attribute-request-policy/krishicks

Conversation

@krishicks

@krishicks krishicks commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

An inspected request's HTTP Activity record named the policy that allowed its TCP connection, even when a different policy allowed or denied the request. Request decision records now name the policy that decided that request, or - when no single policy did, and list the deciding policies in unmapped.matched_policies.

Related Issue

Closes #5922

Changes

  • RequestPolicy::evaluate_request returns L7Decision with the sorted matched_policies that decided the request: the policies that allowed it, or those whose authored deny rules matched. Fail-closed denials, such as a GraphQL operation outside the allowlist, name no policy.
  • Rego: new request_allowing_policies and request_denying_policies rules. allow_request and credential-grant admission derive from request_allowing_policies; deny_request is unchanged. Attribution never changes a decision: a rules file without these rules, or one that returns another shape, records no policy.
  • Cedar: the runtime passes through the determining permits or forbids it already computed. GraphQL operations and JSON-RPC batch calls contribute the union of their deciding policies; a denied batch keeps the first denial's reason and names every policy that denied a member.
  • Request decision records (forward proxy, inspected relay for REST/JSON-RPC/GraphQL, transformed-body re-evaluation, WebSocket messages) set firewall_rule.name to the sole deciding policy, or - when none or several decided, and always set unmapped.matched_policies (empty when none decided).
  • Cedar connection records name the least permitting policy, as Rego does, instead of whichever Cedar listed first.
  • Docs: request attribution in logging.mdx and ocsf-json-export.mdx; Cedar @id guidance in cedar.mdx.

Before and after

Two policy entries match the same host and port. Neither engine sees an order between them, so the connection record names the alphabetically first entry that matches, a_read.

Entry Allows Denies
a_read GET /item, GET /shared
b_write PUT /item, GET /shared DELETE /item

Inspected HTTP request records (forward proxy, one request per connection)

Request Decided by Before: firewall_rule.name After: firewall_rule.name After: unmapped.matched_policies
GET /item a_read allows a_read a_read ["a_read"]
PUT /item b_write allows a_read b_write ["b_write"]
DELETE /item b_write deny rule a_read b_write ["b_write"]
POST /item no entry allows a_read - []
GET /shared both entries allow a_read - ["a_read","b_write"]

PUT /item in shorthand:

Before: HTTP:PUT [INFO] ALLOWED /usr/bin/python3(0) -> PUT http://api.example.test:8080/item [policy:a_read engine:l7]
After:  HTTP:PUT [INFO] ALLOWED /usr/bin/python3(0) -> PUT http://api.example.test:8080/item [policy:b_write engine:l7]

Reused connection (inspected tunnel, three requests on one connection)

Request Before: firewall_rule.name After: firewall_rule.name
GET /item a_read a_read
PUT /item a_read b_write
POST /item (denied) a_read -

Cedar connection records

Two NetworkConnect permits, @id("z_connect") and @id("a_connect"), allow the same endpoint. The policy was loaded 100 times, and each load decided one connection:

Name on the connection record
Before a_connect 51 times, z_connect 49 times
After a_connect 100 times

Unchanged

  • Connection records still name the policy that allowed the connection.
  • Allow and deny decisions, and the 403 response body, are unchanged.
  • Rejections before policy evaluation, such as MCP protocol-version and parse rejections, and records from other request controls, such as middleware and credential binding, still name the connection's policy.

Release Notes

firewall_rule.name on inspected request decision records changes meaning: it now names the policy that allowed or denied that request, instead of the policy that allowed its connection. A request that no rule allows, which previously logged the connection's policy, now shows -, as does a request several policies decided. unmapped.matched_policies lists the deciding policies on every request decision record and is empty when none decided.

Testing

  • cargo fmt --all --check, workspace clippy (--features experimental --locked -D warnings), and lockfile checks pass
  • Unit tests added: forward-proxy attribution (issue reproduction, deny rule, no match, multiple matches), reused-connection relay attribution, JSON-RPC batch allows and denials in both orders, GraphQL default denials, WebSocket messages (multiple allows, audit-mode deny rule, default denial, control frame), rules files without or with malformed attribution rules, Cedar request/GraphQL/connection attribution. Each failed before its fix.
  • openshell-policy-cedar-runtime and openshell-policy-conformance pass. openshell-supervisor-network passes except 8 forward-proxy tests that time out reaching an upstream on macOS; they fail the same way on unmodified main.
  • E2E tests added/updated (if applicable)

Checklist

  • Follows Conventional Commits
  • Commits are signed off (DCO)

@krishicks krishicks added topic:observability Logs, metrics, traces, telemetry, dashboards, event correlation, and operational data export. area:runtime Sandbox execution, isolation, supervision, policy enforcement, networking, and provider lifecycle. topic:policy Policy authoring, validation, proving, distribution, enforcement, ergonomics, and hardening. labels Dec 4, 2026
@github-actions github-actions Bot added the state:accepted A maintainer decided OpenShell should pursue this issue label Dec 4, 2026
@github-actions

github-actions Bot commented Dec 4, 2026

Copy link
Copy Markdown

@krishicks krishicks left a comment

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.

gator-agent

PR Review Status

Thanks @pimlock for reproducing the attribution mismatch on a fresh proxy connection. I checked the patch against that case and the other paths that emit inspected-request records. The review found three cases that need changes before CI handoff.

Action required: Please address the inline findings and add the corresponding regression coverage.

Blocking findings:

  • GATOR-59259c89-01 Preserve decisions when the standalone proxy loads an existing Rego rules file.
  • GATOR-59259c89-02 Report all policies that explicitly deny members of an inspected batch.
  • GATOR-59259c89-03 Keep GraphQL default denials distinct from authored deny-rule matches in request logs.

Carried findings: None.

Non-blocking suggestion: Update the read-only POST example to show policy:- if it depicts a default denial. Clarify how the JSON field represents zero or multiple deciding policies.

Gator metadata
  • Validation: Scoped fix for the reproduced OCSF attribution defect in #5922. GitHub's PR Issue Acceptance check passed.
  • Docs: Existing Fern logging and Cedar pages updated.
  • Checks: Required checks reported for this head pass. Maintainer approval is evaluated after review and E2E.
  • E2E: Required for the network proxy and policy changes after review feedback is addressed.
  • Head SHA: 59259c8
  • Base SHA: 22c8e35
  • Merge base SHA: 22c8e35
  • Patch ID: 0119be40958f020a9c696e7927b98a010a48e17e
  • Gator payload: 24
  • Review mode: initial
  • Previous reviewed SHA: none
  • Review budget exhausted: no
  • Maintainer decision required: no
  • Next state: gator:in-review

@krishicks krishicks added the gator:in-review Gator is reviewing or awaiting PR review feedback label Dec 4, 2026
@krishicks
krishicks force-pushed the fix/5922-attribute-request-policy/krishicks branch from 59259c8 to 17902e4 Compare December 4, 2026 19:48
@krishicks krishicks added the test:e2e Requires end-to-end coverage label Dec 4, 2026

@pimlock pimlock 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.

Review of 59259c8 (correctness, code, API, security, pragmatism, alternatives lenses, plus a live Docker run). Decisions and outcomes look right. Tests pass at head, and a live sandbox with two overlapping policies logged the expected firewall_rule.name for allow, deny rule, no match, and several-allow cases, with unchanged 403 bodies. Two inline comments need a fix before merge. The rest is non-blocking:

  • Docs: ocsf-json-export.mdx does not list unmapped.matched_policies. The logging.mdx:142 sentence reads as covering every request record, but credential-binding and middleware request records still name the connection policy. Scope it to engine:opa/l7 request decisions.
  • - is ambiguous: it means both "no policy decided" (default deny, evaluation error) and "several decided", and the list is emitted only for the second. Consider always emitting unmapped.matched_policies (empty for none), and release-note that firewall_rule.name on request records changed meaning, including default denials that used to log the connection policy.
  • Two definitions of admission in Rego: request_allowing_policies repeats the conditions of _admitted_l7_endpoints (sandbox-policy.rego:257, :267). The first drives forwarding and the second still drives credential grants (:286). Deriving one from the other avoids silent drift.
  • Trait change (note): RequestPolicy::evaluate_request now returns L7Decision, and matched_rule is removed. No breaking indicator needed since the crates are unpublished. #[non_exhaustive] on L7Decision is optional.
  • Duplicated labelling: emit_websocket_l7_event re-implements the sole-policy / matched_policies logic. A shared L7Decision::rule_name() and &L7Decision in place of Option<&L7Decision> plus reason would drop the #[allow(clippy::too_many_arguments)] and about 40 lines.
  • Cost: the allow path now runs three eval_rule calls per request. Compute the names once if latency matters.
  • Test gap: add a test for Rego deny in audit mode naming the denier.
  • Not verified live: unmapped.matched_policies in the OCSF JSON output, and the legacy rules-file case (code reading only).

The existing gator comments on batch denial aggregation and GraphQL default denials cover the same root causes I found.

@krishicks krishicks left a comment

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.

gator-agent

PR Review Status

Thanks @krishicks. I checked the three fixes against the latest revision. GraphQL default denials now leave request attribution empty, and the JSON-RPC and Cedar tests cover explicit denials in both batch orders. The fallback for older Rego files handles absent rules, but a malformed attribution result still interrupts an evaluated decision.

Thanks @pimlock. I checked your attribution concern against the Rego result handling, and your WebSocket coverage request against the emitter and tests. The new tests exercise the shared evaluator. The WebSocket emitter still needs coverage for one deciding policy, several deciding policies, and control messages that retain connection attribution.

Action required: Address the inline findings and the carried review items before CI handoff.

Blocking findings:

  • GATOR-17902e4b-01 Preserve evaluator error handling in the dedicated JSON-RPC relay.
  • GATOR-17902e4b-02 Construct each JSON-RPC policy input without copying the entire batch.
  • GATOR-17902e4b-03 Suppress staged audit records during Cedar attribution after denial.

Carried findings:

  • GATOR-59259c89-01 Preserve the evaluated decision and reason when the attribution lookup for a supplied Rego file fails or returns malformed metadata.
  • GATOR-59259c89-02 Keep the new batch attribution and first-denial reason while restoring the dedicated relay's evaluator error handling. The inline finding above tracks that regression.
Gator metadata
  • Validation: Scoped fix for the reproduced OCSF request attribution issue in #5922. PR Issue Acceptance passed.
  • Docs: Existing Fern logging and Cedar pages were updated. The corrected logging example matches the default denial. The logging description could specify request policy decisions and the JSON export page could document the optional policy list.
  • Checks: Branch Checks and E2E are pending. DCO, Frozen Paths, Helm Lint, and Trivy Changes passed. Maintainer Approval is evaluated at handoff.
  • E2E: Required for network proxy and policy changes. The current head has a queued run.
  • Head SHA: 17902e4b4fa9f09a3c0812b23ba092158c6a086a
  • Base SHA: 22c8e3584481770b802b8adba258e6308d9c83c0
  • Merge base SHA: 22c8e3584481770b802b8adba258e6308d9c83c0
  • Patch ID: 7532a5ac719839282dde8272e1faf87fbbf85a1e
  • Gator payload: 24
  • Review mode: follow_up
  • Previous reviewed SHA: 59259c8912f4ec5be62e315f87c3e52a630a8f0d
  • Review budget exhausted: no
  • Maintainer decision required: no
  • Next state: gator:in-review

@krishicks
krishicks force-pushed the fix/5922-attribute-request-policy/krishicks branch from 17902e4 to b7b59f0 Compare December 4, 2026 20:29
@krishicks

Copy link
Copy Markdown
Contributor Author

Drafted by 🤖, signed off by @krishicks

Addressed in b7b59f0:

  • - ambiguity: every request decision record now carries unmapped.matched_policies, and it's empty when no policy decided. The release note in the description says that firewall_rule.name changed meaning, including for default denials.
  • Docs: ocsf-json-export.mdx documents unmapped.matched_policies. Both pages limit attribution to request policy decisions and say that middleware and credential-binding records still name the connection policy.
  • Two definitions of admission: _admitted_l7_endpoints is now derived from request_allowing_policies.
  • Duplicated labelling: L7Decision::rule_name() replaces sole_policy(), and both emitters use it. emit_websocket_l7_event keeps the Option and the reason parameter, because control frames have no decision and the GraphQL path passes its own reason.
  • Audit-mode deny test: covered by the WebSocket test.
  • Cost: left as is. Removing the extra evaluation would make the allow decision depend on the attribution rule, which is what the first inline comment asks us to avoid.

An inspected request's HTTP Activity record named the policy that
allowed its TCP connection, even when a different policy allowed or
denied the request itself. Requests that no policy allowed also named
the connection's policy. Cedar connection records named whichever
permitting policy Cedar happened to list first.

Request evaluation now returns the policies that decided it: Rego
names the entries that allowed the request or whose deny rules
matched it, and Cedar passes through its determining permits or
forbids. Each request decision record names its sole deciding policy,
or - when none or several decided it, listing several in
unmapped.matched_policies. Connection records keep the connection's
policy, and Cedar now picks the least name, as Rego does. Allow and
deny behavior is unchanged.

Closes #5922

Signed-off-by: Kris Hicks <khicks@nvidia.com>

@krishicks krishicks left a comment

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.

gator-agent

PR Review Status

Thanks @krishicks. I checked the Rego fallback and its regression test. Missing or malformed attribution now leaves the evaluated decision and denial reason intact. The updated Fern pages describe the request decision records and the policy list.

Thanks @pimlock for flagging the attribution fallback and WebSocket coverage. I checked the new fixture for multiple allowing policies, an audit-mode denial, a default denial, and control frames that keep connection attribution.

Action required: Please address the remaining JSON-RPC and Cedar review threads before CI handoff.

Carried findings:

  • GATOR-59259c89-02 and GATOR-17902e4b-01 — Batch attribution now collects deniers, but the dedicated JSON-RPC relay still needs to propagate evaluator errors.
  • GATOR-17902e4b-02 — Per-call evaluation still copies the full JSON-RPC batch.
  • GATOR-17902e4b-03 — Cedar still emits staged audit records while collecting attribution after a batch denial.
Gator metadata
  • Validation: Scoped fix for the OCSF request attribution issue in #5922. PR Issue Acceptance passed.
  • Docs: Fern logging and JSON export pages updated.
  • Checks: Branch Checks and E2E are running. DCO, Frozen Paths, Helm Lint, and Trivy Changes passed. Maintainer Approval is evaluated at handoff.
  • E2E: Required for changes to network proxy and policy behavior. The current run is in progress.
  • Head SHA: b7b59f0
  • Base SHA: 315301a
  • Merge base SHA: 22c8e35
  • Patch ID: 0fcd7d14a0aaf8ca13e70ccb20dcbddf37822266
  • Gator payload: 24
  • Review mode: follow_up
  • Previous reviewed SHA: 17902e4
  • Review budget exhausted: no
  • Maintainer decision required: no
  • Next state: gator:in-review

@krishicks
krishicks force-pushed the fix/5922-attribute-request-policy/krishicks branch from b7b59f0 to f2eaa57 Compare December 4, 2026 20:40

@krishicks krishicks left a comment

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.

gator-agent

PR Review Status

Thanks @krishicks. I verified that JSON-RPC batches retain the first denial reason and collect the deciding policies, that the dedicated relay propagates evaluator errors, and that each per-call evaluation builds its input without copying the batch. I also checked that Cedar skips staged audit records after the first enforced denial. All four Gator threads are resolved, and this follow-up found no new blocking findings.

Thanks @pimlock for flagging the Rego attribution fallback and WebSocket coverage. I checked that the fallback preserves the evaluated decision and that the WebSocket attribution tests remain in place.

Required CI passed, including E2E. A maintainer with the required code-owner authority can now review and approve the PR.

Gator metadata
  • Validation: Scoped fix for inspected-request policy attribution in #5922. PR Issue Acceptance passed.
  • Docs: Existing Fern Logging, OCSF JSON Export, and Cedar pages updated.
  • Checks: DCO, Branch Checks, Frozen Paths, Helm Lint, Trivy Changes, and E2E passed. Maintainer Approval remains outstanding.
  • E2E: Selected by test:e2e and passed on the reviewed head.
  • Head SHA: f2eaa57
  • Base SHA: 315301a
  • Merge base SHA: 22c8e35
  • Patch ID: cd3979b78781bbfa83bbc972a2bcc1db8681f1c5
  • Gator payload: 24
  • Review mode: critical_only
  • Previous reviewed SHA: b7b59f0
  • Review budget exhausted: yes
  • Maintainer decision required: no
  • Next state: gator:approval-needed

@krishicks krishicks added gator:approval-needed Gator completed review; maintainer approval needed and removed gator:in-review Gator is reviewing or awaiting PR review feedback labels Dec 4, 2026
@krishicks krishicks added gator:merge-ready and removed gator:approval-needed Gator completed review; maintainer approval needed labels Dec 4, 2026
@krishicks
krishicks added this pull request to the merge queue Dec 5, 2026
Merged via the queue into main with commit 13cdc6c Dec 5, 2026
280 of 289 checks passed
@krishicks
krishicks deleted the fix/5922-attribute-request-policy/krishicks branch December 5, 2026 00:50
@krishicks

Copy link
Copy Markdown
Contributor Author

gator-agent

Monitoring Complete

PR #6244 merged, and GitHub closed linked issue #5922. Gator review was complete, and required CI, E2E, and maintainer approval passed.

I’m clearing the active Gator label from this PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:runtime Sandbox execution, isolation, supervision, policy enforcement, networking, and provider lifecycle. state:accepted A maintainer decided OpenShell should pursue this issue test:e2e Requires end-to-end coverage topic:observability Logs, metrics, traces, telemetry, dashboards, event correlation, and operational data export. topic:policy Policy authoring, validation, proving, distribution, enforcement, ergonomics, and hardening.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(ocsf): attribute inspected HTTP requests to the policy that governs them

2 participants