mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(iam): check FIS, RAM, OAM and three more services by their REST routes (#8154)
Under enforcement a REST route no rule maps and no vendored model names
runs unchecked. AWS Fault Injection Service, AWS RAM, CloudWatch
Observability Access Manager, AWS Resource Explorer, AWS Account
Management and AWS Control Catalog were among those: none of their 94
served routes had a rule.
Vendors the six models, so each route is checked as its operation's
action, on the resource its request names. A caller holding no grant
for them is now refused where the request used to pass; that is the
behaviour change.
Resource Explorer's five routes that S3 Vectors shares are matched on
the path without the prefix its filter moves them under. The FIS and
Resource Explorer tag routes are the shared controller's and keep its
bare /tags form. OAM's tag routes take the ARN as the rest of the path,
as the controllers serving them do, so an ARN sent with its slash
unencoded is checked too.
The request-resources generator reads these requests with no
hand-written correction, through four rules that hold for any service:
- A bare id after a path segment naming a type names that type:
/safetyLevers/{id}/state is the lever whose state
UpdateSafetyLeverState sets.
- A member fills the variables of a resource's own path before the
account its ARN is in, so Account Management's AccountId is the
member account of an accountInOrganization ARN.
- A type whose ARN is the account alone applies to a request leaving
out its optional account member, when that member names another
type: a request without AccountId acts on the caller's own account.
- A create makes its own type even when a member holds the resources
the action acts on: CreateResourceShare makes the share, and its
resourceArns are what the share holds.
Account Management finds that member account's organization and
management account in the caller's organization, through the lookup
the reader asks a service for the ARNs it stores, so a request naming a
member is checked on the ARN AWS checks.
The first rule also reads four CloudFront web ACL association
operations and four OpenSearch data source attachment operations on the
distribution or application their paths name. Floci serves none of
them.
An ARN fitting both a customer's format and one AWS owns is AWS's, so
an AWS managed permission is not also checked in the caller's account.
Regenerating the tables also brings in what AWS has added since the
last sync: eight Amazon Cognito user pool session operations and eight
Kinesis Analytics snapshot operations, none of which Floci serves. The
snapshot create's tags are read once the pinned botocore has it. The
count of tagged operations in iam.md is now the table's, 589, which
also takes 23 that earlier syncs added without moving it.
This commit is contained in:
1 parent
6b129de242
commit
9f1cccf83f
15 files changed
+971
-61
No files matched your search
@@ -8,10 +8,13 @@ import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
import io.floci.aws.services.account.model.AlternateContact;
|
||||
import io.floci.aws.services.organizations.OrganizationsService;
|
||||
import io.floci.aws.services.organizations.model.Organization;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
@@ -25,6 +28,7 @@ class AccountServiceTest {
|
||||
private static final String ACCOUNT_ID = "123456789012";
|
||||
private final ObjectMapper mapper = new ObjectMapper();
|
||||
private AccountService service;
|
||||
private OrganizationsService organizations;
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings({"unchecked", "rawtypes"})
|
||||
@@ -33,7 +37,8 @@ class AccountServiceTest {
|
||||
AccountAwareStorageBackend<AlternateContact> store = AccountAwareStorageBackend.inMemory(ACCOUNT_ID);
|
||||
when(storageFactory.create(eq("account"), eq("account-alternate-contacts.json"), any(TypeReference.class)))
|
||||
.thenReturn((AccountAwareStorageBackend) store);
|
||||
service = new AccountService(storageFactory, mock(OrganizationsService.class));
|
||||
organizations = mock(OrganizationsService.class);
|
||||
service = new AccountService(storageFactory, organizations);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -77,6 +82,30 @@ class AccountServiceTest {
|
||||
assertEquals("ResourceNotFoundException", deleteError.getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void findsTheMemberAccountOfTheCallersOrganizationARequestNames() {
|
||||
Organization organization = new Organization();
|
||||
organization.setId("o-abcdefghij");
|
||||
organization.setArn("arn:aws:organizations::" + ACCOUNT_ID + ":organization/o-abcdefghij");
|
||||
organization.setMasterAccountId(ACCOUNT_ID);
|
||||
when(organizations.describeOrganization(ACCOUNT_ID)).thenReturn(organization);
|
||||
when(organizations.describeAccount(ACCOUNT_ID, "999988887777"))
|
||||
.thenThrow(new AwsException("AccountNotFoundException", "not a member", 400));
|
||||
|
||||
assertEquals(Optional.of("arn:aws:account::" + ACCOUNT_ID + ":account/o-abcdefghij/111122223333"),
|
||||
service.find("accountInOrganization", List.of("111122223333"), "us-east-1"));
|
||||
// An account the organization does not hold, and another type, find nothing.
|
||||
assertEquals(Optional.empty(), service.find("accountInOrganization", List.of("999988887777"), "us-east-1"));
|
||||
assertEquals(Optional.empty(), service.find("account", List.of("111122223333"), "us-east-1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void findsNoMemberAccountForACallerInNoOrganization() {
|
||||
when(organizations.describeOrganization(ACCOUNT_ID))
|
||||
.thenThrow(new AwsException("AWSOrganizationsNotInUseException", "no organization", 400));
|
||||
assertEquals(Optional.empty(), service.find("accountInOrganization", List.of("111122223333"), "us-east-1"));
|
||||
}
|
||||
|
||||
private ObjectNode contactRequest() {
|
||||
ObjectNode request = mapper.createObjectNode();
|
||||
request.put("AlternateContactType", "SECURITY");
|
||||
|
||||
+307
-1
@@ -3,13 +3,16 @@ package io.floci.aws.services.iam;
|
||||
import io.floci.aws.core.common.XmlParser;
|
||||
import io.floci.aws.testing.EnforcementFixtures;
|
||||
import io.floci.aws.testing.IamEnforcementProfile;
|
||||
import io.floci.aws.testing.OrganizationsRequests;
|
||||
import io.floci.aws.testing.PartitionCleanup;
|
||||
import io.floci.aws.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.common.http.TestHTTPResource;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
import io.restassured.response.Response;
|
||||
import io.restassured.response.ValidatableResponse;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
@@ -17,8 +20,11 @@ import java.net.URI;
|
||||
import java.net.URLEncoder;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.UnaryOperator;
|
||||
|
||||
import static io.floci.aws.testing.EnforcementFixtures.auth;
|
||||
import static io.restassured.RestAssured.given;
|
||||
@@ -36,6 +42,8 @@ class IamRestRouteEnforcementIntegrationTest {
|
||||
|
||||
private static final String ADMIN = "test";
|
||||
private static final String ACCOUNT = "000000000000";
|
||||
/** The management account of an organization of this class's own, which no other test uses. */
|
||||
private static final String MANAGEMENT = "731000000154";
|
||||
|
||||
@TestHTTPResource("/")
|
||||
static URI baseUri;
|
||||
@@ -46,6 +54,11 @@ class IamRestRouteEnforcementIntegrationTest {
|
||||
/** Each user's access key ID, by user name. */
|
||||
private final Map<String, String> keys = new HashMap<>();
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
}
|
||||
|
||||
@Test
|
||||
void apiGatewayManagementRoutesBeyondRestApisAreCheckedByMethod() {
|
||||
String user = user("route-apigateway");
|
||||
@@ -821,6 +834,299 @@ class IamRestRouteEnforcementIntegrationTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void fisRamOamResourceExplorerAccountAndControlCatalogAreCheckedByTheirRoutes() {
|
||||
String user = user("route-governance");
|
||||
|
||||
checkedAs(user, "account", "POST", "/getAlternateContact", "{\"AlternateContactType\":\"BILLING\"}",
|
||||
"account:GetAlternateContact");
|
||||
checkedAs(user, "controlcatalog", "POST", "/list-controls", "{}", "controlcatalog:ListControls");
|
||||
checkedAs(user, "fis", "GET", "/experimentTemplates", null, "fis:ListExperimentTemplates");
|
||||
checkedAs(user, "oam", "POST", "/ListSinks", "{}", "oam:ListSinks");
|
||||
checkedAs(user, "ram", "POST", "/getresourceshares", "{\"resourceOwner\":\"SELF\"}", "ram:GetResourceShares");
|
||||
checkedAs(user, "resource-explorer-2", "POST", "/ListViews", "{}", "resource-explorer-2:ListViews");
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourceExplorerRoutesItsFilterMovesOffSharedPathsAreChecked() {
|
||||
String user = user("route-re2-moved");
|
||||
|
||||
checkedAs(user, "resource-explorer-2", "POST", "/ListIndexes", "{}", "resource-explorer-2:ListIndexes");
|
||||
// AWS authorizes ListResources as Search.
|
||||
checkedAs(user, "resource-explorer-2", "POST", "/ListResources", "{}", "resource-explorer-2:Search");
|
||||
}
|
||||
|
||||
@Test
|
||||
void sharedTagRoutesAreCheckedForFisAndResourceExplorerOnBothPaths() {
|
||||
String user = user("route-shared-tags");
|
||||
String template = encoded("arn:aws:fis:us-east-1:" + ACCOUNT + ":experiment-template/EXTabsent");
|
||||
String view = encoded("arn:aws:resource-explorer-2:us-east-1:" + ACCOUNT + ":view/absent/1");
|
||||
|
||||
checkedAs(user, "fis", "GET", "/tags/" + template, null, "fis:ListTagsForResource");
|
||||
policy(user, allow("sts:GetCallerIdentity", "*"));
|
||||
checkedAs(user, "fis", "GET", "/tags?resourceArn=" + template, null, "fis:ListTagsForResource");
|
||||
checkedAs(user, "resource-explorer-2", "GET", "/tags/" + view, null, "resource-explorer-2:ListTagsForResource");
|
||||
policy(user, allow("sts:GetCallerIdentity", "*"));
|
||||
checkedAs(user, "resource-explorer-2", "GET", "/tags?resourceArn=" + view, null,
|
||||
"resource-explorer-2:ListTagsForResource");
|
||||
}
|
||||
|
||||
@Test
|
||||
void accountIsCheckedOnTheAccountARequestActsOn() {
|
||||
String user = user("route-account");
|
||||
String own = "{\"AlternateContactType\":\"BILLING\"}";
|
||||
String member = "{\"AccountId\":\"111122223333\",\"AlternateContactType\":\"BILLING\"}";
|
||||
String action = "account:GetAlternateContact";
|
||||
|
||||
policy(user, allow(action, "arn:aws:account::" + ACCOUNT + ":account"));
|
||||
request(user, "account", "POST", "/getAlternateContact", own).statusCode(404);
|
||||
refused(request(user, "account", "POST", "/getAlternateContact", member), action);
|
||||
|
||||
policy(user, allow(action, "arn:aws:account::*:account/o-*/111122223333"));
|
||||
// Past the check: the caller is in no organization, which Account Management refuses itself.
|
||||
request(user, "account", "POST", "/getAlternateContact", member)
|
||||
.statusCode(403).body(containsString("The specified account"));
|
||||
refused(request(user, "account", "POST", "/getAlternateContact", own), action);
|
||||
}
|
||||
|
||||
@Test
|
||||
void accountIsCheckedOnTheMemberAccountOfTheCallersOrganization() {
|
||||
OrganizationsRequests.request(MANAGEMENT, "CreateOrganization", "{\"FeatureSet\":\"ALL\"}")
|
||||
.when().post("/").then().statusCode(200);
|
||||
String organization = OrganizationsRequests.request(MANAGEMENT, "DescribeOrganization", "{}")
|
||||
.when().post("/").then().statusCode(200).extract().path("Organization.Id");
|
||||
String member = OrganizationsRequests.request(MANAGEMENT, "CreateAccount",
|
||||
"{\"Email\":\"route-contact@example.com\",\"AccountName\":\"RouteContact\"}")
|
||||
.when().post("/").then().statusCode(200).extract().path("CreateAccountStatus.AccountId");
|
||||
OrganizationsRequests.request(MANAGEMENT, "EnableAWSServiceAccess",
|
||||
"{\"ServicePrincipal\":\"account.amazonaws.com\"}")
|
||||
.when().post("/").then().statusCode(200);
|
||||
String userName = "route-account-member-" + suffix();
|
||||
String accessKeyId = EnforcementFixtures.createUser(cleanup, baseUri.getPort(), auth(MANAGEMENT, "iam"),
|
||||
userName).accessKeyId();
|
||||
String action = "account:GetAlternateContact";
|
||||
String memberArn = "arn:aws:account::" + MANAGEMENT + ":account/" + organization + "/" + member;
|
||||
String body = "{\"AccountId\":\"" + member + "\",\"AlternateContactType\":\"BILLING\"}";
|
||||
Consumer<String> policy = statements -> EnforcementFixtures.putUserPolicy(baseUri.getPort(),
|
||||
auth(MANAGEMENT, "iam"), userName, "p",
|
||||
"{\"Version\":\"2012-10-17\",\"Statement\":[" + statements + "]}");
|
||||
|
||||
// The member account's own ARN, its organization and management account the ones the caller's organization has.
|
||||
policy.accept(allow(action, memberArn));
|
||||
given().header("Authorization", auth(accessKeyId, "account")).contentType("application/json").body(body)
|
||||
.post("/getAlternateContact").then().statusCode(404);
|
||||
policy.accept(allow(action, "arn:aws:account::" + MANAGEMENT + ":account/o-other00000/" + member));
|
||||
refused(given().header("Authorization", auth(accessKeyId, "account")).contentType("application/json")
|
||||
.body(body).post("/getAlternateContact").then(), action);
|
||||
policy.accept(allow(action, "*") + "," + deny(action, memberArn));
|
||||
refused(given().header("Authorization", auth(accessKeyId, "account")).contentType("application/json")
|
||||
.body(body).post("/getAlternateContact").then(), action);
|
||||
}
|
||||
|
||||
@Test
|
||||
void controlCatalogIsCheckedOnTheControlItNames() {
|
||||
String user = user("route-control");
|
||||
String control = "arn:aws:controlcatalog:::control/" + "a".repeat(34);
|
||||
String other = "arn:aws:controlcatalog:::control/" + "b".repeat(34);
|
||||
|
||||
policy(user, allow("controlcatalog:GetControl", control));
|
||||
request(user, "controlcatalog", "POST", "/get-control", "{\"ControlArn\":\"" + control + "\"}").statusCode(404);
|
||||
refused(request(user, "controlcatalog", "POST", "/get-control", "{\"ControlArn\":\"" + other + "\"}"),
|
||||
"controlcatalog:GetControl");
|
||||
}
|
||||
|
||||
@Test
|
||||
void fisIsCheckedOnTheTemplateItsPathNames() {
|
||||
String template = "{\"clientToken\":\"" + suffix() + "\",\"description\":\"d\",\"roleArn\":\"arn:aws:iam::"
|
||||
+ ACCOUNT + ":role/fis\",\"stopConditions\":[{\"source\":\"none\"}],\"targets\":{},\"actions\":"
|
||||
+ "{\"wait\":{\"actionId\":\"aws:fis:wait\",\"parameters\":{\"duration\":\"PT1M\"}}}}";
|
||||
String id = adminOf("fis").body(template).post("/experimentTemplates")
|
||||
.then().statusCode(200).extract().path("experimentTemplate.id");
|
||||
cleanup.register(() -> adminOf("fis").delete("/experimentTemplates/" + id));
|
||||
String arn = "arn:aws:fis:us-east-1:" + ACCOUNT + ":experiment-template/" + id;
|
||||
String user = user("route-fis");
|
||||
|
||||
policy(user, allow("fis:GetExperimentTemplate", arn));
|
||||
request(user, "fis", "GET", "/experimentTemplates/" + id, null)
|
||||
.statusCode(200).body("experimentTemplate.arn", equalTo(arn));
|
||||
refused(request(user, "fis", "GET", "/experimentTemplates/EXTother", null), "fis:GetExperimentTemplate");
|
||||
}
|
||||
|
||||
@Test
|
||||
void fisSafetyLeverUpdateIsCheckedOnTheLever() {
|
||||
String user = user("route-lever");
|
||||
String action = "fis:UpdateSafetyLeverState";
|
||||
String body = "{\"state\":{\"status\":\"disengaged\",\"reason\":\"route test\"}}";
|
||||
|
||||
policy(user, allow(action, "arn:aws:fis:us-east-1:" + ACCOUNT + ":safety-lever/default"));
|
||||
request(user, "fis", "PATCH", "/safetyLevers/default/state", body).statusCode(200);
|
||||
policy(user, allow(action, "arn:aws:fis:us-east-1:" + ACCOUNT + ":safety-lever/other"));
|
||||
refused(request(user, "fis", "PATCH", "/safetyLevers/default/state", body), action);
|
||||
}
|
||||
|
||||
@Test
|
||||
void oamIsCheckedOnTheArnItsIdentifiersHold() {
|
||||
String sink = adminOf("oam").body("{\"Name\":\"route-sink-" + suffix() + "\"}").post("/CreateSink")
|
||||
.then().statusCode(200).extract().path("Arn");
|
||||
cleanup.register(() -> adminOf("oam").body("{\"Identifier\":\"" + sink + "\"}").post("/DeleteSink"));
|
||||
String link = "arn:aws:oam:us-east-1:" + ACCOUNT + ":link/absent";
|
||||
String other = "arn:aws:oam:us-east-1:" + ACCOUNT + ":sink/other";
|
||||
String user = user("route-oam");
|
||||
|
||||
policy(user, allow("oam:GetSink", sink));
|
||||
request(user, "oam", "POST", "/GetSink", "{\"Identifier\":\"" + sink + "\"}")
|
||||
.statusCode(200).body("Arn", equalTo(sink));
|
||||
refused(request(user, "oam", "POST", "/GetSink", "{\"Identifier\":\"" + other + "\"}"), "oam:GetSink");
|
||||
|
||||
policy(user, allow("oam:GetSinkPolicy", sink));
|
||||
request(user, "oam", "POST", "/GetSinkPolicy", "{\"SinkIdentifier\":\"" + sink + "\"}").statusCode(not(403));
|
||||
refused(request(user, "oam", "POST", "/GetSinkPolicy", "{\"SinkIdentifier\":\"" + other + "\"}"),
|
||||
"oam:GetSinkPolicy");
|
||||
|
||||
policy(user, allow("oam:GetLink", link));
|
||||
request(user, "oam", "POST", "/GetLink", "{\"Identifier\":\"" + link + "\"}").statusCode(404);
|
||||
refused(request(user, "oam", "POST", "/GetLink", "{\"Identifier\":\"" + link + "x\"}"), "oam:GetLink");
|
||||
}
|
||||
|
||||
@Test
|
||||
void oamTagRoutesAreCheckedOnTheArnWhetherItsSlashIsEncodedOrNot() {
|
||||
String sink = "arn:aws:oam:us-east-1:" + ACCOUNT + ":sink/allowed";
|
||||
String other = "arn:aws:oam:us-east-1:" + ACCOUNT + ":sink/other";
|
||||
String user = user("route-oam-tags");
|
||||
String tags = "{\"Tags\":{\"team\":\"red\"}}";
|
||||
|
||||
// The tag routes take the ARN as the rest of the path, so a sink's slash may come unencoded too.
|
||||
policy(user, allow("oam:TagResource", sink) + "," + allow("oam:ListTagsForResource", sink) + ","
|
||||
+ allow("oam:UntagResource", sink));
|
||||
for (String arn : List.of(sink, encoded(sink))) {
|
||||
request(user, "oam", "PUT", "/tags/" + arn, tags).statusCode(not(403));
|
||||
request(user, "oam", "GET", "/tags/" + arn, null).statusCode(not(403));
|
||||
request(user, "oam", "DELETE", "/tags/" + arn + "?tagKeys=team", null).statusCode(not(403));
|
||||
}
|
||||
for (String arn : List.of(other, encoded(other))) {
|
||||
refused(request(user, "oam", "PUT", "/tags/" + arn, tags), "oam:TagResource");
|
||||
refused(request(user, "oam", "GET", "/tags/" + arn, null), "oam:ListTagsForResource");
|
||||
refused(request(user, "oam", "DELETE", "/tags/" + arn + "?tagKeys=team", null), "oam:UntagResource");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void ramIsCheckedOnTheResourceShareItNamesInItsBodyAndQuery() {
|
||||
String share = adminOf("ram").body("{\"name\":\"route-share-" + suffix() + "\"}").post("/createresourceshare")
|
||||
.then().statusCode(200).extract().path("resourceShare.resourceShareArn");
|
||||
String other = "arn:aws:ram:us-east-1:" + ACCOUNT + ":resource-share/other";
|
||||
String user = user("route-ram");
|
||||
|
||||
policy(user, allow("ram:UpdateResourceShare", share));
|
||||
request(user, "ram", "POST", "/updateresourceshare",
|
||||
"{\"resourceShareArn\":\"" + share + "\",\"name\":\"route-renamed-" + suffix() + "\"}").statusCode(200);
|
||||
refused(request(user, "ram", "POST", "/updateresourceshare", "{\"resourceShareArn\":\"" + other + "\"}"),
|
||||
"ram:UpdateResourceShare");
|
||||
|
||||
policy(user, allow("ram:DeleteResourceShare", share));
|
||||
refused(request(user, "ram", "DELETE", "/deleteresourceshare?resourceShareArn=" + encoded(other), null),
|
||||
"ram:DeleteResourceShare");
|
||||
request(user, "ram", "DELETE", "/deleteresourceshare?resourceShareArn=" + encoded(share), null).statusCode(200);
|
||||
}
|
||||
|
||||
@Test
|
||||
void ramCreateIsCheckedOnTheShareItMakesAndThePermissionsItNames() {
|
||||
String user = user("route-ram-create");
|
||||
String action = "ram:CreateResourceShare";
|
||||
String shares = "arn:aws:ram:us-east-1:" + ACCOUNT + ":resource-share/*";
|
||||
String permission = "arn:aws:ram::aws:permission/AWSRAMDefaultPermissionSubnet";
|
||||
String named = "{\"permissionArns\":[\"" + permission + "\"]}";
|
||||
|
||||
policy(user, allow(action, shares));
|
||||
madeShare(request(user, "ram", "POST", "/createresourceshare", "{}"));
|
||||
refused(request(user, "ram", "POST", "/createresourceshare", named), action);
|
||||
|
||||
policy(user, allow(action, shares) + "," + allow(action, permission));
|
||||
madeShare(request(user, "ram", "POST", "/createresourceshare", named));
|
||||
|
||||
policy(user, allow(action, permission));
|
||||
refused(request(user, "ram", "POST", "/createresourceshare", named), action);
|
||||
|
||||
// Its tags go on the share it makes.
|
||||
policy(user, allow(action, shares) + "," + allow("ram:TagResource", shares));
|
||||
madeShare(request(user, "ram", "POST", "/createresourceshare",
|
||||
"{\"tags\":[{\"key\":\"team\",\"value\":\"red\"}]}"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resourceExplorerIsCheckedOnTheViewItsMembersName() {
|
||||
String service = "resource-explorer-2";
|
||||
String view = adminOf(service).body("{\"ViewName\":\"route-view-" + suffix() + "\"}").post("/CreateView")
|
||||
.then().statusCode(200).extract().path("View.ViewArn");
|
||||
cleanup.register(() -> adminOf(service).body("{\"ViewArn\":\"" + view + "\"}").post("/DeleteView"));
|
||||
String other = "arn:aws:resource-explorer-2:us-east-1:" + ACCOUNT + ":view/other/1";
|
||||
String user = user("route-re2-view");
|
||||
|
||||
policy(user, allow("resource-explorer-2:GetView", view));
|
||||
request(user, service, "POST", "/GetView", "{\"ViewArn\":\"" + view + "\"}")
|
||||
.statusCode(200).body("View.ViewArn", equalTo(view));
|
||||
refused(request(user, service, "POST", "/GetView", "{\"ViewArn\":\"" + other + "\"}"),
|
||||
"resource-explorer-2:GetView");
|
||||
}
|
||||
|
||||
@Test
|
||||
void createsAreCheckedWithTheTagsTheyCarry() {
|
||||
// These three name too little to be created, so past the check the service refuses them; RAM makes the share.
|
||||
Consumer<ValidatableResponse> refusedByTheService = response -> response.statusCode(400);
|
||||
createIsCheckedWithItsTags("fis", "/experimentTemplates", "fis:CreateExperimentTemplate", "fis:TagResource",
|
||||
team -> "{\"tags\":{\"team\":\"" + team + "\"}}", refusedByTheService);
|
||||
createIsCheckedWithItsTags("oam", "/CreateSink", "oam:CreateSink", "oam:TagResource",
|
||||
team -> "{\"Tags\":{\"team\":\"" + team + "\"}}", refusedByTheService);
|
||||
createIsCheckedWithItsTags("resource-explorer-2", "/CreateView", "resource-explorer-2:CreateView",
|
||||
"resource-explorer-2:TagResource", team -> "{\"Tags\":{\"team\":\"" + team + "\"}}",
|
||||
refusedByTheService);
|
||||
createIsCheckedWithItsTags("ram", "/createresourceshare", "ram:CreateResourceShare", "ram:TagResource",
|
||||
team -> "{\"tags\":[{\"key\":\"team\",\"value\":\"" + team + "\"}]}", this::madeShare);
|
||||
}
|
||||
|
||||
/**
|
||||
* An untagged request needs only the create, one with tags the tagging action too, and a deny on a tag refuses
|
||||
* that tag and no other. {@code passed} takes a response that got past the check.
|
||||
*/
|
||||
private void createIsCheckedWithItsTags(String service, String path, String action, String tagging,
|
||||
UnaryOperator<String> body, Consumer<ValidatableResponse> passed) {
|
||||
String user = user("route-tags-" + service);
|
||||
|
||||
policy(user, allow(action, "*"));
|
||||
passed.accept(request(user, service, "POST", path, "{}"));
|
||||
refused(request(user, service, "POST", path, body.apply("red")), tagging);
|
||||
|
||||
policy(user, allow(action, "*") + "," + allow(tagging, "*") + ",{\"Effect\":\"Deny\",\"Action\":\"" + action
|
||||
+ "\",\"Resource\":\"*\",\"Condition\":{\"StringEquals\":{\"aws:RequestTag/team\":\"red\"}}}");
|
||||
passed.accept(request(user, service, "POST", path, body.apply("blue")));
|
||||
refused(request(user, service, "POST", path, body.apply("red")), action);
|
||||
}
|
||||
|
||||
/** A create that got past the check and made a resource share, removed afterwards. */
|
||||
private void madeShare(ValidatableResponse response) {
|
||||
String share = response.statusCode(200).extract().path("resourceShare.resourceShareArn");
|
||||
cleanup.register(() -> adminOf("ram").queryParam("resourceShareArn", share).delete("/deleteresourceshare"));
|
||||
}
|
||||
|
||||
/** Refuses a request until the caller holds the action, then lets it past the check. */
|
||||
private void checkedAs(String user, String service, String method, String path, String body, String action) {
|
||||
refused(request(user, service, method, path, body), action);
|
||||
policy(user, allow(action, "*"));
|
||||
request(user, service, method, path, body).statusCode(not(403));
|
||||
}
|
||||
|
||||
private ValidatableResponse request(String user, String service, String method, String path, String body) {
|
||||
RequestSpecification request = as(user, service).urlEncodingEnabled(false);
|
||||
if (body != null) {
|
||||
request.body(body);
|
||||
}
|
||||
return request.request(method, path).then();
|
||||
}
|
||||
|
||||
private static RequestSpecification adminOf(String service) {
|
||||
return given().header("Authorization", auth(ADMIN, service)).contentType("application/json");
|
||||
}
|
||||
|
||||
/** Creates a MicroVM image as the account's admin, removed afterwards, and returns its ARN. */
|
||||
private String microvmImage(String name) {
|
||||
admin().body("""
|
||||
@@ -842,7 +1148,7 @@ class IamRestRouteEnforcementIntegrationTest {
|
||||
}
|
||||
|
||||
private static RequestSpecification admin() {
|
||||
return given().header("Authorization", auth(ADMIN, "lambda")).contentType("application/json");
|
||||
return adminOf("lambda");
|
||||
}
|
||||
|
||||
/** Macie's {@code CreateMember} for {@code accountId}, with a {@code team} tag unless {@code team} is null. */
|
||||
|
||||
Reference in new issue
Block a user