mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(iam): generate, claim and answer delegation requests (#5797)
IAM temporary delegation lets an AWS Partner ask a customer for scoped, time-limited access to the customer's account: the partner files a request, the customer claims and answers it, and an accepted request releases an exchange token the partner trades for credentials. Floci dispatched none of it, so all seven lifecycle operations answered UnsupportedOperation 400. The family was filed as a non-goal on the strength of CreateDelegationRequest stating "This API is not available for general use. In order to use this API, a caller first need to go through an onboarding process described in the partner onboarding documentation". That sentence appears exactly once in the whole API reference, and the partner user guide describes a generally available feature with a published lifecycle. The gate is an AWS-side account allowlist for ISV Accelerate partners, "Enable API access for your specified accounts", not a protocol behaviour, and an emulator has no allowlist. Answering NoSuchEntity because nothing can exist would emulate the feature's absence rather than the feature. This is the lifecycle half: Create, Associate, Accept, Reject, Update, Get and List. SendDelegationToken and STS GetDelegatedAccessToken are the token exchange and come next, so no request reaches FINALIZED yet, and GetHumanReadableSummary stays undispatched because its summary is LLM- generated on AWS. A delegation request is the one IAM record two accounts share, which decides how it is stored: keyed by id under the creating account and resolved across accounts on read, because the reference makes the id globally resolvable and decides access from the request's own owner fields. A request nobody owns "can be called by any account"; one naming a target account is readable only from there, which is why a partner loses sight of its own filing once it is aimed. Floci decides that at account granularity, there being no per- identity permission on a request to consult. ListDelegationRequests leaves out a request with no owner even when it names the listing account, as the reference states, so a partner does not list its own filings at all, which matches the guide telling partners to track state from the notifications. Expiry is applied when a request is next read rather than swept by a worker. Each state carries the window AWS publishes, a day for UNASSIGNED and a week for every other state including the terminal ones, and a request past its window reads back as EXPIRED. That needs no scheduler to be correct and no clock to be mocked globally, so the service takes its own Clock and the unit test advances that rather than the shared test clock. Two answers had to be chosen rather than read off. An operation asked to move a request out of a state it no longer holds answers ConcurrentModification: no modeled error says "wrong state", and AcceptDelegationRequest models only NoSuchEntity, ServiceFailure and ConcurrentModification, so the conflict is the closest of the three and is used on all four writers rather than a different code each. PermissionCheckResult answers UNSURE when the check is asked for, which the enum models, because a delegation request carries no permission to evaluate. A member that breaks the format or constraints it declares answers ValidationError. The reference publishes that as a common error, "the input doesn't meet the required format or constraints", for every IAM operation while listing it on no operation at all, which is why it appears in no error table and in none of these; the rest of IAM answers it in the same shape and wording, so these operations do too. The InvalidInput they do model is kept for a value that cannot be read as the member's type, which is where the shared pagination already puts a MaxItems that is not a number. A lifecycle call reads a request, checks its state and writes it back, so all of them take one lock, as the sibling IAM services do with theirs. Without it two callers could both claim the same unassigned request and the later write would decide the owner, and two creates could both pass the workflow-id uniqueness check. Each call also takes a single clock reading, threaded from the lookup into the transition, so a request cannot be expired on the way in and moved on anyway. Two shape details come from the pinned botocore model rather than the reference PDF, which omits both: GetDelegationRequest also takes DelegationPermissionCheck and answers PermissionCheckStatus and PermissionCheckResult, and ListDelegationRequests spells its flag isTruncated in lower case where every other IAM list spells it IsTruncated. The model names the member, so the wire follows the model. SessionDuration's 300 to 43200 range, PolicyParameter's shape and the 100-default, 1000-maximum page size come from there too. The CLI reference supplies the constraints the PDF leaves hard to read: the redirect URL's whole pattern, which the PDF breaks across a line, the character class the free-text members carry, and the printable-ASCII class on a policy parameter's name and values. Each is enforced. It also settles that the Permissions structure is required while both of its members are optional, marking neither. Reading it is what caught an empty required member being treated as an omission: Description is required and its pattern permits an empty string, so Description= is a value and only an absent member is missing, which is a distinction that exists on the wire and is tested there. Notes and RejectionReason both exist on the shape and each gets exactly one writer: an update carries notes for an administrator and a rejection carries the explanation the reference describes for it. An indexed member is read from the keys the request carries rather than counted up from one, so Parameters.member.2 without a member.1 keeps its entry instead of being dropped at the gap, and a boolean member has to carry true or false rather than being read as false for anything else. delegation-request leaves ResourceArnBuilder.UNRESOLVED_TYPES, since that entry claimed the type belongs only to actions nothing dispatches. The four by-id actions mint arn:<partition>:iam::<account>:delegation-request/<id> from the request, the same way the ARN-carrying actions pass an ARN through, one step earlier. CreateDelegationRequest stays at the wildcard because IAM assigns the id, and UpdateDelegationRequest stays there because AWS publishes no authorizable action for it at all. UnresolvedResourceTypesIntegrationTest would have failed until this was done, which is that test working as intended. The console deep link follows the partition too. CreateDelegationRequest answers the URL the partner redirects the customer to, and a caller in China or GovCloud was handed a console their account cannot reach. The host now comes from the region's partition, the way the CodePipeline approval links already resolve theirs, keeping the commercial console's path because that is the only path any partition publishes. The account-root stand-in behind an owner ARN is minted through RegionResolver for the same reason rather than concatenated, which is also the shape IamEnforcementFilter synthesizes. Nothing is enforced that AWS does not publish. LimitExceeded is modeled with no quota behind it, so none is invented. NotificationChannel is validated and stored and nothing reads it, there being no notification to send yet. PolicyTemplateArn is kept as given and resolved against nothing, templates being registered by email with no API. All four new model types are registered for reflection, the state enum included: it is reachable from a stored request, and a native image that cannot read it back loses every delegation request on restart, which is what the persistence guard checks. Twenty-seven unit tests drive the state machine, both expiry windows, the two races and the deep link in each partition, with a clock the test owns, and fifteen integration tests drive the lifecycle over the wire across two accounts, the access key id being the account id as the rest of the suite does it. Routing needs nothing added: #5879 has the Query router read each service's actions from its botocore model, which names all seven already, so the matrix row in docs/services/index.md moving 167 to 174 is the only count this changes.
This commit is contained in:
1 parent
f9bd725b51
commit
66fce77bdc
14 files changed
+1870
-8
No files matched your search
+339
@@ -0,0 +1,339 @@
|
||||
package io.github.hectorvent.floci.services.iam;
|
||||
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
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.hamcrest.Matchers.startsWith;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* The delegation request lifecycle over the wire, across the two accounts it spans.
|
||||
*
|
||||
* <p>The partner files the request and the customer claims and answers it, so each call is signed
|
||||
* with the account that would make it: the access key id is the account id, which is how the rest
|
||||
* of the suite switches accounts.
|
||||
*/
|
||||
@QuarkusTest
|
||||
class DelegationRequestIntegrationTest {
|
||||
|
||||
private static final String PARTNER = "000000000001";
|
||||
private static final String CUSTOMER = "000000000002";
|
||||
private static final String PARTNER_AUTH = "AWS4-HMAC-SHA256 Credential=" + PARTNER
|
||||
+ "/20261011/us-east-1/iam/aws4_request, SignedHeaders=host, Signature=abc";
|
||||
private static final String CUSTOMER_AUTH = "AWS4-HMAC-SHA256 Credential=" + CUSTOMER
|
||||
+ "/20261011/us-east-1/iam/aws4_request, SignedHeaders=host, Signature=abc";
|
||||
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 String workflowId() {
|
||||
return "workflow-" + Long.toString(System.nanoTime(), 36);
|
||||
}
|
||||
|
||||
private static RequestSpecification iam(String authorization) {
|
||||
return given().header("Authorization", authorization);
|
||||
}
|
||||
|
||||
private static ValidatableResponse create(String workflowId, String ownerAccountId,
|
||||
String sessionDuration) {
|
||||
RequestSpecification request = iam(PARTNER_AUTH)
|
||||
.formParam("Action", "CreateDelegationRequest")
|
||||
.formParam("Version", "2010-05-08")
|
||||
.formParam("Description", "Set up the integration")
|
||||
.formParam("NotificationChannel", TOPIC)
|
||||
.formParam("RequestorWorkflowId", workflowId)
|
||||
.formParam("SessionDuration", sessionDuration)
|
||||
.formParam("Permissions.PolicyTemplateArn", TEMPLATE)
|
||||
.formParam("Permissions.Parameters.member.1.Name", "BucketName")
|
||||
.formParam("Permissions.Parameters.member.1.Type", "string")
|
||||
.formParam("Permissions.Parameters.member.1.Values.member.1", "example-bucket");
|
||||
if (ownerAccountId != null) {
|
||||
request = request.formParam("OwnerAccountId", ownerAccountId);
|
||||
}
|
||||
return request.when().post("/").then();
|
||||
}
|
||||
|
||||
private static String createdId() {
|
||||
return create(workflowId(), null, "3600").statusCode(200)
|
||||
.extract().path("CreateDelegationRequestResponse.CreateDelegationRequestResult"
|
||||
+ ".DelegationRequestId");
|
||||
}
|
||||
|
||||
private static ValidatableResponse byId(String authorization, String action, String id) {
|
||||
return iam(authorization)
|
||||
.formParam("Action", action)
|
||||
.formParam("Version", "2010-05-08")
|
||||
.formParam("DelegationRequestId", id)
|
||||
.when().post("/").then();
|
||||
}
|
||||
|
||||
private static ValidatableResponse get(String authorization, String id) {
|
||||
return byId(authorization, "GetDelegationRequest", id).statusCode(200);
|
||||
}
|
||||
|
||||
private static String stateOf(String authorization, String id) {
|
||||
return get(authorization, id).extract()
|
||||
.path("GetDelegationRequestResponse.GetDelegationRequestResult.DelegationRequest.State");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAnswersAnIdAndADeepLinkAndStartsUnassigned() {
|
||||
ValidatableResponse created = create(workflowId(), null, "3600").statusCode(200);
|
||||
|
||||
String id = created.extract().path("CreateDelegationRequestResponse"
|
||||
+ ".CreateDelegationRequestResult.DelegationRequestId");
|
||||
created.body("CreateDelegationRequestResponse.CreateDelegationRequestResult"
|
||||
+ ".ConsoleDeepLink", containsString(id));
|
||||
assertTrue(id.startsWith("dr-"), "the reference's own examples prefix the id with dr-");
|
||||
assertEquals("UNASSIGNED", stateOf(PARTNER_AUTH, id));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theRequestCarriesBackWhatItWasFiledWith() {
|
||||
String id = createdId();
|
||||
|
||||
get(PARTNER_AUTH, id)
|
||||
.body("GetDelegationRequestResponse.GetDelegationRequestResult.DelegationRequest"
|
||||
+ ".Description", equalTo("Set up the integration"))
|
||||
.body("GetDelegationRequestResponse.GetDelegationRequestResult.DelegationRequest"
|
||||
+ ".SessionDuration", equalTo("3600"))
|
||||
.body("GetDelegationRequestResponse.GetDelegationRequestResult.DelegationRequest"
|
||||
+ ".RequestorId", equalTo(PARTNER))
|
||||
.body("GetDelegationRequestResponse.GetDelegationRequestResult.DelegationRequest"
|
||||
+ ".Permissions.PolicyTemplateArn", equalTo(TEMPLATE))
|
||||
.body("GetDelegationRequestResponse.GetDelegationRequestResult.DelegationRequest"
|
||||
+ ".Permissions.Parameters.member.Name", equalTo("BucketName"))
|
||||
.body("GetDelegationRequestResponse.GetDelegationRequestResult.DelegationRequest"
|
||||
+ ".Permissions.Parameters.member.Values.member", equalTo("example-bucket"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void theCustomerClaimsApprovesAndIsRecordedAsOwnerAndApprover() {
|
||||
String id = createdId();
|
||||
|
||||
byId(CUSTOMER_AUTH, "AssociateDelegationRequest", id).statusCode(200);
|
||||
assertEquals("ASSIGNED", stateOf(CUSTOMER_AUTH, id));
|
||||
get(CUSTOMER_AUTH, id).body("GetDelegationRequestResponse.GetDelegationRequestResult"
|
||||
+ ".DelegationRequest.OwnerAccountId", equalTo(CUSTOMER));
|
||||
|
||||
byId(CUSTOMER_AUTH, "AcceptDelegationRequest", id).statusCode(200);
|
||||
assertEquals("ACCEPTED", stateOf(CUSTOMER_AUTH, id));
|
||||
get(CUSTOMER_AUTH, id).body("GetDelegationRequestResponse.GetDelegationRequestResult"
|
||||
+ ".DelegationRequest.ApproverId", startsWith("arn:aws:iam::" + CUSTOMER + ":"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUpdateForwardsForApprovalAndKeepsItsNotes() {
|
||||
String id = createdId();
|
||||
byId(CUSTOMER_AUTH, "AssociateDelegationRequest", id).statusCode(200);
|
||||
|
||||
iam(CUSTOMER_AUTH)
|
||||
.formParam("Action", "UpdateDelegationRequest")
|
||||
.formParam("DelegationRequestId", id)
|
||||
.formParam("Notes", "please review")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
assertEquals("PENDING_APPROVAL", stateOf(CUSTOMER_AUTH, id));
|
||||
get(CUSTOMER_AUTH, id).body("GetDelegationRequestResponse.GetDelegationRequestResult"
|
||||
+ ".DelegationRequest.Notes", equalTo("please review"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectionKeepsItsReasonAndClosesTheRequest() {
|
||||
String id = createdId();
|
||||
byId(CUSTOMER_AUTH, "AssociateDelegationRequest", id).statusCode(200);
|
||||
|
||||
iam(CUSTOMER_AUTH)
|
||||
.formParam("Action", "RejectDelegationRequest")
|
||||
.formParam("DelegationRequestId", id)
|
||||
.formParam("Notes", "not this quarter")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
assertEquals("REJECTED", stateOf(CUSTOMER_AUTH, id));
|
||||
get(CUSTOMER_AUTH, id).body("GetDelegationRequestResponse.GetDelegationRequestResult"
|
||||
+ ".DelegationRequest.RejectionReason", equalTo("not this quarter"));
|
||||
byId(CUSTOMER_AUTH, "AcceptDelegationRequest", id)
|
||||
.statusCode(409)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ConcurrentModification"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRequestAimedAtOneAccountIsNotFoundFromAnother() {
|
||||
String id = create(workflowId(), CUSTOMER, "3600").statusCode(200)
|
||||
.extract().path("CreateDelegationRequestResponse"
|
||||
+ ".CreateDelegationRequestResult.DelegationRequestId");
|
||||
|
||||
// The partner filed it, and once it names a target account only that account sees it.
|
||||
byId(PARTNER_AUTH, "GetDelegationRequest", id)
|
||||
.statusCode(404)
|
||||
.body("ErrorResponse.Error.Code", equalTo("NoSuchEntity"));
|
||||
assertEquals("UNASSIGNED", stateOf(CUSTOMER_AUTH, id));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listingShowsTheClaimedRequestAndSpellsIsTruncatedTheWayTheModelDoes() {
|
||||
String claimed = createdId();
|
||||
byId(CUSTOMER_AUTH, "AssociateDelegationRequest", claimed).statusCode(200);
|
||||
String unclaimed = createdId();
|
||||
|
||||
ValidatableResponse listed = iam(CUSTOMER_AUTH)
|
||||
.formParam("Action", "ListDelegationRequests")
|
||||
.formParam("Version", "2010-05-08")
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
List<String> ids = listed.extract().xmlPath().getList(
|
||||
"ListDelegationRequestsResponse.ListDelegationRequestsResult.DelegationRequests"
|
||||
+ ".member.DelegationRequestId");
|
||||
assertTrue(ids.contains(claimed), "the claimed request is the customer's to list");
|
||||
assertTrue(!ids.contains(unclaimed),
|
||||
"an unowned request is left out even when any account could read it by id");
|
||||
// Lower-cased on this one operation, which is how the model names the member.
|
||||
listed.body("ListDelegationRequestsResponse.ListDelegationRequestsResult.isTruncated",
|
||||
equalTo("false"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void thePermissionCheckIsOnlyAnsweredWhenItIsAskedFor() {
|
||||
String id = createdId();
|
||||
|
||||
// Asserted on the body rather than the path: an absent element reads back as an empty
|
||||
// string through XmlPath, which would pass against a present but empty one.
|
||||
get(PARTNER_AUTH, id).body(not(containsString("PermissionCheckStatus")));
|
||||
|
||||
iam(PARTNER_AUTH)
|
||||
.formParam("Action", "GetDelegationRequest")
|
||||
.formParam("DelegationRequestId", id)
|
||||
.formParam("DelegationPermissionCheck", "true")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.body("GetDelegationRequestResponse.GetDelegationRequestResult"
|
||||
+ ".PermissionCheckStatus", equalTo("COMPLETE"))
|
||||
// A delegation request carries no permission for Floci to evaluate, and the enum
|
||||
// models UNSURE for exactly that.
|
||||
.body("GetDelegationRequestResponse.GetDelegationRequestResult"
|
||||
+ ".PermissionCheckResult", equalTo("UNSURE"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnknownRequestIsNoSuchEntity() {
|
||||
byId(PARTNER_AUTH, "GetDelegationRequest", "dr-000000000000000000000000")
|
||||
.statusCode(404)
|
||||
.body("ErrorResponse.Error.Code", equalTo("NoSuchEntity"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aMalformedIdIsAValidationErrorAsAnywhereElseInIam() {
|
||||
// ValidationError is a common error in the reference, published for every IAM operation
|
||||
// and listed on none of them, so a member that breaks its own pattern is refused with it
|
||||
// here too rather than with the InvalidInput these operations happen to model.
|
||||
byId(PARTNER_AUTH, "GetDelegationRequest", "dr-short")
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aReusedWorkflowIdIsRefused() {
|
||||
String workflowId = workflowId();
|
||||
create(workflowId, null, "3600").statusCode(200);
|
||||
|
||||
create(workflowId, null, "3600")
|
||||
.statusCode(409)
|
||||
.body("ErrorResponse.Error.Code", equalTo("EntityAlreadyExists"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anEmptyDescriptionIsAcceptedAndAnAbsentOneIsNot() {
|
||||
// Over the wire is where the two differ: Description= arrives as an empty value and a
|
||||
// missing Description does not arrive at all. The member is required and its pattern ends
|
||||
// in '*' with no minimum, so only the second is an omission.
|
||||
iam(PARTNER_AUTH)
|
||||
.formParam("Action", "CreateDelegationRequest")
|
||||
.formParam("Description", "")
|
||||
.formParam("NotificationChannel", TOPIC)
|
||||
.formParam("RequestorWorkflowId", workflowId())
|
||||
.formParam("SessionDuration", "3600")
|
||||
.formParam("Permissions.PolicyTemplateArn", TEMPLATE)
|
||||
.when().post("/").then().statusCode(200);
|
||||
|
||||
iam(PARTNER_AUTH)
|
||||
.formParam("Action", "CreateDelegationRequest")
|
||||
.formParam("NotificationChannel", TOPIC)
|
||||
.formParam("RequestorWorkflowId", workflowId())
|
||||
.formParam("SessionDuration", "3600")
|
||||
.formParam("Permissions.PolicyTemplateArn", TEMPLATE)
|
||||
.when().post("/").then()
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void sessionDurationOutsideTheModelsRangeIsRefused() {
|
||||
create(workflowId(), null, "60")
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("ValidationError"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aBooleanMemberHasToCarryABoolean() {
|
||||
// Boolean.valueOf would read anything at all as false, which would store a value the
|
||||
// caller never sent. The Query protocol writes true or false, so nothing else is a value
|
||||
// the member can carry, and it is refused the way a malformed number is.
|
||||
iam(PARTNER_AUTH)
|
||||
.formParam("Action", "CreateDelegationRequest")
|
||||
.formParam("Description", "d")
|
||||
.formParam("NotificationChannel", TOPIC)
|
||||
.formParam("RequestorWorkflowId", workflowId())
|
||||
.formParam("SessionDuration", "3600")
|
||||
.formParam("Permissions.PolicyTemplateArn", TEMPLATE)
|
||||
.formParam("OnlySendByOwner", "yes")
|
||||
.when().post("/").then()
|
||||
.statusCode(400)
|
||||
.body("ErrorResponse.Error.Code", equalTo("InvalidInput"))
|
||||
.body("ErrorResponse.Error.Message", containsString("Member must be a boolean"));
|
||||
|
||||
iam(PARTNER_AUTH)
|
||||
.formParam("Action", "CreateDelegationRequest")
|
||||
.formParam("Description", "d")
|
||||
.formParam("NotificationChannel", TOPIC)
|
||||
.formParam("RequestorWorkflowId", workflowId())
|
||||
.formParam("SessionDuration", "3600")
|
||||
.formParam("Permissions.PolicyTemplateArn", TEMPLATE)
|
||||
.formParam("OnlySendByOwner", "TRUE")
|
||||
.when().post("/").then().statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void aPolicyParameterListNumberedFromTwoKeepsItsEntries() {
|
||||
// An indexed list read by counting up from one stops at the first index that is missing,
|
||||
// which would accept the request and drop what it carried.
|
||||
String id = iam(PARTNER_AUTH)
|
||||
.formParam("Action", "CreateDelegationRequest")
|
||||
.formParam("Description", "d")
|
||||
.formParam("NotificationChannel", TOPIC)
|
||||
.formParam("RequestorWorkflowId", workflowId())
|
||||
.formParam("SessionDuration", "3600")
|
||||
.formParam("Permissions.PolicyTemplateArn", TEMPLATE)
|
||||
.formParam("Permissions.Parameters.member.2.Name", "BucketName")
|
||||
.formParam("Permissions.Parameters.member.2.Type", "string")
|
||||
.formParam("Permissions.Parameters.member.2.Values.member.3", "reports")
|
||||
.when().post("/").then().statusCode(200)
|
||||
.extract().path("CreateDelegationRequestResponse.CreateDelegationRequestResult"
|
||||
+ ".DelegationRequestId");
|
||||
|
||||
byId(PARTNER_AUTH, "GetDelegationRequest", id)
|
||||
.statusCode(200)
|
||||
.body("GetDelegationRequestResponse.GetDelegationRequestResult"
|
||||
+ ".DelegationRequest.Permissions.Parameters.member.Name",
|
||||
equalTo("BucketName"))
|
||||
.body("GetDelegationRequestResponse.GetDelegationRequestResult"
|
||||
+ ".DelegationRequest.Permissions.Parameters.member.Values.member",
|
||||
equalTo("reports"));
|
||||
}
|
||||
}
|
||||
+422
@@ -0,0 +1,422 @@
|
||||
package io.github.hectorvent.floci.services.iam;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.AccountAwareStorageBackend;
|
||||
import io.github.hectorvent.floci.services.iam.model.DelegationPermission;
|
||||
import io.github.hectorvent.floci.services.iam.model.DelegationRequest;
|
||||
import io.github.hectorvent.floci.services.iam.model.DelegationRequestState;
|
||||
import io.github.hectorvent.floci.services.iam.model.PolicyParameter;
|
||||
import io.github.hectorvent.floci.testing.MutableClock;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* The state machine and both expiry windows, driven with a clock this test owns.
|
||||
*
|
||||
* <p>Expiry is the half that cannot be driven over the wire without waiting a day, so the service
|
||||
* takes its own {@link java.time.Clock} and this advances it. The global test clock is deliberately
|
||||
* not touched: it is shared by every class in the Quarkus instance.
|
||||
*/
|
||||
class DelegationRequestServiceTest {
|
||||
|
||||
private static final String PARTNER = "000000000001";
|
||||
private static final String CUSTOMER = "000000000002";
|
||||
private static final String CUSTOMER_ARN = "arn:aws:iam::000000000002:user/admin";
|
||||
private static final String REGION = "us-east-1";
|
||||
|
||||
/** Enough trials and racers to surface an unguarded read-then-write reliably. */
|
||||
private static final int TRIALS = 50;
|
||||
private static final int RACERS = 8;
|
||||
|
||||
private MutableClock clock;
|
||||
private DelegationRequestService service;
|
||||
|
||||
@BeforeEach
|
||||
void setUp() {
|
||||
clock = new MutableClock();
|
||||
service = new DelegationRequestService(
|
||||
AccountAwareStorageBackend.inMemory(PARTNER), clock);
|
||||
}
|
||||
|
||||
private DelegationRequestService.Created createdIn(String region, String workflowId,
|
||||
String ownerAccountId) {
|
||||
return service.create(PARTNER, region, new DelegationRequestService.NewRequest(
|
||||
"Set up the integration", "arn:aws:sns:us-east-1:000000000001:partner-notifications",
|
||||
workflowId, 3600,
|
||||
new DelegationPermission("arn:aws:iam::partner:policy/template/example",
|
||||
List.of(new PolicyParameter("BucketName", PolicyParameter.TYPE_STRING,
|
||||
List.of("example-bucket")))),
|
||||
ownerAccountId, null, null, null));
|
||||
}
|
||||
|
||||
private DelegationRequest created(String workflowId, String ownerAccountId) {
|
||||
return createdIn(REGION, workflowId, ownerAccountId).request();
|
||||
}
|
||||
|
||||
private DelegationRequest assigned(String workflowId) {
|
||||
DelegationRequest request = created(workflowId, null);
|
||||
return service.associate(CUSTOMER, CUSTOMER_ARN, request.getDelegationRequestId());
|
||||
}
|
||||
|
||||
/**
|
||||
* The deep link lands on the console host of the request's own partition, so a partner in
|
||||
* China or GovCloud redirects the customer to a console that exists there. The China and
|
||||
* GovCloud user guides state a host; the EUSC and ISO partitions publish none and keep the
|
||||
* commercial one.
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"us-east-1, console.aws.amazon.com",
|
||||
"cn-north-1, console.amazonaws.cn",
|
||||
"us-gov-west-1, console.amazonaws-us-gov.com",
|
||||
"eusc-de-east-1, console.aws.amazon.com",
|
||||
"us-iso-east-1, console.aws.amazon.com"})
|
||||
void theDeepLinkPointsAtTheConsoleHostOfTheRequestsPartition(String region, String host) {
|
||||
DelegationRequestService.Created created = createdIn(region, "workflow-1", null);
|
||||
|
||||
assertEquals("https://" + host + "/iam/home?region=" + region + "#/delegation_requests/"
|
||||
+ created.request().getDelegationRequestId(), created.consoleDeepLink());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aNewRequestStartsUnassignedAndExpiresInADay() {
|
||||
DelegationRequest request = created("workflow-1", null);
|
||||
|
||||
assertEquals(DelegationRequestState.UNASSIGNED, request.getState());
|
||||
assertTrue(request.getDelegationRequestId().startsWith("dr-"));
|
||||
assertEquals(PARTNER, request.getRequestorId());
|
||||
assertEquals(request.getCreateDate().plus(Duration.ofDays(1)), request.getExpirationTime());
|
||||
// Nothing registers a partner name, so none is invented.
|
||||
assertNull(request.getRequestorName());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUnclaimedRequestIsExpiredAfterADay() {
|
||||
String id = created("workflow-1", null).getDelegationRequestId();
|
||||
|
||||
clock.advance(Duration.ofHours(23));
|
||||
assertEquals(DelegationRequestState.UNASSIGNED, service.get(CUSTOMER, id).getState());
|
||||
|
||||
clock.advance(Duration.ofHours(2));
|
||||
assertEquals(DelegationRequestState.EXPIRED, service.get(CUSTOMER, id).getState());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aClaimedRequestGetsTheWeekTheReferenceGivesIt() {
|
||||
String id = assigned("workflow-1").getDelegationRequestId();
|
||||
|
||||
// Past the one-day window the request would have had while unclaimed.
|
||||
clock.advance(Duration.ofDays(6));
|
||||
assertEquals(DelegationRequestState.ASSIGNED, service.get(CUSTOMER, id).getState());
|
||||
|
||||
clock.advance(Duration.ofDays(2));
|
||||
assertEquals(DelegationRequestState.EXPIRED, service.get(CUSTOMER, id).getState());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anExpiredRequestCannotBeClaimedOrApproved() {
|
||||
String id = created("workflow-1", null).getDelegationRequestId();
|
||||
clock.advance(Duration.ofDays(2));
|
||||
|
||||
assertEquals("ConcurrentModification", assertThrows(AwsException.class,
|
||||
() -> service.associate(CUSTOMER, CUSTOMER_ARN, id)).getErrorCode());
|
||||
assertEquals("ConcurrentModification", assertThrows(AwsException.class,
|
||||
() -> service.accept(CUSTOMER, CUSTOMER_ARN, id)).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void claimingSetsTheOwnerAndMovesToAssigned() {
|
||||
DelegationRequest request = assigned("workflow-1");
|
||||
|
||||
assertEquals(DelegationRequestState.ASSIGNED, request.getState());
|
||||
assertEquals(CUSTOMER, request.getOwnerAccountId());
|
||||
assertEquals(CUSTOMER_ARN, request.getOwnerId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRequestCanOnlyBeClaimedOnce() {
|
||||
DelegationRequest request = assigned("workflow-1");
|
||||
|
||||
assertEquals("ConcurrentModification", assertThrows(AwsException.class,
|
||||
() -> service.associate(CUSTOMER, CUSTOMER_ARN,
|
||||
request.getDelegationRequestId())).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRequestAimedAtOneAccountIsInvisibleFromAnother() {
|
||||
String id = created("workflow-1", CUSTOMER).getDelegationRequestId();
|
||||
|
||||
// Not a refusal naming it: the reference lets only the target account see it at all.
|
||||
assertEquals("NoSuchEntity", assertThrows(AwsException.class,
|
||||
() -> service.get("000000000003", id)).getErrorCode());
|
||||
assertEquals(DelegationRequestState.UNASSIGNED, service.get(CUSTOMER, id).getState());
|
||||
}
|
||||
|
||||
@Test
|
||||
void approvingRecordsTheApprover() {
|
||||
DelegationRequest request = assigned("workflow-1");
|
||||
|
||||
DelegationRequest accepted = service.accept(CUSTOMER, CUSTOMER_ARN,
|
||||
request.getDelegationRequestId());
|
||||
|
||||
assertEquals(DelegationRequestState.ACCEPTED, accepted.getState());
|
||||
assertEquals(CUSTOMER_ARN, accepted.getApproverId());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anUpdateForwardsForApprovalAndThenAcceptanceWorks() {
|
||||
DelegationRequest request = assigned("workflow-1");
|
||||
|
||||
DelegationRequest updated = service.update(CUSTOMER,
|
||||
request.getDelegationRequestId(), "please review");
|
||||
|
||||
assertEquals(DelegationRequestState.PENDING_APPROVAL, updated.getState());
|
||||
assertEquals("please review", updated.getNotes());
|
||||
assertEquals(DelegationRequestState.ACCEPTED, service.accept(CUSTOMER, CUSTOMER_ARN,
|
||||
request.getDelegationRequestId()).getState());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectionKeepsItsExplanationAndIsFinal() {
|
||||
DelegationRequest request = assigned("workflow-1");
|
||||
String id = request.getDelegationRequestId();
|
||||
|
||||
DelegationRequest rejected = service.reject(CUSTOMER, id, "not this quarter");
|
||||
|
||||
assertEquals(DelegationRequestState.REJECTED, rejected.getState());
|
||||
// Reject's notes are the explanation, which is the one writer of RejectionReason.
|
||||
assertEquals("not this quarter", rejected.getRejectionReason());
|
||||
assertNull(rejected.getNotes());
|
||||
// "Once a request is rejected, it cannot be accepted or updated later."
|
||||
assertEquals("ConcurrentModification", assertThrows(AwsException.class,
|
||||
() -> service.accept(CUSTOMER, CUSTOMER_ARN, id)).getErrorCode());
|
||||
assertEquals("ConcurrentModification", assertThrows(AwsException.class,
|
||||
() -> service.update(CUSTOMER, id, "reopen")).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aWorkflowIdCannotBeReusedByThePartnerThatHoldsIt() {
|
||||
created("workflow-1", null);
|
||||
|
||||
assertEquals("EntityAlreadyExists", assertThrows(AwsException.class,
|
||||
() -> created("workflow-1", null)).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aWorkflowIdStaysTakenAfterTheRequestExpires() {
|
||||
created("workflow-1", null);
|
||||
clock.advance(Duration.ofDays(30));
|
||||
|
||||
// The reference qualifies the uniqueness check by existence, not by state.
|
||||
assertEquals("EntityAlreadyExists", assertThrows(AwsException.class,
|
||||
() -> created("workflow-1", null)).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void sessionDurationIsHeldToTheRangeTheModelPublishes() {
|
||||
assertEquals("ValidationError", assertThrows(AwsException.class, () -> service.create(PARTNER,
|
||||
REGION, new DelegationRequestService.NewRequest("d", "topic", "workflow-1", 299,
|
||||
new DelegationPermission(null, List.of()), null, null, null, null)))
|
||||
.getErrorCode());
|
||||
assertEquals("ValidationError", assertThrows(AwsException.class, () -> service.create(PARTNER,
|
||||
REGION, new DelegationRequestService.NewRequest("d", "topic", "workflow-2", 43201,
|
||||
new DelegationPermission(null, List.of()), null, null, null, null)))
|
||||
.getErrorCode());
|
||||
assertNotNull(service.create(PARTNER, REGION, new DelegationRequestService.NewRequest(
|
||||
"d", "topic", "workflow-3", 300, new DelegationPermission(null, List.of()),
|
||||
null, null, null, null)).request());
|
||||
}
|
||||
|
||||
@Test
|
||||
void theRequiredMembersAreRequired() {
|
||||
assertEquals("ValidationError", assertThrows(AwsException.class, () -> service.create(PARTNER,
|
||||
REGION, new DelegationRequestService.NewRequest(null, "topic", "workflow-1", 3600,
|
||||
new DelegationPermission(null, List.of()), null, null, null, null)))
|
||||
.getErrorCode());
|
||||
assertEquals("ValidationError", assertThrows(AwsException.class, () -> service.create(PARTNER,
|
||||
REGION, new DelegationRequestService.NewRequest("d", "topic", "workflow-1", 3600,
|
||||
null, null, null, null, null))).getErrorCode());
|
||||
}
|
||||
|
||||
private AwsException refusedCreate(String description, String workflowId,
|
||||
String redirectUrl, DelegationPermission permissions) {
|
||||
return assertThrows(AwsException.class, () -> service.create(PARTNER, REGION,
|
||||
new DelegationRequestService.NewRequest(description, "topic", workflowId, 3600,
|
||||
permissions, null, redirectUrl, null, null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void anEmptyDescriptionIsAValueRatherThanAnOmission() {
|
||||
// Description is required and its pattern ends in '*' with no minimum, so an empty value
|
||||
// is inside the constraints AWS publishes and is not the same as leaving it out.
|
||||
DelegationRequest request = service.create(PARTNER, REGION,
|
||||
new DelegationRequestService.NewRequest("", "topic", "workflow-1", 3600,
|
||||
new DelegationPermission(null, List.of()), null, null, "", null)).request();
|
||||
|
||||
assertEquals("", request.getDescription());
|
||||
assertEquals("ValidationError", refusedCreate(null, "workflow-2", null,
|
||||
new DelegationPermission(null, List.of())).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void freeTextIsHeldToTheClassTheMembersDeclare() {
|
||||
// The class covers tab, newline, carriage return and the printable range, so a NUL is out.
|
||||
assertEquals("ValidationError", refusedCreate("bad \u0000 text", "workflow-1", null,
|
||||
new DelegationPermission(null, List.of())).getErrorCode());
|
||||
assertNotNull(service.create(PARTNER, REGION, new DelegationRequestService.NewRequest(
|
||||
"line one\nline two\ttabbed", "topic", "workflow-2", 3600,
|
||||
new DelegationPermission(null, List.of()), null, null, null, null)).request());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aRedirectUrlHasToLookLikeOne() {
|
||||
assertEquals("ValidationError", refusedCreate("d", "workflow-1", "not-a-url",
|
||||
new DelegationPermission(null, List.of())).getErrorCode());
|
||||
assertNotNull(service.create(PARTNER, REGION, new DelegationRequestService.NewRequest(
|
||||
"d", "topic", "workflow-2", 3600, new DelegationPermission(null, List.of()),
|
||||
null, "https://partner.example.com/resume?workflow=12345", null, null)).request());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aPolicyParameterIsHeldToPrintableAscii() {
|
||||
assertEquals("ValidationError", refusedCreate("d", "workflow-1", null,
|
||||
new DelegationPermission(null, List.of(
|
||||
new PolicyParameter("BucketName", PolicyParameter.TYPE_STRING,
|
||||
List.of("bad \u0001 value"))))).getErrorCode());
|
||||
assertEquals("ValidationError", refusedCreate("d", "workflow-2", null,
|
||||
new DelegationPermission(null, List.of(
|
||||
new PolicyParameter("Name\u0001", PolicyParameter.TYPE_STRING,
|
||||
List.of("fine"))))).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void anOwnerIdFilterIsHeldToItsPattern() {
|
||||
assertEquals("ValidationError", assertThrows(AwsException.class,
|
||||
() -> service.list(CUSTOMER, "not a principal arn at all")).getErrorCode());
|
||||
assertEquals("ValidationError", assertThrows(AwsException.class,
|
||||
() -> service.list(CUSTOMER, "short")).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void listingShowsOnlyOwnedRequests() {
|
||||
DelegationRequest claimed = assigned("workflow-1");
|
||||
created("workflow-2", null);
|
||||
|
||||
List<DelegationRequest> listed = service.list(CUSTOMER, null);
|
||||
|
||||
// An unowned request is left out even though any account could read it by id.
|
||||
assertEquals(List.of(claimed.getDelegationRequestId()),
|
||||
listed.stream().map(DelegationRequest::getDelegationRequestId).toList());
|
||||
assertEquals(1, service.list(CUSTOMER, CUSTOMER_ARN).size());
|
||||
assertEquals(0, service.list(CUSTOMER, "arn:aws:iam::000000000002:user/someone").size());
|
||||
assertEquals(0, service.list(PARTNER, null).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
void onlyOneOfTwoCallersClaimingAtOnceEndsUpAsTheOwner() throws Exception {
|
||||
// The claim reads the request, checks its state and writes the owner back. Without the
|
||||
// lock around all three both callers pass the check and the later write decides, which is
|
||||
// the race the sibling IAM services guard theirs against.
|
||||
ExecutorService pool = Executors.newFixedThreadPool(RACERS);
|
||||
try {
|
||||
for (int trial = 0; trial < TRIALS; trial++) {
|
||||
setUp();
|
||||
String id = created("workflow-1", null).getDelegationRequestId();
|
||||
CountDownLatch start = new CountDownLatch(1);
|
||||
CountDownLatch done = new CountDownLatch(RACERS);
|
||||
List<String> owners = new CopyOnWriteArrayList<>();
|
||||
List<String> unexpected = new CopyOnWriteArrayList<>();
|
||||
|
||||
for (int racer = 0; racer < RACERS; racer++) {
|
||||
String arn = CUSTOMER_ARN + racer;
|
||||
pool.execute(() -> {
|
||||
try {
|
||||
start.await(10, TimeUnit.SECONDS);
|
||||
owners.add(service.associate(CUSTOMER, arn, id).getOwnerId());
|
||||
} catch (AwsException e) {
|
||||
if (!"ConcurrentModification".equals(e.getErrorCode())) {
|
||||
unexpected.add(e.getErrorCode());
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
} finally {
|
||||
done.countDown();
|
||||
}
|
||||
});
|
||||
}
|
||||
start.countDown();
|
||||
assertTrue(done.await(30, TimeUnit.SECONDS), "claim workers stalled");
|
||||
|
||||
DelegationRequest stored = service.get(CUSTOMER, id);
|
||||
if (owners.size() != 1 || !owners.contains(stored.getOwnerId())
|
||||
|| stored.getState() != DelegationRequestState.ASSIGNED
|
||||
|| !unexpected.isEmpty()) {
|
||||
fail("claim trial " + trial + ": owners=" + owners + " stored="
|
||||
+ stored.getOwnerId() + " state=" + stored.getState()
|
||||
+ " unexpectedErrors=" + unexpected);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
pool.shutdownNow();
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void onlyOneOfTwoCreatesSharingAWorkflowIdSucceeds() throws Exception {
|
||||
// The uniqueness check and the write that follows it are the same read-then-write, so two
|
||||
// creates racing with one workflow id would otherwise both find it free.
|
||||
ExecutorService pool = Executors.newFixedThreadPool(RACERS);
|
||||
try {
|
||||
for (int trial = 0; trial < TRIALS; trial++) {
|
||||
setUp();
|
||||
CountDownLatch start = new CountDownLatch(1);
|
||||
CountDownLatch done = new CountDownLatch(RACERS);
|
||||
List<String> filed = new CopyOnWriteArrayList<>();
|
||||
List<String> unexpected = new CopyOnWriteArrayList<>();
|
||||
|
||||
for (int racer = 0; racer < RACERS; racer++) {
|
||||
pool.execute(() -> {
|
||||
try {
|
||||
start.await(10, TimeUnit.SECONDS);
|
||||
filed.add(created("workflow-1", null).getDelegationRequestId());
|
||||
} catch (AwsException e) {
|
||||
if (!"EntityAlreadyExists".equals(e.getErrorCode())) {
|
||||
unexpected.add(e.getErrorCode());
|
||||
}
|
||||
} catch (InterruptedException e) {
|
||||
Thread.currentThread().interrupt();
|
||||
} finally {
|
||||
done.countDown();
|
||||
}
|
||||
});
|
||||
}
|
||||
start.countDown();
|
||||
assertTrue(done.await(30, TimeUnit.SECONDS), "create workers stalled");
|
||||
|
||||
if (filed.size() != 1 || !unexpected.isEmpty()) {
|
||||
fail("create trial " + trial + ": filed=" + filed
|
||||
+ " unexpectedErrors=" + unexpected);
|
||||
}
|
||||
}
|
||||
} finally {
|
||||
pool.shutdownNow();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -143,8 +143,10 @@ class IamActionResourcesTest {
|
||||
"policy", "mfa", "sms-mfa", "saml-provider", "oidc-provider",
|
||||
// Named by a parameter that is not an IAM entity name.
|
||||
"access-report",
|
||||
// Derived from an id the request carries.
|
||||
"delegation-request",
|
||||
// Only on actions the handler does not dispatch.
|
||||
"delegation-request", "role-template"),
|
||||
"role-template"),
|
||||
inUse,
|
||||
"AWS has changed which resource types IAM actions are authorized against; "
|
||||
+ "teach ResourceArnBuilder the new one or list it as unresolved");
|
||||
|
||||
@@ -61,7 +61,7 @@ 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);
|
||||
IamQueryHandler handler = new IamQueryHandler(service, null, null, null, null, null, null, null, null);
|
||||
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.putSingle("ServerCertificateName", CERTIFICATE_NAME);
|
||||
@@ -90,7 +90,7 @@ class IamQueryHandlerTest {
|
||||
IamService service = mock(IamService.class);
|
||||
when(service.createRole(ROLE_NAME, "/", "{}", 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);
|
||||
IamQueryHandler handler = new IamQueryHandler(service, null, null, null, null, null, null, null, null);
|
||||
|
||||
MultivaluedMap<String, String> params = new MultivaluedHashMap<>();
|
||||
params.putSingle("RoleName", ROLE_NAME);
|
||||
|
||||
@@ -162,6 +162,32 @@ class ResourceArnBuilderTest {
|
||||
"Action=GetUser&UserName=bob"));
|
||||
}
|
||||
|
||||
/**
|
||||
* The delegation family passes an id where the ARN-carrying actions pass an ARN, so its ARN is
|
||||
* minted from the request. Without this the actions fall back to {@code *} and a policy naming
|
||||
* one request never applies, which is the fail-open {@code UNRESOLVED_TYPES} used to cover
|
||||
* while none of them was dispatched.
|
||||
*/
|
||||
@Test
|
||||
void iamNamesTheDelegationRequestABlockOfActionsActsOn() {
|
||||
String id = "dr-0123456789abcdef01234567";
|
||||
for (String action : List.of("AssociateDelegationRequest", "AcceptDelegationRequest",
|
||||
"RejectDelegationRequest", "GetDelegationRequest")) {
|
||||
assertEquals("arn:aws:iam::000000000000:delegation-request/" + id,
|
||||
resourceOf(builder, "Action=" + action + "&DelegationRequestId=" + id), action);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void iamLeavesADelegationRequestItIsAboutToMintAtTheWildcard() {
|
||||
// IAM assigns the id, so the create names no resource to authorize against.
|
||||
assertEquals("*", resourceOf(builder,
|
||||
"Action=CreateDelegationRequest&Description=d&RequestorWorkflowId=w"));
|
||||
// AWS publishes no authorizable action for the update at all, so it carries no type.
|
||||
assertEquals("*", resourceOf(builder,
|
||||
"Action=UpdateDelegationRequest&DelegationRequestId=dr-0123456789abcdef01234567"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Two entities named, one authorized. The reference gives {@code AddUserToGroup} the group as
|
||||
* its only resource type, so taking the user from the request would scope it to the wrong one
|
||||
|
||||
Reference in new issue
Block a user