cd /news/ai-agents/ip-locked-creds-aws-credentials-that… · home › topics › ai-agents › article
[ARTICLE · art-174823] src=gist.github.com ↗ pub= topic=ai-agents verified=true sentiment=↑ positive

ip-locked-creds: AWS credentials that only work from your IP (STS GetScopedCredentials credential_process helper)

A developer built a small Python credential_process helper that uses AWS's new STS GetScopedCredentials API to issue temporary credentials locked to the user's current public IP, so leaked keys fail everywhere except the originating network. The helper applies a scope-down policy with an Allow * plus a NotIpAddress deny on aws:SourceIp (with a BoolIfExists exception for aws:ViaAWSService) and caps credential lifetime at 15 minutes. The writeup notes that roles need an explicit sts:GetScopedCredentials allow and that boto3 1.44.9 or later is required.

recommendation

Issue agent and CLI credentials through a credential_process helper that scopes them to your current IP with a 15-minute lifetime, and add sts:GetScopedCredentials to the role first.

more in playbook: Securing agents and AI tools
read6 min views2 publishedNov 23, 2026

I spend most of my day in AWS accounts across our organization, signed in through Identity Center, usually with an AI coding assistant open next to my terminal. So I think about where my credentials end up more than I used to. When AWS announced a new STS API in November 2026, my first thought was: can I make my credentials useless to anyone who isn't at my desk?

It turns out I can, and it took under 100 lines of Python.

GetScopedCredentials (announcement, AWS Security Blog) takes temporary credentials you already have, plus an inline policy, a shorter duration, or both. It gives you back credentials for the same identity. The new credentials can do only what both your session and the policy allow, so they can never do more than what you started with. CloudTrail logs every call, including the policy you sent.

AWS pitches it mainly for giving AI agents narrower permissions. I wanted something simpler first.

Temporary keys leak in boring ways. They get pasted into a chat or a ticket, printed in a debug log, saved in a test file, or read by an assistant and kept in its transcript. While setting this up, I found 25 old temporary keys pasted into my own ~/.aws/credentials file from months ago. They'd long since expired, but they were a good reminder.

A leaked temporary key normally works from anywhere until it expires, which can be up to 12 hours away. A scope-down policy can carry conditions, so I lock mine to the public IP I'm on:

{
  "Version": "2012-10-17",
  "Statement": [
    {"Effect": "Allow", "Action": "*", "Resource": "*"},
    {"Effect": "Deny", "Action": "*", "Resource": "*",
     "Condition": {
       "NotIpAddress": {"aws:SourceIp": "${IP}"},
       "BoolIfExists": {"aws:ViaAWSService": "false"}
     }}
  ]
}
  • The Allow * is needed. A scope-down policy can only narrow, so a policy with nothing but a deny in it leaves you with no permissions at all.Allow * keeps whatever your role already has.
  • The deny does the locking. It blocks any request that doesn't come from${IP} , which my helper fills in with my current address each time it issues credentials.
  • aws:ViaAWSService is required. Some services make follow-on calls with your credentials. Athena reads your S3 data, and CloudFormation creates resources for you when the stack has no service role. Those calls come from AWS addresses, so without this exception the lock would break them.BoolIfExists keeps the deny aimed at requests you make directly.
  • The lifetime is 15 minutes. A key that leaks fails everywhere except my network, and soon stops working there too.

1. Get current tools. You need Python 3.10 or newer and boto3 1.44.9 or later. The AWS CLI only needs to be v2, because the helper calls STS through boto3. Check that your boto3 has the API:

python3 -c "import boto3; print(boto3.__version__, 'GetScopedCredentials' in boto3.client('sts', region_name='us-east-1').meta.service_model.operation_names)"

One gotcha: the Python that ships with macOS is 3.9. pip there quietly installs an older boto3 that doesn't have the call, and the error you get is just "no attribute get_scoped_credentials".

2. Check that your role is allowed to call it. GetScopedCredentials needs an explicit sts:GetScopedCredentials allow in the role's own permissions. Roles with *, such as AdministratorAccess and PowerUserAccess, have it automatically. Plenty of roles don't. When I first tried it on a read-only security role, I got AccessDenied ... no identity-based policy allows the sts:GetScopedCredentials action. The AWS managed policies I checked, including ReadOnlyAccess and ViewOnlyAccess, don't grant it.

The fix is one statement added to the role, or to the permission set that creates it:

{"Sid": "AllowScopeDown", "Effect": "Allow", "Action": "sts:GetScopedCredentials", "Resource": "*"}

It adds no access, because the call can only return credentials that are narrower than the ones you already have. I tested it on a role with only ReadOnlyAccess: denied before, allowed about 10 seconds after the change, and the scoped credentials still couldn't write anything.

3. Add the helper. ip-locked-creds looks up my public IP and calls GetScopedCredentials with the policy above. It prints the result in the format the CLI's credential_process expects. It caches the credentials until my IP changes or they're close to expiring, because the CLI runs it on every command. The heart of it:

ip = urlopen("https://checkip.amazonaws.com").read().decode().strip()
sts = boto3.Session(profile_name=source).client("sts")
r = sts.get_scoped_credentials(
    Policy=json.dumps(POLICY).replace("${IP}", ip),
    DurationSeconds=900,
    ScopedSessionDescription=f"ip-locked:{source}")

4. Split each profile in two. I renamed each SSO profile with a -sso suffix and added a profile with the original name that calls the helper:

[profile dev-sso]
sso_session = mycompany
sso_account_id = 111122223333
sso_role_name = Developer
region = us-east-1

[profile dev]
credential_process = /path/to/ip-locked-creds dev-sso
region = us-east-1

Profiles that need to chain roles add --allow-assume (see the limits below). I still run aws sso login in the morning as before. Everything that uses --profile dev or AWS_PROFILE=dev now gets IP-locked credentials without knowing it. That includes my scripts, my tools and the assistant. I had about 17 profiles, so I wrote a small script to do the split for me.

The helper, the config splitter and a short README are in this gist.

Don't test this with aws sts get-caller-identity. It's everyone's go-to check, but IAM can't deny it. It succeeds from any IP and under any policy, so it tells you your credentials are valid, not what they're allowed to do. Use something deniable, such as aws s3 ls.

What I saw:

  • aws s3 ls --profile dev worked. The first call took about 2 seconds, and later ones, served from the cache, under 1 second.
  • Credentials locked to a different address got AccessDenied from S3 andUnauthorizedOperation from EC2.get-caller-identity happily succeeded.
  • When I dropped off the VPN and reconnected, my address changed. The next command issued fresh credentials locked to the new address, and I didn't have to do anything.
  • CloudTrail shows each GetScopedCredentials call with the address it came from and the IP written into its policy. They matched every time.

To simulate a leak yourself, export one set of credentials and change networks:

eval "$(aws configure export-credentials --profile dev --format env)"
aws s3 ls        # works
aws s3 ls        # AccessDenied
  • Shared addresses. On a campus network or a VPN, many machines share one public IP, so the lock admits all of them. At home it's much tighter.
  • Role chaining. If you callsts:AssumeRole with IP-locked credentials, the new session has no lock, because the scope-down policy doesn't carry over to the new session. I tested it: a scoped session that couldn't list buckets assumed a role, and the new session listed them fine. Off my network theAssumeRole call itself is denied, but a role I assume from my desk gives me ordinary credentials, and those can leak. So the helper deniessts:AssumeRole* by default. Only two of my profiles, the ones I use to jump into other accounts, run it with--allow-assume . The rest stay locked down.
  • The SSO token. It still sits in~/.aws/sso/cache , and anything that can read it can mint full credentials. That's the problem forPart 2 : keeping the token, and the full credentials, away from the processes I run every day, including that AI assistant.
── more in #ai-agents 4 stories · sorted by recency
── more on @aws 3 stories trending now
sponsored brought to you by zahid.host 4,200+ EU-deployed projects
reading about agents? ship yours in a single git push.

Run your AI side-project on zahid.host

EU-based hosting, git-push deploys, automatic HTTPS, no cold starts. Free tier with a custom domain — perfect for shipping the agent you just read about.

$git push zahid main
→ Live at https://your-agent.zahid.host ✓
Get free account → Pricing
from €0/mo · no card required
LIVE [news/ip-locked-creds-aws-…] indexed:0 read:6min 2026-11-23 · —