Skip to content

About

Zero Standing Permissions (ZSP) for AWS on macOS: removes plaintext keys from ~/.aws; Touch ID unlocks a session that expires (1h default). Menu bar UI with audit trail, rotate and revoke.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

 

History

45 Commits

Folders and files

Repository files navigation

aws-cli-zsp (AWS CLI: ZSP)

Zero Standing Permissions (ZSP) for AWS keys on macOS. It removes the plaintext keys from ~/.aws and asks you to authenticate (Touch ID) before a key is used. One approval gives the CLI a session that is reused without asking until it expires (1 hour by default), so nothing on your Mac holds standing AWS access: there is no readable key to steal, and every session ends on its own. Your access keys are sealed by the Mac's Secure Enclave, the chip will not unseal one without Touch ID, the AWS CLI and SDKs only ever see a session that lasts an hour, and any key that lands in ~/.aws/credentials (from aws configure, a paste, a script) is moved out within seconds.

The problem

This is what any program running as you can read on a normal Mac with the AWS CLI set up (keys redacted here; on the real screen they were in full):

cat ~/.aws/credentials printing three AWS access keys and secrets in plain text, redacted

Every key there is a standing permission: it works from anywhere, forever, for whoever copies it. After aws-cli-zsp the same file holds no keys at all, and the AWS CLI still works.

Overview: a key written to ~/.aws is moved and sealed within seconds; an aws command asks for Touch ID once and gets a 1-hour session; away from the Mac, a code from your phone approves the session

It is built from scratch on the ideas behind aws-vault, and adds:

aws-vault aws-cli-zsp
No plaintext keys on disk, STS sessions to the CLI ✅ Keychain ✅ Secure Enclave, Touch ID enforced by the chip
Keys written to ~/.aws are moved automatically ❌ ✅ launchd watcher plus a 5-minute sweep
Touch ID before a long-lived key is used optional always
Audit trail ❌ hash-chained, with who asked (aws s3 ls ← zsh)
Rotate a key aws-vault rotate one click, verified before the old key is deleted
Revoke sessions already issued (a thief's too) ❌ one click (an aws:TokenIssueTime deny policy)
MFA enforced by AWS, not just asked for locally mfa_serial, a code typed each session this Mac is an MFA device (one Touch ID), and AWS refuses the bare key; set up and undone from the UI
Approve when you are not at the Mac (Claude Code Remote Control) ❌ a code from your phone: aws-cli-zsp approve
When AWS last saw each key used ❌ Check last use in AWS
Menu bar UI ❌ ✅
Works with plain aws and every SDK, no wrapper exec or credential_process credential_process, wired for you

What it looks like

Overview: status, health checks and tests

Overview tab

Keys: test, check in AWS, rotate, revoke, session length, add Google Authenticator

Keys tab

Onboarding: pick which keys move, and whether new keys move automatically

Setup screen

Health checks

Health checks

Touch ID before a key is used

Touch ID dialog: AWS CLI: ZSP is trying to unlock your bedrock AWS key for a 1-hour session, for aws sts get-caller-identity

The MFA & phone tab is shown in MFA, and approving from your phone.

Every step in this README has a button: Setup in the footer re-runs onboarding, Run checks is aws-cli-zsp doctor, Test Touch ID / Test auto-move / Verify audit chain exercise each part without touching your keys, and each key's Test makes a real AWS call with it. The audit trail tab shows every use, with the program that asked.

The panel lives in the menu bar (the shield). If a crowded menu bar hides it behind the notch, open aws-cli-zsp from Spotlight or run aws-cli-zsp ui to get the same panel in a window.

Install

bash scripts/build-app.sh             # tests, build, sign, copy to ~/Applications (changes nothing in ~/.aws)
bash scripts/build-app.sh --install   # the same, then `aws-cli-zsp install`

aws-cli-zsp install:

  1. links ~/.local/bin/aws-cli-zsp
  2. loads consulting.cloudscale.zsp.watch, which runs aws-cli-zsp import --auto whenever either AWS file changes, and every 5 minutes
  3. starts the menu bar app at login, which opens Setup the first time: it lists the keys in ~/.aws, you tick the ones to move, and choose whether keys written later move automatically (the watcher does nothing until you have chosen) and how long a session lasts
  4. for each key moved, adds credential_process = …/aws-cli-zsp credential-process --profile NAME to ~/.aws/config

Without the UI: aws-cli-zsp setup --move default,bedrock --keep personal --auto on --duration 1h. Unticked keys stay in plain text and are never moved automatically.

From then on, aws --profile bedrock s3 ls works as before. The first command each hour shows "AWS CLI: ZSP is trying to unlock your “bedrock” AWS key for a 1-hour session, for aws s3 ls"; the rest reuse the cached session.

Upgrading from 0.1.x (which stored keys as plain Keychain items): run aws-cli-zsp migrate once. macOS asks for your login password once per key, because those items were bound to the exact build that made them. After that, updates never ask for anything but Touch ID.

How it works

1. Intercepting keys written to ~/.aws

Anything that writes a key (aws configure, a paste, an installer script) triggers launchd, which runs the importer. The key is sealed and read back before the file is touched, and the profile is pointed at aws-cli-zsp instead.

Steps: a key written to ~/.aws/credentials triggers launchd, aws-cli-zsp seals it with the Secure Enclave, verifies it, removes it from the file and points the profile at credential_process

2. Where the keys are stored

The Secure Enclave holds a guarded key (Touch ID) and a quiet key; the vault files are sealed to one or the other, and ~/.aws/credentials holds no secrets

Nothing secret is in a plain file, the Keychain or memory longer than one STS call. Copying the folder to another machine gets you nothing: the enclave keys only work inside this Mac's chip.

3. How the AWS CLI gets credentials back

The AWS CLI and every SDK support credential_process: they run a command and read JSON credentials from it. aws-cli-zsp is that command, so nothing needs a wrapper.

aws runs credential_process; a cached session is served with no prompt, otherwise Touch ID opens the key, STS issues a 1-hour session and the key is dropped

The CLI only ever holds a session. A leaked session expires on its own, cannot call IAM to mint a new key, and Revoke sessions kills every one issued so far.

Details

  • Touch ID enforced by hardware. Each key is encrypted (P-256 ECDH, HKDF-SHA256, AES-GCM, bound to its profile name) to a Secure Enclave key created with .userPresence. The enclave will not decrypt until you approve, whichever program asks, and the sealed files are useless on any other Mac. Moving a key in needs only the public key, so it never prompts. Sessions and the audit anchor use a second enclave key that needs no prompt.
  • Named dialogs. The command is a helper app inside the bundle, so every prompt says "AWS CLI: ZSP".
  • Why not Keychain items. macOS binds an item made by a binary with no Apple Team ID to that build's exact code hash. 0.1.0 used them, and every update showed a login-password dialog, with no Touch ID, for the app's own keys.
  • Sessions, not keys. The CLI gets GetSessionToken credentials from the regional STS endpoint, which are valid in opt-in regions such as af-south-1. A leaked session expires on its own and cannot call IAM to mint a new key.
  • Fail closed. A key leaves a file only after its sealed copy has been written and read back. If the audit entry can't be written, no credentials are issued.
  • Audit chain. ~/Library/Application Support/aws-cli-zsp/audit.jsonl: every entry hashes the one before it, and the newest hash is sealed separately, so editing, deleting or truncating the file fails aws-cli-zsp audit --verify.

Client keys with read-only IAM users

A key a client gives you often belongs to an IAM user that may read their account but not change itself. aws-cli-zsp needs nothing changed in the client's account:

  • Sessions work as normal. GetSessionToken needs no IAM permission, so every aws command works, with Touch ID and the sealed vault as for any other key.
  • What the user may not do is not offered. Rotate, revoke, deactivate, delete and the MFA steps all change IAM. Check in AWS asks IAM what the user may do (a policy simulation, when the user is allowed to run one) and hides the rest. Without that, the first refusal from AWS is remembered, and from then on the action is refused at once, before any Touch ID.
  • The Keys card shows read-only · client's key (or limited IAM when only some changes are refused), and the MFA & phone tab explains that AWS-side MFA is up to the account's owner.
  • Mark a key by hand: ⋯ → Mark read-only (client's key), or aws-cli-zsp access --profile P read-only. full offers everything regardless; auto forgets what was learned and asks IAM again.

MFA, and approving from your phone

Touch ID protects the key on this Mac, but AWS does not know about it: a copy of the key would work anywhere. The MFA & phone tab walks through three steps per key, each a button, and each finished step has an undo link under it (Remove MFA, Stop requiring MFA, Turn off phone approval) in case something that uses the key stops working:

MFA and phone tab: bedrock has steps 1 and 2 done with undo links, step 3 Add phone; default has not started

The same steps as commands make AWS itself demand MFA, without adding a step locally:

aws-cli-zsp mfa setup   --profile bedrock   # this Mac becomes a virtual MFA device for the key's IAM user
aws-cli-zsp mfa enforce --profile bedrock   # AWS denies everything the key does without MFA

mfa setup creates a virtual MFA device in IAM and seals its seed with the key, so every session the Mac issues carries MFA and still costs one Touch ID. mfa enforce attaches an inline policy (aws-cli-zsp-require-mfa) that denies every action except GetSessionToken and GetCallerIdentity when aws:MultiFactorAuthPresent is false. Because MFA sessions may call IAM, a second statement requires MFA from the last 5 minutes for creating keys, MFA devices or policies: aws-cli-zsp's own admin calls use a fresh session, while a leaked hour-long CLI session cannot mint itself a permanent key. It refuses to run until an MFA session from this Mac has worked, so it cannot lock you out.

To undo: aws-cli-zsp mfa unenforce --profile bedrock removes the policy (the key works without MFA again, everywhere); aws-cli-zsp mfa remove --profile bedrock undoes everything, removing the policy first while this Mac can still give MFA, then deactivating and deleting its MFA device. If the Mac cannot get an MFA session any more (its device deleted in the console), AWS refuses both, and the fix is to delete the inline policy aws-cli-zsp-require-mfa in the IAM console.

When nobody is at the Mac (Claude Code driven over Remote Control from your phone, or the screen locked), a Touch ID prompt would wait where nobody can see it. Instead, when the screen is locked or the Mac has had no keyboard or mouse input for 5 minutes, a new session fails at once with what to do. With remote approval enabled, a code from your phone's authenticator approves it:

aws-cli-zsp mfa add-phone --profile bedrock    # once, at the Mac: a QR code for your authenticator app
aws-cli-zsp mfa confirm-phone --profile bedrock --serial ARN 123456 654321   # two codes in a row: enabled, approval on
aws-cli-zsp approve --profile bedrock 123456   # what Claude Code runs after asking you for the code

In the UI, Add Google Authenticator… on a key's card (or Add phone… on step 3) does the first two: it creates the device in AWS, shows its QR code, and asks for two codes. Any authenticator app works. A key that AWS does not yet require MFA on goes to the guide first.

Add phone dialog: a QR code to scan with an authenticator app, the secret to type in by hand, and two code fields

Any TOTP app works: Google Authenticator, Microsoft Authenticator, 1Password, Authy. There is no push approval: AWS IAM MFA is codes only, so you read the code and send it. A phone you added in the IAM console already works too: Phone already in IAM… (aws-cli-zsp remote enable --profile bedrock).

Added a phone but never typed its two codes? aws-cli-zsp status says so and gives the exact command to finish or start again, and so does the error when nobody is at the Mac.

With Claude Code Remote Control, from your phone:

  1. Ask Claude for something that needs AWS. Nobody is at the Mac, so instead of a Touch ID prompt nobody can see, the command fails at once, telling Claude to ask you for a code.
  2. Claude asks: "I need the 6-digit code for bedrock."
  3. Copy the code from your authenticator app and send it in the chat.
  4. Claude runs aws-cli-zsp approve, AWS checks the code, and the session lasts the usual hour: nothing asks again until it expires.

Claude Code over Remote Control asks you for a code, you send it from your phone, aws-cli-zsp approve gets a session from STS with it

Why this is safe: approval by code needs a copy of the key that opens without Touch ID (sealed to the enclave's no-prompt key, so still useless off this Mac). That copy has no MFA seed, and remote enable refuses to make it until mfa enforce has run. So a program that reads it gets a key AWS refuses without a code from your phone, which it does not have. The code AWS sees once and rejects on reuse; it is in your chat for 30 seconds of usefulness.

This works with the screen locked. That no-prompt key opens after the first unlock since the Mac started, locked or not, so a program already running as you can read cached sessions and that copy while the screen is locked, as it could while unlocked. Long-lived keys stay behind Touch ID. After a restart nothing opens until you log in at the Mac, so phone approval cannot bring back a Mac that has rebooted. Vaults from before 0.3.7 reseal at the first unlock.

The account pin lives in the login Keychain, which asks before a new build reads an item, so after an update it cannot be read until someone answers that dialog. approve never waits on it, even if the Mac was touched moments ago: its session goes ahead without that check, compared only to the account last shown, and writes pin.unverified to the audit trail. So does any session while nobody is at the Mac. The full check resumes the next time you use Touch ID at the Mac. A program running as you could exploit that gap with a forged cached session, but not to get your key. If another command holds the profile, waiting on a dialog at the Mac, approve gives up after 5 seconds without using your code.

The IAM user needs iam:CreateVirtualMFADevice, iam:EnableMFADevice, iam:ListMFADevices, iam:PutUserPolicy and iam:GetUserPolicy (phone approval checks the require-MFA policy is still attached) on itself for these commands, and iam:DeleteUserPolicy, iam:DeactivateMFADevice and iam:DeleteVirtualMFADevice to undo them.

Commands

aws-cli-zsp setup [--move P,..] [--keep P,..] [--auto on|off] [--duration 1h]
                                              choose what moves and whether new keys move automatically
aws-cli-zsp doctor                            every check that must pass to be protected, no prompt
aws-cli-zsp diagnostics [--output FILE]       a redacted report for support (default: on the Desktop)
aws-cli-zsp test --profile P                  a real AWS call (GetCallerIdentity) with the key
aws-cli-zsp selftest-watcher                  write AWS's example key to ~/.aws and time the move
aws-cli-zsp list                              keys in the vault, sessions, last use and by whom
aws-cli-zsp scan                              plaintext keys left in ~/.aws (exit 1 if any)
aws-cli-zsp add --profile P                   type a key in, secret hidden; it never touches a file
aws-cli-zsp inspect --profile P               ARN, and when AWS last saw each key used
aws-cli-zsp rotate --profile P [--keep-old]   new key, verified, then the old one deleted (or deactivated)
aws-cli-zsp revoke-sessions --profile P       deny every session issued before now
aws-cli-zsp clear-sessions [--profile P]      drop cached sessions here (the next command needs Touch ID)
aws-cli-zsp duration --profile P 8h           session length, 15m to 12h (default 1h); `default` undoes it
aws-cli-zsp exec --profile P -- terraform plan
aws-cli-zsp disable-key | delete-key | forget --profile P
aws-cli-zsp mfa setup | enforce --profile P
aws-cli-zsp mfa unenforce | remove --profile P   undo: MFA no longer required / this Mac's device deleted too
aws-cli-zsp mfa add-phone --profile P           QR code for Google Authenticator (or any TOTP app)
aws-cli-zsp mfa confirm-phone --profile P --serial ARN CODE1 CODE2
aws-cli-zsp mfa cancel-phone --profile P --serial ARN
aws-cli-zsp remote enable [--serial ARN] | disable --profile P
aws-cli-zsp approve --profile P CODE
aws-cli-zsp access --profile P read-only|full|auto   a client's key: hide or offer IAM changes
aws-cli-zsp pin show | reset --profile P      the AWS account and user the profile is pinned to
aws-cli-zsp audit [--verify] [--limit N]
aws-cli-zsp migrate                           move 0.1.x Keychain items into the vault
aws-cli-zsp check-touch-id                    show the Touch ID prompt, unlock nothing
aws-cli-zsp ui                                open the panel in a window
aws-cli-zsp uninstall [--restore-plaintext]

--json on any command prints a machine-readable result, which is what the menu bar app uses. --help or -h on any command prints the command list and does nothing else; after --, as in exec --profile P -- aws --help, it goes to the command being run.

A command stops without changing anything (exit 2) if it is given an option it does not take, an option with no value, or too many arguments. A typo such as clear-sessions --profil P cannot end up applying to every key.

Support and diagnostics

When something does not work, open the panel: Overview › Health checks › Run checks. Each check says what is wrong in plain words, and the ones one command can fix have a Repair or Move now button. Besides the vault, ~/.aws and the watcher, the checks look for the problems people actually hit:

Check What it catches
AWS reachable offline, VPN or proxy in the way, DNS, and a Mac clock more than 4 minutes off (AWS refuses signed requests at 5)
No keys in shell files export AWS_ACCESS_KEY_ID=… in ~/.zshrc and the like: the AWS CLI prefers it to any profile, so the vault is bypassed
AWS CLI wired to the vault a credential_process line pointing at a moved or old copy of the app
AWS CLI not installed, or version 1
Touch ID no sensor or lid closed: macOS asks for the login password instead
Keys active in AWS a key someone deactivated in the IAM console
Errors in the last day the latest error from the support log

Warnings and errors also show as Recent problems on the Overview until you dismiss them, and any error banner has a Save diagnostics for support… link.

  • Support log: ~/Library/Application Support/aws-cli-zsp/logs/aws-cli-zsp.log (rotated at 1 MB). Every AWS call that fails is logged with its HTTP status, AWS error code and RequestId, so AWS support can find it. Also in Console.app under the subsystem consulting.cloudscale.zsp. ZSP_DEBUG=1 adds every call with its timing.
  • Diagnostics report: aws-cli-zsp diagnostics, or Save diagnostics… in the panel, writes ~/Desktop/aws-cli-zsp-diagnostics-<date>.txt (readable by you only): versions, checks, settings, profiles, credential_process lines, the last 200 log lines and the last 200 audit entries. Secrets, session tokens and MFA seeds are removed, key ids are masked and account ids keep only their last 4 digits, so it is safe to attach to a ticket.
  • Error messages carry a hint for the common AWS and Keychain errors: clock skew, InvalidClientTokenId (key deleted or deactivated), ExpiredToken, MFA refused, throttling, a locked Keychain and a cancelled prompt.
  • A damaged profiles.json is moved aside as profiles.json.damaged-<time> and logged, never overwritten; the keys themselves are in the vault and unaffected.

Limits

What it protects against, and what it does not

Threat Protected?
A stolen laptop, backup, or a copy of ~/.aws or the vault folder ✅ nothing in them works off this Mac's chip
A script, package or tool that reads ~/.aws/credentials ✅ the file holds no keys
A program that wants your long-lived key ✅ only the Secure Enclave can unseal it, and only after Touch ID
A key copied off the Mac some other way ✅ with MFA enforced, AWS refuses it without a code
Malware running as you, while a session is cached ⚠️ it can use that session until it expires (1 hour by default)
Malware running as you swapping your key for its own ✅ refused: the profile is pinned to its AWS account
Malware running as you planting a session of its own ✅ refused: only the session aws-cli-zsp issued is served
Malware running as you swapping the vault's sealing key ✅ refused: the sealing key is pinned in the login Keychain
Malware running as you rewiring ~/.aws/config to its own program ⚠️ not prevented: Run checks shows it
Malware running as you rewriting the audit trail ⚠️ not prevented: see below

The ⚠️ rows come from one fact: malware running under your macOS user can do what you can do without Touch ID.

  • It can use a cached session. Reusing a session without asking is the point of a session, so anything running as you gets one too, until it expires; the same trade-off aws-vault makes. clear-sessions, a shorter duration, or Revoke all sessions narrow the window. It never gets the long-lived key.
  • Swapping your key is caught by account pinning. Sealing a key into the vault needs only the Secure Enclave's public key, which is not secret (Touch ID opens a key, it is not needed to lock one). So malware cannot read your bedrock key, but it could store a key for its own AWS account under the name bedrock, and your commands would quietly run against the attacker's account (aws s3 cp backup.zip s3://… would upload to their bucket). To stop that, the first session for a profile records its AWS account and IAM user in the login Keychain, and every later session is checked against it (one GetCallerIdentity call per session, not per command). A key to another account or user gets nothing: the session is thrown away, key.swapped goes in the audit trail, and the error says what happened. Rotating the key, or re-importing a new key for the same user, passes.
    • Why not just a hash? Anything malware can write, it can re-hash: a hash in the vault folder or profiles.json would simply be recomputed for the attacker's key. The pin works because of where it lives: a login Keychain item trusts only the program that made it, so anything else changing or deleting it gets a macOS prompt.
    • The pin also records which session aws-cli-zsp issued, so a session written into the vault by something else is deleted, not served (session.swapped).
    • Changed the key to another account yourself? aws-cli-zsp pin reset --profile P (Touch ID). Deleting or forgetting a key removes its pin.
    • The public key itself is pinned the same way. Otherwise malware could replace the vault's public key with one of its own, and every key sealed after that (a rotation, a new key, the MFA seed) would be readable by it. aws-cli-zsp checks the public key against the enclave key beside it and against its hash in the login Keychain before every seal, and refuses on a mismatch.
  • It can point ~/.aws/config at a program of its own. The credential_process line is a plain file; malware can change it so the AWS CLI asks something else for credentials. aws-cli-zsp is then not involved at all, so it cannot refuse anything. Run checks (and aws-cli-zsp doctor) shows any profile not wired to aws-cli-zsp: the line must run exactly this binary for exactly that profile. Setting ZSP_HOME (meant for demos and tests) in your shell is a variant: it points aws-cli-zsp at another vault without account pins. doctor warns when it is set.
  • It can rewrite the audit trail. Each entry is hash-chained to the one before, and the newest hash is sealed in the vault, so editing or deleting entries by hand is caught by Verify chain. But that seal uses the no-prompt key (so sessions can be reused without Touch ID), so malware running as you can rewrite the whole log and re-seal its anchor, and Verify chain still says "intact". Treat the trail as a record of what happened, not as evidence against an attacker on this Mac; AWS CloudTrail is the record it cannot touch.

What would close the rest (see PLAN.md): sending the audit trail off the Mac (CloudWatch, or S3 with Object Lock), and signing with an Apple Developer ID so the enclave keys can be restricted to this app alone.

Other limits

  • Rotate, revoke and disable call IAM with the profile's own key, so the IAM user needs iam:ListAccessKeys, iam:CreateAccessKey, iam:DeleteAccessKey, iam:UpdateAccessKey, iam:GetAccessKeyLastUsed and iam:PutUserPolicy on itself. Without them those actions are hidden (see Client keys above); sessions do not need any of them.
  • Profiles with mfa_serial and role_arn (AssumeRole with MFA) are not handled by aws-cli-zsp yet; its own MFA covers the key's direct use. See PLAN.md.
  • The "for aws s3 ls, from Claude Code" in the Touch ID dialog is what the asking process says about itself (its command line), which that process controls. It helps you spot a prompt you did not expect, but a malicious program can claim to be anything; decline any prompt you did not cause.
  • Only the standard AWS partition works: sessions come from sts.us-east-1.amazonaws.com and IAM calls go to iam.amazonaws.com, so keys for AWS China (aws-cn) or GovCloud (aws-us-gov) are refused with InvalidClientTokenId.
  • Writing keys back with uninstall --restore-plaintext, or removing a key from this Mac, is refused while MFA is enforced for it: this Mac's MFA lives only in the vault, so the key would be locked out. Run aws-cli-zsp mfa remove --profile P first.
  • Away detection is a heuristic: 5 minutes without input (ZSP_AWAY_AFTER) or a locked screen. Sitting still and reading counts as away; touch the trackpad and retry.

Development

swift test                               # 65 tests, including the real Secure Enclave (no-prompt tier)
ZSP_NETWORK_TESTS=1 swift test           # adds a real STS call with a fake key (expects InvalidClientTokenId)

To try it without touching your real setup, point it at a sandbox with AWS_SHARED_CREDENTIALS_FILE, AWS_CONFIG_FILE and ZSP_HOME. ZSPMenu --snapshot out.png [--keys|--mfa|--audit|--setup|--about|--checks|--qr] renders the panel to a file (the screenshots above are made that way, from a sandbox holding AWS's documented example keys). The app icon is drawn by swift scripts/make-icon.swift. The diagrams are HTML in docs/diagrams/diagrams.html, rendered to PNG by bash scripts/render-diagrams.sh (needs Playwright; images rather than Mermaid because GitHub's mobile app shows Mermaid as source).

License

MIT. See LICENSE.

About

Zero Standing Permissions (ZSP) for AWS on macOS: removes plaintext keys from ~/.aws; Touch ID unlocks a session that expires (1h default). Menu bar UI with audit trail, rotate and revoke.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages