Bug Description
When the configured aws_session_duration exceeds the IAM role's MaxSessionDuration, saml2aws exits with a ValidationError instead of falling back to the role's maximum allowed duration.
Error Message
Error logging into AWS role using SAML assertion.: Error retrieving STS credentials using SAML.: ValidationError: The requested DurationSeconds exceeds the MaxSessionDuration set for this role.
status code: 400, request id: e8f027af-xxxx-xxxx-xxxx-5def568bcff2(Masked Id for privacy)
Steps to Reproduce
- Configure saml2aws with
aws_session_duration = 43200 (12 hours)
- Use an IAM role with
MaxSessionDuration less than 12 hours (e.g., 1 hour/3600 seconds)
- Run
saml2aws login
- Error occurs preventing login
Expected Behavior
When the requested session duration exceeds the role's limit, saml2aws should:
- Detect the ValidationError
- Log a warning message
- Automatically retry with the role's default/maximum duration
- Complete the login successfully
Current Behavior
saml2aws exits with an error, preventing login entirely.
Environment
- saml2aws version: 2.36.19
- Platform: Windows/Linux/macOS
- IdP: Okta (may affect other providers as well)
Configuration Example
[default]
aws_session_duration = 43200
Workaround
Manually set aws_session_duration to match or be lower than the role's MaxSessionDuration, but this requires knowing each role's limit beforehand.
Proposed Solution
Add error handling in the loginToStsUsingRole function to:
- Catch the specific ValidationError about MaxSessionDuration
- Retry the AssumeRoleWithSAML call without the DurationSeconds parameter
- Let AWS use the role's configured maximum
- Provide clear user feedback about what happened
- This provides a better user experience by automatically handling the common misconfiguration case.
Bug Description
When the configured
aws_session_durationexceeds the IAM role'sMaxSessionDuration, saml2aws exits with a ValidationError instead of falling back to the role's maximum allowed duration.Error Message
Error logging into AWS role using SAML assertion.: Error retrieving STS credentials using SAML.: ValidationError: The requested DurationSeconds exceeds the MaxSessionDuration set for this role.
status code: 400, request id: e8f027af-xxxx-xxxx-xxxx-5def568bcff2(Masked Id for privacy)
Steps to Reproduce
aws_session_duration = 43200(12 hours)MaxSessionDurationless than 12 hours (e.g., 1 hour/3600 seconds)saml2aws loginExpected Behavior
When the requested session duration exceeds the role's limit, saml2aws should:
Current Behavior
saml2aws exits with an error, preventing login entirely.
Environment
Configuration Example
[default]
aws_session_duration = 43200
Workaround
Manually set aws_session_duration to match or be lower than the role's MaxSessionDuration, but this requires knowing each role's limit beforehand.
Proposed Solution
Add error handling in the loginToStsUsingRole function to: