AWS CLI Guard is a local wrapper around AWS CLI v2 that sits earlier on PATH and asks for approval before commands run under a guarded profile. You choose allow, prompt, or deny per profile, grant temporary access from your terminal, and optionally apply stricter rules when a coding agent is recognized.
It is meant to reduce accidental misuse—not to replace IAM, SSO, or organizational controls. The wrapper does not evaluate what a profile is permitted to do in AWS; it only enforces your local policy. See Limitations for what it does not block.
Prerequisites: Linux or macOS, with curl, minisign, sha256sum or shasum, and AWS CLI v2 on PATH. install.sh exits 3 when one of those tools is missing.
Binaries for Linux and macOS (amd64 and arm64) ship on GitHub Releases. Pin a version and run one line (bash); the example uses 0.1.0—substitute a newer tag when you install:
VERSION=0.1.0; curl -fsSL "https://github.com/joonarafael/aws-cli-guard/releases/download/v${VERSION}/install.sh" | sh -s -- --version "$VERSION" && export PATH="$HOME/.local/share/aws-cli-guard:$PATH" && aws-guard shell bash && aws-guard initFor zsh, use aws-guard shell zsh instead of aws-guard shell bash. Re-running the install line upgrades binaries in place. A second aws-guard init reports that the policy file already exists. Run aws-guard help to list every control-plane command.
AWS CLI Guard is a PATH-based local wrapper. It makes accidental misuse less likely; it does not guarantee that every process on the machine reaches AWS only through it.
- Invoking the real AWS CLI through an absolute path, a different installation, or a different executable name never hits the wrapper. Another
PATHdoes the same. - A process that does not inherit the wrapper's
PATH, or a change toPATHor the environment, skips it. - SDKs, other applications, and a credential provider used directly never go through the wrapper.
- Credentials already stored by the CLI or another tool can be read and reused outside it.
- Agent detection is best-effort. Omitting or spoofing its signals defeats it, and a missing signal does not prove the caller is a person.
- A process that can change the installation,
PATH, or local files can step around the wrapper. - An AWS CLI older than 2.9.0, or one whose version cannot be read, is handed through after a warning, with no policy.
- This build recognizes
aws sso login, including with--profileor--sso-session, and hands it through with no policy and no grant. A login form this build does not recognize follows the normal guarded path. A later command that uses a profile is still subject to policy. aws loginand thelogin_sessionprofile key are not treated specially; they follow the normal guarded path.
For the current terminal session only, aws-guard off (with confirmation on the controlling terminal) and aws-guard on turn policy off and on. A new terminal starts with policy on. A recognized AI agent still follows policy when detection is on. Writing sessions.json under the state directory is a same-user bypass, like editing policy or grants locally. Persistent installation-wide disable is separate (see Architecture). For actual authorization, AWS-side controls remain authoritative.
A cancellation means AWS CLI Guard stopped the command. The wrapper exits with status 3 and writes the reason to stderr. Every one of those lines starts with aws-cli-guard: error: and says the command was not executed. Warnings that leave the command running start with aws-cli-guard: warning:.
Status 3 is reserved for this. The real AWS CLI keeps its own codes, including 0, 1, 2, 130, 252, 253, 254, and 255. After an allowed command, the wrapper is gone and the exit code is the CLI's code. The CLI's own output is not prefixed.
The supported AWS CLI is 2.9.0 through the verified ceiling (2.40.3 in this release). An older CLI is run as-is after a warning, with no policy applied (Limitations). Recognized aws sso login is handed through without policy (Limitations). Behavior is documented in Architecture.
Logging is tight by default: an allowed command adds no extra stderr. Set AWS_CLI_GUARD_LOG=verbose for one invocation, or set level = "verbose" under [logging] in settings.toml, to print a troubleshooting decision block on stderr.
Download install.sh for a pinned version from GitHub Releases (do not rely on a floating latest URL). You need curl, minisign, and sha256sum or shasum on PATH.
curl -fsSLO "https://github.com/joonarafael/aws-cli-guard/releases/download/vX.Y.Z/install.sh"
sh install.sh --version X.Y.Zinstall.sh downloads the platform archive, checksums.txt, and checksums.txt.minisig, verifies the minisign signature on checksums.txt, then checks the archive SHA-256 from that file. To verify checksums yourself before running the script:
minisign -Vm checksums.txt -P "$(sed -n '2p' path/to/minisign.pub)"The pinned public key in install.sh matches internal/update/minisign.pub. Compare install.sh to the git tag if you need assurance about the script itself.
install.sh accepts optional --prefix and --base-url. Default prefix: ~/.local/share/aws-cli-guard.
Put the install prefix before the real AWS CLI on PATH. After install, run aws-guard shell bash or aws-guard shell zsh so new terminals pick up the wrapper automatically (marked block in .bashrc or .zshrc). Remove it with aws-guard shell bash --remove or aws-guard shell zsh --remove. Run aws-guard init once to create policy files.
aws-guard install (or a second run of install.sh on an existing prefix) writes or upgrades the wrapper, control plane, persistent-disable script, and manifest under the prefix. Use aws-guard disable and aws-guard enable, or aws-cli-guard-disable in the install directory, to turn policy off or on for the whole installation without uninstalling. A fresh install refuses to overwrite unexpected files in the prefix; upgrades replace the shipped binaries in place.
After aws-guard init, every profile in config.toml defaults to prompt, including default. Commands such as aws --version, aws help, aws configure, and aws configure sso use the default profile when you do not pass --profile, so they are blocked until you allow that profile or create a grant. aws sso login is handed through without a grant.
To proceed:
- Grant temporary access:
aws-guard allow <profile> --ttl 8h(confirm on the controlling terminal). - Allow a profile permanently in
~/.config/aws-cli-guard/config.toml, for example[profiles.dev]withaction = "allow". You can setapproval_ttlunder[defaults]for grants created without--ttl. Quote profile names that contain dots. - Inspect policy with
aws-guard policy explain <profile>and grants withaws-guard grants list. - Turn policy off for this terminal only with
aws-guard off(with confirmation).
The default profile warning appears on stderr before each guarded command that resolves to default.
When the install prefix already holds a valid installation, a second install upgrades in place:
sh install.sh --version X.Y.Z
# or, with the same prefix on PATH:
aws-guard installYou can also run aws-guard upgrade explicitly (aws-guard upgrade [--prefix dir]). Upgrade refreshes aws, aws-guard, the disable stub, and the manifest. It does not change the recorded real AWS CLI path. After a successful replace it runs aws-guard migrate logic on your policy and grants files in ~/.config/aws-cli-guard and ~/.local/state/aws-cli-guard (or your user-database paths).
If migrate fails after upgrade, stderr prints diagnosis plus recovery steps: use a *.migrated.* sibling if one was created, fix the file and run aws-guard migrate, use aws-guard recover policy or aws-guard recover grants on a terminal for corrupt files, or move the config, state, and cache directories aside and run aws-guard init to start over. Moving config also moves settings.toml; you can move that file back. A broken install prefix can be moved aside and reinstalled without deleting policy.
- If the installation is persistently disabled, run
aws-guard enablefirst.aws-guard shell --removerefuses while the prefix is in the disabled layout. - Run
aws-guard shell bash --removeand/oraws-guard shell zsh --remove. Pass--prefixwhen you used a custom install directory. If the marked block is missing, delete the lines from# aws-cli-guard beginthrough# aws-cli-guard endby hand in.bashrcor.zshrc. - Delete
~/.local/share/aws-cli-guard(or your--prefixdirectory). For a shared prefix, remove onlyaws,aws-guard,aws-cli-guard-disable,aws-cli-guard-manifest, and anyaws.asideoraws-cli-guard-disabledartifacts the disable swap created. - Optional: delete
~/.config/aws-cli-guard,~/.local/state/aws-cli-guard, and~/.cache/aws-cli-guardif you do not want policy, grants, or cache data to remain. - Open a new terminal and run
command -v aws. You should see the real AWS CLI; the wrapper never modified it.
- Design — what the tool is for and how it is meant to behave
- Architecture — behavior, on-disk formats, and operator commands
- Security — how to report vulnerabilities
- Contributing — build from source, test, release, and send pull requests
- Findings — implementation pitfalls (mainly for contributors)
- Coding style — repository conventions
AI-assisted development notes are in AGENTS.md.