mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
fix(sts): return ExpiredTokenException for an expired web identity token (#3210)
* fix(sts): return ExpiredTokenException for an expired web identity token AssumeRoleWithWebIdentity mapped every WebIdentityTokenVerifier failure to InvalidIdentityToken, so an expired but otherwise valid IRSA token got the same wire error as a bad signature or wrong issuer. Real STS reports the expiry case as ExpiredTokenException so callers can refresh and retry. Fixes #3205 * test(eks): inject EksOidcService through the test constructor
This commit is contained in:
1 parent
e31590bba5
commit
90fa707145
6 files changed
+75
-9
No files matched your search
@@ -53,6 +53,17 @@ public class WebIdentityTokenVerifier {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Thrown when a token is past its {@code exp} claim. STS reports this as
|
||||
* {@code ExpiredTokenException} rather than {@code InvalidIdentityToken}, so callers can tell
|
||||
* a stale token apart from one that can never verify.
|
||||
*/
|
||||
public static class ExpiredTokenException extends InvalidTokenException {
|
||||
public ExpiredTokenException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reads the {@code iss} claim without verifying the signature. Returns empty when {@code token}
|
||||
* is not a parseable JWT at all — the caller must reject it.
|
||||
@@ -123,7 +134,7 @@ public class WebIdentityTokenVerifier {
|
||||
throw new InvalidTokenException("The web identity token has no expiration claim");
|
||||
}
|
||||
if (now > exp.asLong() + CLOCK_SKEW_SECONDS) {
|
||||
throw new InvalidTokenException("The web identity token has expired");
|
||||
throw new ExpiredTokenException("The web identity token has expired");
|
||||
}
|
||||
|
||||
JsonNode nbf = claims.get("nbf");
|
||||
|
||||
@@ -274,6 +274,12 @@ public class StsQueryHandler {
|
||||
WebIdentityToken claims;
|
||||
try {
|
||||
claims = tokenVerifier.verify(token, key.get(), issuer.get(), STS_AUDIENCE);
|
||||
} catch (WebIdentityTokenVerifier.ExpiredTokenException e) {
|
||||
LOG.debugv("Rejecting web identity token for role {0}: {1}", roleArn, e.getMessage());
|
||||
return WebIdentityOutcome.deny(AwsQueryResponse.error("ExpiredTokenException",
|
||||
"The web identity token that was passed is expired or is not valid. Get a new "
|
||||
+ "identity token from the identity provider and then retry the request.",
|
||||
AwsNamespaces.STS, 400));
|
||||
} catch (WebIdentityTokenVerifier.InvalidTokenException e) {
|
||||
LOG.debugv("Rejecting web identity token for role {0}: {1}", roleArn, e.getMessage());
|
||||
return WebIdentityOutcome.deny(AwsQueryResponse.error("InvalidIdentityToken",
|
||||
|
||||
Reference in new issue
Block a user