feat: warn when long-term IAM credentials (AKIA) are detected#4751
feat: warn when long-term IAM credentials (AKIA) are detected#4751sotanengel wants to merge 2 commits intoboto:developfrom
Conversation
When boto3 detects that a session is using long-term IAM user credentials (access key IDs prefixed with 'AKIA'), it now emits a CredentialSecurityWarning via Python's warnings module. Long-term credentials do not expire automatically and carry a higher risk than temporary credentials obtained through IAM roles, IAM Identity Center (SSO), or AWS STS AssumeRole. Behaviour: - Warning is emitted at most once per Session instance. - Skipped when the caller explicitly passes aws_access_key_id to client() or resource(), as the override is assumed intentional. - Silenced by setting AWS_SUPPRESS_CREDENTIAL_WARNINGS=1. - Temporary credentials (ASIA prefix) are not warned about. A new CredentialSecurityWarning class is added to boto3.exceptions so callers can filter or silence the warning with warnings.filterwarnings. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
Hi @alexgromero 👋 Thank you so much for your continued work on boto3! I'd love to get your thoughts on this PR when you have a moment. 🙏 Summary of the change: Long-term credentials don't expire automatically, which makes them a higher-risk option compared to temporary credentials from IAM roles, IAM Identity Center (SSO), or AWS STS AssumeRole. A gentle, opt-out-able warning at the point of Design decisions I'd appreciate feedback on:
All 36 existing unit tests pass, 6 new test cases are included, and ruff lint/format checks are clean. No rush at all — I really appreciate any feedback you can share! 😊 |
Summary
When boto3 detects that a session is using long-term IAM user credentials (access key IDs prefixed with
AKIA), it now emits aCredentialSecurityWarningvia Python'swarningsmodule.Long-term credentials do not expire automatically and carry a higher risk than temporary credentials obtained through IAM roles, IAM Identity Center (SSO), or AWS STS AssumeRole.
Behaviour
Sessioninstance.aws_access_key_idtoclient()orresource(), as the override is assumed intentional.AWS_SUPPRESS_CREDENTIAL_WARNINGS=1.ASIAprefix from STS) are not warned about.Usage example
Warning message
Changes
boto3/exceptions.pyCredentialSecurityWarningclassboto3/session.py_warn_if_long_term_credentials(), call fromclient()tests/unit/test_session.pyTests
All 36 tests pass (
python -m pytest tests/unit/test_session.py).New test cases:
AKIAcredentialsASIAcredentialsaws_access_key_idis passedAWS_SUPPRESS_CREDENTIAL_WARNINGS=1None