AWS › AWS Secrets Manager & Parameter Store

How can IAM policies restrict access to specific secrets, ensuring only authorized applications or users can retrieve sensitive credentials?

Intermediate

Answer

IAM policies attached to users, roles, or the secret's own resource policy can restrict access to a specific secret by its exact resource identifier, meaning you can grant one application's IAM role permission to retrieve only its own specific database password while explicitly denying access to every other secret in the account, following the principle of least privilege and significantly limiting the impact if any single application's credentials were ever compromised.
aws secretsmanager put-resource-policy --secret-id db-password --resource-policy file://secret-access-policy.json
Real-world example A company ensures that its payment processing service's IAM role can only retrieve the specific secret containing its own payment gateway API key, and is explicitly denied access to secrets belonging to any other unrelated service in the same account.

Common follow-ups: How do you audit which IAM roles currently have access to a specific secret?;What is the difference between an identity based policy and a resource based policy for controlling secret access?