Asterrr's Handbook

Secrets and least privilege

Removing hardcoded credentials, choosing Secrets Manager or Parameter Store, and trimming IAM permissions in an existing system with Access Analyzer, boundaries and Roles Anywhere.

Exam tasks: 3.2 (determine a strategy to improve security: secrets and credentials management, least privilege, traceability)

The decision: where does a credential live today, and what's the smallest change that moves it somewhere rotated and audited? Then: which permissions does each principal actually use, and how do you cut the rest safely?

Where should the credential go?

Secrets Manager vs Parameter Store

Secrets ManagerParameter Store (SecureString)
Built forCredentials with a lifecycleConfiguration, including some encrypted values
RotationBuilt in. Managed rotation for RDS, Aurora, Redshift and DocumentDB; Lambda rotation for anything elseNone. Build it yourself
EncryptionAlways KMS encryptedSecureString uses KMS. String and StringList are plain
Cross-account accessResource policy on the secret, plus a customer managed KMS key the other account can useAdvanced parameters can be shared with AWS RAM
Multi-RegionReplica secrets in other Regions, kept in syncNo replication
SizeUp to 64 KB4 KB standard, 8 KB advanced
CostPer secret per month + API callsStandard tier free; advanced tier and high throughput cost extra
4 hours
Shortest rotation schedule Secrets Manager supports.
7–30 days
Recovery window after you delete a secret, unless you force immediate deletion.
90 days
Default CloudTrail event history, and the maximum activity Access Analyzer reads to generate a policy.

Exam signal

"Rotate the database password automatically every 30 days" is always Secrets Manager. Parameter Store is right when the question stresses lowest cost and doesn't mention rotation.

Cross-account secret with the default key

A secret encrypted with the AWS managed key aws/secretsmanager can't be read from another account, because you can't edit that key's policy. Re-encrypt it with a customer managed key and grant the other account kms:Decrypt in the key policy, in addition to the secret's resource policy.

Removing hardcoded credentials

A typical fix for a legacy app that keeps a DB password in a config file and an access key in an environment variable:

Create the secret in Secrets Manager and turn on rotation (managed rotation for RDS).
Give the app's compute an IAM role that can call secretsmanager:GetSecretValue on that secret only.
Change the app to read the secret at startup and cache it, using the caching client or the Lambda extension. Retry on authentication failure to pick up a rotated value.
Remove the access key from the code, replace it with the role, then deactivate and delete the key.
Scan repositories and images for leftover secrets and treat any exposed key as compromised.
  • ECS task definitions and EKS (through the Secrets Store CSI driver) can inject secrets at start without app changes. CloudFormation can use dynamic references so templates never contain the value.
  • For RDS, you can also let RDS manage the master user password in Secrets Manager, or use IAM database authentication so the app gets short-lived tokens instead of a password.

IAM Roles Anywhere

For servers outside AWS that need AWS APIs, instead of long-lived access keys:

  • Register a trust anchor: AWS Private CA or your own CA certificate bundle.
  • Create a profile that lists the roles the certificates may assume.
  • On the server, the credential helper signs with the certificate's private key and returns temporary credentials, usable through the standard SDK credential process.
  • Revoke by certificate (CRL) and scope roles with conditions on certificate attributes.

Finding unused and excess access

ToolAnswersScope
Access Analyzer: external accessWhich resources (buckets, roles, KMS keys, secrets, queues) are shared outside my account or organization?Account or organization, free
Access Analyzer: unused accessWhich roles, users, access keys, passwords and permissions haven't been used?Account or organization, paid
Access Analyzer: internal accessWhich principals inside my organization can reach this critical resource?Organization
Access Analyzer: policy generationWhat policy matches what this role actually did?Reads CloudTrail activity for a chosen period
Policy validation and custom checksIs this new policy valid, and does it grant new or public access?Run in CI before deploy
Last accessed informationWhen did this principal last use each service (and actions, for some services)?IAM entity, OU or account
Credential reportEvery IAM user's passwords, access keys, MFA and last useAccount, CSV

Right-sizing a role

"Reduce a role to the permissions it actually uses, based on past activity" points to Access Analyzer policy generation from CloudTrail. "Find roles nobody has used in 90 days across the organization" points to the unused access analyzer or last accessed data.

Delegating safely with permissions boundaries

A permissions boundary sets the maximum permissions an IAM user or role can have. Effective permissions are the intersection of the identity policy and the boundary (and any SCPs and RCPs that apply).

  • Use it to let app teams create their own roles without being able to create an admin role.
  • Also deny them the ability to change or delete the boundary policy itself.

Boundaries don't grant

A permissions boundary never grants anything by itself. A role with a boundary but no identity policy can do nothing. And an SCP restricts whole accounts, so it can't delegate role creation within one account.

Traceability

  • CloudTrail records who called which API. An organization trail covers every account (see central security logging).
  • Set role session names and source identity so actions through assumed roles trace back to a person.
  • CloudTrail Lake or Athena on the trail bucket answers "who changed this, and when" across months.

Scenarios

Scenario
A travel booking platform runs on EC2 and keeps its Aurora MySQL password in a properties file baked into the AMI. A security review requires the password to rotate every 30 days with no application downtime and no credentials in the AMI. Which solution requires the LEAST development effort?
Scenario · choose 2
A company has 300 IAM roles across its accounts, many created years ago with broad policies. The security team wants to find roles and permissions that haven't been used and generate tighter policies from real activity. Which TWO actions should the architect recommend?
Scenario
An on-premises batch server uploads nightly files to S3 using an IAM user's access key that has not been rotated in two years. The company already runs AWS Private CA. How should the architect remove the long-lived key?

Further reading

On this page