mirror of
https://github.com/floci-io/floci.git
synced 2026-11-28 08:09:43 -05:00
fix(sts): enforce SAML role duration limit (#7121)
This commit is contained in:
1 parent
87a733edea
commit
ad9de3022a
3 files changed
+206
-8
No files matched your search
@@ -373,10 +373,9 @@ public class StsQueryHandler {
|
||||
}
|
||||
}
|
||||
|
||||
if (durationSeconds > role.getMaxSessionDuration()) {
|
||||
return AwsQueryResponse.error("ValidationError",
|
||||
"The requested DurationSeconds exceeds the MaxSessionDuration set for this role.",
|
||||
AwsNamespaces.STS, 400);
|
||||
Response roleDurationError = validateMaxSessionDuration(durationSeconds, role);
|
||||
if (roleDurationError != null) {
|
||||
return roleDurationError;
|
||||
}
|
||||
|
||||
String accessKeyId = "ASIA" + randomId(16);
|
||||
@@ -574,16 +573,17 @@ public class StsQueryHandler {
|
||||
throw new AwsException("AccessDenied", "Not authorized to perform sts:AssumeRoleWithSAML on resource: " + roleArn, 403);
|
||||
}
|
||||
|
||||
Response roleDurationError = validateMaxSessionDuration(durationSeconds, role);
|
||||
if (roleDurationError != null) {
|
||||
return roleDurationError;
|
||||
}
|
||||
|
||||
String sessionName = verified.subject().replaceAll("[^A-Za-z0-9+=,.@_-]", "_");
|
||||
if (sessionName.length() > 64) {
|
||||
sessionName = sessionName.substring(0, 64);
|
||||
}
|
||||
Instant requestedExpiration = clock.instant().plusSeconds(durationSeconds);
|
||||
Instant roleExpiration = clock.instant().plusSeconds(role.getMaxSessionDuration());
|
||||
Instant expiration = verified.expiration().isBefore(requestedExpiration) ? verified.expiration() : requestedExpiration;
|
||||
if (roleExpiration.isBefore(expiration)) {
|
||||
expiration = roleExpiration;
|
||||
}
|
||||
String accessKeyId = "ASIA" + randomId(16);
|
||||
String secretKey = randomSecret(40);
|
||||
String sessionToken = randomSecret(200);
|
||||
@@ -847,6 +847,15 @@ public class StsQueryHandler {
|
||||
return Response.ok(AwsQueryResponse.envelope("DecodeAuthorizationMessage", AwsNamespaces.STS, result)).build();
|
||||
}
|
||||
|
||||
private static Response validateMaxSessionDuration(int durationSeconds, IamRole role) {
|
||||
if (durationSeconds > role.getMaxSessionDuration()) {
|
||||
return AwsQueryResponse.error("ValidationError",
|
||||
"The requested DurationSeconds exceeds the MaxSessionDuration set for this role.",
|
||||
AwsNamespaces.STS, 400);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* The constraints the model declares for {@code action}, answered the way this handler answers
|
||||
* every other refusal: one {@code ValidationError} naming every violation it found, in the
|
||||
|
||||
Reference in new issue
Block a user