fix(iam): hold a root approval of a delegation request to four hours (#6321)

Delegated access has two ceilings and only one of them belongs to the request.
The twelve hours sessionDurationType declares are held at the filing, where
SessionDuration arrives. The other is the approver's, and the user guide's own
note states it: "The maximum duration for delegated access is 12 hours.
However, root users can only approve delegation requests with a duration of 4
hours or less. If a request specifies more than 4 hours, you must use a
non-root identity to approve the request." Nothing read it, so the account root
could approve a twelve-hour delegation and the credentials it bought ran that
long.

It is read at the approval rather than at the filing, because that is where the
approver is known: a request longer than four hours is refused for root and the
same request is approvable by an IAM user or role of that account, which is the
remedy the note itself names. Root is the caller whose ARN ends in :root, what
this family already names an approver by, and what a key naming no IAM user
resolves to, so approving a long request locally means signing as a user rather
than with a bare account id.

AcceptDelegationRequest models NoSuchEntity, ServiceFailure and
ConcurrentModification and nothing for this, and no source gives the code AWS
answers, so AccessDenied is chosen and recorded in docs/services/iam.md: the
guide states the rule as which identity may approve, which is what the
release's own OnlySendByOwner rule already answers that way.

Five tests. Three on the service: the refusal at five hours with the privileged
user then approving the same request, the cap itself approved at four hours
exactly, and twelve hours approved by a user to show the cap is the approver's.
Two over the wire: the same refusal where the account id is the signing key,
and the release's id check answered for an id that breaks its pattern rather
than one that is absent, which the absent half's test left uncovered.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-10-23 07:27:14 -05:00
1 parent 756e72273c
commit a8b5e8b8ec
4 files changed
+132

No files matched your search

@@ -90,6 +90,15 @@ public class DelegationRequestService {
private static final int SESSION_DURATION_MIN = 300;
private static final int SESSION_DURATION_MAX = 43200;
/**
* The longest delegation the account root may approve. Not a declared constraint but a
* documented one, and it belongs to the approval rather than to the request: the user guide's
* own note reads "The maximum duration for delegated access is 12 hours. However, root users
* can only approve delegation requests with a duration of 4 hours or less. If a request
* specifies more than 4 hours, you must use a non-root identity to approve the request."
*/
private static final int ROOT_APPROVAL_DURATION_MAX = 14400;
/**
* {@code summaryStateType}, of which {@code FAILED} is unreachable here: it reports a
* generation that ran and did not finish, and nothing is generated asynchronously.
@@ -277,6 +286,7 @@ public class DelegationRequestService {
DelegationRequest request = visible(callerAccountId, id, now, notices);
requireState(request, DelegationRequestState.ASSIGNED,
DelegationRequestState.PENDING_APPROVAL);
requireApproverMayHoldItThatLong(request, callerArn);
request.setApproverId(callerArn);
return moveTo(request, DelegationRequestState.ACCEPTED, now, notices);
}
@@ -648,6 +658,35 @@ public class DelegationRequestService {
+ " and cannot be changed from that state.", 409);
}
/**
* The four-hour cap on what the account root may approve, which {@code create} cannot apply:
* the twelve hours it enforces belong to the request, and this one belongs to whoever
* approves it, so it is read here where the approver is known.
*
* <p>Root is the caller whose ARN ends in {@code :root}, which is what this family already
* names an approver by, and covers a root credential itself as well as a key resolving to no
* IAM user, which this service answers with the account-root stand-in.
*
* <p>{@code AcceptDelegationRequest} models {@code NoSuchEntity}, {@code ServiceFailure} and
* {@code ConcurrentModification} and nothing for this, and no source gives the code AWS
* answers, so the code is chosen: the guide states the rule as which identity may approve,
* which is what {@code SendDelegationToken}'s own owner rule answers {@code AccessDenied}
* for. A duration the record does not carry is nothing to hold to a cap.
*/
private static void requireApproverMayHoldItThatLong(DelegationRequest request,
String callerArn) {
if (callerArn == null || !callerArn.endsWith(":root")
|| request.getSessionDuration() == null
|| request.getSessionDuration() <= ROOT_APPROVAL_DURATION_MAX) {
return;
}
throw new AwsException("AccessDenied", "User is not authorized to perform: "
+ "iam:AcceptDelegationRequest on " + request.getDelegationRequestId()
+ ", which asks for " + request.getSessionDuration() + " seconds: the root user may"
+ " only approve a delegation of " + ROOT_APPROVAL_DURATION_MAX / 3600
+ " hours or less. Approve it as an IAM user or role instead.", 403);
}
private void put(DelegationRequest request) {
requests.putForAccount(request.getRequestorId(), request.getDelegationRequestId(), request);
}