Skip to content

fix(restriction_policies): drop stale principals instead of skipping the whole policy (2/4)#630

Open
michael-richey wants to merge 1 commit into
drop-unresolvable-principals-scaffoldingfrom
drop-unresolvable-principals-restriction-policies
Open

fix(restriction_policies): drop stale principals instead of skipping the whole policy (2/4)#630
michael-richey wants to merge 1 commit into
drop-unresolvable-principals-scaffoldingfrom
drop-unresolvable-principals-restriction-policies

Conversation

@michael-richey

@michael-richey michael-richey commented Jul 14, 2026

Copy link
Copy Markdown
Collaborator

Context

Stacked PR 2 of 4. Base: drop-unresolvable-principals-scaffolding (PR #629).

This PR

Overrides connect_resources on RestrictionPolicies so that, under --drop-unresolvable-principals, a principal absent from both destination and source is dropped from its binding and the policy still syncs, instead of the whole restriction policy being skipped on a single dead reference.

  • Principals present in source but not destination keep today's hard-fail/retry behavior.
  • If dropping empties a binding whose source list was non-empty, it is treated as a normal resource-connection failure. Without --skip-failed-resource-connections, the resource is skipped. With that flag enabled, the failure is intentionally suppressed and sync continues; an immediate ERROR explicitly says DESTINATION RESOURCE MAY BE UNRESTRICTED, and the successful action receives the dedicated risk metric and end-of-run ERROR summary.
  • The "id" (dashboard/slo/notebook) connections keep the generic path unchanged.
  • extract_source_ids intentionally remains unaffected so --minimize-reads lazy-loading can still resolve which principals to check.

Testing

TestRestrictionPoliciesConnectResources covers flag off, drop-and-continue, source-present hard-fail, both empty-binding connection modes, metric/log propagation, multi-binding partial-empty, middle-element index-shift regression, extract_source_ids, org/non-composite pass-through, and dangling IDs. Focused tests green; ruff clean.

@michael-richey michael-richey force-pushed the drop-unresolvable-principals-scaffolding branch from 7db6366 to a7514ad Compare July 14, 2026 21:32
@michael-richey michael-richey force-pushed the drop-unresolvable-principals-restriction-policies branch 3 times, most recently from d71030b to 8a645fa Compare July 15, 2026 13:37
@michael-richey michael-richey marked this pull request as ready for review July 15, 2026 13:39
@michael-richey michael-richey requested a review from a team as a code owner July 15, 2026 13:39
@michael-richey michael-richey requested a review from Copilot July 15, 2026 13:46

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Pull request overview

Adds drop-aware resource-connection behavior for restriction policies so that, when --drop-unresolvable-principals is enabled, principals missing from both source and destination are removed from bindings (instead of skipping the entire restriction policy), while still preserving the existing hard-fail behavior for “pending” (source-present, destination-missing) principals and for non-principal ID connections.

Changes:

  • Override RestrictionPolicies.connect_resources() to special-case attributes.bindings.principals and delegate principal filtering to the shared drop-aware binding helper.
  • Preserve the existing id-based connection behavior (dashboards/SLOs/notebooks) via the generic find_attr/connect_id path.
  • Add a comprehensive unit test suite covering flag-off behavior, drop-and-continue behavior, hard-fail conditions, empty-binding risk/escalation behavior, and regression cases.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
datadog_sync/model/restriction_policies.py Overrides connect_resources() to drop stale principals per-binding while keeping generic ID connection logic unchanged.
tests/unit/test_restriction_policies.py Adds unit tests validating drop/keep/hard-fail semantics, empty-binding escalation behavior, and key regressions.

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

Comment thread datadog_sync/model/restriction_policies.py Outdated
…the whole policy

Overrides `connect_resources` so that, under `--drop-unresolvable-principals`, a principal
absent from both destination and source state (permanently gone — e.g. a role deleted
before the org's first-ever import) is dropped from its binding and the policy still syncs,
instead of the entire restriction policy being skipped on a single dead reference.

- Principals present in source but not destination keep today's hard-fail/retry behavior.
- If dropping empties a binding whose source list was non-empty, the resource is still
  skipped and flagged as an access-elevation risk (ERROR + metric), governed by
  `--skip-failed-resource-connections` like any other connection failure.
- The "id" (dashboard/slo/notebook) connections keep the generic path unchanged.
- `extract_source_ids` is intentionally left unaffected (documented) so minimize-reads
  lazy-loading can still resolve which principals to check.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@michael-richey michael-richey force-pushed the drop-unresolvable-principals-restriction-policies branch from 8a645fa to 6213034 Compare July 15, 2026 14:09
@michael-richey michael-richey marked this pull request as draft July 15, 2026 14:28
@michael-richey michael-richey marked this pull request as ready for review July 15, 2026 14:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants