mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
feat(iam): evaluate ResourcePolicy on SimulatePrincipalPolicy for a user source (#9583)
SimulatePrincipalPolicy ignored ResourcePolicy, so a simulation answered from the identity policies alone. For an IAM user source the supplied resource policy is now evaluated through the same decide the enforcement path uses, with CallerArn, which defaults to the source user, as its principal, and its condition keys counted in MissingContextValues. Each resource's owner is the account its ARN names, otherwise ResourceOwner, otherwise the caller's account, and RoleResourceAccessAuthorizer.relationship picks the same- or cross-account rules. A role source still ignores it, as the reference says resource-based policy simulation isn't supported for roles, and CallerArn is held to its declared length.
This commit is contained in:
1 parent
885874f5a4
commit
a36725ec2d
4 files changed
+239
-44
No files matched your search
+14
-7
@@ -1166,13 +1166,20 @@ neither a user nor a role still answers the `InvalidInput` about the entity type
|
||||
the shape. The length wording follows the captures of real IAM length violations, naming only the
|
||||
bound the value broke and leaving the value itself out of the message. Either simulation action
|
||||
accepts only one `PermissionsBoundaryPolicyInputList` document, matching AWS's own documented
|
||||
limit; extra documents beyond the first are ignored. Neither evaluates a resource-based policy
|
||||
(`ResourcePolicy`), so a cross-account simulation is not modelled and `EvalDecisionDetails`, which
|
||||
"is populated for only cross-account simulations", carries nothing. The reference distinguishes the
|
||||
two ways of carrying nothing, and both are answered: "if the simulation evaluates policies within
|
||||
the same account and includes a resource ARN, then the parameter is present but the response is
|
||||
empty. If the simulation evaluates policies within the same account and specifies all resources
|
||||
(`*`), then the parameter is not returned."
|
||||
limit. Extra documents beyond the first are ignored. `SimulatePrincipalPolicy` evaluates
|
||||
`ResourcePolicy` for an IAM user source and ignores it for a role source. It reads `CallerArn`
|
||||
as the principal for the resource policy, defaulting to the source user. The reference says an
|
||||
assumed role, federated user or service principal cannot be the `CallerArn` and names no error
|
||||
for one, so Floci evaluates it as written. The source user supplies the
|
||||
identity policies and the populated principal condition keys. Each resource ARN supplies its
|
||||
owner account when present. Otherwise the simulator reads `ResourceOwner` as an account ID or
|
||||
account ARN, defaulting to the caller's account. Across accounts, both the identity policies and
|
||||
the resource policy must allow access. Identity-only simulations use same-account rules.
|
||||
Resource policy condition keys count toward `MissingContextValues`. Resource policy statements
|
||||
are not listed in `MatchedStatements` yet, and `SimulateCustomPolicy` ignores `ResourcePolicy`.
|
||||
AWS returns a decision per policy type in `EvalDecisionDetails` for cross-account simulations.
|
||||
Floci leaves it empty for now. For same-account simulations, AWS returns the empty member when
|
||||
the request includes a resource ARN and omits it when the request specifies all resources (`*`).
|
||||
|
||||
A result names the statements that decided it. `MatchedStatements` reports each one by the policy
|
||||
it came from and the place it sits in that policy's text: a supplied document is
|
||||
|
||||
@@ -484,16 +484,48 @@ public class IamPolicyEvaluator {
|
||||
String action,
|
||||
String resource,
|
||||
Map<String, List<String>> conditionCtx) {
|
||||
return simulate(caller, null, action, resource, conditionCtx);
|
||||
}
|
||||
|
||||
record SimulatedResourcePolicy(String document, String callerArn, String callerAccount,
|
||||
String defaultOwnerAccount) {
|
||||
ResourceAccountRelationship relationship(String resource) {
|
||||
String ownerAccount = AwsArnUtils.accountOrDefault(resource, defaultOwnerAccount);
|
||||
return RoleResourceAccessAuthorizer.relationship(callerAccount, ownerAccount);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* A resource policy the call supplies is evaluated for {@code CallerArn}, which defaults to
|
||||
* the source user's ARN. Each resource ARN identifies its owner account or takes the account
|
||||
* specified by {@code ResourceOwner}, which defaults to the caller's account. Across accounts
|
||||
* both the identity policies and the resource policy must allow access. An identity-only
|
||||
* simulation uses the same-account decision rules.
|
||||
*/
|
||||
SimulationReport simulate(CallerContext caller,
|
||||
SimulatedResourcePolicy resourcePolicy,
|
||||
String action,
|
||||
String resource,
|
||||
Map<String, List<String>> conditionCtx) {
|
||||
Map<String, List<String>> ctx = normalizeConditionContext(conditionCtx);
|
||||
String loweredAction = lowercase(action);
|
||||
SimulatedPolicies policies = simulatedPolicies(caller, loweredAction, resource, ctx);
|
||||
DecisionRecord record = decide(policies, ResourcePolicyDecision.NEUTRAL,
|
||||
ResourceAccountRelationship.SAME_ACCOUNT, loweredAction, resource, ctx);
|
||||
// A boundary the simulation applies counts as the principal's own: a Deny's NotPrincipal never
|
||||
// spares a principal that has one, as on the enforcement path.
|
||||
ResourcePolicyDecision resourceDecision = resourcePolicy == null
|
||||
? ResourcePolicyDecision.NEUTRAL
|
||||
: evaluateResourcePolicyFor(List.of(resourcePolicy.document()),
|
||||
new RequestPrincipal(RequestPrincipal.Type.IAM, resourcePolicy.callerArn(), null, null,
|
||||
policies.boundary() != null), action, resource, ctx);
|
||||
ResourceAccountRelationship relationship = resourcePolicy == null
|
||||
? ResourceAccountRelationship.SAME_ACCOUNT : resourcePolicy.relationship(resource);
|
||||
DecisionRecord record = decide(policies, resourceDecision, relationship, loweredAction, resource, ctx);
|
||||
SimulationDecision decision = SimulationDecision.from(record.outcome());
|
||||
List<CachedDocument> boundary = policies.boundary();
|
||||
return new SimulationReport(decision,
|
||||
matchedStatements(decision, caller, policies.identity(), loweredAction, resource, ctx),
|
||||
missingContextValues(policies, loweredAction, resource, ctx),
|
||||
missingContextValues(policies, resourcePolicy == null
|
||||
? List.of() : List.of(parseDocument(resourcePolicy.document())), loweredAction, resource, ctx),
|
||||
caller.scpLevels() == null
|
||||
? null : policies.scp().firstDeny() == null && policies.scp().allows(),
|
||||
boundary == null ? null : !anyMatch(boundary, true, loweredAction, resource, ctx)
|
||||
@@ -608,10 +640,10 @@ public class IamPolicyEvaluator {
|
||||
* negated operator holds against a key that matches nothing. {@code Null} asking for presence,
|
||||
* {@code "key": "false"}, does require the key, and reports it.
|
||||
*/
|
||||
private List<String> missingContextValues(SimulatedPolicies policies, String action,
|
||||
String resource, Map<String, List<String>> ctx) {
|
||||
private List<String> missingContextValues(SimulatedPolicies policies, List<CachedDocument> resourcePolicy,
|
||||
String action, String resource, Map<String, List<String>> ctx) {
|
||||
Map<String, String> missing = new LinkedHashMap<>();
|
||||
for (List<CachedDocument> layer : List.of(policies.identity(),
|
||||
for (List<CachedDocument> layer : List.of(policies.identity(), resourcePolicy,
|
||||
policies.session() == null ? List.<CachedDocument>of() : policies.session(),
|
||||
policies.boundary() == null ? List.<CachedDocument>of() : policies.boundary())) {
|
||||
for (CachedDocument document : layer) {
|
||||
|
||||
@@ -6,6 +6,7 @@ import io.floci.aws.core.common.AwsQueryLists;
|
||||
import io.floci.aws.core.common.RegionResolver;
|
||||
import io.floci.aws.core.common.RequestContext;
|
||||
import io.floci.aws.core.common.SmithyValidationErrors;
|
||||
import io.floci.aws.services.iam.IamPolicyEvaluator.SimulatedResourcePolicy;
|
||||
import io.floci.aws.services.iam.model.AccessKey;
|
||||
import io.floci.aws.services.iam.model.AccountPasswordPolicy;
|
||||
import io.floci.aws.services.iam.model.CallerContext;
|
||||
@@ -2254,9 +2255,16 @@ public class IamQueryHandler {
|
||||
*/
|
||||
private Response handleSimulatePrincipalPolicy(MultivaluedMap<String, String> params) {
|
||||
String policySourceArn = validatedPolicySourceArn(params);
|
||||
String suppliedCallerArn = getParam(params, "CallerArn");
|
||||
if (suppliedCallerArn != null) {
|
||||
arnOfDeclaredLength(suppliedCallerArn, "callerArn", 1);
|
||||
}
|
||||
PolicyExclusions exclusions = PolicyExclusions.from(params);
|
||||
SuppliedPolicies inputDocuments = readablePolicyInputList(params);
|
||||
String inputBoundary = inputBoundaryDocument(params);
|
||||
// Read for every source and applied to a user's only: the reference says simulation of
|
||||
// resource-based policies "isn't supported for IAM roles" and names no error for one.
|
||||
String suppliedResourcePolicy = readableSinglePolicyDocument(getParam(params, "ResourcePolicy"));
|
||||
// SCPs enter a simulation only when the call asks for them, the way the console includes
|
||||
// them only when "AWS Organizations SCPs" is ticked, so the levels the call handed in are
|
||||
// the whole of the organization the simulation runs against. They are read where the other
|
||||
@@ -2281,13 +2289,13 @@ public class IamQueryHandler {
|
||||
Map<String, List<String>> populated = new HashMap<>();
|
||||
Optional<IamService.CallerArns> principal = iamService.simulationPrincipalKeys(policySourceArn);
|
||||
principal.ifPresent(arns -> arns.putPrincipalKeys(populated));
|
||||
String userArn = principal.map(IamService.CallerArns::principalArn).orElse(null);
|
||||
// The account comes from the identity that was resolved where there is one, and otherwise
|
||||
// from the ARN the call wrote, which by here has been resolved to a user or a role. The
|
||||
// keys that say which account and which organization a principal is in are answered for
|
||||
// either source: they are properties of the account the source names rather than of a
|
||||
// credential, which is what the keys above it describe.
|
||||
String sourceAccount = AwsArnUtils.accountOrDefault(
|
||||
principal.map(IamService.CallerArns::principalArn).orElse(policySourceArn), null);
|
||||
String sourceAccount = AwsArnUtils.accountOrDefault(userArn == null ? policySourceArn : userArn, null);
|
||||
if (sourceAccount != null) {
|
||||
populated.put("aws:PrincipalAccount", List.of(sourceAccount));
|
||||
// The same lookup an enforced request takes, so a simulation reads the keys an
|
||||
@@ -2297,7 +2305,21 @@ public class IamQueryHandler {
|
||||
.ifPresent(organization -> organization.putOrganizationKeys(populated));
|
||||
}
|
||||
populated.forEach(context::putIfAbsent);
|
||||
return simulationResults("SimulatePrincipalPolicy", params, caller, actionNames, resourceArns, context);
|
||||
SimulatedResourcePolicy resourcePolicy = null;
|
||||
if (suppliedResourcePolicy != null && userArn != null) {
|
||||
// CallerArn simulates calling as that user with the source user's policies. It defaults
|
||||
// to the source user. ResourceOwner supplies the owner when a resource ARN omits it,
|
||||
// and defaults to the caller's account.
|
||||
String callerArn = suppliedCallerArn == null ? userArn : suppliedCallerArn;
|
||||
String callerAccount = AwsArnUtils.accountOrDefault(callerArn, sourceAccount);
|
||||
String resourceOwner = getParam(params, "ResourceOwner");
|
||||
String defaultOwnerAccount = AccountResolver.isAccountId(resourceOwner)
|
||||
? resourceOwner : AwsArnUtils.accountOrDefault(resourceOwner, callerAccount);
|
||||
resourcePolicy = new SimulatedResourcePolicy(suppliedResourcePolicy, callerArn, callerAccount,
|
||||
defaultOwnerAccount);
|
||||
}
|
||||
return simulationResults("SimulatePrincipalPolicy", params, caller,
|
||||
resourcePolicy, actionNames, resourceArns, context);
|
||||
}
|
||||
|
||||
private Response handleSimulateCustomPolicy(MultivaluedMap<String, String> params) {
|
||||
@@ -2313,7 +2335,7 @@ public class IamQueryHandler {
|
||||
CallerContext caller = CallerContext.named(policyInputList.documents(), policyInputList.sources(),
|
||||
inputBoundaryDocument(params))
|
||||
.withScpLevels(scpLevels);
|
||||
return simulationResults("SimulateCustomPolicy", params, caller, actionNames, resourceArns, context);
|
||||
return simulationResults("SimulateCustomPolicy", params, caller, null, actionNames, resourceArns, context);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2384,17 +2406,14 @@ public class IamQueryHandler {
|
||||
*/
|
||||
private String inputBoundaryDocument(MultivaluedMap<String, String> params) {
|
||||
List<String> boundaryInputList = getMemberList(params, "PermissionsBoundaryPolicyInputList");
|
||||
if (boundaryInputList.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
String boundary = boundaryInputList.get(0);
|
||||
if (!policyEvaluator.readsAsPolicyDocument(boundary)) {
|
||||
// The member carries one document, so the refusal identifies none: this is the fixed
|
||||
// sentence AWS's own emulator answers for every supplied document but an entry of
|
||||
// PolicyInputList, which is named by its index instead.
|
||||
return readableSinglePolicyDocument(boundaryInputList.isEmpty() ? null : boundaryInputList.getFirst());
|
||||
}
|
||||
|
||||
private String readableSinglePolicyDocument(String document) {
|
||||
if (document != null && !policyEvaluator.readsAsPolicyDocument(document)) {
|
||||
throw new AwsException("InvalidInput", "Syntax errors in policy.", 400);
|
||||
}
|
||||
return boundary;
|
||||
return document;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2473,14 +2492,14 @@ public class IamQueryHandler {
|
||||
* inputs do not change between the calls that page it.
|
||||
*/
|
||||
private Response simulationResults(String action, MultivaluedMap<String, String> params, CallerContext caller,
|
||||
List<String> actionNames, List<String> resourceArns,
|
||||
Map<String, List<String>> context) {
|
||||
SimulatedResourcePolicy resourcePolicy, List<String> actionNames,
|
||||
List<String> resourceArns, Map<String, List<String>> context) {
|
||||
List<SimulatedAction> actions = new ArrayList<>();
|
||||
for (String actionName : actionNames) {
|
||||
actions.add(new SimulatedAction(positionKey(actions.size()), actionName));
|
||||
}
|
||||
return pagedList(action, actions, SimulatedAction::key, params, (xml, simulated) ->
|
||||
evaluationResult(xml, caller, simulated.name(), resourceArns, context));
|
||||
evaluationResult(xml, caller, resourcePolicy, simulated.name(), resourceArns, context));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2507,17 +2526,16 @@ public class IamQueryHandler {
|
||||
* held to "only statements that contributed to the reported decision", and the top-level keys
|
||||
* "the deduplicated set of missing context values across all requested resources".
|
||||
*
|
||||
* <p>{@code EvalDecisionDetails} carries nothing, these simulations being within one
|
||||
* account, and the reference distinguishes the two ways of carrying nothing: "if the simulation
|
||||
* evaluates policies within the same account and includes a resource ARN, then the parameter is
|
||||
* present but the response is empty. If the simulation evaluates policies within the same
|
||||
* account and specifies all resources (*), then the parameter is not returned." So a call that
|
||||
* named resources gets the member empty and a call that named none gets no member.
|
||||
* <p>AWS returns a decision per policy type in {@code EvalDecisionDetails} for cross-account
|
||||
* simulations. Floci leaves it empty for now. For same-account simulations, AWS returns the
|
||||
* empty member when the request includes a resource ARN and omits it when the request specifies
|
||||
* all resources ({@code *}). Floci includes the empty member when the call names resources
|
||||
* and omits it when the call names none.
|
||||
*/
|
||||
private void evaluationResult(XmlBuilder xml, CallerContext caller, String actionName,
|
||||
List<String> resourceArns, Map<String, List<String>> context) {
|
||||
private void evaluationResult(XmlBuilder xml, CallerContext caller, SimulatedResourcePolicy resourcePolicy,
|
||||
String actionName, List<String> resourceArns, Map<String, List<String>> context) {
|
||||
List<IamPolicyEvaluator.SimulationReport> reports = resourceArns.stream()
|
||||
.map(resourceArn -> policyEvaluator.simulate(caller, actionName, resourceArn, context))
|
||||
.map(resourceArn -> policyEvaluator.simulate(caller, resourcePolicy, actionName, resourceArn, context))
|
||||
.toList();
|
||||
IamPolicyEvaluator.SimulationDecision decision = mostRestrictive(
|
||||
reports.stream().map(IamPolicyEvaluator.SimulationReport::decision).toList());
|
||||
@@ -2874,7 +2892,7 @@ public class IamQueryHandler {
|
||||
if (arn == null) {
|
||||
return null;
|
||||
}
|
||||
return arnOfDeclaredLength(arn, "policySourceArn");
|
||||
return arnOfDeclaredLength(arn, "policySourceArn", ARN_MIN_LENGTH);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2883,13 +2901,13 @@ public class IamQueryHandler {
|
||||
* operations, which have nothing to look it up in.
|
||||
*/
|
||||
private String requiredArn(MultivaluedMap<String, String> params, String name) {
|
||||
return arnOfDeclaredLength(requireParam(params, name), memberPath(name));
|
||||
return arnOfDeclaredLength(requireParam(params, name), memberPath(name), ARN_MIN_LENGTH);
|
||||
}
|
||||
|
||||
private static String arnOfDeclaredLength(String arn, String path) {
|
||||
if (arn.length() < ARN_MIN_LENGTH) {
|
||||
private static String arnOfDeclaredLength(String arn, String path, int minLength) {
|
||||
if (arn.length() < minLength) {
|
||||
throw SmithyValidationErrors.validationError("Value at '" + path + "' failed to satisfy "
|
||||
+ "constraint: Member must have length greater than or equal to " + ARN_MIN_LENGTH);
|
||||
+ "constraint: Member must have length greater than or equal to " + minLength);
|
||||
}
|
||||
if (arn.length() > ARN_MAX_LENGTH) {
|
||||
throw SmithyValidationErrors.validationError("Value at '" + path + "' failed to satisfy "
|
||||
|
||||
+139
-1
@@ -2,13 +2,19 @@ package io.floci.aws.services.iam;
|
||||
|
||||
import io.floci.aws.testing.PartitionCleanup;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.restassured.path.xml.XmlPath;
|
||||
import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import static io.floci.aws.testing.IamSimulationRequests.answer;
|
||||
import static io.floci.aws.testing.IamSimulationRequests.strings;
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.jupiter.api.Assertions.assertAll;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
/**
|
||||
@@ -43,6 +49,18 @@ class IamSimulatePrincipalInputDocumentsIntegrationTest {
|
||||
private static final String INPUT = "PolicyInputList.member.";
|
||||
private static final String BOUNDARY = "PermissionsBoundaryPolicyInputList.member.";
|
||||
|
||||
private static final String RESOURCE_POLICY = """
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [{
|
||||
"Effect": "%s",
|
||||
"Principal": {"AWS": "%s"},
|
||||
"Action": "%s",
|
||||
"Resource": "%s"
|
||||
}]
|
||||
}
|
||||
""";
|
||||
|
||||
/** One character past the 131072 a policy document is declared with. */
|
||||
private static final int PAST_THE_MAXIMUM = 131073;
|
||||
|
||||
@@ -123,10 +141,14 @@ class IamSimulatePrincipalInputDocumentsIntegrationTest {
|
||||
}
|
||||
|
||||
private static RequestSpecification simulate(String userName, String action) {
|
||||
return simulate(userName, action, "*");
|
||||
}
|
||||
|
||||
private static RequestSpecification simulate(String userName, String action, String resource) {
|
||||
return iam("SimulatePrincipalPolicy")
|
||||
.formParam("PolicySourceArn", userArn(userName))
|
||||
.formParam("ActionNames.member.1", action)
|
||||
.formParam("ResourceArns.member.1", "*");
|
||||
.formParam("ResourceArns.member.1", resource);
|
||||
}
|
||||
|
||||
/** The same simulation with every part a {@code PolicyType} can name left out. */
|
||||
@@ -179,6 +201,122 @@ class IamSimulatePrincipalInputDocumentsIntegrationTest {
|
||||
.formParam(INPUT + "1", deny("s3:GetObject"))));
|
||||
}
|
||||
|
||||
@Test
|
||||
void aResourcePolicyGrantsAndDeniesAccessForAnIamUser() {
|
||||
String user = createUser("input-resource-policy");
|
||||
String arn = userArn(user);
|
||||
String action = "s3:GetObject";
|
||||
String resource = "arn:aws:s3:::input-resource-policy/k";
|
||||
String allowPolicy = RESOURCE_POLICY.formatted("Allow", arn, action, resource);
|
||||
String denyPolicy = RESOURCE_POLICY.formatted("Deny", arn, action, resource);
|
||||
|
||||
String resourceAllow = decision(simulate(user, action, resource)
|
||||
.formParam("ResourcePolicy", allowPolicy));
|
||||
|
||||
attachNewPolicy(user, "input-reader", action);
|
||||
String resourceDeny = decision(simulate(user, action, resource)
|
||||
.formParam("ResourcePolicy", denyPolicy));
|
||||
|
||||
putBoundary(user, "ec2:RunInstances");
|
||||
String resourceAllowWithBoundary = decision(simulate(user, action, resource)
|
||||
.formParam("ResourcePolicy", allowPolicy));
|
||||
|
||||
String boundedUser = createUser("input-resource-not-principal");
|
||||
String boundedUserArn = userArn(boundedUser);
|
||||
attachNewPolicy(boundedUser, "input-reader", action);
|
||||
putBoundary(boundedUser, action);
|
||||
String notPrincipalDenyPolicy = """
|
||||
{
|
||||
"Version": "2012-10-17",
|
||||
"Statement": [{
|
||||
"Effect": "Deny",
|
||||
"NotPrincipal": {"AWS": ["arn:aws:iam::%s:root", "%s"]},
|
||||
"Action": "%s",
|
||||
"Resource": "%s"
|
||||
}]
|
||||
}
|
||||
""".formatted(ACCOUNT, boundedUserArn, action, resource);
|
||||
String notPrincipalDenyWithBoundary = decision(simulate(boundedUser, action, resource)
|
||||
.formParam("ResourcePolicy", notPrincipalDenyPolicy));
|
||||
|
||||
String conditionalUser = createUser("input-resource-missing-context");
|
||||
String conditionalPolicy = """
|
||||
{"Version":"2012-10-17","Statement":[{
|
||||
"Effect":"Allow","Principal":{"AWS":"%s"},"Action":"%s","Resource":"%s",
|
||||
"Condition":{"StringEquals":{"aws:SourceVpce":"vpce-1a2b3c4d"}}
|
||||
}]}
|
||||
""".formatted(userArn(conditionalUser), action, resource);
|
||||
XmlPath conditionalResult = answer(simulate(conditionalUser, action, resource)
|
||||
.formParam("ResourcePolicy", conditionalPolicy));
|
||||
|
||||
assertAll(
|
||||
() -> assertEquals("allowed", resourceAllow, "Resource allow without an identity policy"),
|
||||
() -> assertEquals("explicitDeny", resourceDeny, "Resource deny with an identity allow"),
|
||||
() -> assertEquals("allowed", resourceAllowWithBoundary, "Resource allow with a boundary implicit deny"),
|
||||
() -> assertEquals("explicitDeny", notPrincipalDenyWithBoundary,
|
||||
"NotPrincipal deny for a listed user with a permissions boundary"),
|
||||
() -> assertEquals("implicitDeny", conditionalResult.getString(DECISION)),
|
||||
() -> assertEquals(List.of("aws:SourceVpce"), strings(conditionalResult,
|
||||
"SimulatePrincipalPolicyResponse.SimulatePrincipalPolicyResult"
|
||||
+ ".EvaluationResults.member.MissingContextValues.member")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void callerAndResourceOwnerDetermineHowResourcePolicyGrantsApply() {
|
||||
String david = createUser("David");
|
||||
String bobArn = userArn(createUser("Bob"));
|
||||
String davidArn = userArn(david);
|
||||
String object = "arn:aws:s3:::bucket/k";
|
||||
String getObject = "s3:GetObject";
|
||||
String queue = "arn:aws:sqs:us-east-1:222222222222:q";
|
||||
String sendMessage = "sqs:SendMessage";
|
||||
String otherOwner = "arn:aws:iam::222222222222:root";
|
||||
String objectAllowForDavid = RESOURCE_POLICY.formatted("Allow", davidArn, getObject, object);
|
||||
String objectAllowForBob = RESOURCE_POLICY.formatted("Allow", bobArn, getObject, object);
|
||||
String queueAllowForDavid = RESOURCE_POLICY.formatted("Allow", davidArn, sendMessage, queue);
|
||||
|
||||
String bobWithDavidsGrant = decision(simulate(david, getObject, object)
|
||||
.formParam("CallerArn", bobArn)
|
||||
.formParam("ResourcePolicy", objectAllowForDavid));
|
||||
String bobWithBobsGrant = decision(simulate(david, getObject, object)
|
||||
.formParam("CallerArn", bobArn)
|
||||
.formParam("ResourcePolicy", objectAllowForBob));
|
||||
String queueWithResourceAllow = decision(simulate(david, sendMessage, queue)
|
||||
.formParam("ResourcePolicy", queueAllowForDavid));
|
||||
String objectWithOtherOwner = decision(simulate(david, getObject, object)
|
||||
.formParam("ResourceOwner", otherOwner)
|
||||
.formParam("ResourcePolicy", objectAllowForDavid));
|
||||
String objectWithDefaultOwner = decision(simulate(david, getObject, object)
|
||||
.formParam("ResourcePolicy", objectAllowForDavid));
|
||||
|
||||
attachNewPolicy(david, "input-sqs-sender", sendMessage);
|
||||
String queueWithBothAllows = decision(simulate(david, sendMessage, queue)
|
||||
.formParam("ResourcePolicy", queueAllowForDavid));
|
||||
String queueWithIdentityAllow = decision(simulate(david, sendMessage, queue));
|
||||
|
||||
assertAll(
|
||||
() -> assertEquals("implicitDeny", bobWithDavidsGrant,
|
||||
"CallerArn Bob with a resource policy that grants access to David"),
|
||||
() -> assertEquals("allowed", bobWithBobsGrant,
|
||||
"CallerArn Bob with a resource policy that grants access to Bob"),
|
||||
() -> assertEquals("implicitDeny", queueWithResourceAllow,
|
||||
"Cross-account SQS ARN with a resource allow and no identity policy"),
|
||||
() -> assertEquals("allowed", queueWithBothAllows,
|
||||
"Cross-account SQS ARN with both identity and resource allows"),
|
||||
() -> assertEquals("implicitDeny", objectWithOtherOwner,
|
||||
"S3 object with a resource allow and a cross-account ResourceOwner"),
|
||||
() -> assertEquals("allowed", objectWithDefaultOwner,
|
||||
"S3 object with a resource allow and the default ResourceOwner"),
|
||||
() -> assertEquals("allowed", queueWithIdentityAllow,
|
||||
"Cross-account SQS ARN with an identity allow and no ResourcePolicy"),
|
||||
() -> simulate(david, getObject)
|
||||
.formParam("CallerArn", "")
|
||||
.when().post("/").then().statusCode(400)
|
||||
.body(CODE, equalTo("ValidationError"))
|
||||
.body(MESSAGE, equalTo("1 validation error detected: Value at 'callerArn' failed to satisfy"
|
||||
+ " constraint: Member must have length greater than or equal to 1")));
|
||||
}
|
||||
|
||||
/** Every index the request numbers is read, the bare spelling and a gap among them. */
|
||||
@Test
|
||||
void everyDocumentTheRequestNumbersIsRead() {
|
||||
|
||||
Reference in new issue
Block a user