fix(iam): apply the permissions boundary a delegation registers (#8465)

A delegation request's RolePermissionRestrictionArns was stored, echoed and
counted, and nothing applied it, so a role created with delegated credentials
carried no boundary where AWS forces one. The partner guide says long-term
permissions "limit the permissions of any roles that are created or managed
through temporary access" and are "implemented as IAM permissions boundaries",
so a partner's cap did not reach the roles it exists to cap.

The member is also not an input. It is absent from CreateDelegationRequest and
appears only in the DelegationRequest output shape, where
GetDelegationRequest's own example reports it empty, because AWS fills it from
the partner's registration rather than from a request. Those boundaries are
registered by emailing AWS, with no API at all, under ARNs shaped
arn:aws:iam::partner:policy/permission_boundary/<partner_domain>/<policy_name>_<date>,
which carry the word partner where an account id goes. So no caller can create
one, no account holds one, and the only way this emulator can hold what AWS
holds out of band is to be handed it.

It is handed it by configuration. services.iam.partner-permission-boundaries-path
names a JSON file of partner account id to an object of boundary ARN to policy
document, which is the shape of the registration it stands in for. Unset, which
is the default, registers nothing: a request reports no restriction, a role
created with delegated credentials carries only the boundary its call asks for,
and nothing moves for a deployment that configures no file. A file that cannot
be read registers nothing rather than failing startup, an unreadable
registration being the same situation as a partner that never onboarded.

From there the chain is the one the guide describes. A request a registered
partner files reports those ARNs on itself, GetDelegatedAccessToken carries them
onto the delegated session, and CreateRole with that session takes one as the
role's boundary. The session is minted in the partner's account and used in the
customer's, so the lookup spans accounts, which is what findSessionAnyAccount is
for.

A registered document is read as a boundary and as nothing else. One reader
answers a boundary ARN, taking the registration ahead of the store, so GetPolicy
does not answer these ARNs, no Attach call can attach one as an identity policy,
no list reports one, and a policy stored under the same ARN cannot shadow the
cap. Every write that sets a boundary accepts a registered ARN without requiring
it as a policy of the account, the create and the two puts alike, so one ARN
behaves the same way wherever a boundary is set.

The cap also stays where it was put. The credentials a delegation issued cannot
replace or remove the boundary they gave a role, since the guide limits roles
"created or managed through temporary access" and the registration is immutable,
and iam:PermissionsBoundary publishes the boundary the write will apply rather
than the one the call asked for, so a policy conditioned on it is told the value
the role ends up with. Both refusal and reading are this emulator's own, no
source wording either.

A stack's roles are capped too. CloudFormation provisions after the request
returns, on a background executor, so the caller cannot be read when the role is
created and the cap travels with the stack instead: CreateStack and UpdateStack
record the boundary the caller's delegation registers, the dispatcher puts it in
the provisioning context, and the role provisioner prefers it to the template's
PermissionsBoundary, the same precedence a direct CreateRole has. An update
records it as well, the guide capping roles "created or managed through temporary
access". Every existing caller of the context and the dispatcher keeps its
signature, the new component and overload defaulting to no cap.

Two readings here are this emulator's own, both documented. A delegation's cap
beats a PermissionsBoundary the CreateRole call names, since the cap is what the
customer registered rather than a choice of the caller. And where a request
names several boundaries, the first is applied, a role carrying one. Only a
boundary still registered is applied, so a request stored before the
registration changed cannot bound a role by a document nobody can read.

Nothing new is refused and no code or status moves: with no registration the
behaviour is what it was, and with one the role simply carries the boundary AWS
would have given it.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-15 17:43:55 -04:00
1 parent d51af1ecff
commit 2b372cc0fc
24 files changed
+1032 -24

No files matched your search

@@ -50,8 +50,10 @@ class CloudFormationStackPolicyServiceTest {
@BeforeEach
void setUp() {
provisioner = mock(CfnResourceDispatcher.class);
// The last argument is the permissions boundary a delegation registered for the caller,
// which a stack deployed by an ordinary caller carries as null.
when(provisioner.provision(anyString(), anyString(), any(), any(), anyString(), anyString(), anyString(),
any(), any(), any(), any(), any())).thenAnswer(invocation -> {
any(), any(), any(), any(), any(), any())).thenAnswer(invocation -> {
StackResource resource = new StackResource();
resource.setLogicalId(invocation.getArgument(0));
resource.setResourceType(invocation.getArgument(1));
@@ -0,0 +1,177 @@
package io.floci.aws.services.iam;
import io.floci.aws.core.common.RequestScopes;
import io.floci.aws.testing.PartnerPermissionBoundaryEnforcementProfile;
import io.floci.aws.testutil.S3RequestSigner;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
import java.util.UUID;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.equalTo;
/**
* What authorization is told about the boundary a delegated role write will apply.
*
* <p>{@code iam:PermissionsBoundary} is the key a policy conditions on to say which boundary a
* principal may be created with, and the enforcement filter reads it from the request before the
* write runs. A role created under a delegation carries the cap the delegation registered rather
* than whatever the call named, so the key has to carry that same value or a policy written about
* it would judge a boundary the role never ends up with.
*
* <p>The caller here is a delegated session, which acts as the identity that approved the request,
* so the approver's own policy is what authorizes the write and what the condition is read against.
*/
@QuarkusTest
@TestProfile(PartnerPermissionBoundaryEnforcementProfile.class)
class DelegationRoleBoundaryEnforcementIntegrationTest {
private static final String CUSTOMER = "222233334444";
private static final String PARTNER = "000000000001";
private static final String TOPIC = "arn:aws:sns:us-east-1:000000000001:partner-notifications";
private static final String TEMPLATE = "arn:aws:iam::partner:policy/template/example";
private static final String BOUNDARY =
"arn:aws:iam::partner:policy/permission_boundary/example.com/ReadOnlyAccess_20261101";
private static final String OTHER_BOUNDARY = "arn:aws:iam::222233334444:policy/SomethingElse";
private static final String TRUST = """
{"Version":"2012-10-17","Statement":[{"Effect":"Allow",
"Principal":{"Service":"ec2.amazonaws.com"},"Action":"sts:AssumeRole"}]}""";
private static final String DELEGATION_ACCESS = """
{"Effect":"Allow","Action":["iam:AssociateDelegationRequest","iam:AcceptDelegationRequest",
"iam:SendDelegationToken"],"Resource":"*"}""";
@Inject
DelegationRequestService delegationRequests;
@Test
void aPolicyConditionedOnTheRegisteredCapAllowsTheRoleItCaps() {
S3RequestSigner approver = approverAllowedToCreateRolesBoundedBy(BOUNDARY);
String[] credentials = delegatedCredentials(approvedBy(approver));
// No PermissionsBoundary member: the cap comes from the delegation, and the condition is
// told that value, so the approver's policy allows the write.
createRole(credentials).statusCode(200)
.body("CreateRoleResponse.CreateRoleResult.Role.PermissionsBoundary"
+ ".PermissionsBoundaryArn", equalTo(BOUNDARY));
}
@Test
void aPolicyConditionedOnAnotherBoundaryRefusesItEvenWhenTheCallNamesThatOne() {
S3RequestSigner approver = approverAllowedToCreateRolesBoundedBy(OTHER_BOUNDARY);
String[] credentials = delegatedCredentials(approvedBy(approver));
// The call names the boundary the approver's policy allows, and the delegation's cap is
// what the role will carry instead, so the key carries the cap and the condition fails.
// Naming it is what makes this a guard: were the key still read from the request member,
// the condition would match the name and the write would be authorized for a boundary the
// role never ends up with.
createRole(credentials, OTHER_BOUNDARY).statusCode(403);
}
private static ValidatableResponse createRole(String[] credentials) {
return createRole(credentials, null);
}
/** The same write, naming {@code boundaryArn} when it is not null, which the cap overrides. */
private static ValidatableResponse createRole(String[] credentials, String boundaryArn) {
RequestSpecification request = given().header("Authorization", auth(credentials[0], "iam"))
.header("X-Amz-Security-Token", credentials[2])
.formParam("Action", "CreateRole")
.formParam("Version", "2010-05-08")
.formParam("RoleName", "delegated-" + UUID.randomUUID().toString().substring(0, 8))
.formParam("AssumeRolePolicyDocument", TRUST);
if (boundaryArn != null) {
request = request.formParam("PermissionsBoundary", boundaryArn);
}
return request.when().post("/").then();
}
/** A customer identity that may create a role only when its boundary is {@code boundaryArn}. */
private static S3RequestSigner approverAllowedToCreateRolesBoundedBy(String boundaryArn) {
String userName = "approver-" + UUID.randomUUID().toString().substring(0, 8);
String policy = """
{"Version":"2012-10-17","Statement":[%s,
{"Effect":"Allow","Action":"iam:CreateRole","Resource":"*",
"Condition":{"StringEquals":{"iam:PermissionsBoundary":"%s"}}}]}"""
.formatted(DELEGATION_ACCESS, boundaryArn);
return userWithPolicy(userName, policy);
}
private String approvedBy(S3RequestSigner approver) {
String id = partnerCreate();
byUser(approver, "AssociateDelegationRequest", id);
byUser(approver, "AcceptDelegationRequest", id);
byUser(approver, "SendDelegationToken", id);
return id;
}
/** The access key, secret and session token the partner gets for the released token. */
private String[] delegatedCredentials(String id) {
String token = RequestScopes.callAs(CUSTOMER,
() -> delegationRequests.get(CUSTOMER, id).getExchangeToken());
ExtractableResponse<Response> exchanged = given().header("Authorization", auth(PARTNER, "sts"))
.formParam("Action", "GetDelegatedAccessToken")
.formParam("Version", "2011-06-15")
.formParam("TradeInToken", token)
.when().post("/").then().statusCode(200).extract();
String result = "GetDelegatedAccessTokenResponse.GetDelegatedAccessTokenResult.Credentials.";
return new String[] {
exchanged.path(result + "AccessKeyId"),
exchanged.path(result + "SecretAccessKey"),
exchanged.path(result + "SessionToken"),
};
}
private static String partnerCreate() {
return given().header("Authorization", auth(PARTNER, "iam"))
.formParam("Action", "CreateDelegationRequest")
.formParam("Version", "2010-05-08")
.formParam("Description", "Set up the integration")
.formParam("NotificationChannel", TOPIC)
.formParam("RequestorWorkflowId", "workflow-" + Long.toString(System.nanoTime(), 36))
.formParam("SessionDuration", "3600")
.formParam("OwnerAccountId", CUSTOMER)
.formParam("Permissions.PolicyTemplateArn", TEMPLATE)
.when().post("/").then().statusCode(200)
.extract().path("CreateDelegationRequestResponse.CreateDelegationRequestResult"
+ ".DelegationRequestId");
}
private static S3RequestSigner userWithPolicy(String userName, String policy) {
iam("CreateUser", "UserName", userName);
iam("PutUserPolicy", "UserName", userName, "PolicyName", "inline", "PolicyDocument", policy);
ExtractableResponse<Response> key = given().formParam("Action", "CreateAccessKey")
.formParam("UserName", userName)
.header("Authorization", auth(CUSTOMER, "iam")).when().post("/")
.then().statusCode(200).extract();
return S3RequestSigner.signedAs(
key.path("CreateAccessKeyResponse.CreateAccessKeyResult.AccessKey.AccessKeyId"),
key.path("CreateAccessKeyResponse.CreateAccessKeyResult.AccessKey.SecretAccessKey"));
}
private static void byUser(S3RequestSigner caller, String action, String id) {
given().filter(caller).formParam("Action", action).formParam("Version", "2010-05-08")
.formParam("DelegationRequestId", id).when().post("/").then().statusCode(200);
}
private static void iam(String action, String... params) {
RequestSpecification request = given().formParam("Action", action)
.header("Authorization", auth(CUSTOMER, "iam"));
for (int i = 0; i < params.length; i += 2) {
request = request.formParam(params[i], params[i + 1]);
}
request.when().post("/").then().statusCode(200);
}
private static String auth(String accessKeyId, String service) {
return "AWS4-HMAC-SHA256 Credential=" + accessKeyId + "/20261002/us-east-1/" + service
+ "/aws4_request, SignedHeaders=host, Signature=abc";
}
}
@@ -0,0 +1,312 @@
package io.floci.aws.services.iam;
import io.floci.aws.core.common.RequestScopes;
import io.floci.aws.testing.CfnStackWaits;
import io.floci.aws.testing.PartnerPermissionBoundaryProfile;
import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.junit.TestProfile;
import io.restassured.response.ExtractableResponse;
import io.restassured.response.Response;
import io.restassured.response.ValidatableResponse;
import io.restassured.specification.RequestSpecification;
import jakarta.inject.Inject;
import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* The long-term half of temporary delegation: the partner guide says long-term permissions "limit
* the permissions of any roles that are created or managed through temporary access" and are
* "implemented as IAM permissions boundaries", registered for the partner out of band, by email,
* with no API at all.
*
* <p>So the boundaries come from configuration here, keyed by the partner account AWS registered
* them for, and the chain is the one AWS describes: a request a registered partner files reports
* the boundaries on itself, which is where {@code RolePermissionRestrictionArns} comes from on AWS
* rather than from any input, the credentials exchanged for that request's token carry them, and a
* role created with those credentials is bounded by one. Without a registration nothing carries
* anything, which is the partner that never onboarded.
*/
@QuarkusTest
@TestProfile(PartnerPermissionBoundaryProfile.class)
class DelegationRoleBoundaryIntegrationTest {
/** One double quote, so a template can be written without escaping every quote twice. */
private static final String Q = "\"";
private static final String CUSTOMER = "222233334444";
private static final String PARTNER = "000000000001";
private static final String UNREGISTERED_PARTNER = "000000000002";
private static final String TOPIC = "arn:aws:sns:us-east-1:000000000001:partner-notifications";
private static final String TEMPLATE = "arn:aws:iam::partner:policy/template/example";
private static final String BOUNDARY =
"arn:aws:iam::partner:policy/permission_boundary/example.com/ReadOnlyAccess_20261101";
private static final String CODE = "ErrorResponse.Error.Code";
private static final String ALLOW_NOTHING = """
{"Version":"2012-10-17","Statement":[{"Effect":"Deny","Action":"*","Resource":"*"}]}""";
private static final String TRUST_JSON =
"{" + Q + "Version" + Q + ":" + Q + "2012-10-17" + Q + ","
+ Q + "Statement" + Q + ":[{" + Q + "Effect" + Q + ":" + Q + "Allow" + Q + ","
+ Q + "Principal" + Q + ":{" + Q + "Service" + Q + ":" + Q + "ec2.amazonaws.com" + Q + "},"
+ Q + "Action" + Q + ":" + Q + "sts:AssumeRole" + Q + "}]}";
private static final String TRUST = """
{"Version":"2012-10-17","Statement":[{"Effect":"Allow",
"Principal":{"Service":"ec2.amazonaws.com"},"Action":"sts:AssumeRole"}]}""";
@Inject
DelegationRequestService delegationRequests;
@Inject
IamService iamService;
@Test
void aRequestFiledByARegisteredPartnerReportsTheBoundariesRegisteredForIt() {
String id = partnerCreate(PARTNER);
assertEquals(List.of(BOUNDARY), RequestScopes.callAs(CUSTOMER,
() -> delegationRequests.get(CUSTOMER, id).getRolePermissionRestrictionArns()));
}
@Test
void aRequestFiledByAPartnerWithNoRegistrationReportsNone() {
String id = partnerCreate(UNREGISTERED_PARTNER);
assertEquals(List.of(), RequestScopes.callAs(CUSTOMER,
() -> delegationRequests.get(CUSTOMER, id).getRolePermissionRestrictionArns()));
}
@Test
void aRoleCreatedWithDelegatedCredentialsCarriesTheRegisteredBoundary() {
String id = approved(partnerCreate(PARTNER));
String[] credentials = delegatedCredentials(PARTNER, id);
// The session is where the cap travels: the request named it and the exchange carried it.
assertEquals(Optional.of(BOUNDARY), RequestScopes.callAs(CUSTOMER,
() -> iamService.delegatedRoleBoundaryArn(credentials[0])));
given().header("Authorization", sessionAuth(credentials[0]))
.header("X-Amz-Security-Token", credentials[2])
.formParam("Action", "CreateRole")
.formParam("Version", "2010-05-08")
.formParam("RoleName", unique("delegated"))
.formParam("AssumeRolePolicyDocument", TRUST)
.when().post("/").then().statusCode(200)
.body("CreateRoleResponse.CreateRoleResult.Role.PermissionsBoundary"
+ ".PermissionsBoundaryArn", equalTo(BOUNDARY));
}
@Test
void aRoleCreatedByAnyoneElseCarriesOnlyTheBoundaryTheCallAsksFor() {
given().header("Authorization", auth(CUSTOMER, "iam"))
.formParam("Action", "CreateRole")
.formParam("Version", "2010-05-08")
.formParam("RoleName", unique("undelegated"))
.formParam("AssumeRolePolicyDocument", TRUST)
.when().post("/").then().statusCode(200)
.body(not(containsString("PermissionsBoundary")));
}
@Test
void theCapCannotBeLiftedWithTheCredentialsThatSetIt() {
String id = approved(partnerCreate(PARTNER));
String[] credentials = delegatedCredentials(PARTNER, id);
String roleName = createdRole(credentials);
String other = managedPolicy();
// The guide limits roles "created or managed through temporary access", and a registered
// boundary is immutable, so these credentials cannot move the cap they were given.
delegated(credentials, "PutRolePermissionsBoundary", "RoleName", roleName,
"PermissionsBoundary", other).statusCode(403)
.body(CODE, equalTo("AccessDenied"));
delegated(credentials, "DeleteRolePermissionsBoundary", "RoleName", roleName)
.statusCode(403).body(CODE, equalTo("AccessDenied"));
// And the role still carries it.
delegated(credentials, "GetRole", "RoleName", roleName).statusCode(200)
.body("GetRoleResponse.GetRoleResult.Role.PermissionsBoundary.PermissionsBoundaryArn",
equalTo(BOUNDARY));
}
@Test
void theRegisteredCapWinsOverABoundaryTheCallNames() {
String id = approved(partnerCreate(PARTNER));
String[] credentials = delegatedCredentials(PARTNER, id);
String other = managedPolicy();
delegated(credentials, "CreateRole",
"RoleName", unique("delegated-other"),
"AssumeRolePolicyDocument", TRUST,
"PermissionsBoundary", other).statusCode(200)
.body("CreateRoleResponse.CreateRoleResult.Role.PermissionsBoundary"
+ ".PermissionsBoundaryArn", equalTo(BOUNDARY));
}
@Test
void aRegisteredBoundaryIsAPolicyNowhere() {
// It caps and does nothing else: no read, no attach and no version of it exists, so no
// document stored under its ARN can shadow the registration either.
String userName = unique("boundary-reader");
byCustomer2("CreateUser", "UserName", userName);
byCustomer2Expecting("GetPolicy", 404, "PolicyArn", BOUNDARY);
byCustomer2Expecting("AttachUserPolicy", 404, "UserName", userName, "PolicyArn", BOUNDARY);
// An identity document, so the write's own reading of the document cannot answer first:
// what is under test is that the ARN resolves to no policy of this account.
byCustomer2Expecting("CreatePolicyVersion", 404, "PolicyArn", BOUNDARY,
"PolicyDocument", ALLOW_NOTHING, "SetAsDefault", "true");
byCustomer2("DeleteUser", "UserName", userName);
}
/** A managed policy of the customer's own, for the cases that need a second boundary ARN. */
private String managedPolicy() {
return given().header("Authorization", auth(CUSTOMER, "iam"))
.formParam("Action", "CreatePolicy")
.formParam("Version", "2010-05-08")
.formParam("PolicyName", unique("other-boundary"))
.formParam("PolicyDocument", ALLOW_NOTHING)
.when().post("/").then().statusCode(200)
.extract().path("CreatePolicyResponse.CreatePolicyResult.Policy.Arn");
}
/** A role created with the delegated credentials, which the cap is applied to. */
private String createdRole(String[] credentials) {
String roleName = unique("delegated");
delegated(credentials, "CreateRole", "RoleName", roleName,
"AssumeRolePolicyDocument", TRUST).statusCode(200);
return roleName;
}
private static ValidatableResponse delegated(String[] credentials,
String action,
String... params) {
RequestSpecification request = given().header("Authorization", sessionAuth(credentials[0]))
.header("X-Amz-Security-Token", credentials[2])
.formParam("Action", action)
.formParam("Version", "2010-05-08");
for (int i = 0; i < params.length; i += 2) {
request = request.formParam(params[i], params[i + 1]);
}
return request.when().post("/").then();
}
private static void byCustomer2(String action, String... params) {
byCustomer2Expecting(action, 200, params);
}
private static void byCustomer2Expecting(String action, int status, String... params) {
RequestSpecification request = given().header("Authorization", auth(CUSTOMER, "iam"))
.formParam("Action", action)
.formParam("Version", "2010-05-08");
for (int i = 0; i < params.length; i += 2) {
request = request.formParam(params[i], params[i + 1]);
}
request.when().post("/").then().statusCode(status);
}
private static String unique(String prefix) {
return prefix + "-" + UUID.randomUUID().toString().substring(0, 8);
}
@Test
void aRoleAStackProvisionsForADelegatedCallerCarriesTheCapToo() {
String id = approved(partnerCreate(PARTNER));
String[] credentials = delegatedCredentials(PARTNER, id);
String stackName = unique("delegated-stack");
String roleName = unique("stack-role");
String template = "{\"Resources\":{\"R\":{\"Type\":\"AWS::IAM::Role\",\"Properties\":{"
+ "\"RoleName\":\"" + roleName + "\",\"AssumeRolePolicyDocument\":" + TRUST_JSON + "}}}}";
// The stack is created with the delegated credentials, so the roles it provisions are
// created through temporary access and the guide caps them.
// The router dispatches on the service the credential scope names, so a stack call signs
// for cloudformation while the same session's IAM calls sign for iam.
given().header("Authorization", auth(credentials[0], "cloudformation"))
.header("X-Amz-Security-Token", credentials[2])
.formParam("Action", "CreateStack")
.formParam("Version", "2010-05-15")
.formParam("StackName", stackName)
.formParam("TemplateBody", template)
.when().post("/").then().statusCode(200);
// The session acts in the customer's account, so that is where the stack and its role live.
CfnStackWaits.awaitStatus(stackName, "CREATE_COMPLETE", auth(CUSTOMER, "cloudformation"));
try {
given().header("Authorization", auth(CUSTOMER, "iam"))
.formParam("Action", "GetRole")
.formParam("Version", "2010-05-08")
.formParam("RoleName", roleName)
.when().post("/").then().statusCode(200)
.body("GetRoleResponse.GetRoleResult.Role.PermissionsBoundary.PermissionsBoundaryArn",
equalTo(BOUNDARY));
} finally {
CfnStackWaits.deleteStack(stackName, auth(CUSTOMER, "cloudformation"));
}
}
private String approved(String id) {
byCustomer("AssociateDelegationRequest", id);
byCustomer("AcceptDelegationRequest", id);
byCustomer("SendDelegationToken", id);
return id;
}
/** The access key, secret and session token the partner gets for the released token. */
private String[] delegatedCredentials(String partnerAccountId, String id) {
String token = RequestScopes.callAs(CUSTOMER,
() -> delegationRequests.get(CUSTOMER, id).getExchangeToken());
ExtractableResponse<Response> exchanged = given()
.header("Authorization", auth(partnerAccountId, "sts"))
.formParam("Action", "GetDelegatedAccessToken")
.formParam("Version", "2011-06-15")
.formParam("TradeInToken", token)
.when().post("/").then().statusCode(200).extract();
String result = "GetDelegatedAccessTokenResponse.GetDelegatedAccessTokenResult.Credentials.";
return new String[] {
exchanged.path(result + "AccessKeyId"),
exchanged.path(result + "SecretAccessKey"),
exchanged.path(result + "SessionToken"),
};
}
private static String partnerCreate(String partnerAccountId) {
return given().header("Authorization", auth(partnerAccountId, "iam"))
.formParam("Action", "CreateDelegationRequest")
.formParam("Version", "2010-05-08")
.formParam("Description", "Set up the integration")
.formParam("NotificationChannel", TOPIC)
.formParam("RequestorWorkflowId", "workflow-" + Long.toString(System.nanoTime(), 36))
.formParam("SessionDuration", "3600")
.formParam("OwnerAccountId", CUSTOMER)
.formParam("Permissions.PolicyTemplateArn", TEMPLATE)
.when().post("/").then().statusCode(200)
.extract().path("CreateDelegationRequestResponse.CreateDelegationRequestResult"
+ ".DelegationRequestId");
}
private static void byCustomer(String action, String id) {
given().header("Authorization", auth(CUSTOMER, "iam"))
.formParam("Action", action)
.formParam("Version", "2010-05-08")
.formParam("DelegationRequestId", id)
.when().post("/").then().statusCode(200);
}
private static String auth(String accessKeyId, String service) {
return "AWS4-HMAC-SHA256 Credential=" + accessKeyId + "/20261002/us-east-1/" + service
+ "/aws4_request, SignedHeaders=host, Signature=abc";
}
private static String sessionAuth(String accessKeyId) {
return auth(accessKeyId, "iam");
}
}
@@ -1,5 +1,6 @@
package io.floci.aws.services.iam;
import io.floci.aws.core.common.RequestContext;
import io.floci.aws.core.common.XmlParser;
import io.floci.aws.services.iam.model.IamRole;
import io.floci.aws.services.iam.model.ServerCertificate;
@@ -62,7 +63,8 @@ class IamQueryHandlerTest {
"fabricated-key", null, Map.of())).thenReturn(certificate);
when(service.getServerCertificate(CERTIFICATE_NAME)).thenReturn(certificate);
when(service.listServerCertificates(null)).thenReturn(List.of(certificate));
IamQueryHandler handler = new IamQueryHandler(service, null, null, null, null, null, null, null, null, null);
IamQueryHandler handler = new IamQueryHandler(service, null, null, null, null, null, null, null, null,
new RequestContext(), null);
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
params.putSingle("ServerCertificateName", CERTIFICATE_NAME);
@@ -91,7 +93,8 @@ class IamQueryHandlerTest {
IamService service = mock(IamService.class);
when(service.createRole(ROLE_NAME, "/", EMPTY_POLICY_DOCUMENT, null, 3600, Map.of(), null)).thenReturn(role);
when(service.getValidatedRole(ROLE_NAME)).thenReturn(role);
IamQueryHandler handler = new IamQueryHandler(service, null, null, null, null, null, null, null, null, null);
IamQueryHandler handler = new IamQueryHandler(service, null, null, null, null, null, null, null, null,
new RequestContext(), null);
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
params.putSingle("RoleName", ROLE_NAME);
@@ -1143,9 +1143,11 @@ class StsQueryHandlerTest {
assertTrue(((String) response.getEntity()).contains(
"<AssumedPrincipal>arn:aws:iam::000000000002:user/admin</AssumedPrincipal>"),
(String) response.getEntity());
// The eighth argument is what the request restricts a role to, which is nothing here: no
// partner boundary is registered in this fixture.
verify(iamService).registerDelegatedSession(anyString(), anyString(), anyString(),
eq("arn:aws:iam::000000000002:user/admin"), eq(expiry), isNull(),
eq("000000000002"));
eq("000000000002"), eq(List.of()));
verify(iamService, never()).registerIssuedSession(anyString(), anyString(), anyString(),
anyString(), any(), any(), anyString(), any());
}
@@ -0,0 +1,25 @@
package io.floci.aws.testing;
import io.quarkus.test.junit.QuarkusTestProfile;
import java.util.Map;
/**
* A deployment that enforces IAM policies and has registered permissions boundaries for a
* delegation partner, which is what it takes to see the condition key a delegated role write
* publishes: without enforcement nothing reads it, and without a registration there is no cap to
* publish.
*
* <p>Both overrides are inert for every class that does not ask for this profile, and
* {@link PartnerPermissionBoundaryProfile} covers the cases that need the registration alone.
*/
public class PartnerPermissionBoundaryEnforcementProfile implements QuarkusTestProfile {
@Override
public Map<String, String> getConfigOverrides() {
return Map.of(
"floci.services.iam.enforcement-enabled", "true",
"floci.services.iam.partner-permission-boundaries-path",
"src/test/resources/partner-permission-boundaries.json");
}
}
@@ -0,0 +1,24 @@
package io.floci.aws.testing;
import io.quarkus.test.junit.QuarkusTestProfile;
import java.util.Map;
/**
* A deployment that has registered permissions boundaries for a delegation partner, which AWS does
* by email and this emulator reads from a file.
*
* <p>The one override, {@code floci.services.iam.partner-permission-boundaries-path}, names
* {@code src/test/resources/partner-permission-boundaries.json}, which registers one read-only
* boundary for partner account {@code 000000000001}. Unset, which every other profile leaves it,
* registers nothing and a delegation request carries no boundary, so this is inert for every class
* that does not ask for it.
*/
public class PartnerPermissionBoundaryProfile implements QuarkusTestProfile {
@Override
public Map<String, String> getConfigOverrides() {
return Map.of("floci.services.iam.partner-permission-boundaries-path",
"src/test/resources/partner-permission-boundaries.json");
}
}