Conversation
92d77ab to
f103ee6
Compare
Enhance the existing agentless API call Lambda to ensure the SecurityAudit AWS managed policy is attached to the Datadog integration role during stack creation. This is required for agentless scanning to work, even when CSPM or Resource Collection are not explicitly enabled. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
boto3 is available in the Lambda runtime but not in CI. Move the import inside ensure_security_audit_policy so the module loads without boto3, and mock it in tests via sys.modules. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
f103ee6 to
ad9a386
Compare
ksirrah13
left a comment
There was a problem hiding this comment.
❓Question(non-blocking): Is there any kind of clean up needed during delete for this policy and attachment? Thinking that may have unexpected consequences like removing the security audit policy when it was added by another service, but just wanted to clarify the expected behavior on delete and if the lingering policy would be a problem.
Not really. I don't think we'll need clean-ups. The Security Audit policy is AWS managed and attached. Our lambda just attaches it to the Datadog Integration role if it's missing. |
Summary
datadog_agentless_api_call.pyLambda to attach theSecurityAuditAWS managed policy to the Datadog integration role during stack creation, which is required for agentless scanningensure_security_audit_policy()function that checks if SecurityAudit is already attached (idempotent) and attaches it if missing, with graceful skip when no role name is providediam:ListAttachedRolePolicies,iam:AttachRolePolicyrestricted to SecurityAudit ARN) to the Lambda execution role in all three agentless templatesDatadogIntegrationRoleNameparameter is optional — when empty, the IAM policy resource is not created and the Lambda skips attachmentTemplates modified
datadog_agentless_scanning.yaml— IAM policy + custom resource propertiesdatadog_agentless_delegate_role.yaml— parameter + condition + IAM policy + custom resource properties + metadatadatadog_agentless_delegate_role_stackset.yaml— same as delegate roleTest plan
ensure_security_audit_policy: already-attached, not-attached, empty role name, error propagation, GovCloud partition)cfn-linton all three modified YAML templatesdatadog_agentless_scanning.yamland verify SecurityAudit is attached to integration roleDatadogIntegrationRoleName— verify graceful skipDatadogIntegrationRoleName— verify attachment🤖 Generated with Claude Code