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,6 +8,7 @@ import jakarta.ws.rs.container.ContainerRequestContext;
|
||||
import jakarta.ws.rs.core.MultivaluedMap;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
@@ -184,8 +185,10 @@ public final class RequestResources {
|
||||
if (resource.arn() != null) {
|
||||
for (String value : values(form, body, resource.arn())) {
|
||||
String named = before(value, resource.before());
|
||||
// An ARN fitting a customer's format and one AWS owns is AWS's: the account `aws` tells them apart.
|
||||
resource.types().stream().map(formats::get).filter(format -> format.pattern().matcher(named).matches())
|
||||
.findFirst().ifPresent(format -> addNamed(arns, format.checked(named), format.awsOwned(),
|
||||
.min(Comparator.comparing(format -> !format.awsOwned()))
|
||||
.ifPresent(format -> addNamed(arns, format.checked(named), format.awsOwned(),
|
||||
partition, region, accountId));
|
||||
}
|
||||
} else if (resource.through() != null) {
|
||||
|
||||
@@ -2,9 +2,11 @@ package io.floci.aws.services.account;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import io.floci.aws.core.common.AwsArnUtils;
|
||||
import io.floci.aws.core.common.AwsException;
|
||||
import io.floci.aws.core.common.Resettable;
|
||||
import io.floci.aws.core.common.ServicePrincipals;
|
||||
import io.floci.aws.core.common.StoredResourceArns;
|
||||
import io.floci.aws.core.storage.AccountAwareStorageBackend;
|
||||
import io.floci.aws.core.storage.StorageFactory;
|
||||
import io.floci.aws.services.account.model.AlternateContact;
|
||||
@@ -14,12 +16,14 @@ import io.floci.aws.services.organizations.model.OrganizationAccount;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Set;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ApplicationScoped
|
||||
public class AccountService implements Resettable {
|
||||
public class AccountService implements Resettable, StoredResourceArns {
|
||||
private static final String ACCOUNT_MANAGEMENT_SERVICE_PRINCIPAL = ServicePrincipals.of("account");
|
||||
private static final Pattern ACCOUNT_ID = Pattern.compile("\\d{12}");
|
||||
private static final Pattern EMAIL = Pattern.compile("\\s*[\\w+=.#|!&-]+@[\\w.-]+\\.[\\w]+\\s*");
|
||||
@@ -116,6 +120,36 @@ public class AccountService implements Resettable {
|
||||
contacts.clear();
|
||||
}
|
||||
|
||||
/** The namespace of the resource types this service finds, as the request-resources table names it. */
|
||||
@Override
|
||||
public String namespace() {
|
||||
return "account";
|
||||
}
|
||||
|
||||
/**
|
||||
* The ARN of the member account of the caller's organization a request names by its {@code AccountId}, which
|
||||
* Account Management acts on: {@code arn:aws:account::<management account>:account/<organization>/<member>}, its
|
||||
* organization and management account being ones no request gives. Empty for a caller in no organization or an
|
||||
* account its organization does not hold, which the handler refuses.
|
||||
*/
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
if (!"accountInOrganization".equals(type) || names.size() != 1 || names.getFirst() == null) {
|
||||
return Optional.empty();
|
||||
}
|
||||
String callerAccountId = contacts.accountId();
|
||||
Organization organization;
|
||||
try {
|
||||
organization = organizationsService.describeOrganization(callerAccountId);
|
||||
organizationsService.describeAccount(callerAccountId, names.getFirst());
|
||||
} catch (AwsException e) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return Optional.of(AwsArnUtils.Arn.global(AwsArnUtils.parse(organization.getArn()).partition(), "account",
|
||||
organization.getMasterAccountId(), "account/" + organization.getId() + "/" + names.getFirst())
|
||||
.toString());
|
||||
}
|
||||
|
||||
private static String requireContactType(JsonNode request) {
|
||||
String value = requireLength(request, "AlternateContactType", 1, 32);
|
||||
if (!CONTACT_TYPES.contains(value)) {
|
||||
|
||||
Reference in new issue
Block a user