Skip to content

Guard iam_policy grant emission behind WillSyncResourceType#142

Open
laurenleach wants to merge 2 commits into
mainfrom
lauren.leach/guard-iam-policy-grant-emission
Open

Guard iam_policy grant emission behind WillSyncResourceType#142
laurenleach wants to merge 2 commits into
mainfrom
lauren.leach/guard-iam-policy-grant-emission

Conversation

@laurenleach

Copy link
Copy Markdown
Contributor

Summary

  • iamUser, role, iamGroup, and permissionSet each emit cross-type iam_policy "attached" grants as a sync optimization (their API responses already include attached-policy info), but did so unconditionally — even when a customer's sync filter excludes iam_policy.
  • Each builder's behavior is now gated on cli.ConnectorOpts.WillSyncResourceType("iam_policy") (nil-safe: a missing opts is treated as "no filter", i.e. sync everything), computed once in connector.New() and threaded into all four builders as syncIAMPolicyGrants bool — following the pattern in Only emit user grants (where we emit the role grants) if role resource type is enabled  baton-linear#55.
  • Two different mechanisms are used, per resource type:
    • role and iamGroup also emit legitimate same-type grants (trust-policy-principal grants; group membership grants) alongside the cross-type iam_policy grants. For these, only the iam_policy-emitting portion of Grants() is gated in place — the same-type grants stay unconditional.
    • iamUser and permissionSet exist solely to emit cross-type iam_policy grants (no entitlements, no same-type grants of their own). For these, the gating is expressed as an SDK-level annotation on ResourceType() instead: when iam_policy is being synced, the resource type is returned unchanged (already carries a static SkipEntitlements annotation); when it isn't, a proto.Clone'd copy is returned annotated with SkipEntitlementsAndGrants, so the SDK skips calling Entitlements()/Grants() for that type entirely rather than the connector short-circuiting internally.
  • The capabilities-doc-generation path (defaultCapabilitiesBuilder, no ConnectorOpts available) passes a literal true, so baton_capabilities.json is unaffected — confirmed via diff against a freshly rebuilt connector's capabilities output (no diff).

Test plan

  • go build ./...
  • go vet ./...
  • go test ./... — full suite passes
  • Unit tests assert both states for each mechanism:
    • role/iamGroup: Grants() output with the gate on/off
    • iamUser/permissionSet: ResourceType() annotations with the gate on/off, plus assertions that the shared package-level resource-type vars are never mutated by the clone
  • Rebuilt the connector binary and diffed baton_capabilities.json against fresh capabilities output — no diff

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>

laurenleach and others added 2 commits July 24, 2026 19:29
iamUser, role, iamGroup, and permissionSet each emit cross-type
iam_policy "attached" grants as a sync optimization, but did so
unconditionally -- even when a customer's sync filter excludes
iam_policy. Gate each emission on
cli.ConnectorOpts.WillSyncResourceType("iam_policy"), following the
pattern in ConductorOne/baton-linear#55. Same-type grants (role
trust-policy principals, group membership) remain unconditional.

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
…ions

For iamUser and permissionSet -- whose Grants() methods emit only the
cross-type iam_policy grants, with no entitlements or same-type grants
of their own -- express the sync-filter gating as an SDK-level
annotation on ResourceType() instead of an in-Grants() early return.
When iam_policy is being synced, return the resource type unchanged
(already carries the static SkipEntitlements annotation); when it
isn't, return a cloned copy annotated with SkipEntitlementsAndGrants so
the SDK skips calling Entitlements()/Grants() for that type entirely.

role and iamGroup keep their existing in-Grants() partial gating
unchanged, since both emit legitimate same-type grants (trust-policy
principals; group membership) alongside the cross-type iam_policy
grants -- a whole-resource-type annotation would incorrectly suppress
that real data for those two.

Verified baton_capabilities.json is unaffected: the capabilities-doc
generation path passes syncIAMPolicyGrants=true, which returns the
resource type unchanged (byte-identical output, confirmed via diff).

Co-authored-by: c1-squire-dev[bot] <c1-squire-dev[bot]@users.noreply.github.com>
@laurenleach
laurenleach requested a review from a team July 24, 2026 20:22
@github-actions

github-actions Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

Connector PR Review: Guard iam_policy grant emission behind WillSyncResourceType

Blocking Issues: 0 | Suggestions: 0 | Threads Resolved: 0
Criteria: Criteria status: loaded .claude/skills/ci-review.md from trusted base 7a0050d.
Review mode: full
View review run

Review Summary

Scanned the full PR diff for security and correctness. This gates the cross-type iam_policy attached grants emitted by iamUser, role, iamGroup, and permissionSet behind ConnectorOpts.WillSyncResourceType(iam_policy), threaded from New() as syncIAMPolicyGrants. The nil-safe default (a nil opts means sync everything) matches the SDK WillSyncResourceType semantics, so existing installs and the capabilities-generation path are unaffected. The two mechanisms are sound: role and iamGroup gate only the iam_policy-emitting portion in place while keeping same-type grants (trust-policy principals, group membership) unconditional; iamUser and permissionSet attach SkipEntitlementsAndGrants on a proto.Clone-d resource type so the SDK skips their entitlements/grants entirely (shared package-level resource-type vars are not mutated, and tests assert this). All builder call sites were updated and unit tests cover both gate states. No new issues found.

Security Issues

None found.

Correctness Issues

None found.

Suggestions

None.

@github-actions github-actions Bot 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.

No blocking issues found.

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.

1 participant