Skip to content

Include web identity token in cache key to prevent credential collision - #10670

Open
luigi617 wants to merge 1 commit into
v2from
fix-web-identity-cache
Open

luigi617 wants to merge 1 commit into
v2from
fix-web-identity-cache

Conversation

@luigi617

Copy link
Copy Markdown

Issue #, if available:

Description of changes:
Include web identity token in cache key to prevent credential collision

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

@luigi617
luigi617 marked this pull request as ready for review September 21, 2026 21:22
@luigi617
luigi617 requested a review from a team as a code owner September 21, 2026 21:22
expiry_window_seconds=expiry_window_seconds,
)

def _cache_key_args(self):

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have you tested this code end to end besides unit test and if so how? can you add to PR description

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't the unit test not enough? I have a small script that I used for check:

import unittest.mock as mock
from awscli.botocore import credentials
from awscli.botocore.utils import FileWebIdentityTokenLoader

# 1. Define two token files with different contents (same role)
with open("/tmp/token_a.jwt", "w") as f: f.write("header.payload-AAA.sig")
with open("/tmp/token_b.jwt", "w") as f: f.write("header.payload-BBB.sig")

ROLE = "arn:aws:iam::123456789012:role/demo-role"
client_creator = mock.Mock()

def key_for(token_file):
    loader = FileWebIdentityTokenLoader(token_file)
    fetcher = credentials.AssumeRoleWithWebIdentityCredentialFetcher(
        client_creator, loader, ROLE
    )
    return fetcher._cache_key

ka = key_for("/tmp/token_a.jwt")
kb = key_for("/tmp/token_b.jwt")
print("token_a -> cache file:", ka + ".json")
print("token_b -> cache file:", kb + ".json")
print("same file?", ka == kb, "-> ", "COLLISION (bug)" if ka == kb else "distinct (fixed)")

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants