feat(iam): read SageMaker from the generated tables (#9373)

Move `sagemaker` from NOT_COVERED to NAMESPACES in
regen_iam_request_resources.py, so SageMaker requests are checked on the
resources they name instead of `*`: a model, an endpoint configuration, an
endpoint, a training job or any other resource by its name, as
<type>/<name>, the ARN Floci mints, and a tag call on its ResourceArn.
CreateEndpoint and UpdateEndpoint are checked on the endpoint and the
endpoint configuration they name. No other namespace's rows change.

The reading of a member that names a type's variable gains its mirror: for
the type an operation is about, a name or id with a word of its own that the
variable's name ends in names it, also where a create leaves its id open, so
SageMaker's JobName names the inference recommendations job
(${InferenceRecommendationsJobName}) of CreateInferenceRecommendationsJob,
DescribeInferenceRecommendationsJob and StopInferenceRecommendationsJob.
Over the whole table it changes these three operations.

CreateEndpoint marked neither of its rows as what it makes, as the stem of
`endpoint-config` is `endpoint` too, so a tagged create needed
sagemaker:AddTags on the configuration it runs as well as on the endpoint.
A create's type is now matched by its whole name before its stem, so the
endpoint alone is made; over the whole table this changes CreateEndpoint.
This commit is contained in:
Priamo Germosen authored and GitHub committed 2026-11-24 16:16:17 -04:00
1 parent 6018a41837
commit 08b6339a6a
7 files changed
+618 -18

No files matched your search

@@ -3670,6 +3670,69 @@ class IamRequestResourceEnforcementIntegrationTest {
return id;
}
/**
* A SageMaker model is checked on the ARN its name gives, {@code model/<name>}, so a grant on one lets the request
* reach SageMaker, which answers that the model does not exist, and the same grant refuses another.
*/
@Test
void aSageMakerModelIsCheckedOnTheArnItsNameGives() {
String model = "res-model-" + suffix();
User user = user("res-sagemaker");
user.policy(allowOn("sagemaker:DescribeModel", "arn:aws:sagemaker:" + REGION + ":" + ACCOUNT + ":model/" + model));
send(user, "sagemaker", "SageMaker.DescribeModel", "1.1", "{\"ModelName\":\"" + model + "\"}")
.statusCode(400).body(containsString("Could not find model"));
refusedJson(send(user, "sagemaker", "SageMaker.DescribeModel", "1.1",
"{\"ModelName\":\"" + model + "-other\"}"), "sagemaker:DescribeModel");
}
/**
* A SageMaker create that tags what it makes also needs {@code sagemaker:AddTags}, which the Service Reference
* lists among CreateModel's authorized actions: a caller allowed the create alone is refused it with tags, and
* one allowed AddTags too is not.
*/
@Test
void aTaggedSageMakerCreateAlsoNeedsAddTags() {
String model = "res-tagged-model-" + suffix();
String request = "{\"ModelName\":\"" + model + "\",\"ExecutionRoleArn\":\"arn:aws:iam::" + ACCOUNT
+ ":role/res-sagemaker-role\",\"PrimaryContainer\":{\"Image\":\"example/model:1\"},"
+ "\"Tags\":[{\"Key\":\"team\",\"Value\":\"a\"}]}";
cleanup.register(() -> adminJson("sagemaker", "SageMaker.DeleteModel")
.body("{\"ModelName\":\"" + model + "\"}").post("/"));
User creator = user("res-sagemaker-create");
creator.policy(allowOn("sagemaker:CreateModel", "*") + "," + allowOn("iam:PassRole", "*"));
refusedJson(send(creator, "sagemaker", "SageMaker.CreateModel", "1.1", request), "sagemaker:AddTags");
User tagger = user("res-sagemaker-tag");
tagger.policy(allowOn("sagemaker:CreateModel", "*") + "," + allowOn("iam:PassRole", "*") + ","
+ allowOn("sagemaker:AddTags", "*"));
send(tagger, "sagemaker", "SageMaker.CreateModel", "1.1", request)
.body(not(containsString("not authorized to perform")));
}
/**
* A tagged SageMaker CreateEndpoint needs {@code sagemaker:AddTags} on the endpoint it makes alone, not on the
* endpoint configuration it runs: a caller allowed to tag the new endpoint creates it, one allowed to tag the
* configuration alone is refused.
*/
@Test
void aTaggedSageMakerEndpointNeedsAddTagsOnTheEndpointAlone() {
String endpoint = "res-tagged-endpoint-" + suffix();
String config = "res-endpoint-config-" + suffix();
String prefix = "arn:aws:sagemaker:" + REGION + ":" + ACCOUNT + ":";
String request = "{\"EndpointName\":\"" + endpoint + "\",\"EndpointConfigName\":\"" + config + "\","
+ "\"Tags\":[{\"Key\":\"team\",\"Value\":\"a\"}]}";
String create = allowOn("sagemaker:CreateEndpoint", prefix + "endpoint/" + endpoint) + ","
+ allowOn("sagemaker:CreateEndpoint", prefix + "endpoint-config/" + config);
cleanup.register(() -> adminJson("sagemaker", "SageMaker.DeleteEndpoint")
.body("{\"EndpointName\":\"" + endpoint + "\"}").post("/"));
User endpointTagger = user("res-sagemaker-endpoint-tag");
endpointTagger.policy(create + "," + allowOn("sagemaker:AddTags", prefix + "endpoint/" + endpoint));
send(endpointTagger, "sagemaker", "SageMaker.CreateEndpoint", "1.1", request)
.body(not(containsString("not authorized to perform")));
User configTagger = user("res-sagemaker-config-tag");
configTagger.policy(create + "," + allowOn("sagemaker:AddTags", prefix + "endpoint-config/" + config));
refusedJson(send(configTagger, "sagemaker", "SageMaker.CreateEndpoint", "1.1", request), "sagemaker:AddTags");
}
private static ValidatableResponse glue(String operation, String body) {
return adminJson("glue", "AWSGlue." + operation).body(body).post("/").then();
}
@@ -2116,6 +2116,24 @@ class ResourceArnBuilderTest {
ACCOUNT, "aws"));
}
// ── SageMaker ───────────────────────────────────────────────────────────────
/**
* A SageMaker request is checked on the model, endpoint configuration, endpoint or training job its name names, as
* {@code <type>/<name>}, the ARN Floci's SageMaker mints: CreateEndpoint on the endpoint it makes and the
* configuration it runs, each named after its type.
*/
@Test
void sageMakerChecksTheResourceItsNameNames() {
setJsonBody("{\"ModelName\":\"churn\"}");
assertEquals(List.of("arn:aws:sagemaker:us-east-1:000000000000:model/churn"),
builder.buildResources("sagemaker", "sagemaker:DescribeModel", ctx, "us-east-1", ACCOUNT, "aws"));
setJsonBody("{\"EndpointName\":\"churn\",\"EndpointConfigName\":\"churn-config\"}");
assertEquals(List.of("arn:aws:sagemaker:us-east-1:000000000000:endpoint/churn",
"arn:aws:sagemaker:us-east-1:000000000000:endpoint-config/churn-config"),
builder.buildResources("sagemaker", "sagemaker:CreateEndpoint", ctx, "us-east-1", ACCOUNT, "aws"));
}
// ── S3 and S3 Control ───────────────────────────────────────────────────────
/** The resources an S3 or S3 Control request names, read from the generated table on the route it matches. */