Skip to content

feat(dir): serve excluded records to named auditors, and the enforcement runbook - #2253

Merged
muscariello merged 7 commits into
feat/policy-enforcement-backfillfrom
feat/policy-audit-bypass
Oct 2, 2026
Merged

muscariello merged 7 commits into
feat/policy-enforcement-backfillfrom
feat/policy-audit-bypass

Conversation

@muscariello

@muscariello muscariello commented Oct 1, 2026 •

Copy link
Copy Markdown
Member

Closes #2209 (third and last PR: stage 4 and the runbook). Part of #2205. Stacked on #2249: main ← #2226 ← #2229 ← #2235 ← #2237 ← #2238 ← #2241 ← #2246 ← #2248 ← #2249 ← this.

Why

#2209's stage 4 asks for "a privileged, separately-authorized path for admins/auditors to see excluded content, logged, never a parameter on the normal endpoints". Its acceptance also asks for a runbook for enabling enforcement per endpoint.

What this adds

  • agntcy.dir.policy.v1.PolicyAuditService, a new API service:
    • GetRecord returns a record by CID whether or not it is excluded, with its policy verdicts.
    • ListExcludedRecords streams the excluded records with their verdicts, paged by limit and offset; zero means no limit, as in search.
    • It's generated with the pinned buf plugins. Regenerating every package changes no other file, and buf lint and buf breaking against main pass.
  • Its own permission. Both methods join the identity-only list from feat(dir): grant registry credentials only to peer nodes named by SPIFFE ID #2246: only a rule naming the caller's SPIFFE ID grants them, never one for a whole trust domain. The server offers the service only while policies are checked and authorization is enabled, because that permission is all that protects it.
  • An audit log. Every call writes a line from the audit component with the caller's SPIFFE ID, the method and the CIDs handed out. Failed calls are logged too, and a listing that stops part way logs what it had already sent.
  • What "excluded" means. A record is excluded when it has no passing verdict under the current version of a policy, whatever the search and fetch modes. That way an auditor also sees, during shadow mode, what enforcing would hide.
  • A runbook, docs/content/dir/dir-content-policy-enforcement.md, under Deploy:
    • prerequisites;
    • the settings, what each mode and kind of read covers, and what a caller is told about an excluded record;
    • the metrics;
    • turning enforcement on;
    • editing a policy: the new version is enforced at once, and every record is hidden until it has been evaluated under it;
    • rolling back;
    • the audit service.
  • The authz README documents both identity-only methods.

No CLI command calls the service yet. Any gRPC client with the auditor's SVID can.

Testing

  • Controller:
    • GetRecord returns excluded, compliant and nothing-enforced records, with their verdicts.
    • Failures (invalid CID, record not held, database error) return the right codes without leaking internals, and are logged.
    • The listing streams under the policies in force and pages as asked.
    • With nothing enforced it doesn't query the database.
    • It logs what it sent before a failure.
    • Every audit line is checked through an in-memory log handler.
  • Database: paging of excluded records works, including an offset without a limit on SQLite. The compliance check answers for the policies it's given, whatever the view enforces.
  • Authz: the node's own trust domain and a peer node can't call either method; a named auditor can.
  • Server:
    • The service is registered only with policies checked, authorization on and a database that can list excluded records.
    • Database setup hands on the enforcement only when a read checks it.
  • Docs: the runbook's authorization rule passes the test that checks every documented policy against the registered services.
  • Mutation-checked, every mutant compiling and changing one file. Each of these makes a test fail:
    • inverting excluded;
    • not logging a successful read;
    • not logging the caller;
    • ignoring paging;
    • ignoring the offset in the database;
    • dropping a method from the identity-only list;
    • offering the service without authorization.
  • Build: all modules vet clean, and the affected server packages pass with CGO_ENABLED=0.

@muscariello muscariello added area/dir/server area/dir/api kind/security Categorizes issue or PR as related to security. labels Oct 1, 2026
@muscariello
muscariello requested a review from a team as a code owner October 1, 2026 07:28
@github-actions

github-actions Bot commented Oct 1, 2026 •

Copy link
Copy Markdown
Contributor

The latest Buf updates on your PR. Results from workflow Buf CI / verify-proto (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed⏩ skipped⏩ skipped✅ passedOct 2, 2026, 12:59 PM

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown
Contributor

The latest Buf updates on your PR. Results from workflow Buf CI / verify-proto (pull_request).

BuildFormatLintBreakingUpdated (UTC)
✅ passed⏩ skipped⏩ skipped✅ passedOct 1, 2026, 7:28 AM

@github-actions github-actions Bot added the size/M Denotes a PR that changes 200-999 lines label Oct 1, 2026
@muscariello
muscariello added this pull request to stack #2234 October 1, 2026 07:28
@codecov

codecov Bot commented Oct 1, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.97980% with 2 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
server/controller/policy_audit.go 98.5% 1 Missing ⚠️
server/database/gorm/policy_gate.go 90.9% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

csirmazbendeguz
csirmazbendeguz previously approved these changes Oct 2, 2026
@muscariello
muscariello dismissed csirmazbendeguz’s stale review October 2, 2026 12:05

The merge-base changed after approval.

@muscariello
muscariello force-pushed the feat/policy-audit-bypass branch from 97d3f3f to 9551f52 Compare October 2, 2026 12:05
@muscariello
muscariello force-pushed the feat/policy-audit-bypass branch from 9551f52 to cdd52f6 Compare October 2, 2026 12:33
Records the enforced content policies exclude must stay reachable for
auditors, through a path that is not a parameter on the normal reads and
that is authorized on its own. agntcy.dir.policy.v1.PolicyAuditService
is that path:

- GetRecord returns a record by CID whether or not it is excluded, with
  its policy verdicts;
- ListExcludedRecords streams the excluded records with their verdicts,
  paged by limit and offset.

Generated with the pinned buf plugins; regenerating every package
changes no other file.

Refs #2209

Signed-off-by: Luca Muscariello <[email protected]>
The policy audit service reads through the unfiltered database and store,
the one read path the content-policy gate does not apply to. To keep it
from becoming a way around the gate:

- only a rule naming the caller's SPIFFE ID grants it, never one for a
  whole trust domain, like registry credentials;
- the server offers it only while policies are checked and authorization
  is enabled, since its own permission is all that protects it;
- every call, failed ones included, writes an audit line naming the
  caller, the method and the CIDs handed out.

A record counts as excluded when it fails a policy at the version in
force, whatever the search and fetch modes, so an auditor sees what
enforcing would hide during shadow mode too.

Refs #2209

Signed-off-by: Luca Muscariello <[email protected]>
How to turn enforcement on one kind of read at a time, from shadow mode
through the backfill to enforcing; how to bump a policy version, in the
order that keeps records served; how to roll back; and how auditors see
excluded records.

Refs #2209

Signed-off-by: Luca Muscariello <[email protected]>
openDatabase gained a fourth result, which left the failure case
discarding three of them (dogsled). It now checks that the database, the
served view and the enforcement are all nil when opening fails.

Refs #2209

Signed-off-by: Luca Muscariello <[email protected]>
An audit call that fails must still be logged, and must not leak why.
Tests now check reads whose verdicts cannot be read, and listings that
cannot run or cannot read a record's verdicts: each answers Internal
without the database's error, sends nothing, and writes a failed audit
line naming the caller. Database setup is checked to fail on an invalid
enforcement config and when the gate's metrics cannot be registered.

Refs #2209

Signed-off-by: Luca Muscariello <[email protected]>
The task's settings moved to reconciler.config.policy_evaluation; the runbook still pointed at reconciler.config.policy, which the chart fills from config.policy.

Refs #2209

Signed-off-by: Luca Muscariello <[email protected]>
Policies are listed by ID and their versions are followed, so the runbook
no longer has a version bump procedure with an order to get right. It now
says what editing a policy does: the new version is enforced at once, and
every record is hidden until it has been evaluated under it, because
content already delivered cannot be recalled. It names the metric that
shows how many records are still hidden, and how a first rollout differs.

Refs #2209

Signed-off-by: Luca Muscariello <[email protected]>
@muscariello
muscariello force-pushed the feat/policy-audit-bypass branch from cdd52f6 to 890eb75 Compare October 2, 2026 12:59
@muscariello
muscariello added this pull request to the merge queue Oct 2, 2026
Merged via the queue into main with commit d9cea2c Oct 2, 2026
37 checks passed
@muscariello
muscariello deleted the feat/policy-audit-bypass branch October 2, 2026 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/dir/api area/dir/server kind/security Categorizes issue or PR as related to security. size/M Denotes a PR that changes 200-999 lines

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Stage the read-path enforcement rollout: shadow mode, fail-closed, audited bypass

2 participants