Sub topic 12
Keeping access secure
This chapter assumes you can sign in to the Console, run basic CLI commands, and know what a named profile is. It covers the habits that keep an AWS account safe whichever tool you use.
Why access practices matter
Anyone holding valid credentials can act as you. The Console, the CLI, and CloudShell all send requests as an identity. If that identity is over-privileged or its credentials leak, the damage is limited only by its permissions. Three habits reduce the risk: turn on multi-factor authentication (MFA), grant only the permissions needed, and prefer temporary credentials.
Protect the root user
The root user is the identity created with the account. It has full access that permissions cannot restrict. Use it only for the few tasks that require it, such as changing the account's support plan or closing the account.
- Enable MFA on the root user.
- Do not create access keys for root.
- Do daily work with an IAM Identity Center user or an IAM role instead.
Turn on MFA
MFA asks for a second proof of identity, such as a code from an authenticator app or a passkey or hardware security key. A stolen password alone then cannot sign in. Enable it for the root user and for every person who signs in. With IAM Identity Center, you configure MFA in the Identity Center settings, and it applies to the browser sign-in that aws sso login opens.
Apply least privilege
Least privilege means giving an identity only the actions it needs on only the resources it needs. Start narrow and widen when a real task is blocked. The ReadOnly role in the earlier dev profile is an example: it can inspect resources but not change them.
Avoid attaching broad policies such as AdministratorAccess for convenience. When a command fails with an AccessDenied error, add the specific permission the error names rather than a wildcard.
Prefer temporary credentials
Long-lived access keys are an AccessKeyId and SecretAccessKey that never expire until you delete them. If one is committed to a repository or left in a shell history, it stays usable. Temporary credentials expire automatically, usually within hours.
| Method | Credential lifetime | Typical use |
|---|---|---|
| IAM Identity Center (`aws sso login`) | Temporary, refreshed by signing in | People using the CLI |
| CloudShell | Temporary, taken from your Console sign-in | Quick tasks in the browser |
| IAM role assumed with STS | Temporary | Applications and cross-account access |
| IAM user access key | Long-lived | Avoid; use only when nothing else fits |
If you must keep an access key, rotate it regularly, delete it when unused, and never put it in code.
Keep secrets out of the wrong places
- Store credentials only in
~/.aws/credentialsor~/.aws/config, not in scripts or repositories. - Restrict the file permissions on those files so only you can read them.
- Avoid passing secrets as command-line arguments, because they can appear in shell history and process lists.
- Add
.awsand any.envfiles to.gitignore.
Check who you are before you act
Before running a change, confirm the active identity and Region:
aws sts get-caller-identity --profile dev
aws configure get region --profile devThe first command prints the account ID and the ARN of the identity. If the account is not the one you expected, stop and fix the profile.
Exercise
Why is an IAM Identity Center profile safer than an IAM user access key stored in ~/.aws/credentials, and which command confirms which identity a profile uses?
Show answer
Identity Center issues temporary credentials that expire automatically, so a leaked copy stops working, while an access key stays valid until someone deletes it. Run aws sts get-caller-identity --profile <name> to see the account ID and ARN the profile resolves to.