fix(sts): mint global STS and IAM ARNs per partition and add a strict partition mode (#4743)

* fix(sts): mint global STS and IAM ARNs per partition and add a strict partition mode

GetCallerIdentity's root fallback, the AssumeRole family's session ARNs, the
OIDC provider ARN and GetFederationToken built their ARNs with an empty
region, which falls back to the commercial partition, so they carried arn:aws:
whatever partition the request signed. They now go through
RegionResolver.buildGlobalArn. GetAccountSummary reports
GlobalEndpointTokenVersion only where the partition publishes a global STS
host, which is aws alone.

floci.partitions.strict (FLOCI_PARTITIONS_STRICT, default false) refuses a
request signed for a service AWS publishes in another partition but not in
the request's one (CloudFront in GovCloud, IAM in aws-eusc) with the
unknown-service guard's 404, mirroring the host that never resolves on AWS.
endpoints.json omits the services that ship only an endpoint ruleset, so a
service the data lists nowhere is served everywhere. Credential scopes carry
signing names, and 46 of them differ from the endpoints.json keys they cover
(73 keys, such as ecr for api.ecr); regen_partitions.py vendors that map as
signingNames and AwsPartition.offersSigningName joins it.

Part of #4272

* fix(core): read the gzipped botocore models the pip package ships when collecting signing names

The botocore wheel ships each service model as service-2.json.gz, while the checkout under local/aws/botocore ships it plain. collect_signing_names looked only for the plain file, so in CI, which resolves botocore to the installed package, it found no models, generated an empty signingNames and failed aws-data-check against the committed map. It now reads either form, as regen_dynamodb_shapes.py already does.

* fix(sts): keep an assumed-role session in its role's partition, and answer strict-mode Query requests in XML

GetCallerIdentity rebuilt an assumed-role session's ARN with an empty region, which falls back to the commercial partition, so a session AssumeRole issued as arn:aws-cn:sts:: came back as arn:aws:sts::, and a chained AssumeRole was then refused by a China trust policy as a caller from another partition. The session ARN now takes the partition its role ARN names.

Strict partition mode refused a form-encoded Query request (IAM in aws-eusc) with a JSON body; it now returns the Query XML error the unknown-region guard beside it already returns for such requests.

* fix(iam): mint IAM resource ARNs in the request's partition and keep them there

CreateUser, CreateGroup, CreateRole, CreatePolicy, CreateInstanceProfile and
CreateOpenIDConnectProvider minted arn:aws: whatever partition the request
signed, while STS now followed the request. Under China that denied
AssumeRoleWithWebIdentity (the trust policy names the arn:aws: provider ARN
CreateOpenIDConnectProvider returned, matched against arn:aws-cn:), and
AssumeRole reported the request's partition while GetCallerIdentity reported
the role's.

An IAM resource is now created in the request's partition and keeps it:
UpdateUser and UpdateGroup re-mint in the stored ARN's partition. Anything
derived from a stored role follows the role: all three AssumeRole handlers,
resolveCallerArn and the web identity OIDC provider ARN take the role ARN's
partition through AwsArnUtils.partitionOrDefault. The credential report's
root row takes the request's partition.

* fix(sts): mint a session from the stored role, and keep one credential report per partition

AssumeRole, AssumeRoleWithWebIdentity and AssumeRoleWithSAML find the role by
account and name, but minted the session ARN from the RoleArn the request
named. A China role assumed with an arn:aws: RoleArn therefore came back as an
arn:aws:sts:: session, while AssumeRole registered the session under the
stored role's ARN, so GetCallerIdentity reported aws-cn. All three handlers
now mint the session from the stored role's ARN when the role exists and
register it under the same ARN.

The credential report was cached once per account, so a report generated for
one partition was handed to a caller in another for four hours, with the
wrong partition's root row. It is now kept per partition.
This commit is contained in:
Hector Ventura authored and GitHub committed 2026-09-30 20:48:20 -04:00
1 parent 865dd1d658
commit 0bc85f3ef8
24 files changed
+1086 -37

No files matched your search

@@ -74,6 +74,15 @@ public interface EmulatorConfig {
interface PartitionsConfig {
Optional<String> id();
/**
* Refuse requests signed for a service AWS does not publish in the request's partition
* (CloudFront in GovCloud, IAM in {@code aws-eusc}). On AWS such a request never reaches
* an API because its endpoint does not resolve; Floci serves every enabled service in
* every partition unless this is set.
*/
@WithDefault("false")
boolean strict();
/**
* Accept a request whose SigV4 credential scope names a region that no partition
* publishes or admits by its region pattern ({@code polygondwanaland-west-1}). Refused by
@@ -80,6 +80,7 @@ public class AccountContextFilter implements ContainerRequestFilter {
String region = regionResolver.resolveRegionFromAuth(auth);
applyRegion(region);
rejectUnknownRegion(ctx, region, SigV4CredentialScope.serviceName(auth));
rejectPartitionAbsentService(ctx, SigV4CredentialScope.serviceName(auth).orElse(null));
} else {
String credential = ctx.getUriInfo().getQueryParameters().getFirst("X-Amz-Credential");
if (credential != null && !credential.isEmpty()) {
@@ -89,6 +90,8 @@ public class AccountContextFilter implements ContainerRequestFilter {
String region = regionResolver.resolveRegionFromPresignedCredential(credential);
applyRegion(region);
rejectUnknownRegion(ctx, region, SigV4CredentialScope.serviceNameFromCredential(credential));
rejectPartitionAbsentService(ctx,
SigV4CredentialScope.serviceNameFromCredential(credential).orElse(null));
} else {
requestContext.setAccountId(accountResolver.resolve(null));
applyRegion(regionResolver.resolveRegionFromAuth(null));
@@ -143,6 +146,38 @@ public class AccountContextFilter implements ContainerRequestFilter {
&& "x-www-form-urlencoded".equalsIgnoreCase(mediaType.getSubtype());
}
/**
* Strict partition mode. AWS publishes no endpoint for a service outside the partitions it
* exists in (CloudFront in GovCloud, IAM in {@code aws-eusc}); a client there never reaches
* an API because the host does not resolve, which the SDKs surface as an
* {@code UnknownHostException}. Floci cannot fail DNS, so it answers the request with the
* same 404 shape the unknown-service-scope guard uses. Only a service the published data
* lists in some other partition is refused: {@code endpoints.json} omits the newer services
* entirely, and silence there is not absence. Off by default: Floci serves every enabled
* service in every partition.
*/
private void rejectPartitionAbsentService(ContainerRequestContext ctx, String signingName) {
if (signingName == null || !configProvider.get().partitions().strict()) {
return;
}
Optional<AwsPartition> partition = AwsPartitions.find(requestContext.getPartition());
if (partition.isEmpty() || !AwsPartitions.publishesSomewhere(signingName)
|| partition.get().offersSigningName(signingName)) {
return;
}
String partitionId = partition.get().id();
LOG.infov("Rejecting request signed for {0} in partition {1}, which publishes no endpoint for it: {2} {3}",
signingName, partitionId, ctx.getMethod(), ctx.getUriInfo().getPath());
String message = "Service " + signingName + " has no endpoint in partition " + partitionId
+ ": on AWS the host does not resolve there (the SDKs report an UnknownHostException). "
+ "Floci is running with floci.partitions.strict=true.";
if (isFormEncoded(ctx.getMediaType())) {
ctx.abortWith(AwsQueryResponse.error("UnknownOperationException", message, null, 404));
return;
}
ctx.abortWith(AwsProtocolClaimFilter.unknownOperationResponse(404, message));
}
/**
* Applies the account-resolution precedence. A 12-digit AKID is already reflected in
* {@code resolvedDefault} (the account or default returned by {@link AccountResolver});
@@ -103,6 +103,15 @@ public final class AwsArnUtils {
}
}
/**
* Returns the partition an ARN names, or {@code defaultPartition} when the value is null or
* not an ARN. Anything derived from a stored IAM resource (a role's sessions, its account's
* OIDC provider) takes the partition that resource was created in, not the request's.
*/
public static String partitionOrDefault(String arn, String defaultPartition) {
return isArn(arn) ? parse(arn).partition() : defaultPartition;
}
/**
* Regex fragment matching any AWS partition id: {@code aws}, {@code aws-cn},
* {@code aws-us-gov}, and the classified {@code aws-iso*} and {@code aws-eusc} partitions.
@@ -91,6 +91,23 @@ public record AwsPartition(
return service != null && services.contains(service);
}
/**
* True when a request whose SigV4 credential scope names {@code signingName} targets a
* service this partition publishes: the signing name itself, or any of the endpoint
* prefixes it covers ({@code ecr} for {@code api.ecr}).
*/
public boolean offersSigningName(String signingName) {
if (offers(signingName)) {
return true;
}
for (String endpointPrefix : AwsPartitions.endpointPrefixes(signingName)) {
if (services.contains(endpointPrefix)) {
return true;
}
}
return false;
}
public Optional<GlobalEndpoint> globalEndpoint(String service) {
return Optional.ofNullable(service == null ? null : globalServices.get(service));
}
@@ -44,7 +44,9 @@ public final class AwsPartitions {
Map<String, AwsPartition> byRegion,
Map<String, AwsPartition> byPseudoRegion,
Set<String> regionIds,
List<String> dnsSuffixesLongestFirst) {
List<String> dnsSuffixesLongestFirst,
Map<String, Set<String>> endpointPrefixesBySigningName,
Set<String> signingNamesPublishedSomewhere) {
}
private static final class Holder {
@@ -82,6 +84,28 @@ public final class AwsPartitions {
return Holder.CATALOG.byId().keySet();
}
/**
* The {@code endpoints.json} service keys a SigV4 signing name covers when the two differ
* ({@code ecr} signs for {@code api.ecr}, {@code bedrock} for {@code bedrock-runtime} and
* its siblings), or an empty set when the signing name is its own endpoint prefix.
*/
public static Set<String> endpointPrefixes(String signingName) {
if (signingName == null) {
return Set.of();
}
return Holder.CATALOG.endpointPrefixesBySigningName().getOrDefault(signingName, Set.of());
}
/**
* True when at least one published partition lists the service {@code signingName} signs
* for. {@code endpoints.json} does not cover every service (the newer ones ship only an
* endpoint ruleset), so a false answer means the data says nothing about the service, not
* that AWS lacks it.
*/
public static boolean publishesSomewhere(String signingName) {
return signingName != null && Holder.CATALOG.signingNamesPublishedSomewhere().contains(signingName);
}
/**
* The partition {@code region} belongs to, or empty for null, blank and unrecognised
* labels. A {@code <partition>-global} pseudo-region resolves to its partition.
@@ -225,8 +249,27 @@ public final class AwsPartitions {
}
List<String> suffixesLongestFirst = new ArrayList<>(dnsSuffixes);
suffixesLongestFirst.sort(Comparator.comparingInt(String::length).reversed().thenComparing(Comparator.naturalOrder()));
Map<String, Set<String>> endpointPrefixesBySigningName = new LinkedHashMap<>();
JsonNode signingNames = root.path("signingNames");
signingNames.fieldNames().forEachRemaining(signingName -> {
Set<String> prefixes = new LinkedHashSet<>();
for (JsonNode prefix : signingNames.get(signingName)) {
prefixes.add(prefix.asText());
}
endpointPrefixesBySigningName.put(signingName, Set.copyOf(prefixes));
});
Set<String> publishedSomewhere = new LinkedHashSet<>();
for (AwsPartition partition : partitions) {
publishedSomewhere.addAll(partition.services());
}
endpointPrefixesBySigningName.forEach((signingName, prefixes) -> {
if (prefixes.stream().anyMatch(publishedSomewhere::contains)) {
publishedSomewhere.add(signingName);
}
});
return new Catalog(List.copyOf(partitions), Map.copyOf(byId), Map.copyOf(byRegion),
Map.copyOf(byPseudoRegion), Set.copyOf(regionIds), List.copyOf(suffixesLongestFirst));
Map.copyOf(byPseudoRegion), Set.copyOf(regionIds), List.copyOf(suffixesLongestFirst),
Map.copyOf(endpointPrefixesBySigningName), Set.copyOf(publishedSomewhere));
}
private static AwsPartition parsePartition(JsonNode node) {
@@ -3,6 +3,7 @@ package io.github.hectorvent.floci.services.iam;
import io.github.hectorvent.floci.config.EmulatorConfig;
import io.github.hectorvent.floci.core.common.AwsArnUtils;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.AwsPartitions;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.common.ServicePrincipals;
import io.github.hectorvent.floci.core.common.SessionAccountLookup;
@@ -166,8 +167,9 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
private final StorageBackend<String, String> serviceLinkedRoleDeletions;
private final StorageBackend<String, OrganizationRootFeatures> orgRootFeatures;
/**
* Holds at most one entry per account under {@link #CREDENTIAL_REPORT_KEY}: the same
* single-value-per-account shape as {@link #accountAliases}.
* Holds at most one report per account and partition, keyed by {@link #credentialReportKey}:
* the report's root row names the partition it was generated for, so a report generated for
* one partition is never handed to a caller in another.
*/
private final StorageBackend<String, CredentialReport> credentialReports;
private final RegionResolver regionResolver;
@@ -512,7 +514,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
users.delete(userName);
user.setUserName(newUserName);
if (newPath != null) user.setPath(normalizePath(newPath));
user.setArn(iamArn("user", user.getPath(), newUserName));
user.setArn(iamArnBeside(user.getArn(), "user", user.getPath(), newUserName));
users.put(newUserName, user);
loginProfiles.get(userName).ifPresent(profile -> {
loginProfiles.delete(userName);
@@ -533,7 +535,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
} else {
if (newPath != null) {
user.setPath(normalizePath(newPath));
user.setArn(iamArn("user", user.getPath(), userName));
user.setArn(iamArnBeside(user.getArn(), "user", user.getPath(), userName));
}
users.put(userName, user);
}
@@ -607,7 +609,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
if (newPath != null) {
group.setPath(normalizePath(newPath));
}
group.setArn(iamArn("group", group.getPath(), newGroupName));
group.setArn(iamArnBeside(group.getArn(), "group", group.getPath(), newGroupName));
groups.put(newGroupName, group);
// Keep member references in sync so group policies still resolve after a rename.
for (String memberName : group.getUserNames()) {
@@ -620,7 +622,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
} else {
if (newPath != null) {
group.setPath(normalizePath(newPath));
group.setArn(iamArn("group", group.getPath(), groupName));
group.setArn(iamArnBeside(group.getArn(), "group", group.getPath(), groupName));
}
groups.put(groupName, group);
}
@@ -1182,7 +1184,11 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
summary.put("AccountAccessKeysPresent", 0L);
summary.put("AccountSigningCertificatesPresent", 0L);
summary.put("AccountPasswordPresent", 0L);
summary.put("GlobalEndpointTokenVersion", 1L);
// The STS global endpoint (and so the v1/v2 token choice it reports) exists only where
// the partition publishes one: aws today. Elsewhere AWS has no such entry to report.
if (AwsPartitions.byId(regionResolver.getPartition()).hasGlobalSts()) {
summary.put("GlobalEndpointTokenVersion", 1L);
}
return summary;
}
@@ -1952,7 +1958,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
/**
* AWS identifies a provider by URL, so the ARN is derived from it rather than from a random
* id, and the scheme is stripped: {@code https://host/path} becomes
* {@code arn:aws:iam::<account>:oidc-provider/host/path}. Creating the same URL twice is
* {@code arn:<partition>:iam::<account>:oidc-provider/host/path}. Creating the same URL twice is
* therefore a duplicate resource, not a second provider.
*/
public OpenIDConnectProvider createOpenIDConnectProvider(String url, List<String> clientIdList,
@@ -2641,8 +2647,11 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
sessionName = session.getEc2InstanceId() != null
? session.getEc2InstanceId() : "floci-session";
}
return Optional.of(AwsArnUtils.Arn.of("sts", "", accountId, "assumed-role/" + roleName + "/"
+ sessionName).toString());
// The session lives in its role's partition, as AssumeRole issued it, whatever region
// a later call is signed for.
String partition = AwsArnUtils.partitionOrDefault(roleArn, regionResolver.getPartition());
return Optional.of(AwsArnUtils.Arn.global(partition, "sts", accountId,
"assumed-role/" + roleName + "/" + sessionName).toString());
}
return Optional.empty();
@@ -2867,8 +2876,21 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
return docs;
}
/**
* Mints the ARN of a new IAM resource in the request's partition (the deployment's outside a
* request, as for the seeded deployer user). An IAM resource then stays in the partition it was
* created in: AWS never has to choose, since an account belongs to one partition, but Floci
* keys IAM by account and serves every partition from one process.
*/
private String iamArn(String resourceType, String path, String name) {
return AwsArnUtils.Arn.of("iam", "", regionResolver.getAccountId(), resourceType + path + name).toString();
return regionResolver.buildGlobalArn("iam", resourceType + path + name);
}
/** Re-mints a renamed or moved resource's ARN in the partition its current ARN names. */
private String iamArnBeside(String currentArn, String resourceType, String path, String name) {
String partition = AwsArnUtils.partitionOrDefault(currentArn, regionResolver.getPartition());
return AwsArnUtils.Arn.global(partition, "iam", regionResolver.getAccountId(),
resourceType + path + name).toString();
}
private static <T> boolean containsNameIgnoreCase(StorageBackend<String, T> storage,
@@ -3080,22 +3102,26 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
*/
public CredentialReportGeneration generateCredentialReport() {
Instant now = Instant.now();
Optional<CredentialReport> existing = credentialReports.get(CREDENTIAL_REPORT_KEY);
Optional<CredentialReport> existing = credentialReports.get(credentialReportKey());
if (existing.isPresent() && now.isBefore(existing.get().getGeneratedTime().plus(CREDENTIAL_REPORT_MAX_AGE))) {
return new CredentialReportGeneration("COMPLETE",
"Current report has already been generated within the past 4 hours.");
}
String csv = buildCredentialReportCsv();
String base64Content = Base64.getEncoder().encodeToString(csv.getBytes(StandardCharsets.UTF_8));
credentialReports.put(CREDENTIAL_REPORT_KEY, new CredentialReport(base64Content, now));
credentialReports.put(credentialReportKey(), new CredentialReport(base64Content, now));
String description = existing.isEmpty()
? "No report exists. Starting a new report generation task"
: "The previous report has expired. Starting a new report generation task";
return new CredentialReportGeneration("STARTED", description);
}
private String credentialReportKey() {
return CREDENTIAL_REPORT_KEY + "/" + regionResolver.getPartition();
}
public CredentialReportContent getCredentialReport() {
CredentialReport report = credentialReports.get(CREDENTIAL_REPORT_KEY)
CredentialReport report = credentialReports.get(credentialReportKey())
.orElseThrow(() -> new AwsException("ReportNotPresent",
"The request was rejected because the credential report does not exist. "
+ "To generate a credential report, use GenerateCredentialReport.", 410));
@@ -3132,7 +3158,7 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
}
private String rootAccountReportRow() {
String arn = AwsArnUtils.Arn.of("iam", "", regionResolver.getAccountId(), "root").toString();
String arn = regionResolver.buildGlobalArn("iam", "root");
return String.join(",",
"<root_account>", arn, "N/A",
"FALSE", "N/A", "N/A", "not_supported",
@@ -131,7 +131,8 @@ public class StsQueryHandler {
return trustDenied;
}
String assumedRoleArn = AwsArnUtils.Arn.of("sts", "", accountId, "assumed-role/" + roleName + "/" + sessionName).toString();
String sessionRoleArn = role != null ? role.getArn() : roleArn;
String assumedRoleArn = assumedRoleArn(sessionRoleArn, accountId, roleName, sessionName);
String assumedRoleId = "AROA" + randomId(16) + ":" + sessionName;
// Register session so IAM enforcement can resolve the role's policies, RDS/ElastiCache
@@ -140,7 +141,6 @@ public class StsQueryHandler {
// role's own ARN, path included: it is the session's aws:PrincipalArn, and it keeps naming
// the role that issued the session even if a role of the same name replaces it later.
String sessionPolicy = getParam(params, "Policy");
String sessionRoleArn = role != null ? role.getArn() : roleArn;
iamService.registerSession(
accessKeyId, secretKey, sessionToken, sessionRoleArn, expiration, sessionPolicy, callerAccountId,
sessionName, assumedRoleId);
@@ -179,7 +179,7 @@ public class StsQueryHandler {
String callerAccount = regionResolver.getAccountId();
String accessKeyId = auth == null ? null : accountResolver.extractAccessKeyId(auth);
String callerArn = iamService.resolveCallerArn(accessKeyId)
.orElse(AwsArnUtils.Arn.of("iam", "", callerAccount, "root").toString());
.orElse(regionResolver.buildGlobalArn("iam", callerAccount, "root"));
String principalArn = iamService.resolvePrincipalArn(accessKeyId).orElse(callerArn);
Map<String, List<String>> requestContext = IamConditionContextResolver.withGlobalContext(
null, roleArn, regionResolver.getRegion(), callerAccount, roleAccountId);
@@ -202,7 +202,7 @@ public class StsQueryHandler {
String authorization = headers == null ? null : headers.getHeaderString("Authorization");
String accessKeyId = authorization == null ? null : accountResolver.extractAccessKeyId(authorization);
String arn = iamService.resolveCallerArn(accessKeyId)
.orElse(AwsArnUtils.Arn.of("iam", "", accountId, "root").toString());
.orElse(regionResolver.buildGlobalArn("iam", accountId, "root"));
String userId = iamService.resolveCallerUserId(accessKeyId).orElse(accountId);
String result = new XmlBuilder()
.elem("UserId", userId)
@@ -260,7 +260,8 @@ public class StsQueryHandler {
String sessionToken = randomSecret(200);
Instant expiration = Instant.now().plusSeconds(durationSeconds);
String assumedRoleArn = AwsArnUtils.Arn.of("sts", "", accountId, "assumed-role/" + roleName + "/" + sessionName).toString();
String sessionRoleArn = iamService.findRole(accountId, roleName).map(IamRole::getArn).orElse(roleArn);
String assumedRoleArn = assumedRoleArn(sessionRoleArn, accountId, roleName, sessionName);
String assumedRoleId = "AROA" + randomId(16) + ":" + sessionName;
String provider = verified != null ? verified.issuer()
@@ -270,7 +271,7 @@ public class StsQueryHandler {
String sessionPolicy = getParam(params, "Policy");
iamService.registerSession(
accessKeyId, secretKey, sessionToken, roleArn, expiration, sessionPolicy, callerAccountId,
accessKeyId, secretKey, sessionToken, sessionRoleArn, expiration, sessionPolicy, callerAccountId,
sessionName, assumedRoleId);
String result = new XmlBuilder()
@@ -343,8 +344,10 @@ public class StsQueryHandler {
}
String issuerKeyPrefix = stripScheme(issuer.get());
String oidcProviderArn = AwsArnUtils.Arn.of("iam", "", roleAccountId,
"oidc-provider/" + issuerKeyPrefix).toString();
// The provider is an IAM resource of the role's account, so it shares the role's partition.
String oidcProviderArn = AwsArnUtils.Arn.global(
AwsArnUtils.partitionOrDefault(role.get().getArn(), regionResolver.getPartition()),
"iam", roleAccountId, "oidc-provider/" + issuerKeyPrefix).toString();
Map<String, List<String>> conditionClaims = Map.of(
"sub", List.of(claims.subject()),
"aud", claims.audiences());
@@ -361,6 +364,17 @@ public class StsQueryHandler {
new VerifiedWebIdentity(claims.issuer(), claims.subject(), STS_AUDIENCE));
}
/**
* A session on a role lives in the role's partition, whatever region AssumeRole is signed
* for. Callers pass the stored role's ARN when the role exists, not the RoleArn the request
* named, and register the session under the same ARN, so {@link IamService#resolveCallerArn}
* always agrees with the ARN returned here.
*/
private String assumedRoleArn(String roleArn, String accountId, String roleName, String sessionName) {
return AwsArnUtils.Arn.global(AwsArnUtils.partitionOrDefault(roleArn, regionResolver.getPartition()),
"sts", accountId, "assumed-role/" + roleName + "/" + sessionName).toString();
}
private Response accessDenied(String roleArn) {
return AwsQueryResponse.error("AccessDenied",
"Not authorized to perform sts:AssumeRoleWithWebIdentity on resource: " + roleArn,
@@ -430,10 +444,10 @@ public class StsQueryHandler {
String accessKeyId = "ASIA" + randomId(16);
String secretKey = randomSecret(40);
String sessionToken = randomSecret(200);
String assumedRoleArn = AwsArnUtils.Arn.of("sts", "", accountId, "assumed-role/" + roleName + "/" + sessionName).toString();
String assumedRoleArn = assumedRoleArn(role.getArn(), accountId, roleName, sessionName);
String assumedRoleId = "AROA" + randomId(16) + ":" + sessionName;
iamService.registerSession(accessKeyId, secretKey, sessionToken, roleArn, expiration, null,
iamService.registerSession(accessKeyId, secretKey, sessionToken, role.getArn(), expiration, null,
callerAccountId, sessionName, assumedRoleId);
String result = new XmlBuilder()
.raw(credentialsXml(accessKeyId, secretKey, sessionToken, expiration))
@@ -461,7 +475,7 @@ public class StsQueryHandler {
Instant expiration = Instant.now().plusSeconds(durationSeconds);
String accountId = regionResolver.getAccountId();
String federatedUserId = accountId + ":" + name;
String federatedUserArn = AwsArnUtils.Arn.of("sts", "", accountId, "federated-user/" + name).toString();
String federatedUserArn = regionResolver.buildGlobalArn("sts", accountId, "federated-user/" + name);
String sessionPolicy = getParam(params, "Policy");
// Register federation token so enforcement can scope its policies via session policy.