mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(iam): check the tags an OpenSearch domain is created with (#7616)
OpenSearch's CreateDomain and the legacy CreateElasticsearchDomain store the TagList they carry, but the tag-on-create table did not read the `es` namespace, so under IAM enforcement a caller allowed to create a domain could tag it with no es:AddTags, and a policy allowing the create only with some tag did not hold. The reason the generator gave, that no rule maps its REST routes, has not been true since they were vendored. `es` moves to the generator's namespaces. The Service Reference lists OpenSearch Service's operations for the `es` client alone, so, as the request-resources generator does, an operation of a vendored REST model it lists for no client is read as the action of its own name: it needs the tagging actions of the operations the reference lists that action for, and is checked with the request's tags when that action takes them. The `opensearch` client's CreateDomain is es:CreateDomain, which the reference lists for CreateElasticsearchDomain beside es:AddTags, as the OpenSearch Service developer guide's policy for creating a domain only with a tag grants es:CreateDomain and es:AddTags. Both creates now need es:AddTags on the domain they name, and are checked with the tags as aws:RequestTag/<key> and aws:TagKeys (587 operations over 72 namespaces, no other entry changed). The handler also read a TagList the model does not allow, and not as the check reads it: a tag with no value was dropped, though the check lets it replace an earlier tag of its key, and an object's structures were tags, though the check lets a member of the same name replace them. Either got a denied tag past a deny on it. The model requires a list of tags, each with a Key of 1 to 128 characters and a Value of up to 256, so CreateDomain and AddTags now refuse anything else with a ValidationException, before changing anything, and the tags checked are the tags a domain gets.
This commit is contained in:
1 parent
4296d11934
commit
6110825561
7 files changed
+214
-16
No files matched your search
@@ -2202,7 +2202,11 @@ tags and adds tags (`TagResource`, `CreateTags`, `AddTags`, `AddTagsToResource`,
|
||||
IAM's `TagRole`, STS's `TagSession` and the like), in the services Floci serves over the JSON and
|
||||
Query protocols and Smithy RPC v2 CBOR and in the REST services whose routes are authorized as
|
||||
operations, is checked from a second table generated the same way,
|
||||
`src/main/resources/aws/iam-tag-on-create.json`.
|
||||
`src/main/resources/aws/iam-tag-on-create.json`. The Service Reference lists OpenSearch Service's
|
||||
operations for the `es` client alone, so a REST operation it lists for no client is read as the action
|
||||
of its own name, needing the tagging actions of the operations it lists that action for: the
|
||||
`opensearch` client's `CreateDomain` needs `es:AddTags`, as `CreateElasticsearchDomain`, listed with
|
||||
`es:CreateDomain`, does.
|
||||
When the request carries tags, the tagging action is checked for each resource's tags apart, with
|
||||
each tag as `aws:RequestTag/<key>` and their keys as `aws:TagKeys`, so a policy that allows tagging
|
||||
only with some tags or keys holds at creation too. A tag specification's tags are checked on the
|
||||
@@ -2213,8 +2217,8 @@ on: Lambda's `CreateFunction` is checked on the function its body names, in the
|
||||
Region, as the Service Reference gives it the `function` resource, so a function's tags are checked
|
||||
there too, and a create of a service the table of request resources reads is checked on the resource
|
||||
it creates (a target group on `targetgroup/<Name>/*`, an application load balancer on
|
||||
`loadbalancer/app/<Name>/*`, an Access Analyzer analyzer on `analyzer/<analyzerName>`). A create of
|
||||
a resource under a parent its action acts on tags the new
|
||||
`loadbalancer/app/<Name>/*`, an Access Analyzer analyzer on `analyzer/<analyzerName>`, an OpenSearch
|
||||
domain on `domain/<DomainName>`). A create of a resource under a parent its action acts on tags the new
|
||||
resource, so its tags are checked on that one, built from the parent's ARN with its own id open:
|
||||
`CreateListener` acts on a load balancer and its tags are checked on
|
||||
`listener/app/<load balancer name>/<load balancer id>/*`, and `CreateRule`'s on the new
|
||||
@@ -2229,7 +2233,7 @@ its namespace's `CreateAction` key, as `ec2:CreateTags`, `ecs:TagResource`, Clou
|
||||
`TagResource` and Elastic Load Balancing's `AddTags` do, the key is the operation's name:
|
||||
`ec2:CreateAction` is `RunInstances` for an instance launched with tags. The operation's own action
|
||||
is checked with the same `aws:RequestTag/<key>` and `aws:TagKeys`, once for each resource's tags,
|
||||
wherever the Service Reference lists those keys for it or for a resource it acts on, which it does for 546 of the operations read, so
|
||||
wherever the Service Reference lists those keys for it or for a resource it acts on, which it does for 548 of the operations read, so
|
||||
"allow `sqs:CreateQueue` only with `aws:RequestTag/team`" and "deny it when `aws:RequestTag/team` is
|
||||
null" hold as on AWS; keys a service's own condition keys already give, as EC2's `RunInstances`
|
||||
does, are kept. It is checked once for each reading of the tags and refused if any is denied: the
|
||||
|
||||
@@ -55,6 +55,8 @@ services:
|
||||
| `ListTags` | `GET /2021-01-01/tags/?arn=` | List tags for a domain |
|
||||
| `RemoveTags` | `POST /2021-01-01/tags-removal` | Remove tag keys from a domain |
|
||||
|
||||
Under IAM enforcement, a `CreateDomain` or `CreateElasticsearchDomain` that carries a `TagList` also needs `es:AddTags` on the domain it names, and its own action is checked with the tags as `aws:RequestTag/<key>` and `aws:TagKeys`: the Service Reference lists both keys for it, and the developer guide's policy for creating a domain only with a tag grants `es:CreateDomain` and `es:AddTags`. A `TagList` that is not a list of tags, each with a `Key` of 1 to 128 characters and a `Value` of up to 256, gets a `ValidationException`, on `AddTags` too, as the model requires both.
|
||||
|
||||
### VPC Endpoints
|
||||
|
||||
OpenSearch Service-managed VPC endpoints, which Terraform's `aws_opensearch_vpc_endpoint` manages.
|
||||
|
||||
@@ -40,6 +40,8 @@ import java.util.UUID;
|
||||
public class OpenSearchController {
|
||||
|
||||
private static final Logger LOG = Logger.getLogger(OpenSearchController.class);
|
||||
private static final int TAG_KEY_MAX_LENGTH = 128;
|
||||
private static final int TAG_VALUE_MAX_LENGTH = 256;
|
||||
|
||||
private final OpenSearchService service;
|
||||
private final OpenSearchVpcEndpointService vpcEndpoints;
|
||||
@@ -1041,18 +1043,28 @@ public class OpenSearchController {
|
||||
return opts;
|
||||
}
|
||||
|
||||
/**
|
||||
* The tags a request carries, refused unless as the model has them: a list of structures, each with a {@code Key}
|
||||
* and a {@code Value} of text within their lengths. What the IAM check reads as tags is then what a domain gets.
|
||||
*/
|
||||
private Map<String, String> parseTags(JsonNode node) {
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
if (node == null || node.isMissingNode() || node.isNull()) {
|
||||
return tags;
|
||||
}
|
||||
node.forEach(tag -> {
|
||||
String key = tag.path("Key").asText(null);
|
||||
String value = tag.path("Value").asText(null);
|
||||
if (key != null && value != null) {
|
||||
tags.put(key, value);
|
||||
if (!node.isArray()) {
|
||||
throw new AwsException("ValidationException", "TagList must be a list of tags.", 400);
|
||||
}
|
||||
for (JsonNode tag : node) {
|
||||
JsonNode key = tag.path("Key");
|
||||
JsonNode value = tag.path("Value");
|
||||
if (!key.isTextual() || key.asText().isEmpty() || key.asText().length() > TAG_KEY_MAX_LENGTH
|
||||
|| !value.isTextual() || value.asText().length() > TAG_VALUE_MAX_LENGTH) {
|
||||
throw new AwsException("ValidationException", "Each tag needs a Key of 1 to " + TAG_KEY_MAX_LENGTH
|
||||
+ " characters and a Value of up to " + TAG_VALUE_MAX_LENGTH + " characters.", 400);
|
||||
}
|
||||
});
|
||||
tags.put(key.asText(), value.asText());
|
||||
}
|
||||
return tags;
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"_source": {"generator": "tools/aws/regen_iam_tag_on_create.py", "reference": "https://servicereference.us-east-1.amazonaws.com/", "botocore": "botocore 1.43.118 (installed package)", "retrieved": "2026-11-05", "note": "make iam-tag-on-create-check re-derives every member from botocore; make iam-tag-on-create-verify checks every operation against AWS."},
|
||||
"namespaces": {"access-analyzer": ["accessanalyzer"], "acm": ["acm"], "application-autoscaling": ["application-autoscaling"], "athena": ["athena"], "autoscaling": ["autoscaling"], "bcm-data-exports": ["bcm-data-exports"], "bcm-pricing-calculator": ["bcm-pricing-calculator"], "budgets": ["budgets"], "ce": ["ce"], "cloudformation": ["cloudformation"], "cloudhsm": ["cloudhsmv2"], "cloudtrail": ["cloudtrail"], "cloudwatch": ["cloudwatch", "cloudwatchomni"], "codedeploy": ["codedeploy"], "codepipeline": ["codepipeline"], "cognito-identity": ["cognito-identity"], "cognito-idp": ["cognito-idp"], "comprehend": ["comprehend"], "config": ["config"], "cur": ["cur"], "datasync": ["datasync"], "dms": ["dms"], "dsql": ["dsql"], "dynamodb": ["dynamodb"], "ec2": ["ec2"], "ecr": ["ecr"], "ecs": ["ecs"], "eks": ["eks"], "elasticache": ["elasticache"], "elasticloadbalancing": ["elb", "elbv2"], "elasticmapreduce": ["emr"], "events": ["eventbridgev2", "events"], "firehose": ["firehose"], "globalaccelerator": ["globalaccelerator"], "glue": ["glue"], "iam": ["iam"], "kinesis": ["kinesis"], "kinesisanalytics": ["kinesisanalytics", "kinesisanalyticsv2"], "kms": ["kms"], "lambda": ["lambda", "lambda-core", "lambda-microvms", "lambda-web"], "lightsail": ["lightsail"], "logs": ["logs"], "memorydb": ["memorydb"], "network-firewall": ["network-firewall"], "organizations": ["organizations"], "payment-cryptography": ["payment-cryptography"], "pipes": ["pipes"], "rds": ["docdb", "neptune", "rds"], "redshift": ["redshift"], "redshift-serverless": ["redshift-serverless"], "rekognition": ["rekognition"], "resource-groups": ["resource-groups"], "route53resolver": ["route53resolver"], "sagemaker": ["sagemaker"], "scheduler": ["scheduler"], "secretsmanager": ["secretsmanager"], "servicediscovery": ["servicediscovery"], "ses": ["mailmanager", "pinpoint-email", "ses", "sesv2"], "sns": ["sns"], "sqs": ["sqs"], "ssm": ["ssm"], "sso": ["sso-admin"], "states": ["stepfunctions"], "sts": ["sts"], "swf": ["swf"], "textract": ["textract"], "timestream-influxdb": ["timestream-influxdb"], "transcribe": ["transcribe"], "transfer": ["transfer"], "translate": ["translate"], "wafv2": ["wafv2"]},
|
||||
"notCovered": {"airflow": "REST routes no rule maps yet", "app-integrations": "REST routes no rule maps yet", "appconfig": "REST routes no rule maps yet", "appsync": "REST routes no rule maps yet", "aps": "REST routes no rule maps yet", "aws-marketplace": "REST routes no rule maps yet", "backup": "REST routes no rule maps yet", "batch": "REST routes no rule maps yet", "bedrock": "REST routes no rule maps yet", "bedrock-agentcore": "REST routes no rule maps yet", "cloudfront": "REST routes no rule maps yet", "codeguru-reviewer": "REST routes no rule maps yet", "connect": "REST routes no rule maps yet", "controltower": "REST routes no rule maps yet", "detective": "REST routes no rule maps yet", "dlm": "REST routes no rule maps yet", "elasticfilesystem": "REST routes no rule maps yet", "emr-serverless": "REST routes no rule maps yet", "es": "REST routes no rule maps yet", "fis": "REST routes no rule maps yet", "guardduty": "REST routes no rule maps yet", "inspector2": "REST routes no rule maps yet", "iot": "REST routes no rule maps yet", "kafka": "REST routes no rule maps yet", "macie2": "REST routes no rule maps yet", "mq": "REST routes no rule maps yet", "oam": "REST routes no rule maps yet", "quicksight": "metadata-only REST subset; creation-tag IAM authorization is not implemented", "ram": "REST routes no rule maps yet", "resource-explorer-2": "REST routes no rule maps yet", "rum": "REST routes no rule maps yet", "s3": "authorized by route; S3 checks s3:PutObjectTagging for an object it creates with tags itself", "s3tables": "REST routes no rule maps yet", "securityhub": "REST routes no rule maps yet", "servicecatalog": "its operations that tag are AppRegistry's, whose REST routes no rule maps yet"},
|
||||
"namespaces": {"access-analyzer": ["accessanalyzer"], "acm": ["acm"], "application-autoscaling": ["application-autoscaling"], "athena": ["athena"], "autoscaling": ["autoscaling"], "bcm-data-exports": ["bcm-data-exports"], "bcm-pricing-calculator": ["bcm-pricing-calculator"], "budgets": ["budgets"], "ce": ["ce"], "cloudformation": ["cloudformation"], "cloudhsm": ["cloudhsmv2"], "cloudtrail": ["cloudtrail"], "cloudwatch": ["cloudwatch", "cloudwatchomni"], "codedeploy": ["codedeploy"], "codepipeline": ["codepipeline"], "cognito-identity": ["cognito-identity"], "cognito-idp": ["cognito-idp"], "comprehend": ["comprehend"], "config": ["config"], "cur": ["cur"], "datasync": ["datasync"], "dms": ["dms"], "dsql": ["dsql"], "dynamodb": ["dynamodb"], "ec2": ["ec2"], "ecr": ["ecr"], "ecs": ["ecs"], "eks": ["eks"], "elasticache": ["elasticache"], "elasticloadbalancing": ["elb", "elbv2"], "elasticmapreduce": ["emr"], "es": ["es", "opensearch"], "events": ["eventbridgev2", "events"], "firehose": ["firehose"], "globalaccelerator": ["globalaccelerator"], "glue": ["glue"], "iam": ["iam"], "kinesis": ["kinesis"], "kinesisanalytics": ["kinesisanalytics", "kinesisanalyticsv2"], "kms": ["kms"], "lambda": ["lambda", "lambda-core", "lambda-microvms", "lambda-web"], "lightsail": ["lightsail"], "logs": ["logs"], "memorydb": ["memorydb"], "network-firewall": ["network-firewall"], "organizations": ["organizations"], "payment-cryptography": ["payment-cryptography"], "pipes": ["pipes"], "rds": ["docdb", "neptune", "rds"], "redshift": ["redshift"], "redshift-serverless": ["redshift-serverless"], "rekognition": ["rekognition"], "resource-groups": ["resource-groups"], "route53resolver": ["route53resolver"], "sagemaker": ["sagemaker"], "scheduler": ["scheduler"], "secretsmanager": ["secretsmanager"], "servicediscovery": ["servicediscovery"], "ses": ["mailmanager", "pinpoint-email", "ses", "sesv2"], "sns": ["sns"], "sqs": ["sqs"], "ssm": ["ssm"], "sso": ["sso-admin"], "states": ["stepfunctions"], "sts": ["sts"], "swf": ["swf"], "textract": ["textract"], "timestream-influxdb": ["timestream-influxdb"], "transcribe": ["transcribe"], "transfer": ["transfer"], "translate": ["translate"], "wafv2": ["wafv2"]},
|
||||
"notCovered": {"airflow": "REST routes no rule maps yet", "app-integrations": "REST routes no rule maps yet", "appconfig": "REST routes no rule maps yet", "appsync": "REST routes no rule maps yet", "aps": "REST routes no rule maps yet", "aws-marketplace": "REST routes no rule maps yet", "backup": "REST routes no rule maps yet", "batch": "REST routes no rule maps yet", "bedrock": "REST routes no rule maps yet", "bedrock-agentcore": "REST routes no rule maps yet", "cloudfront": "REST routes no rule maps yet", "codeguru-reviewer": "REST routes no rule maps yet", "connect": "REST routes no rule maps yet", "controltower": "REST routes no rule maps yet", "detective": "REST routes no rule maps yet", "dlm": "REST routes no rule maps yet", "elasticfilesystem": "REST routes no rule maps yet", "emr-serverless": "REST routes no rule maps yet", "fis": "REST routes no rule maps yet", "guardduty": "REST routes no rule maps yet", "inspector2": "REST routes no rule maps yet", "iot": "REST routes no rule maps yet", "kafka": "REST routes no rule maps yet", "macie2": "REST routes no rule maps yet", "mq": "REST routes no rule maps yet", "oam": "REST routes no rule maps yet", "quicksight": "metadata-only REST subset; creation-tag IAM authorization is not implemented", "ram": "REST routes no rule maps yet", "resource-explorer-2": "REST routes no rule maps yet", "rum": "REST routes no rule maps yet", "s3": "authorized by route; S3 checks s3:PutObjectTagging for an object it creates with tags itself", "s3tables": "REST routes no rule maps yet", "securityhub": "REST routes no rule maps yet", "servicecatalog": "its operations that tag are AppRegistry's, whose REST routes no rule maps yet"},
|
||||
"otherNamespaces": ["account-access", "acm-pca", "aco-automation", "agent-registry", "aidevops", "aiops", "airflow-serverless", "amplify", "amplifyuibuilder", "aoss", "appfabric", "appflow", "application-signals", "appmesh", "apprunner", "appstream", "arc-region-switch", "artifact", "auditmanager", "b2bi", "backup-gateway", "backup-search", "bcm-dashboards", "billing", "billingconductor", "braket", "cases", "cassandra", "chatbot", "chime", "cleanrooms", "cleanrooms-ml", "cloud9", "codecommit", "codeconnections", "codeguru-profiler", "codeguru-security", "codestar-connections", "codestar-notifications", "connect-campaigns", "databrew", "dataexchange", "datapipeline", "datazone", "dax", "deadline", "directconnect", "docdb-elastic", "drs", "ds", "ebs", "ecr-public", "elemental-inference", "emr-containers", "entityresolution", "evs", "fms", "forecast", "frauddetector", "fsx", "gamelift", "gameliftstreams", "geo", "grafana", "greengrass", "groundstation", "health-agent", "healthlake", "imagebuilder", "interconnect", "internetmonitor", "invoicing", "iotdeviceadvisor", "iotfleetwise", "iotmanagedintegrations", "iotsitewise", "iottwinmaker", "iotwireless", "ivs", "ivschat", "kafkaconnect", "kendra", "kendra-ranking", "kinesisvideo", "launchwizard", "lex", "license-manager", "license-manager-linux-subscriptions", "license-manager-user-subscriptions", "lookoutequipment", "m2", "managedblockchain", "mediaconnect", "mediaconvert", "medialive", "mediapackage", "mediapackage-vod", "mediapackagev2", "mediastore", "mediatailor", "medical-imaging", "mgn", "migrationhub-orchestrator", "mobiletargeting", "mpa", "neptune-graph", "network-security-manager", "networkflowmonitor", "networkmanager", "networkmonitor", "notifications", "notifications-contacts", "observabilityadmin", "odb", "omics", "opensearch", "osis", "outposts", "partnercentral", "pca-connector-ad", "pca-connector-scep", "pcs", "personalize", "pi", "polly", "profile", "proton", "qbusiness", "rbin", "refactor-spaces", "repostspace", "resiliencehub", "rolesanywhere", "route53-recovery-control-config", "route53-recovery-readiness", "route53globalresolver", "route53profiles", "rtbfabric", "s3files", "sagemaker-geospatial", "savingsplans", "schemas", "scn", "security-ir", "securityagent", "securitylake", "shield", "signer", "sms-voice", "snow-device-management", "social-messaging", "ssm-contacts", "ssm-incidents", "ssm-quicksetup", "ssm-sap", "storagegateway", "supportauthz", "synthetics", "thinclient", "timestream", "voiceid", "vpc-lattice", "waf", "waf-regional", "wellarchitected", "wickr", "wisdom", "workspaces", "workspaces-instances", "workspaces-web", "xray"],
|
||||
"resourceArns": {"ec2": {"application-status-check": "arn:${Partition}:ec2:${Region}:${Account}:application-status-check/*", "capacity-block": "arn:${Partition}:ec2:${Region}:${Account}:capacity-block/*", "capacity-manager-data-export": "arn:${Partition}:ec2:${Region}:${Account}:capacity-manager-data-export/*", "capacity-reservation": "arn:${Partition}:ec2:${Region}:${Account}:capacity-reservation/*", "capacity-reservation-cancellation-quote": "arn:${Partition}:ec2:${Region}:${Account}:capacity-reservation-cancellation-quote/*", "capacity-reservation-fleet": "arn:${Partition}:ec2:${Region}:${Account}:capacity-reservation-fleet/*", "carrier-gateway": "arn:${Partition}:ec2:${Region}:${Account}:carrier-gateway/*", "certificate": "arn:${Partition}:acm:${Region}:${Account}:certificate/*", "client-vpn-endpoint": "arn:${Partition}:ec2:${Region}:${Account}:client-vpn-endpoint/*", "coip-pool": "arn:${Partition}:ec2:${Region}:${Account}:coip-pool/*", "customer-gateway": "arn:${Partition}:ec2:${Region}:${Account}:customer-gateway/*", "declarative-policies-report": "arn:${Partition}:ec2:${Region}:${Account}:declarative-policies-report/*", "dedicated-host": "arn:${Partition}:ec2:${Region}:${Account}:dedicated-host/*", "dhcp-options": "arn:${Partition}:ec2:${Region}:${Account}:dhcp-options/*", "egress-only-internet-gateway": "arn:${Partition}:ec2:${Region}:${Account}:egress-only-internet-gateway/*", "elastic-gpu": "arn:${Partition}:ec2:${Region}:${Account}:elastic-gpu/*", "elastic-inference": "arn:${Partition}:elastic-inference:${Region}:${Account}:elastic-inference-accelerator/*", "elastic-ip": "arn:${Partition}:ec2:${Region}:${Account}:elastic-ip/*", "export-image-task": "arn:${Partition}:ec2:${Region}:${Account}:export-image-task/*", "export-instance-task": "arn:${Partition}:ec2:${Region}:${Account}:export-instance-task/*", "fleet": "arn:${Partition}:ec2:${Region}:${Account}:fleet/*", "fpga-image": "arn:${Partition}:ec2:${Region}:${Account}:fpga-image/*", "group": "arn:${Partition}:resource-groups:${Region}:${Account}:group/*", "host-reservation": "arn:${Partition}:ec2:${Region}:${Account}:host-reservation/*", "image": "arn:${Partition}:ec2:${Region}::image/*", "image-usage-report": "arn:${Partition}:ec2:${Region}:${Account}:image-usage-report/*", "import-image-task": "arn:${Partition}:ec2:${Region}:${Account}:import-image-task/*", "import-snapshot-task": "arn:${Partition}:ec2:${Region}:${Account}:import-snapshot-task/*", "instance": "arn:${Partition}:ec2:${Region}:${Account}:instance/*", "instance-connect-endpoint": "arn:${Partition}:ec2:${Region}:${Account}:instance-connect-endpoint/*", "instance-event-window": "arn:${Partition}:ec2:${Region}:${Account}:instance-event-window/*", "internet-gateway": "arn:${Partition}:ec2:${Region}:${Account}:internet-gateway/*", "ipam": "arn:${Partition}:ec2::${Account}:ipam/*", "ipam-external-resource-verification-token": "arn:${Partition}:ec2::${Account}:ipam-external-resource-verification-token/*", "ipam-internet-registry-association": "arn:${Partition}:ec2::${Account}:ipam-internet-registry-association/*", "ipam-policy": "arn:${Partition}:ec2::${Account}:ipam-policy/*", "ipam-pool": "arn:${Partition}:ec2::${Account}:ipam-pool/*", "ipam-pool-allocation": "arn:${Partition}:ec2:${Region}:${Account}:ipam-pool-allocation/*", "ipam-prefix-list-resolver": "arn:${Partition}:ec2::${Account}:ipam-prefix-list-resolver/*", "ipam-prefix-list-resolver-target": "arn:${Partition}:ec2::${Account}:ipam-prefix-list-resolver-target/*", "ipam-resource-discovery": "arn:${Partition}:ec2::${Account}:ipam-resource-discovery/*", "ipam-resource-discovery-association": "arn:${Partition}:ec2::${Account}:ipam-resource-discovery-association/*", "ipam-scope": "arn:${Partition}:ec2::${Account}:ipam-scope/*", "ipv4pool-ec2": "arn:${Partition}:ec2:${Region}:${Account}:ipv4pool-ec2/*", "ipv6pool-ec2": "arn:${Partition}:ec2:${Region}:${Account}:ipv6pool-ec2/*", "key-pair": "arn:${Partition}:ec2:${Region}:${Account}:key-pair/*", "launch-template": "arn:${Partition}:ec2:${Region}:${Account}:launch-template/*", "license-configuration": "arn:${Partition}:license-manager:${Region}:${Account}:license-configuration:*", "local-gateway": "arn:${Partition}:ec2:${Region}:${Account}:local-gateway/*", "local-gateway-route-table": "arn:${Partition}:ec2:${Region}:${Account}:local-gateway-route-table/*", "local-gateway-route-table-virtual-interface-group-association": "arn:${Partition}:ec2:${Region}:${Account}:local-gateway-route-table-virtual-interface-group-association/*", "local-gateway-route-table-vpc-association": "arn:${Partition}:ec2:${Region}:${Account}:local-gateway-route-table-vpc-association/*", "local-gateway-virtual-interface": "arn:${Partition}:ec2:${Region}:${Account}:local-gateway-virtual-interface/*", "local-gateway-virtual-interface-group": "arn:${Partition}:ec2:${Region}:${Account}:local-gateway-virtual-interface-group/*", "mac-modification-task": "arn:${Partition}:ec2:${Region}:${Account}:mac-modification-tasLine truncated
|
||||
"operations": {
|
||||
@@ -277,6 +277,8 @@
|
||||
"elasticmapreduce:RunJobFlow": {"tagging": ["elasticmapreduce:AddTags"], "requestTags": true, "tags": [{"member": "Tags[]", "key": "Key", "value": "Value"}]},
|
||||
"elasticmapreduce:StartNotebookExecution": {"tagging": ["elasticmapreduce:AddTags"], "requestTags": true, "tags": [{"member": "Tags[]", "key": "Key", "value": "Value"}]},
|
||||
"elasticmapreduce:StartSession": {"tagging": ["elasticmapreduce:AddTags"], "requestTags": true, "tags": [{"member": "Tags[]", "key": "Key", "value": "Value"}]},
|
||||
"es:CreateDomain": {"tagging": ["es:AddTags"], "requestTags": true, "tags": [{"member": "TagList[]", "key": "Key", "value": "Value"}]},
|
||||
"es:CreateElasticsearchDomain": {"tagging": ["es:AddTags"], "requestTags": true, "tags": [{"member": "TagList[]", "key": "Key", "value": "Value"}]},
|
||||
"events:CreateEventBus": {"tagging": ["events:TagResource"], "requestTags": true, "tags": [{"member": "Tags[]", "key": "Key", "value": "Value"}, {"member": "Tags{}"}]},
|
||||
"events:CreateEventSource": {"tagging": ["events:TagResource"], "requestTags": true, "tags": [{"member": "Tags{}"}]},
|
||||
"events:CreateSubscriber": {"tagging": ["events:TagResource"], "requestTags": true, "tags": [{"member": "Tags{}"}]},
|
||||
|
||||
@@ -16,6 +16,8 @@ import io.restassured.specification.RequestSpecification;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.RegisterExtension;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.URI;
|
||||
@@ -405,6 +407,79 @@ class IamTagOnCreateEnforcementIntegrationTest {
|
||||
cleanup.register(() -> admin("access-analyzer").delete("/analyzer/{name}", name + "-untagged"));
|
||||
}
|
||||
|
||||
/**
|
||||
* A domain created with tags needs {@code es:AddTags} on the domain its body names, in both OpenSearch API
|
||||
* versions, as the OpenSearch Service developer guide's policy for creating a domain only with a tag grants
|
||||
* {@code es:CreateDomain} and {@code es:AddTags}; the create's own action is checked with the tags it carries,
|
||||
* and one created with none needs that action alone.
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@CsvSource({"/2021-01-01/opensearch/domain, es:CreateDomain",
|
||||
"/2015-01-01/es/domain, es:CreateElasticsearchDomain"})
|
||||
void aDomainCreatedWithTagsNeedsAddTagsOnTheDomain(String path, String create) {
|
||||
User user = user("tag-domain");
|
||||
String name = "tag-os-" + suffix();
|
||||
String arn = "arn:aws:es:us-east-1:" + ACCOUNT + ":domain/" + name;
|
||||
String addTags = "{\"Effect\":\"Allow\",\"Action\":\"es:AddTags\",\"Resource\":\"" + arn + "\"}";
|
||||
user.policy(allow(create));
|
||||
refusedRest(user.rest("es").body(domain(name, "blue")).post(path).then(), "es:AddTags");
|
||||
|
||||
user.policy("{\"Effect\":\"Allow\",\"Action\":\"" + create + "\",\"Resource\":\"*\","
|
||||
+ "\"Condition\":{\"StringEquals\":{\"aws:RequestTag/team\":\"blue\"}}}," + addTags);
|
||||
refusedRest(user.rest("es").body(domain(name, "red")).post(path).then(), create);
|
||||
refusedRest(user.rest("es").body(domain(name + "-other", "blue")).post(path).then(), "es:AddTags");
|
||||
user.rest("es").body(domain(name, "blue")).post(path).then().statusCode(200);
|
||||
cleanup.register(() -> admin("es").delete(path + "/{name}", name));
|
||||
admin("es").queryParam("arn", arn).get("/2021-01-01/tags/").then().statusCode(200)
|
||||
.body("TagList.find { it.Key == 'team' }.Value", equalTo("blue"));
|
||||
|
||||
user.policy(allow(create));
|
||||
user.rest("es").body(domain(name + "-bare", null)).post(path).then().statusCode(200);
|
||||
cleanup.register(() -> admin("es").delete(path + "/{name}", name + "-bare"));
|
||||
}
|
||||
|
||||
/**
|
||||
* OpenSearch refuses a {@code TagList} that is not as its model has it, before it changes anything, so no reading
|
||||
* of one can differ from the tags a domain gets: under every grant and a deny on {@code team=red}, none of these
|
||||
* creates a domain, among them an object whose structure's key is also its member's name and a tag of the denied
|
||||
* key with no value after it. {@code AddTags} shares the reader, and tags at the model's limits are kept.
|
||||
*/
|
||||
@ParameterizedTest
|
||||
@CsvSource({"/2021-01-01/opensearch/domain, es:CreateDomain",
|
||||
"/2015-01-01/es/domain, es:CreateElasticsearchDomain"})
|
||||
void aDomainIsNotCreatedWithATagListItsModelDoesNotAllow(String path, String create) {
|
||||
User user = user("tag-domain-shapes");
|
||||
String name = "tag-os-" + suffix();
|
||||
String arn = "arn:aws:es:us-east-1:" + ACCOUNT + ":domain/" + name;
|
||||
String red = "{\"Key\":\"team\",\"Value\":\"red\"}";
|
||||
user.policy(allow(create));
|
||||
refusedRest(user.rest("es").body(domainWithTagList(name, "{\"team\":" + red + "}")).post(path).then(),
|
||||
"es:AddTags");
|
||||
|
||||
user.policy(allow(create) + "," + allow("es:AddTags") + ",{\"Effect\":\"Deny\",\"Action\":\"es:AddTags\","
|
||||
+ "\"Resource\":\"*\",\"Condition\":{\"StringEquals\":{\"aws:RequestTag/team\":\"red\"}}}");
|
||||
refusedRest(user.rest("es").body(domainWithTagList(name, "[" + red + "]")).post(path).then(), "es:AddTags");
|
||||
for (String tagList : List.of("{\"team\":" + red + "}", "[" + red + ",{\"Key\":\"team\"}]",
|
||||
"[" + red + ",{\"Key\":\"team\",\"Value\":null}]", "[{\"Value\":\"blue\"}]",
|
||||
"[{\"Key\":\"\",\"Value\":\"blue\"}]", "[{\"Key\":123,\"Value\":\"blue\"}]",
|
||||
"[{\"Key\":\"team\",\"Value\":{\"a\":1}}]", "[\"team\"]",
|
||||
"[{\"Key\":\"" + "k".repeat(129) + "\",\"Value\":\"blue\"}]",
|
||||
"[{\"Key\":\"team\",\"Value\":\"" + "v".repeat(257) + "\"}]")) {
|
||||
user.rest("es").body(domainWithTagList(name, tagList)).post(path).then().statusCode(400);
|
||||
admin("es").get("/2021-01-01/opensearch/domain/{name}", name).then().statusCode(409);
|
||||
}
|
||||
|
||||
String longest = "k".repeat(128);
|
||||
user.rest("es").body(domainWithTagList(name, "[{\"Key\":\"team\",\"Value\":\"\"},{\"Key\":\"" + longest
|
||||
+ "\",\"Value\":\"" + "v".repeat(256) + "\"}]")).post(path).then().statusCode(200);
|
||||
cleanup.register(() -> admin("es").delete(path + "/{name}", name));
|
||||
admin("es").contentType("application/json").body("{\"ARN\":\"" + arn + "\",\"TagList\":[{\"Key\":\"team\"}]}")
|
||||
.post("/2021-01-01/tags").then().statusCode(400);
|
||||
admin("es").queryParam("arn", arn).get("/2021-01-01/tags/").then().statusCode(200)
|
||||
.body("TagList.find { it.Key == 'team' }.Value", equalTo(""))
|
||||
.body("TagList.size()", equalTo(2));
|
||||
}
|
||||
|
||||
/**
|
||||
* CodeDeploy's handler reads a tag's key and value in either case, so the tagging action is checked for both,
|
||||
* and the create's own action sees them.
|
||||
@@ -472,6 +547,16 @@ class IamTagOnCreateEnforcementIntegrationTest {
|
||||
return "{\"analyzerName\":\"" + name + "\",\"type\":\"ORGANIZATION\"" + tags + "}";
|
||||
}
|
||||
|
||||
/** A body creating a domain, in either API version, tagged with the {@code team} given, or with no tags. */
|
||||
private static String domain(String name, String team) {
|
||||
return team == null ? "{\"DomainName\":\"" + name + "\"}"
|
||||
: domainWithTagList(name, "[{\"Key\":\"team\",\"Value\":\"" + team + "\"}]");
|
||||
}
|
||||
|
||||
private static String domainWithTagList(String name, String tagList) {
|
||||
return "{\"DomainName\":\"" + name + "\",\"TagList\":" + tagList + "}";
|
||||
}
|
||||
|
||||
private static ValidatableResponse createTopic(User user, String name, Map<String, String> tags) {
|
||||
RequestSpecification request = user.query("sns", "CreateTopic").formParam("Name", name);
|
||||
int index = 1;
|
||||
|
||||
@@ -32,6 +32,16 @@ model no longer gives it (`QUERY_MEMBERS`).
|
||||
|
||||
Only the namespaces in `NAMESPACES` are read, and in them every operation the reference lists with a
|
||||
tagging action, whether Floci serves it or not, so an operation Floci adds is checked from the start.
|
||||
The reference lists the operations of one SDK client of a namespace, though: OpenSearch Service's are
|
||||
the `es` client's alone, while the `opensearch` client's are named after `es` actions all the same. So a
|
||||
namespace also takes the operations of each botocore model Floci reads REST routes for under it
|
||||
(`regen_rest_routes.MODELS`) that the reference lists for none of its clients, each read as the action
|
||||
of its own name: it needs the tagging actions the reference lists for the operations of its namespace
|
||||
that need that action, and is marked `requestTags` when that action takes the request's tags. The
|
||||
`opensearch` client's `CreateDomain` is `es:CreateDomain`, which the reference lists for
|
||||
`CreateElasticsearchDomain` beside `es:AddTags`, as the OpenSearch Service developer guide's policy for
|
||||
creating a domain only with a tag grants `es:CreateDomain` and `es:AddTags`. One with no action of its
|
||||
name, or no tagging action going with that action, is left out.
|
||||
Each of those operations ends up in exactly one of three places, and generation fails on an operation
|
||||
that would end up in none:
|
||||
|
||||
@@ -86,6 +96,7 @@ from regen_iam_authorized_actions import fetch_references
|
||||
from regen_iam_passed_roles import (BODY_LOCATIONS, MEMBER_PATH_RE, NAMESPACE_RE, OPERATION_RE, _shown, load_models,
|
||||
namespace_of)
|
||||
from regen_partitions import resolve_botocore_data
|
||||
from regen_rest_routes import MODELS as REST_MODELS
|
||||
|
||||
REPO_ROOT = Path(__file__).resolve().parents[2]
|
||||
OUTPUT = REPO_ROOT / "src/main/resources/aws/iam-tag-on-create.json"
|
||||
@@ -97,7 +108,7 @@ NAMESPACES = (
|
||||
"bcm-pricing-calculator", "budgets", "ce", "cloudformation", "cloudhsm", "cloudtrail", "cloudwatch",
|
||||
"codedeploy", "codepipeline", "cognito-identity", "cognito-idp", "comprehend", "config", "cur", "datasync",
|
||||
"dms", "dsql", "dynamodb", "ec2", "ecr", "ecs", "eks", "elasticache", "elasticloadbalancing",
|
||||
"elasticmapreduce", "events", "firehose", "globalaccelerator", "glue", "iam", "kinesis", "kinesisanalytics",
|
||||
"elasticmapreduce", "es", "events", "firehose", "globalaccelerator", "glue", "iam", "kinesis", "kinesisanalytics",
|
||||
"kms", "lambda", "lightsail", "logs", "memorydb", "network-firewall", "organizations", "payment-cryptography",
|
||||
"pipes", "rds", "redshift", "redshift-serverless", "rekognition", "resource-groups", "route53resolver",
|
||||
"sagemaker", "scheduler", "secretsmanager", "servicediscovery", "ses", "sns", "sqs", "ssm", "sso", "states",
|
||||
@@ -113,7 +124,7 @@ NOT_COVERED = {
|
||||
"batch": _NO_ROUTES, "bedrock": _NO_ROUTES, "bedrock-agentcore": _NO_ROUTES,
|
||||
"cloudfront": _NO_ROUTES, "codeguru-reviewer": _NO_ROUTES, "connect": _NO_ROUTES,
|
||||
"controltower": _NO_ROUTES, "detective": _NO_ROUTES, "dlm": _NO_ROUTES,
|
||||
"elasticfilesystem": _NO_ROUTES, "emr-serverless": _NO_ROUTES, "es": _NO_ROUTES, "fis": _NO_ROUTES,
|
||||
"elasticfilesystem": _NO_ROUTES, "emr-serverless": _NO_ROUTES, "fis": _NO_ROUTES,
|
||||
"guardduty": _NO_ROUTES, "inspector2": _NO_ROUTES, "iot": _NO_ROUTES, "kafka": _NO_ROUTES,
|
||||
"macie2": _NO_ROUTES, "mq": _NO_ROUTES, "oam": _NO_ROUTES,
|
||||
"quicksight": "metadata-only REST subset; creation-tag IAM authorization is not implemented",
|
||||
@@ -271,6 +282,60 @@ def tag_on_create_operations(documents: list[dict]) -> dict[str, dict]:
|
||||
for key, value in sorted(found.items())}
|
||||
|
||||
|
||||
def rest_operations(data: Path) -> dict[str, set[str]]:
|
||||
"""The operation names of each botocore model whose REST routes Floci reads under a namespace the file reads."""
|
||||
return {client: set(model["operations"])
|
||||
for client, model in load_models(data, {client for client, namespace in REST_MODELS.items()
|
||||
if namespace in NAMESPACES}).items()}
|
||||
|
||||
|
||||
def with_rest_operations(upstream: dict[str, dict], documents: list[dict],
|
||||
given: dict[str, set[str]]) -> dict[str, dict]:
|
||||
"""`upstream` with the operations of the models Floci reads REST routes for (`regen_rest_routes.MODELS`), each
|
||||
given as its operation names: an operation `upstream` has gets the model among its clients, and one the reference
|
||||
lists for none of its clients is read as the action of its own name, needing the tagging actions `upstream` gives
|
||||
the operations of its namespace that the reference lists that action for, and taking the request's tags when that
|
||||
action does. One with no action of its name, or no tagging action going with it, is left out, so `--verify`
|
||||
reports a vendored one as no longer listed."""
|
||||
actions = _actions(documents)
|
||||
lowered = {key.lower(): action for key, action in actions.items()}
|
||||
resource_keys = _resource_keys(documents)
|
||||
listed: set[str] = set()
|
||||
needing: dict[str, set[str]] = {}
|
||||
for document in documents:
|
||||
namespace = document["Name"]
|
||||
for operation in document.get("Operations", []):
|
||||
listed.add(f"{namespace}:{operation['Name']}")
|
||||
for entry in operation.get("AuthorizedActions") or []:
|
||||
if entry.get("Service") == namespace and isinstance(entry.get("Name"), str):
|
||||
needing.setdefault(f"{namespace}:{entry['Name']}".lower(), set()).add(
|
||||
f"{namespace}:{operation['Name']}")
|
||||
found = dict(upstream)
|
||||
for client, names in sorted(given.items()):
|
||||
namespace = REST_MODELS[client]
|
||||
for name in sorted(names):
|
||||
operation = f"{namespace}:{name}"
|
||||
if operation in found:
|
||||
if client not in found[operation]["clients"]:
|
||||
found[operation] = {**found[operation], "clients": sorted(found[operation]["clients"] + [client])}
|
||||
continue
|
||||
action = lowered.get(operation.lower())
|
||||
if operation in listed or action is None or _tagging_only(action):
|
||||
continue
|
||||
tagging = sorted({tag for other in needing.get(operation.lower(), set()) if other in upstream
|
||||
for tag in upstream[other]["tagging"]})
|
||||
if not tagging:
|
||||
continue
|
||||
found[operation] = {
|
||||
"tagging": tagging,
|
||||
"createAction": any(f"{namespace_of(tag)}:{CREATE_ACTION}"
|
||||
in actions[tag].get("ActionConditionKeys", []) for tag in tagging),
|
||||
"requestTags": bool(REQUEST_TAG_KEYS & _condition_keys(namespace, action, resource_keys)),
|
||||
"clients": [client],
|
||||
}
|
||||
return dict(sorted(found.items()))
|
||||
|
||||
|
||||
# --------------------------------------------------------------------------- #
|
||||
# botocore: which members of the request carry the tags
|
||||
# --------------------------------------------------------------------------- #
|
||||
@@ -403,7 +468,7 @@ def entry_for(operation: str, upstream: dict, models: dict[str, dict]) -> dict:
|
||||
|
||||
|
||||
def build(documents: list[dict], provenance: str, data: Path, botocore: str) -> dict:
|
||||
upstream = tag_on_create_operations(documents)
|
||||
upstream = with_rest_operations(tag_on_create_operations(documents), documents, rest_operations(data))
|
||||
covered = {operation: value for operation, value in upstream.items() if namespace_of(operation) in NAMESPACES}
|
||||
_check_overrides(covered)
|
||||
namespaces: dict[str, list[str]] = {}
|
||||
@@ -638,7 +703,11 @@ def main(argv: list[str] | None = None) -> int:
|
||||
return 0
|
||||
try:
|
||||
documents, provenance = fetch_references(args.source_dir)
|
||||
upstream = tag_on_create_operations(documents)
|
||||
listed = tag_on_create_operations(documents)
|
||||
upstream = with_rest_operations(listed, documents, {
|
||||
client: {operation.split(":", 1)[1] for operation in document["operations"]
|
||||
if namespace_of(operation) == namespace and operation not in listed}
|
||||
for client, namespace in REST_MODELS.items() if client in document["namespaces"].get(namespace, [])})
|
||||
arns = resource_arns(documents, set(document.get("resourceArns", {})))
|
||||
except (OSError, ValueError) as e:
|
||||
print(f"error: could not read the Service Reference ({e})", file=sys.stderr)
|
||||
|
||||
@@ -121,6 +121,25 @@ def test_an_operation_with_no_action_of_its_name_goes_by_the_other_actions_of_it
|
||||
assert r.tag_on_create_operations([document])["svc:CreateACL"]["requestTags"] is True
|
||||
|
||||
|
||||
def test_a_rest_operation_the_reference_does_not_list_needs_the_tagging_of_the_operations_needing_its_action(
|
||||
monkeypatch):
|
||||
monkeypatch.setattr(r, "REST_MODELS", {"svc": "svc", "svcv2": "svc"})
|
||||
document = reference("svc", {"CreateLegacyThing": ["svc:CreateThing", "svc:PutThing", "other:DescribeThing",
|
||||
"svc:AddTags"], "PutThing": []}, tagging={"AddTags": []})
|
||||
document["Actions"] += [{"Name": name, "ActionConditionKeys": keys,
|
||||
"Annotations": {"Properties": {"IsTaggingOnly": False}}}
|
||||
for name, keys in (("CreateThing", ["aws:RequestTag/${TagKey}"]), ("DescribeThing", []))]
|
||||
found = r.with_rest_operations(r.tag_on_create_operations([document]), [document], {
|
||||
"svcv2": {"CreateLegacyThing", "CreateThing", "PutThing", "DescribeThing", "AddTags", "Unknown"}})
|
||||
# The action of its name needs the legacy create's tagging action; the legacy create gains the client.
|
||||
assert found["svc:CreateThing"] == {"tagging": ["svc:AddTags"], "createAction": False, "requestTags": True,
|
||||
"clients": ["svcv2"]}
|
||||
assert found["svc:CreateLegacyThing"]["clients"] == ["svc", "svcv2"]
|
||||
# Listed with no tagging action, listed for another namespace only, the tagging action itself, or of no action:
|
||||
# left out.
|
||||
assert set(found) == {"svc:CreateLegacyThing", "svc:CreateThing"}
|
||||
|
||||
|
||||
def test_an_unusable_namespace_is_rejected():
|
||||
with pytest.raises(ValueError, match="not usable"):
|
||||
r.tag_on_create_operations([{"Name": "Not A Namespace", "Operations": []}])
|
||||
@@ -394,4 +413,9 @@ def test_the_vendored_file_is_well_formed():
|
||||
assert document["resourceArns"]["ec2"]["instance"] == "arn:${Partition}:ec2:${Region}:${Account}:instance/*"
|
||||
assert document["resourceArns"]["ec2"]["image"] == "arn:${Partition}:ec2:${Region}::image/*"
|
||||
assert operations["budgets:CreateBudget"]["requestTags"] is True
|
||||
# The opensearch client's CreateDomain, which the reference does not list, as es's CreateElasticsearchDomain.
|
||||
assert document["namespaces"]["es"] == ["es", "opensearch"]
|
||||
for operation in ("es:CreateDomain", "es:CreateElasticsearchDomain"):
|
||||
assert operations[operation] == {"tagging": ["es:AddTags"], "requestTags": True,
|
||||
"tags": [{"member": "TagList[]", "key": "Key", "value": "Value"}]}
|
||||
assert operations["logs:CreateLogGroup"].get("byHand")
|
||||
Reference in new issue
Block a user