Skip to content

Comments

Scope IAM resource collection policy names to role name#274

Merged
raymondeah merged 3 commits intomasterfrom
ray.eah/quickstart-permissions-api-fix-naming
Feb 13, 2026
Merged

Scope IAM resource collection policy names to role name#274
raymondeah merged 3 commits intomasterfrom
ray.eah/quickstart-permissions-api-fix-naming

Conversation

@raymondeah
Copy link
Contributor

@raymondeah raymondeah commented Feb 11, 2026

Summary

  • Scopes managed IAM policy names to the integration role name to prevent EntityAlreadyExists errors when re-creating CloudFormation stacks
  • Extracts _detach_and_delete_policy helper to reduce duplication in cleanup logic
  • Applies the same fix to both attach_integration_permissions.py and the inline Lambda in datadog_integration_role.yaml

Problem

The Lambda that attaches resource collection permissions uses hardcoded policy names like datadog-aws-integration-resource-collection-permissions-1. These names are global per AWS account. When a stack is deleted and re-created:

  1. cleanup_existing_policies tries to detach + delete old policies
  2. If detach fails silently (e.g. policy still attached to another entity), delete throws DeleteConflictException which is only logged as a warning
  3. create_policy then fails with EntityAlreadyExists because the old policy wasn't deleted

Fix

Include the IAM role name in policy names:

# Before
datadog-aws-integration-resource-collection-permissions-1

# After
datadog-aws-integration-resource-collection-permissions-DatadogIntegrationRole-1

Since IAM role names are unique per AWS account, this guarantees policy name uniqueness per integration. The existing wildcard ARN in the Lambda execution role (policy/datadog-aws-integration-resource-collection-permissions-*) already covers any suffix.

Risk

None. This was introduced in PR #250 and has not been released in Datadog UI yet.

Test plan

  • Deploy stack with ResourceCollectionPermissions=true, verify policies created with role-scoped names
  • Delete stack, verify policies cleaned up
  • Re-create stack with same role name, verify no EntityAlreadyExists error
  • Verify with custom IAMRoleName parameter

raymondeah and others added 2 commits February 11, 2026 15:16
… re-creation

The Lambda that attaches resource collection permissions used hardcoded
policy names (e.g. datadog-aws-integration-resource-collection-permissions-1)
which are global per AWS account. When a stack is deleted and re-created
with the same role name, cleanup may fail to delete the old policies
(e.g. still attached), causing create_policy to fail with EntityAlreadyExists.

Fix: include the IAM role name in policy names so they are unique per
integration role. The existing wildcard ARN in the Lambda execution role
already covers any suffix pattern.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@raymondeah raymondeah marked this pull request as ready for review February 11, 2026 20:30
@raymondeah raymondeah requested a review from a team as a code owner February 11, 2026 20:30

- Scope IAM policy names to role name to prevent `EntityAlreadyExists` errors on stack re-creation

# 4.5.0 (February 11, 2026)
Copy link
Contributor Author

Choose a reason for hiding this comment

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

drive-by add here

@raymondeah raymondeah merged commit 39796e5 into master Feb 13, 2026
4 checks passed
@raymondeah raymondeah deleted the ray.eah/quickstart-permissions-api-fix-naming branch February 13, 2026 21:13
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.

2 participants