mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(iam): check Redshift Data API requests on the cluster or workgroup they name (#7234)
Under IAM enforcement, Redshift Data API requests were checked on `*`,
so a grant scoped to a cluster or a serverless workgroup was refused
and a deny scoped to one never applied.
The Service Reference gives ExecuteStatement, BatchExecuteStatement,
DescribeTable, ListDatabases, ListSchemas and ListTables two resource
types: Redshift's `cluster:${ClusterName}`, which ClusterIdentifier
fills, and Redshift Serverless's `workgroup/${WorkgroupId}`. A
workgroup's ARN ends in the id Redshift Serverless gives it (its
workgroupId, "The unique identifier of the workgroup"; botocore's
WorkgroupNameString takes an ARN ending in workgroup/<uuid>), while a
request names it by WorkgroupName, "The serverless workgroup name or
Amazon Resource Name (ARN)". So the workgroup is a FOUND_BY type,
found by WorkgroupName.
FOUND_BY named a type by its members only where the rule had derived
a fill for the type to replace, as ResourceId fills a scalable target's
${ResourceId}. No member fills ${WorkgroupId}, so FOUND_BY now names
every FOUND_BY type the action acts on whose members the request has,
as its docstring already said. The Application Auto Scaling entries
are unchanged.
RedshiftDataResourceResolver, which resolves the target a request
runs on, now implements StoredResourceArns for redshift-data: it
gives the ARN of the workgroup a name or an ARN finds, through
RedshiftServerlessService.findWorkgroupByNameOrArn, which the
service's own name-or-ARN lookup now uses as well.
Redshift Data joins the table (12 operations, 1048 over 26
namespaces). The six operations above are checked on the cluster's
ARN or on the stored workgroup's, and on `workgroup/*` for a workgroup
there is none of; their SecretArn names neither. A request naming only
its SessionId stays on `*`, and so do CancelStatement,
DescribeStatement, GetStatementResult, GetStatementResultV2,
ListSessions and ListStatements, which the Service Reference gives no
resource type.
This commit is contained in:
1 parent
8c32e9f6ba
commit
9bd90d6580
11 files changed
+219
-35
No files matched your search
@@ -1606,8 +1606,8 @@ Pipes, Aurora DSQL, EKS, API Gateway, CloudWatch Logs, Secrets Manager and STS.
|
||||
Step Functions, EventBridge, Amazon Cognito user pools and identity pools, Amazon Data Firehose, Cloud
|
||||
Map, ACM, CodePipeline, CodeBuild, Amazon Managed Service for Apache Flink (Kinesis Data Analytics v2),
|
||||
Application Auto Scaling, AWS Budgets, Cost and Usage Reports, Service Quotas, Amazon Textract, Amazon Translate, Amazon Athena,
|
||||
AWS Data Exports, AWS Pricing Calculator, Cost Explorer, CloudTrail, Global Accelerator and Amazon
|
||||
Timestream for InfluxDB they come from a table generated from AWS's Service Reference and botocore, `src/main/resources/aws/iam-request-resources.json`, which gives each
|
||||
AWS Data Exports, AWS Pricing Calculator, Cost Explorer, CloudTrail, Global Accelerator, Amazon
|
||||
Timestream for InfluxDB and the Amazon Redshift Data API they come from a table generated from AWS's Service Reference and botocore, `src/main/resources/aws/iam-request-resources.json`, which gives each
|
||||
operation's action, the resource types that action acts on with their ARN formats, and the request
|
||||
members that name them: a member holding a resource's ARN, which counts when it matches the format
|
||||
of a type the action acts on, or members filling the variables of a type's format. A member holding
|
||||
@@ -1673,7 +1673,11 @@ none yet, as for its create. An Application Auto Scaling scalable target, whose
|
||||
Application Auto Scaling assigns it, `scalable-target/<id>`, while its requests name it by
|
||||
`ServiceNamespace`, `ResourceId` and `ScalableDimension`, is checked on the ARN it is stored under, and
|
||||
on `scalable-target/*` when there is none yet, as for a `RegisterScalableTarget` registering a new one;
|
||||
its tag operations name it by its ARN. EventBridge V2's API, which Floci does not serve, is not read. A
|
||||
its tag operations name it by its ARN. A Redshift Data API request is checked on the cluster its
|
||||
`ClusterIdentifier` names, or on the ARN of the Redshift Serverless workgroup its `WorkgroupName`
|
||||
names by name or by ARN, which ends in the id Redshift Serverless gives it, `workgroup/<id>`, and on
|
||||
`workgroup/*` when there is no such workgroup; one naming only its session, by `SessionId`, is
|
||||
checked on `*`. EventBridge V2's API, which Floci does not serve, is not read. A
|
||||
state machine's version or alias
|
||||
(`stateMachine:<name>:<qualifier>`) is checked on the state machine's ARN, as Step Functions
|
||||
authorizes it, so a grant or a deny on `stateMachine:<name>` covers its versions and aliases, and
|
||||
|
||||
@@ -44,6 +44,8 @@ A request identifies its target cluster or serverless workgroup one of three way
|
||||
|
||||
A statement run against a workgroup reports `WorkgroupName` and omits `ClusterIdentifier`, and the reverse holds for a cluster statement. `ListDatabases`, `ListSchemas`, `ListTables` and `DescribeTable` accept `WorkgroupName` the same way.
|
||||
|
||||
Under IAM enforcement, `ExecuteStatement`, `BatchExecuteStatement`, `ListDatabases`, `ListSchemas`, `ListTables` and `DescribeTable` are checked on the cluster's ARN, or on the ARN of the workgroup `WorkgroupName` names, `workgroup/<id>`, whichever form it takes; a workgroup that does not exist is checked on `workgroup/*`, and a request naming only a `SessionId` on `*`.
|
||||
|
||||
## Session reuse
|
||||
|
||||
`ExecuteStatement` and `BatchExecuteStatement` accept `SessionKeepAliveSeconds`, an integer from
|
||||
|
||||
@@ -7,10 +7,12 @@ import java.util.Optional;
|
||||
* Finds the ARN a service stores a resource under, for a type of the request-resources table whose ARN carries an id
|
||||
* the service mints, which only the service knows: after the name a request gives ({@code connection/<name>/<id>}),
|
||||
* or as all of it, a request naming the resource by members its ARN does not hold
|
||||
* ({@code scalable-target/<id>}, named by its service namespace, resource id and scalable dimension).
|
||||
* ({@code scalable-target/<id>}, named by its service namespace, resource id and scalable dimension;
|
||||
* {@code workgroup/<id>}, named by its name).
|
||||
*
|
||||
* <p>Implemented by the service that owns such resources (EventBridge, for its connections and API destinations;
|
||||
* Application Auto Scaling, for its scalable targets); looked up lazily by {@code ResourceArnBuilder} through
|
||||
* <p>Implemented by the service that owns such resources or whose requests name them (EventBridge, for its
|
||||
* connections and API destinations; Application Auto Scaling, for its scalable targets; Redshift Data, for the
|
||||
* Redshift Serverless workgroups it runs statements on); looked up lazily by {@code ResourceArnBuilder} through
|
||||
* {@code Instance<StoredResourceArns>} for the namespace a request is of, so IAM never depends on that service
|
||||
* directly.</p>
|
||||
*/
|
||||
@@ -21,8 +23,9 @@ public interface StoredResourceArns {
|
||||
|
||||
/**
|
||||
* The ARN the caller's resource of the type in the Region is stored under, named by {@code names}, the values the
|
||||
* request names it by in the order the table reads them: a connection's name, or a scalable target's service
|
||||
* namespace, resource id and scalable dimension; empty when there is none, or the type is not one it finds.
|
||||
* request names it by in the order the table reads them: a connection's name, a scalable target's service
|
||||
* namespace, resource id and scalable dimension, or a workgroup's name or ARN; empty when there is none, or the
|
||||
* type is not one it finds.
|
||||
*/
|
||||
Optional<String> find(String type, List<String> names, String region);
|
||||
}
|
||||
+20
-1
@@ -6,12 +6,14 @@ import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.DatabaseSecretCredentials;
|
||||
import io.github.hectorvent.floci.core.common.RegionResolver;
|
||||
import io.github.hectorvent.floci.core.common.StoredResourceArns;
|
||||
import io.github.hectorvent.floci.services.redshift.RedshiftCredentialBroker;
|
||||
import io.github.hectorvent.floci.services.redshift.RedshiftService;
|
||||
import io.github.hectorvent.floci.services.redshift.model.Cluster;
|
||||
import io.github.hectorvent.floci.services.redshift.spectrum.SpectrumSession;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.RedshiftServerlessRuntime;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.RedshiftServerlessService;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.model.Workgroup;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.SecretsManagerService;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.model.Secret;
|
||||
import io.github.hectorvent.floci.services.secretsmanager.model.SecretVersion;
|
||||
@@ -19,8 +21,11 @@ import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@ApplicationScoped
|
||||
class RedshiftDataResourceResolver {
|
||||
class RedshiftDataResourceResolver implements StoredResourceArns {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(RedshiftDataResourceResolver.class);
|
||||
|
||||
@@ -46,6 +51,20 @@ class RedshiftDataResourceResolver {
|
||||
this.serverlessService = serverlessService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String namespace() {
|
||||
return "redshift-data";
|
||||
}
|
||||
|
||||
/** The ARN of the serverless workgroup a request names by its name or ARN, as {@link #resolve} reads it. */
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
if (!"workgroup".equals(type) || names.size() != 1) {
|
||||
return Optional.empty();
|
||||
}
|
||||
return serverlessService.findWorkgroupByNameOrArn(names.getFirst(), region).map(Workgroup::getWorkgroupArn);
|
||||
}
|
||||
|
||||
DatabaseTarget resolve(JsonNode request, String region) {
|
||||
String database = requiredText(request, "Database");
|
||||
if (hasText(request, "WorkgroupName")) {
|
||||
|
||||
+8
-2
@@ -1234,14 +1234,20 @@ public class RedshiftServerlessService implements Resettable {
|
||||
}
|
||||
}
|
||||
|
||||
/** The workgroup a workgroup name or ARN names in the Region, as the Data API reads either; empty when none. */
|
||||
public Optional<Workgroup> findWorkgroupByNameOrArn(String nameOrArn, String region) {
|
||||
return AwsArnUtils.looksLikeArn(nameOrArn) ? workgroupByArn(nameOrArn, region)
|
||||
: findWorkgroup(nameOrArn, region);
|
||||
}
|
||||
|
||||
private Workgroup resolveWorkgroup(String nameOrArn, String region) {
|
||||
if (nameOrArn == null || nameOrArn.isBlank()) {
|
||||
throw ServerlessSupport.validation("workgroupName is required.");
|
||||
}
|
||||
if (!AwsArnUtils.looksLikeArn(nameOrArn)) {
|
||||
return getWorkgroup(nameOrArn, region);
|
||||
validateWorkgroupName(nameOrArn);
|
||||
}
|
||||
return workgroupByArn(nameOrArn, region).orElseThrow(() -> workgroupNotFound(nameOrArn));
|
||||
return findWorkgroupByNameOrArn(nameOrArn, region).orElseThrow(() -> workgroupNotFound(nameOrArn));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
{
|
||||
"_source": {"generator": "tools/aws/regen_iam_request_resources.py", "reference": "https://servicereference.us-east-1.amazonaws.com/", "botocore": "botocore 1.43.113 (installed package)", "retrieved": "2026-11-01", "note": "make iam-request-resources-check re-derives every operation's resources from botocore; make iam-request-resources-verify checks every action, type and format against AWS."},
|
||||
"namespaces": {"acm": ["acm"], "application-autoscaling": ["application-autoscaling"], "athena": ["athena"], "bcm-data-exports": ["bcm-data-exports"], "bcm-pricing-calculator": ["bcm-pricing-calculator"], "budgets": ["budgets"], "ce": ["ce"], "cloudtrail": ["cloudtrail"], "codebuild": ["codebuild"], "codepipeline": ["codepipeline"], "cognito-identity": ["cognito-identity"], "cognito-idp": ["cognito-idp"], "cur": ["cur"], "ecr": ["ecr"], "elasticloadbalancing": ["elb", "elbv2"], "events": ["eventbridgev2", "events"], "firehose": ["firehose"], "globalaccelerator": ["globalaccelerator"], "kinesisanalytics": ["kinesisanalyticsv2"], "servicediscovery": ["servicediscovery"], "servicequotas": ["service-quotas"], "states": ["stepfunctions"], "textract": ["textract"], "timestream-influxdb": ["timestream-influxdb"], "translate": ["translate"]},
|
||||
"namespaces": {"acm": ["acm"], "application-autoscaling": ["application-autoscaling"], "athena": ["athena"], "bcm-data-exports": ["bcm-data-exports"], "bcm-pricing-calculator": ["bcm-pricing-calculator"], "budgets": ["budgets"], "ce": ["ce"], "cloudtrail": ["cloudtrail"], "codebuild": ["codebuild"], "codepipeline": ["codepipeline"], "cognito-identity": ["cognito-identity"], "cognito-idp": ["cognito-idp"], "cur": ["cur"], "ecr": ["ecr"], "elasticloadbalancing": ["elb", "elbv2"], "events": ["eventbridgev2", "events"], "firehose": ["firehose"], "globalaccelerator": ["globalaccelerator"], "kinesisanalytics": ["kinesisanalyticsv2"], "redshift-data": ["redshift-data"], "servicediscovery": ["servicediscovery"], "servicequotas": ["service-quotas"], "states": ["stepfunctions"], "textract": ["textract"], "timestream-influxdb": ["timestream-influxdb"], "translate": ["translate"]},
|
||||
"clientsNotRead": {"kinesisanalytics": "Kinesis Data Analytics v1, SQL applications on the KinesisAnalytics_20150814 target, which Floci does not serve (it serves v2, kinesisanalyticsv2); its operations share v2's names and name their resources by other members"},
|
||||
"handBuilt": ["apigateway", "bedrock", "dsql", "dynamodb", "eks", "iam", "kinesis", "kms", "lambda", "logs", "pipes", "resource-groups", "s3", "scheduler", "secretsmanager", "sns", "sqs", "ssm", "sts"],
|
||||
"notCovered": {"access-analyzer": "REST: its requests name their resources in the path, which RequestResources does not read yet", "account": "REST: its requests name their resources in the path, which RequestResources does not read yet", "airflow": "REST: its requests name their resources in the path, which RequestResources does not read yet", "app-integrations": "REST: its requests name their resources in the path, which RequestResources does not read yet", "appconfig": "REST: its requests name their resources in the path, which RequestResources does not read yet", "appsync": "REST: its requests name their resources in the path, which RequestResources does not read yet", "aps": "REST: its requests name their resources in the path, which RequestResources does not read yet", "autoscaling": "not read yet: AWS's group and launch configuration ARNs carry an id the service mints, `autoScalingGroup:<id>:autoScalingGroupName/<name>`, while Floci mints `autoScalingGroup:<name>`, which other services (ECS capacity providers) read back; the mint is fixed first", "aws-marketplace": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "backup": "REST: its requests name their resources in the path, which RequestResources does not read yet", "batch": "REST: its requests name their resources in the path, which RequestResources does not read yet", "bedrock-agentcore": "REST: its requests name their resources in the path, which RequestResources does not read yet", "cloudformation": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "cloudfront": "REST: its requests name their resources in the path, which RequestResources does not read yet", "cloudhsm": "not read yet: its ARN formats end in ${CloudHsmClusterInstanceName} and ${CloudHsmBackupInstanceName}, names, while its requests give ClusterId and BackupId, ids, which the rule does not fill a name from, so nearly every operation needs a correction", "cloudwatch": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "codeartifact": "REST: its requests name their resources in the path, which RequestResources does not read yet", "codedeploy": "not read yet: the Service Reference gives an on-premises instance's ARN as `instance:${InstanceName}`, while the CodeDeploy permissions reference gives arn:aws:codedeploy:region:account-id:instance/instance-ID and AWS's GetOnPremisesInstance example answers instance/<name>_<id>, an id the service mints after the name; reading it needs that format corrected", "codeguru-reviewer": "REST: its requests name their resources in the path, which RequestResources does not read yet", "comprehend": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "config": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "connect": "REST: its requests name their resources in the path, which RequestResources does not read yet", "controlcatalog": "REST: its requests name their resources in the path, which RequestResources does not read yet", "controltower": "REST: its requests name their resources in the path, which RequestResources does not read yet", "datasync": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "detective": "REST: its requests name their resources in the path, which RequestResources does not read yet", "dlm": "REST: its requests name their resources in the path, which RequestResources does not read yet", "dms": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "ec2": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "ecs": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "elasticache": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "elasticbeanstalk": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "elasticfilesystem": "REST: its requests name their resources in the path, which RequestResources does not read yet", "elasticmapreduce": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "emr-serverless": "REST: its requests name their resources in the path, which RequestResources does not read yet", "es": "REST: its requests name their resources in the path, which RequestResources does not read yet", "execute-api": "REST: its requests name their resources in the path, which RequestResources does not read yet", "fis": "REST: its requests name their resources in the path, which RequestResources does not read yet", "glue": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "guardduty": "REST: its requests name their resources in the path, which RequesLine truncated
|
||||
"notCovered": {"access-analyzer": "REST: its requests name their resources in the path, which RequestResources does not read yet", "account": "REST: its requests name their resources in the path, which RequestResources does not read yet", "airflow": "REST: its requests name their resources in the path, which RequestResources does not read yet", "app-integrations": "REST: its requests name their resources in the path, which RequestResources does not read yet", "appconfig": "REST: its requests name their resources in the path, which RequestResources does not read yet", "appsync": "REST: its requests name their resources in the path, which RequestResources does not read yet", "aps": "REST: its requests name their resources in the path, which RequestResources does not read yet", "autoscaling": "not read yet: AWS's group and launch configuration ARNs carry an id the service mints, `autoScalingGroup:<id>:autoScalingGroupName/<name>`, while Floci mints `autoScalingGroup:<name>`, which other services (ECS capacity providers) read back; the mint is fixed first", "aws-marketplace": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "backup": "REST: its requests name their resources in the path, which RequestResources does not read yet", "batch": "REST: its requests name their resources in the path, which RequestResources does not read yet", "bedrock-agentcore": "REST: its requests name their resources in the path, which RequestResources does not read yet", "cloudformation": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "cloudfront": "REST: its requests name their resources in the path, which RequestResources does not read yet", "cloudhsm": "not read yet: its ARN formats end in ${CloudHsmClusterInstanceName} and ${CloudHsmBackupInstanceName}, names, while its requests give ClusterId and BackupId, ids, which the rule does not fill a name from, so nearly every operation needs a correction", "cloudwatch": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "codeartifact": "REST: its requests name their resources in the path, which RequestResources does not read yet", "codedeploy": "not read yet: the Service Reference gives an on-premises instance's ARN as `instance:${InstanceName}`, while the CodeDeploy permissions reference gives arn:aws:codedeploy:region:account-id:instance/instance-ID and AWS's GetOnPremisesInstance example answers instance/<name>_<id>, an id the service mints after the name; reading it needs that format corrected", "codeguru-reviewer": "REST: its requests name their resources in the path, which RequestResources does not read yet", "comprehend": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "config": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "connect": "REST: its requests name their resources in the path, which RequestResources does not read yet", "controlcatalog": "REST: its requests name their resources in the path, which RequestResources does not read yet", "controltower": "REST: its requests name their resources in the path, which RequestResources does not read yet", "datasync": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "detective": "REST: its requests name their resources in the path, which RequestResources does not read yet", "dlm": "REST: its requests name their resources in the path, which RequestResources does not read yet", "dms": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "ec2": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "ecs": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "elasticache": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "elasticbeanstalk": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "elasticfilesystem": "REST: its requests name their resources in the path, which RequestResources does not read yet", "elasticmapreduce": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "emr-serverless": "REST: its requests name their resources in the path, which RequestResources does not read yet", "es": "REST: its requests name their resources in the path, which RequestResources does not read yet", "execute-api": "REST: its requests name their resources in the path, which RequestResources does not read yet", "fis": "REST: its requests name their resources in the path, which RequestResources does not read yet", "glue": "not read yet: a later batch, with the tests that show its ARNs are the ones its handlers mint", "guardduty": "REST: its requests name their resources in the path, which RequesLine truncated
|
||||
"otherNamespaces": ["a4b", "account-access", "acm-pca", "aco-automation", "agent-registry", "aidevops", "aiops", "airflow-serverless", "amplify", "amplifybackend", "amplifyuibuilder", "aoss", "appfabric", "appflow", "application-signals", "application-signals-mcp", "appmesh", "appmesh-preview", "apprunner", "appstream", "apptest", "arc-region-switch", "arc-zonal-shift", "artifact", "assurance", "auditmanager", "aws-external-anthropic", "b2bi", "backup-gateway", "backup-search", "bedrock-mantle", "bedrock-websearch", "billing", "billingconductor", "braket", "bugbust", "cases", "cassandra", "chatbot", "chime", "cleanrooms", "cleanrooms-ml", "cloud9", "clouddirectory", "cloudfront-keyvaluestore", "cloudsearch", "cloudshell", "cloudtrail-data", "codecatalyst", "codecommit", "codeconnections", "codeguru-profiler", "codeguru-security", "codestar-connections", "codestar-notifications", "codewhisperer", "cognito-sync", "connect-campaigns", "consoleapp", "continuum", "databrew", "dataexchange", "datapipeline", "datazone", "dax", "deadline", "devicefarm", "devops-guru", "directconnect", "docdb-elastic", "drs", "ds", "ds-data", "ebs", "ec2-instance-connect", "ecr-public", "eks-auth", "elastictranscoder", "elemental-appliances-software", "elemental-inference", "elemental-support-cases", "emr-containers", "end-user-messaging", "entityresolution", "evs", "finspace", "finspace-api", "fms", "forecast", "frauddetector", "freertos", "fsx", "gamelift", "gameliftstreams", "geo", "geo-maps", "geo-places", "geo-routes", "glacier", "grafana", "greengrass", "groundstation", "health", "health-agent", "healthlake", "honeycode", "identity-sync", "imagebuilder", "interconnect", "internetmonitor", "invoicing", "iotanalytics", "iotdeviceadvisor", "iotfleethub", "iotfleetwise", "iotjobsdata", "iotmanagedintegrations", "iotsitewise", "iottwinmaker", "iotwireless", "iq", "iq-permission", "ivs", "ivschat", "kafka-cluster", "kafkaconnect", "kendra", "kendra-ranking", "kinesisvideo", "launchwizard", "lex", "license-manager", "license-manager-linux-subscriptions", "license-manager-user-subscriptions", "lookoutequipment", "lookoutmetrics", "lookoutvision", "m2", "machinelearning", "managedblockchain", "mapcredits", "mediaconnect", "mediaconvert", "medialive", "mediapackage", "mediapackage-vod", "mediapackagev2", "mediastore", "mediatailor", "medical-imaging", "mgh", "mgn", "migrationhub-orchestrator", "mobiletargeting", "monitron", "mpa", "neptune-db", "neptune-graph", "network-security-manager", "networkflowmonitor", "networkmanager", "networkmonitor", "nimble", "notifications", "notifications-contacts", "nova-act", "observabilityadmin", "odb", "omics", "one", "opensearch", "opsworks", "osis", "outposts", "panorama", "partnercentral", "payment-cryptography", "payments", "pca-connector-ad", "pca-connector-scep", "pcs", "personalize", "pi", "polly", "private-networks", "profile", "proton", "purchase-orders", "q", "qapps", "qbusiness", "qdeveloper", "qldb", "quicksight", "rbin", "rds-db", "refactor-spaces", "repostspace", "resiliencehub", "robomaker", "rolesanywhere", "route53-recovery-cluster", "route53-recovery-control-config", "route53-recovery-readiness", "route53globalresolver", "route53profiles", "rtbfabric", "s3-object-lambda", "s3-outposts", "s3express", "s3files", "sagemaker-geospatial", "sagemaker-mlflow", "savingsplans", "schemas", "scn", "sdb", "security-ir", "securityagent", "securitylake", "serverlessrepo", "shield", "signer", "simspaceweaver", "sms-voice", "snow-device-management", "social-messaging", "sqlworkbench", "ssm-contacts", "ssm-incidents", "ssm-quicksetup", "ssm-sap", "storagegateway", "supportauthz", "synthetics", "thinclient", "timestream", "tnb", "transform", "transform-custom", "trustedadvisor", "ts", "vendor-insights", "voiceid", "vpc-lattice", "vpc-lattice-svcs", "vpce", "waf", "waf-regional", "wellarchitected", "wickr", "wisdom", "workdocs", "worklink", "workmail", "workmailmessageflow", "workspaces", "workspaces-instances", "workspaces-web", "xray"],
|
||||
"arnFormats": {"acm": {"acme-domain-validation": "arn:${Partition}:acm:${Region}:${Account}:acme-endpoint/${AcmeEndpointId}/acme-domain-validation/${AcmeDomainValidationId}", "acme-endpoint": "arn:${Partition}:acm:${Region}:${Account}:acme-endpoint/${AcmeEndpointId}", "acme-external-account-binding": "arn:${Partition}:acm:${Region}:${Account}:acme-endpoint/${AcmeEndpointId}/acme-external-account-binding/${ExternalAccountBindingId}", "certificate": "arn:${Partition}:acm:${Region}:${Account}:certificate/${CertificateId}"}, "application-autoscaling": {"ScalableTarget": "arn:${Partition}:application-autoscaling:${Region}:${Account}:scalable-target/${ResourceId}"}, "athena": {"capacity-reservation": "arn:${Partition}:athena:${Region}:${Account}:capacity-reservation/${CapacityReservationName}", "datacatalog": "arn:${Partition}:athena:${Region}:${Account}:datacatalog/${DataCatalogName}", "session": "arn:${Partition}:athena:${Region}:${Account}:workgroup/${WorkGroupName}/session/${SessionId}", "workgroup": "arn:${Partition}:athena:${Region}:${Account}:workgroup/${WorkGroupName}"}, "bcm-data-exports": {"billingview": "arn:${Partition}:billing::${Account}:billingview/${ResourceId}", "export": "arn:${Partition}:bcm-data-exports:${Region}:${Account}:export/${Identifier}", "table": "arn:${Partition}:bcm-data-exports:${Region}:${Account}:table/${Identifier}"}, "bcm-pricing-calculator": {"bill-estimate": "arn:${Partition}:bcm-pricing-calculator::${Account}:bill-estimate/${BillEstimateId}", "bill-scenario": "arn:${Partition}:bcm-pricing-calculator::${Account}:bill-scenario/${BillScenarioId}", "workload-estimate": "arn:${Partition}:bcm-pricing-calculator::${Account}:workload-estimate/${WorkloadEstimateId}"}, "budgets": {"budget": "arn:${Partition}:budgets::${Account}:budget/${BudgetName}", "budgetAction": "arn:${Partition}:budgets::${Account}:budget/${BudgetName}/action/${ActionId}"}, "ce": {"anomalymonitor": "arn:${Partition}:ce::${Account}:anomalymonitor/${Identifier}", "anomalysubscription": "arn:${Partition}:ce::${Account}:anomalysubscription/${Identifier}", "billingview": "arn:${Partition}:billing::${Account}:billingview/${ResourceId}", "costcategory": "arn:${Partition}:ce::${Account}:costcategory/${Identifier}"}, "cloudtrail": {"channel": "arn:${Partition}:cloudtrail:${Region}:${Account}:channel/${ChannelId}", "dashboard": "arn:${Partition}:cloudtrail:${Region}:${Account}:dashboard/${DashboardName}", "eventdatastore": "arn:${Partition}:cloudtrail:${Region}:${Account}:eventdatastore/${EventDataStoreId}", "trail": "arn:${Partition}:cloudtrail:${Region}:${Account}:trail/${TrailName}"}, "codebuild": {"build": "arn:${Partition}:codebuild:${Region}:${Account}:build/${BuildId}", "build-batch": "arn:${Partition}:codebuild:${Region}:${Account}:build-batch/${BuildBatchId}", "fleet": "arn:${Partition}:codebuild:${Region}:${Account}:fleet/${FleetName}:${FleetId}", "project": "arn:${Partition}:codebuild:${Region}:${Account}:project/${ProjectName}", "report": "arn:${Partition}:codebuild:${Region}:${Account}:report/${ReportGroupName}:${ReportId}", "report-group": "arn:${Partition}:codebuild:${Region}:${Account}:report-group/${ReportGroupName}", "sandbox": "arn:${Partition}:codebuild:${Region}:${Account}:sandbox/${SandboxId}"}, "codepipeline": {"action": "arn:${Partition}:codepipeline:${Region}:${Account}:${PipelineName}/${StageName}/${ActionName}", "actiontype": "arn:${Partition}:codepipeline:${Region}:${Account}:actiontype:${Owner}/${Category}/${Provider}/${Version}", "pipeline": "arn:${Partition}:codepipeline:${Region}:${Account}:${PipelineName}", "stage": "arn:${Partition}:codepipeline:${Region}:${Account}:${PipelineName}/${StageName}", "webhook": "arn:${Partition}:codepipeline:${Region}:${Account}:webhook:${WebhookName}"}, "cognito-identity": {"identitypool": "arn:${Partition}:cognito-identity:${Region}:${Account}:identitypool/${IdentityPoolId}"}, "cognito-idp": {"userpool": "arn:${Partition}:cognito-idp:${Region}:${Account}:userpool/${UserPoolId}", "webacl": "arn:${Partition}:wafv2:${Region}:${Account}:${Scope}/webacl/${Name}/${Id}"}, "cur": {"cur": "arn:${Partition}:cur:${Region}:${Account}:definition/${ReportName}"}, "ecr": {"repository": "arn:${Partition}:ecr:${Region}:${Account}:repository/${RepositoryName}"}, "elasticloadbalancing": {"listener-rule/app": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:listener-rule/app/${LoadBalancerName}/${LoadBalancerId}/${ListenerId}/${ListenerRuleId}", "listener-rule/net": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:listener-rule/net/${LoadBalancerName}/${LoadBalancerId}/${ListenerId}/${ListenerRuleId}", "listener/app": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:listener/app/${LoadBalancerName}/${LoadBalancerId}/${ListenerId}", "listener/gwy": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:listener/gwy/${LoadBalancerName}/${LoadBalancerId}/${ListenerId}", "listener/net": "arn:${Partition}:elasticloadbalancing:${Region}:${AccoLine truncated
|
||||
"arnFormats": {"acm": {"acme-domain-validation": "arn:${Partition}:acm:${Region}:${Account}:acme-endpoint/${AcmeEndpointId}/acme-domain-validation/${AcmeDomainValidationId}", "acme-endpoint": "arn:${Partition}:acm:${Region}:${Account}:acme-endpoint/${AcmeEndpointId}", "acme-external-account-binding": "arn:${Partition}:acm:${Region}:${Account}:acme-endpoint/${AcmeEndpointId}/acme-external-account-binding/${ExternalAccountBindingId}", "certificate": "arn:${Partition}:acm:${Region}:${Account}:certificate/${CertificateId}"}, "application-autoscaling": {"ScalableTarget": "arn:${Partition}:application-autoscaling:${Region}:${Account}:scalable-target/${ResourceId}"}, "athena": {"capacity-reservation": "arn:${Partition}:athena:${Region}:${Account}:capacity-reservation/${CapacityReservationName}", "datacatalog": "arn:${Partition}:athena:${Region}:${Account}:datacatalog/${DataCatalogName}", "session": "arn:${Partition}:athena:${Region}:${Account}:workgroup/${WorkGroupName}/session/${SessionId}", "workgroup": "arn:${Partition}:athena:${Region}:${Account}:workgroup/${WorkGroupName}"}, "bcm-data-exports": {"billingview": "arn:${Partition}:billing::${Account}:billingview/${ResourceId}", "export": "arn:${Partition}:bcm-data-exports:${Region}:${Account}:export/${Identifier}", "table": "arn:${Partition}:bcm-data-exports:${Region}:${Account}:table/${Identifier}"}, "bcm-pricing-calculator": {"bill-estimate": "arn:${Partition}:bcm-pricing-calculator::${Account}:bill-estimate/${BillEstimateId}", "bill-scenario": "arn:${Partition}:bcm-pricing-calculator::${Account}:bill-scenario/${BillScenarioId}", "workload-estimate": "arn:${Partition}:bcm-pricing-calculator::${Account}:workload-estimate/${WorkloadEstimateId}"}, "budgets": {"budget": "arn:${Partition}:budgets::${Account}:budget/${BudgetName}", "budgetAction": "arn:${Partition}:budgets::${Account}:budget/${BudgetName}/action/${ActionId}"}, "ce": {"anomalymonitor": "arn:${Partition}:ce::${Account}:anomalymonitor/${Identifier}", "anomalysubscription": "arn:${Partition}:ce::${Account}:anomalysubscription/${Identifier}", "billingview": "arn:${Partition}:billing::${Account}:billingview/${ResourceId}", "costcategory": "arn:${Partition}:ce::${Account}:costcategory/${Identifier}"}, "cloudtrail": {"channel": "arn:${Partition}:cloudtrail:${Region}:${Account}:channel/${ChannelId}", "dashboard": "arn:${Partition}:cloudtrail:${Region}:${Account}:dashboard/${DashboardName}", "eventdatastore": "arn:${Partition}:cloudtrail:${Region}:${Account}:eventdatastore/${EventDataStoreId}", "trail": "arn:${Partition}:cloudtrail:${Region}:${Account}:trail/${TrailName}"}, "codebuild": {"build": "arn:${Partition}:codebuild:${Region}:${Account}:build/${BuildId}", "build-batch": "arn:${Partition}:codebuild:${Region}:${Account}:build-batch/${BuildBatchId}", "fleet": "arn:${Partition}:codebuild:${Region}:${Account}:fleet/${FleetName}:${FleetId}", "project": "arn:${Partition}:codebuild:${Region}:${Account}:project/${ProjectName}", "report": "arn:${Partition}:codebuild:${Region}:${Account}:report/${ReportGroupName}:${ReportId}", "report-group": "arn:${Partition}:codebuild:${Region}:${Account}:report-group/${ReportGroupName}", "sandbox": "arn:${Partition}:codebuild:${Region}:${Account}:sandbox/${SandboxId}"}, "codepipeline": {"action": "arn:${Partition}:codepipeline:${Region}:${Account}:${PipelineName}/${StageName}/${ActionName}", "actiontype": "arn:${Partition}:codepipeline:${Region}:${Account}:actiontype:${Owner}/${Category}/${Provider}/${Version}", "pipeline": "arn:${Partition}:codepipeline:${Region}:${Account}:${PipelineName}", "stage": "arn:${Partition}:codepipeline:${Region}:${Account}:${PipelineName}/${StageName}", "webhook": "arn:${Partition}:codepipeline:${Region}:${Account}:webhook:${WebhookName}"}, "cognito-identity": {"identitypool": "arn:${Partition}:cognito-identity:${Region}:${Account}:identitypool/${IdentityPoolId}"}, "cognito-idp": {"userpool": "arn:${Partition}:cognito-idp:${Region}:${Account}:userpool/${UserPoolId}", "webacl": "arn:${Partition}:wafv2:${Region}:${Account}:${Scope}/webacl/${Name}/${Id}"}, "cur": {"cur": "arn:${Partition}:cur:${Region}:${Account}:definition/${ReportName}"}, "ecr": {"repository": "arn:${Partition}:ecr:${Region}:${Account}:repository/${RepositoryName}"}, "elasticloadbalancing": {"listener-rule/app": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:listener-rule/app/${LoadBalancerName}/${LoadBalancerId}/${ListenerId}/${ListenerRuleId}", "listener-rule/net": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:listener-rule/net/${LoadBalancerName}/${LoadBalancerId}/${ListenerId}/${ListenerRuleId}", "listener/app": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:listener/app/${LoadBalancerName}/${LoadBalancerId}/${ListenerId}", "listener/gwy": "arn:${Partition}:elasticloadbalancing:${Region}:${Account}:listener/gwy/${LoadBalancerName}/${LoadBalancerId}/${ListenerId}", "listener/net": "arn:${Partition}:elasticloadbalancing:${Region}:${AccoLine truncated
|
||||
"unqualified": {"states": ["statemachine"]},
|
||||
"mintedIds": {"events": ["api-destination", "connection"]},
|
||||
"operations": {
|
||||
@@ -884,6 +884,18 @@
|
||||
"kinesisanalytics:UntagResource": {"action": "kinesisanalytics:UntagResource", "types": ["application"], "resources": [{"types": ["application"], "arn": "ResourceARN"}]},
|
||||
"kinesisanalytics:UpdateApplication": {"action": "kinesisanalytics:UpdateApplication", "types": ["application"], "resources": [{"type": "application", "fill": {"ApplicationName": "ApplicationName"}}]},
|
||||
"kinesisanalytics:UpdateApplicationMaintenanceConfiguration": {"action": "kinesisanalytics:UpdateApplicationMaintenanceConfiguration", "types": ["application"], "resources": [{"type": "application", "fill": {"ApplicationName": "ApplicationName"}}]},
|
||||
"redshift-data:BatchExecuteStatement": {"action": "redshift-data:BatchExecuteStatement", "types": ["cluster", "workgroup"], "resources": [{"types": ["cluster", "workgroup"], "arn": "SecretArn"}, {"type": "cluster", "fill": {"ClusterName": "ClusterIdentifier"}}, {"type": "workgroup", "fill": {}, "find": ["WorkgroupName"]}]},
|
||||
"redshift-data:CancelStatement": {"action": "redshift-data:CancelStatement", "types": [], "resources": []},
|
||||
"redshift-data:DescribeStatement": {"action": "redshift-data:DescribeStatement", "types": [], "resources": []},
|
||||
"redshift-data:DescribeTable": {"action": "redshift-data:DescribeTable", "types": ["cluster", "workgroup"], "resources": [{"types": ["cluster", "workgroup"], "arn": "SecretArn"}, {"type": "cluster", "fill": {"ClusterName": "ClusterIdentifier"}}, {"type": "workgroup", "fill": {}, "find": ["WorkgroupName"]}]},
|
||||
"redshift-data:ExecuteStatement": {"action": "redshift-data:ExecuteStatement", "types": ["cluster", "workgroup"], "resources": [{"types": ["cluster", "workgroup"], "arn": "SecretArn"}, {"type": "cluster", "fill": {"ClusterName": "ClusterIdentifier"}}, {"type": "workgroup", "fill": {}, "find": ["WorkgroupName"]}]},
|
||||
"redshift-data:GetStatementResult": {"action": "redshift-data:GetStatementResult", "types": [], "resources": []},
|
||||
"redshift-data:GetStatementResultV2": {"action": "redshift-data:GetStatementResult", "types": [], "resources": []},
|
||||
"redshift-data:ListDatabases": {"action": "redshift-data:ListDatabases", "types": ["cluster", "workgroup"], "resources": [{"types": ["cluster", "workgroup"], "arn": "SecretArn"}, {"type": "cluster", "fill": {"ClusterName": "ClusterIdentifier"}}, {"type": "workgroup", "fill": {}, "find": ["WorkgroupName"]}]},
|
||||
"redshift-data:ListSchemas": {"action": "redshift-data:ListSchemas", "types": ["cluster", "workgroup"], "resources": [{"types": ["cluster", "workgroup"], "arn": "SecretArn"}, {"type": "cluster", "fill": {"ClusterName": "ClusterIdentifier"}}, {"type": "workgroup", "fill": {}, "find": ["WorkgroupName"]}]},
|
||||
"redshift-data:ListSessions": {"action": "redshift-data:ListSessions", "types": [], "resources": []},
|
||||
"redshift-data:ListStatements": {"action": "redshift-data:ListStatements", "types": [], "resources": []},
|
||||
"redshift-data:ListTables": {"action": "redshift-data:ListTables", "types": ["cluster", "workgroup"], "resources": [{"types": ["cluster", "workgroup"], "arn": "SecretArn"}, {"type": "cluster", "fill": {"ClusterName": "ClusterIdentifier"}}, {"type": "workgroup", "fill": {}, "find": ["WorkgroupName"]}]},
|
||||
"servicediscovery:CreateHttpNamespace": {"action": "servicediscovery:CreateHttpNamespace", "types": [], "resources": []},
|
||||
"servicediscovery:CreatePrivateDnsNamespace": {"action": "servicediscovery:CreatePrivateDnsNamespace", "types": [], "resources": []},
|
||||
"servicediscovery:CreatePublicDnsNamespace": {"action": "servicediscovery:CreatePublicDnsNamespace", "types": [], "resources": []},
|
||||
|
||||
@@ -461,6 +461,45 @@ class RequestResourcesTest {
|
||||
stored));
|
||||
}
|
||||
|
||||
/**
|
||||
* A Data API request runs on the cluster its {@code ClusterIdentifier} names, or on the serverless workgroup
|
||||
* stored under the name or ARN its {@code WorkgroupName} gives, whose ARN ends in the id Redshift Serverless
|
||||
* mints; its {@code SecretArn} names neither, and a request naming its session alone names none.
|
||||
*/
|
||||
@Test
|
||||
void aDataApiRequestIsOnTheClusterOrTheStoredWorkgroupItNames() {
|
||||
String workgroups = "arn:aws:redshift-serverless:us-east-1:000000000000:workgroup/";
|
||||
String id = "0f1e2d3c-4b5a-4978-8a9b-0c1d2e3f4a5b";
|
||||
StoredResourceArns stored = new StoredResourceArns() {
|
||||
@Override
|
||||
public String namespace() {
|
||||
return "redshift-data";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<String> find(String type, List<String> names, String region) {
|
||||
return "workgroup".equals(type) && "us-east-1".equals(region)
|
||||
&& (List.of("analytics").equals(names) || List.of(workgroups + id).equals(names))
|
||||
? Optional.of(workgroups + id) : Optional.empty();
|
||||
}
|
||||
};
|
||||
String secret = ",\"SecretArn\":\"arn:aws:secretsmanager:us-east-1:000000000000:secret:db-AbCdEf\"";
|
||||
assertEquals(List.of("arn:aws:redshift:us-east-1:000000000000:cluster:warehouse"), RequestResources.of(
|
||||
"redshift-data:ExecuteStatement", json("{\"Sql\":\"select 1\",\"ClusterIdentifier\":\"warehouse\""
|
||||
+ secret + "}"), "aws", "us-east-1", "000000000000", stored));
|
||||
for (String named : List.of("analytics", workgroups + id)) {
|
||||
assertEquals(List.of(workgroups + id), RequestResources.of("redshift-data:ListDatabases",
|
||||
json("{\"Database\":\"dev\",\"WorkgroupName\":\"" + named + "\"" + secret + "}"), "aws",
|
||||
"us-east-1", "000000000000", stored), named);
|
||||
}
|
||||
assertEquals(List.of(workgroups + "*"), RequestResources.of("redshift-data:ListDatabases",
|
||||
json("{\"Database\":\"dev\",\"WorkgroupName\":\"other\"}"), "aws", "us-east-1", "000000000000",
|
||||
stored));
|
||||
assertEquals(List.of(), RequestResources.of("redshift-data:ExecuteStatement",
|
||||
json("{\"Sql\":\"select 1\",\"SessionId\":\"" + id + "\"}"), "aws", "us-east-1", "000000000000",
|
||||
stored));
|
||||
}
|
||||
|
||||
/** A request value is a name, so a {@code ${...}} in it is kept, not read as a variable of the format. */
|
||||
@Test
|
||||
void aValueIsTakenLiterally() {
|
||||
|
||||
+69
@@ -3,10 +3,13 @@ package io.github.hectorvent.floci.services.iam;
|
||||
import com.fasterxml.jackson.databind.JsonNode;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.dataformat.cbor.CBORFactory;
|
||||
import io.github.hectorvent.floci.services.redshift.model.Endpoint;
|
||||
import io.github.hectorvent.floci.services.redshiftserverless.RedshiftServerlessRuntime;
|
||||
import io.github.hectorvent.floci.testing.EnforcementFixtures;
|
||||
import io.github.hectorvent.floci.testing.IamEnforcementProfile;
|
||||
import io.github.hectorvent.floci.testing.PartitionCleanup;
|
||||
import io.github.hectorvent.floci.testing.RestAssuredJsonUtils;
|
||||
import io.quarkus.test.InjectMock;
|
||||
import io.quarkus.test.common.http.TestHTTPResource;
|
||||
import io.quarkus.test.junit.QuarkusTest;
|
||||
import io.quarkus.test.junit.TestProfile;
|
||||
@@ -33,6 +36,9 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyBoolean;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* A request of a service whose ARNs the vendored table of request resources gives is checked on the resource it
|
||||
@@ -49,6 +55,8 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
private static final String ELB = "arn:aws:elasticloadbalancing:" + REGION + ":" + ACCOUNT + ":";
|
||||
private static final String EVENTS = "arn:aws:events:" + REGION + ":" + ACCOUNT + ":";
|
||||
private static final String TARGETS = "arn:aws:application-autoscaling:" + REGION + ":" + ACCOUNT + ":scalable-target/";
|
||||
private static final String REDSHIFT = "arn:aws:redshift:" + REGION + ":" + ACCOUNT + ":";
|
||||
private static final String WORKGROUPS = "arn:aws:redshift-serverless:" + REGION + ":" + ACCOUNT + ":workgroup/";
|
||||
/** The AWS Load Balancer Controller's create, tag-on-create and listener statements (its policy v2.14.0). */
|
||||
private static final String CONTROLLER_CREATE = "{\"Effect\":\"Allow\",\"Action\":[\"elasticloadbalancing:CreateLoadBalancer\","
|
||||
+ "\"elasticloadbalancing:CreateTargetGroup\"],\"Resource\":\"*\","
|
||||
@@ -74,6 +82,10 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
@RegisterExtension
|
||||
final PartitionCleanup cleanup = new PartitionCleanup();
|
||||
|
||||
/** A serverless workgroup's PostgreSQL container is not needed to check a request on it, so none starts. */
|
||||
@InjectMock
|
||||
RedshiftServerlessRuntime runtime;
|
||||
|
||||
@BeforeAll
|
||||
static void configureRestAssured() {
|
||||
RestAssuredJsonUtils.configureAwsContentTypes();
|
||||
@@ -1270,6 +1282,63 @@ class IamRequestResourceEnforcementIntegrationTest {
|
||||
.then();
|
||||
}
|
||||
|
||||
/**
|
||||
* A Data API request is checked on the cluster it names, or on the serverless workgroup its name or ARN finds,
|
||||
* whose ARN ends in the id Redshift Serverless gave it; one naming a workgroup there is none of is checked with
|
||||
* that id open. Before, these were checked on {@code *}.
|
||||
*/
|
||||
@Test
|
||||
void aDataApiRequestIsCheckedOnTheClusterOrWorkgroupItNames() {
|
||||
when(runtime.start(any(String.class), any(String.class), any(String.class), any(String.class),
|
||||
any(String.class), any(String.class), any(Endpoint.class), anyBoolean(), any()))
|
||||
.thenReturn(new RedshiftServerlessRuntime.Backend("127.0.0.1", 55432));
|
||||
String name = "res-wg-" + suffix();
|
||||
String arn = createWorkgroup(name);
|
||||
assertTrue(arn.startsWith(WORKGROUPS), arn);
|
||||
|
||||
User user = user("res-data");
|
||||
user.policy(allowOn("redshift-data:ListDatabases", arn) + ","
|
||||
+ allowOn("redshift-data:ListDatabases", REDSHIFT + "cluster:res-cluster"));
|
||||
// Authorized, a database the workgroup does not have, or a cluster Floci does not have, is refused by the
|
||||
// Data API, not by IAM.
|
||||
for (String named : List.of(name, arn)) {
|
||||
listDatabases(user, "\"WorkgroupName\":\"" + named + "\"").statusCode(400)
|
||||
.body(containsString("does not exist in workgroup"));
|
||||
}
|
||||
listDatabases(user, "\"ClusterIdentifier\":\"res-cluster\",\"DbUser\":\"admin\"").statusCode(400)
|
||||
.body(containsString("was not found"));
|
||||
refusedJson(listDatabases(user, "\"ClusterIdentifier\":\"res-other\",\"DbUser\":\"admin\""),
|
||||
"redshift-data:ListDatabases");
|
||||
refusedJson(listDatabases(user, "\"WorkgroupName\":\"res-wg-missing\""), "redshift-data:ListDatabases");
|
||||
// A deny on the workgroup holds, whether a request names it by its name or by its ARN.
|
||||
user.policy(allowOn("redshift-data:*", "*") + ",{\"Effect\":\"Deny\","
|
||||
+ "\"Action\":\"redshift-data:ListDatabases\",\"Resource\":\"" + arn + "\"}");
|
||||
for (String named : List.of(name, arn)) {
|
||||
refusedJson(listDatabases(user, "\"WorkgroupName\":\"" + named + "\""), "redshift-data:ListDatabases");
|
||||
}
|
||||
}
|
||||
|
||||
/** Creates a serverless workgroup and its namespace as the admin and gives the workgroup's ARN. */
|
||||
private String createWorkgroup(String name) {
|
||||
adminJson("redshift-serverless", "RedshiftServerless.CreateNamespace")
|
||||
.body("{\"namespaceName\":\"" + name + "-ns\",\"adminUsername\":\"admin\","
|
||||
+ "\"adminUserPassword\":\"Secret123!\"}").post("/").then().statusCode(200);
|
||||
cleanup.register(() -> adminJson("redshift-serverless", "RedshiftServerless.DeleteNamespace")
|
||||
.body("{\"namespaceName\":\"" + name + "-ns\"}").post("/"));
|
||||
String arn = adminJson("redshift-serverless", "RedshiftServerless.CreateWorkgroup")
|
||||
.body("{\"workgroupName\":\"" + name + "\",\"namespaceName\":\"" + name + "-ns\"}").post("/").then()
|
||||
.statusCode(200).extract().path("workgroup.workgroupArn");
|
||||
cleanup.register(() -> adminJson("redshift-serverless", "RedshiftServerless.DeleteWorkgroup")
|
||||
.body("{\"workgroupName\":\"" + name + "\"}").post("/"));
|
||||
return arn;
|
||||
}
|
||||
|
||||
/** A ListDatabases of a database no workgroup or cluster has, on the target the members name. */
|
||||
private static ValidatableResponse listDatabases(User user, String members) {
|
||||
return user.json("redshift-data", "RedshiftData.ListDatabases", "1.1")
|
||||
.body("{\"Database\":\"res-none\"," + members + "}").post("/").then();
|
||||
}
|
||||
|
||||
/** A monthly cost budget of the name, with a billing view ARN when one is given. */
|
||||
private static String budget(String name, String billingViewArn) {
|
||||
return "{\"BudgetName\":\"" + name + "\",\"BudgetType\":\"COST\",\"TimeUnit\":\"MONTHLY\",\"BudgetLimit\":"
|
||||
|
||||
+16
@@ -435,6 +435,22 @@ class RedshiftServerlessServiceTest {
|
||||
() -> service.untagResource(absent, List.of("a"), REGION)).getErrorCode());
|
||||
}
|
||||
|
||||
@Test
|
||||
void aWorkgroupIsFoundByItsNameOrArnInItsRegion() {
|
||||
create("find-ns");
|
||||
String arn = createWorkgroup("find-wg", "find-ns").getWorkgroupArn();
|
||||
assertTrue(arn.matches("arn:aws:redshift-serverless:" + REGION + ":" + ACCOUNT_ID
|
||||
+ ":workgroup/[0-9a-f-]{36}"), arn);
|
||||
for (String named : List.of("find-wg", arn)) {
|
||||
assertEquals(Optional.of(arn),
|
||||
service.findWorkgroupByNameOrArn(named, REGION).map(Workgroup::getWorkgroupArn), named);
|
||||
}
|
||||
assertEquals(Optional.empty(), service.findWorkgroupByNameOrArn("other-wg", REGION));
|
||||
assertEquals(Optional.empty(), service.findWorkgroupByNameOrArn("find-wg", "eu-west-1"));
|
||||
assertEquals(Optional.empty(), service.findWorkgroupByNameOrArn(arn.substring(0, arn.lastIndexOf('/') + 1)
|
||||
+ "00000000-0000-0000-0000-000000000000", REGION));
|
||||
}
|
||||
|
||||
@Test
|
||||
void tagsSurviveAnUnrelatedNamespaceUpdate() {
|
||||
Namespace created = service.createNamespace("keep-tags-ns", "admin", null, null, null, null, null,
|
||||
|
||||
@@ -90,7 +90,8 @@ all an id their service mints, which a request names by members the ARN does not
|
||||
members: each operation whose request has them all names the type by them (`find`), and the reader
|
||||
asks the service for the ARN they find, or else checks the ARN with its id open, as for a create; an
|
||||
Application Auto Scaling scalable target, `scalable-target/<id>`, is named by its service namespace,
|
||||
resource id and scalable dimension.
|
||||
resource id and scalable dimension, and the Redshift Serverless workgroup a Data API request runs on,
|
||||
`workgroup/<id>`, by its name or ARN.
|
||||
|
||||
The Service Reference is live rather than a pinned dependency, so a fresh generation is not
|
||||
byte-identical. The two gates split along the sources:
|
||||
@@ -129,8 +130,8 @@ OUTPUT = REPO_ROOT / "src/main/resources/aws/iam-request-resources.json"
|
||||
# are the ones its handlers mint.
|
||||
NAMESPACES = ("acm", "application-autoscaling", "athena", "bcm-data-exports", "bcm-pricing-calculator", "budgets", "ce", "cloudtrail",
|
||||
"codebuild", "codepipeline", "cognito-identity", "cognito-idp", "cur", "ecr", "elasticloadbalancing",
|
||||
"events", "firehose", "globalaccelerator", "kinesisanalytics", "servicediscovery", "servicequotas",
|
||||
"states", "textract", "timestream-influxdb", "translate")
|
||||
"events", "firehose", "globalaccelerator", "kinesisanalytics", "redshift-data", "servicediscovery",
|
||||
"servicequotas", "states", "textract", "timestream-influxdb", "translate")
|
||||
|
||||
# SDK clients the reference lists for a namespace's operations whose requests Floci does not serve, and why: their
|
||||
# members are not read.
|
||||
@@ -212,9 +213,6 @@ NOT_COVERED: dict[str, str] = {
|
||||
"rds": _LATER,
|
||||
"rds-data": _REST,
|
||||
"redshift": _LATER,
|
||||
"redshift-data": "not read yet: a serverless workgroup's ARN ends in an id the service mints, `workgroup/<id>`, "
|
||||
"while its requests name the workgroup by WorkgroupName, a name or an ARN, so its resource is the "
|
||||
"stored ARN that name finds, a FOUND_BY type its service does not look up yet",
|
||||
"redshift-serverless": _LATER,
|
||||
"rekognition": _LATER,
|
||||
"resource-explorer-2": _REST,
|
||||
@@ -446,6 +444,12 @@ FOUND_BY: dict[str, tuple[list[str], str]] = {
|
||||
"target', Application Auto Scaling User Guide), which the reference names ${ResourceId}, while its requests "
|
||||
"name the target by ServiceNamespace, ResourceId and ScalableDimension; ResourceId is the target's "
|
||||
"resource (service/<cluster>/<service>), not that id"),
|
||||
"redshift-data:workgroup": (
|
||||
["WorkgroupName"],
|
||||
"a serverless workgroup's ARN ends in the id Redshift Serverless gives it, workgroup/<id> (its Workgroup's "
|
||||
"workgroupId, 'The unique identifier of the workgroup'; botocore's WorkgroupNameString takes an ARN ending "
|
||||
"in workgroup/<uuid>), while a Data API request names the workgroup by WorkgroupName, 'The serverless "
|
||||
"workgroup name or Amazon Resource Name (ARN)'"),
|
||||
}
|
||||
|
||||
# The variables of an ARN format the account, partition and Region fill.
|
||||
@@ -805,7 +809,8 @@ def entry_for(operation: str, upstream: dict, formats: dict[str, str], models: d
|
||||
raise ValueError(f"CORRECTIONS serves {operation} on {sorted(unknown)}, no endpoint prefix of the clients "
|
||||
f"it reads ({sorted(endpoints)})")
|
||||
else:
|
||||
resources = with_found(resources_for(operation, types, formats, members), namespace_of(operation), members)
|
||||
resources = with_found(resources_for(operation, types, formats, members), namespace_of(operation), types,
|
||||
members)
|
||||
resources = with_account(resources, formats, account_members(models, operation.split(":", 1)[1]))
|
||||
resources = with_arn_of(resources, formats, name_or_arn_members(models, operation.split(":", 1)[1]))
|
||||
resources = with_made(resources, operation, formats)
|
||||
@@ -816,16 +821,14 @@ def entry_for(operation: str, upstream: dict, formats: dict[str, str], models: d
|
||||
return entry
|
||||
|
||||
|
||||
def with_found(resources: list[dict], namespace: str, members: dict[str, str]) -> list[dict]:
|
||||
"""The resources, each a `FOUND_BY` type fills named by the members its service finds it by instead, when the
|
||||
request has them all, and left out when it does not: its variables are an id the request does not give."""
|
||||
found = []
|
||||
for resource in resources:
|
||||
key = f"{namespace}:{resource.get('type')}"
|
||||
if "fill" not in resource or key not in FOUND_BY:
|
||||
found.append(resource)
|
||||
elif all(members.get(member) == member for member in FOUND_BY[key][0]):
|
||||
found.append({"type": resource["type"], "fill": {}, "find": list(FOUND_BY[key][0])})
|
||||
def with_found(resources: list[dict], namespace: str, types: list[str], members: dict[str, str]) -> list[dict]:
|
||||
"""The resources, a `FOUND_BY` type the action acts on named by the members its service finds it by, when the
|
||||
request has them all, rather than by any it fills: its variables are an id the request does not give."""
|
||||
found = [resource for resource in resources if f"{namespace}:{resource.get('type')}" not in FOUND_BY]
|
||||
for kind in types:
|
||||
by = FOUND_BY.get(f"{namespace}:{kind}", ([], ""))[0]
|
||||
if by and all(members.get(member) == member for member in by):
|
||||
found.append({"type": kind, "fill": {}, "find": list(by)})
|
||||
return found
|
||||
|
||||
|
||||
|
||||
@@ -264,13 +264,17 @@ def test_a_type_whose_service_mints_an_id_after_its_name_is_recorded_and_must_be
|
||||
|
||||
|
||||
def test_a_type_whose_arn_is_all_an_id_its_service_mints_is_found_by_the_members_naming_it(corrections, tmp_path):
|
||||
documents = [reference("svc", {"PutTarget": ["target"], "TagTarget": ["target"], "GetByResource": ["target"]},
|
||||
{"target": "arn:${Partition}:svc:${Region}:${Account}:target/${ResourceId}"})]
|
||||
documents = [reference("svc", {"PutTarget": ["target"], "TagTarget": ["target"], "GetByResource": ["target"],
|
||||
"RunOn": ["target", "group"]},
|
||||
{"target": "arn:${Partition}:svc:${Region}:${Account}:target/${ResourceId}",
|
||||
"group": "arn:${Partition}:svc:${Region}:${Account}:group/${GroupId}"})]
|
||||
write_models(tmp_path, {"svc": model({"PutTarget": {"Namespace": "String", "ResourceId": "String",
|
||||
"Dimension": "String"},
|
||||
"TagTarget": {"ResourceArn": "String"},
|
||||
"GetByResource": {"ResourceId": "String"}})})
|
||||
corrections.setattr(r, "FOUND_BY", {"svc:target": (["Namespace", "ResourceId", "Dimension"], "its service mints the id")})
|
||||
"GetByResource": {"ResourceId": "String"},
|
||||
"RunOn": {"GroupName": "String"}})})
|
||||
corrections.setattr(r, "FOUND_BY", {"svc:target": (["Namespace", "ResourceId", "Dimension"], "its service mints the id"),
|
||||
"svc:group": (["GroupName"], "its service mints the id")})
|
||||
document = r.build(documents, "test", tmp_path, "botocore test")
|
||||
assert r.validate(document) == [] and r.derive(document, tmp_path) == []
|
||||
operations = document["operations"]
|
||||
@@ -280,6 +284,8 @@ def test_a_type_whose_arn_is_all_an_id_its_service_mints_is_found_by_the_members
|
||||
# Its ARN names it as given, and a request lacking a member names none.
|
||||
assert operations["svc:TagTarget"]["resources"] == [{"types": ["target"], "arn": "ResourceArn"}]
|
||||
assert operations["svc:GetByResource"]["resources"] == []
|
||||
# Found by its name though no member fills its id, so the rule derives nothing for it.
|
||||
assert operations["svc:RunOn"]["resources"] == [{"type": "group", "fill": {}, "find": ["GroupName"]}]
|
||||
# A hand edit no longer matches, and a type the file has no format for fails the build.
|
||||
operations["svc:PutTarget"]["resources"] = [{"type": "target", "fill": {"ResourceId": "ResourceId"}}]
|
||||
assert r.validate(document) == [] and len(r.derive(document, tmp_path)) == 1
|
||||
@@ -572,6 +578,11 @@ def test_the_vendored_file_is_well_formed():
|
||||
{"type": "ScalableTarget", "fill": {}, "find": ["ServiceNamespace", "ResourceId", "ScalableDimension"]}]
|
||||
assert operations["application-autoscaling:TagResource"]["resources"] == [
|
||||
{"types": ["ScalableTarget"], "arn": "ResourceARN"}]
|
||||
# A Data API request runs on the cluster it names, or on the serverless workgroup its name or ARN finds.
|
||||
assert operations["redshift-data:ExecuteStatement"]["resources"][1:] == [
|
||||
{"type": "cluster", "fill": {"ClusterName": "ClusterIdentifier"}},
|
||||
{"type": "workgroup", "fill": {}, "find": ["WorkgroupName"]}]
|
||||
assert operations["redshift-data:ListStatements"]["resources"] == []
|
||||
# The v2 API's Type picks the load balancer it creates, application when it gives none.
|
||||
assert operations["elasticloadbalancing:CreateLoadBalancer"]["resources"][1] == {
|
||||
"type": "loadbalancer/app/", "fill": {"LoadBalancerName": "Name"}, "when": {"Type": ["application", None]}}
|
||||
Reference in new issue
Block a user