Files
floci/docs/services
soreavis c8403ac6fc feat(iam): add service-linked role create, delete and deletion status (#2179)
* feat(iam): add service-linked role create, delete and deletion status

aws_iam_service_linked_role calls CreateServiceLinkedRole directly, and one
unsupported operation fails a whole account-bootstrap module. Delete and
GetServiceLinkedRoleDeletionStatus come with it, because create alone leaves
terraform destroy broken.

The role lands under /aws-service-role/<principal>/ with a trust policy for
that principal, and is readable by GetRole afterwards, which is what the
issue asks for.

The role NAME is a deterministic stand-in, not AWS's. The prefix is chosen
by the linked service and is not computable from the principal — AWS turns
lex.amazonaws.com into AWSServiceRoleForLexBots — so this derives a name
from the principal's labels instead: es.amazonaws.com becomes
AWSServiceRoleForEs.
Every label contributes, because rds.amazonaws.com and
rds.application-autoscaling.amazonaws.com are separate roles on AWS and a
config declaring both must not collide on one name.

A CustomSuffix is joined with an underscore, which is the separator callers
parse back out; Terraform recovers custom_suffix by splitting the role name
on it, and that attribute forces replacement, so any other join never
converges.

Deletion is synchronous, so the returned task id is already complete and its
status is SUCCEEDED. Task ids use the documented
task/aws-service-role/<principal>/<role>/<uuid> shape and are held in a
StorageFactory-backed store, so they are account-scoped and survive a
restart like every other IAM record.

Closes #2122

* fix(iam): classify service-linked roles by origin, not by path

CreateRole accepts the /aws-service-role/ prefix, so a role sitting at a
well-formed service-linked path is not necessarily one. Path-based
classification let DeleteServiceLinkedRole delete an ordinary role that
merely lived there.

Roles minted by CreateServiceLinkedRole now carry a marker, and the delete
path keys on that instead. The field is additive, so a role persisted
before this change reads as not service-linked, which is correct.

* fix(iam): protect service-linked roles from ordinary role mutations

DeleteServiceLinkedRole could answer 409 DeleteConflict, a code absent from
that action's published error list (LimitExceeded, NoSuchEntity,
ServiceFailure). It got there by routing through deleteRole, which refuses a
role that still has policies attached — and nothing stopped a caller from
attaching one to a service-linked role first.

AWS never reaches that state. It publishes UnmodifiableEntity (400) on twelve
role actions, and the message names the linked service to go through instead.
So refuse the mutation rather than handle the conflict it would otherwise
cause. This guards the eleven the emulator implements — AttachRolePolicy,
DetachRolePolicy, PutRolePolicy, DeleteRolePolicy,
Put/DeleteRolePermissionsBoundary, UpdateRole, UpdateAssumeRolePolicy,
Add/RemoveRoleFromInstanceProfile and DeleteRole; UpdateRoleDescription is the
twelfth and has no handler here. Several were silent: DeleteRole removed a
service-linked role at 200, UpdateAssumeRolePolicy rewrote its trust policy,
and AddRoleToInstanceProfile attached it to an instance profile. TagRole and
UntagRole stay open, matching AWS. DeleteServiceLinkedRole now removes the
role directly, since deleteRole refuses it.

Also validate CreateServiceLinkedRole's own inputs. CustomSuffix must match
[\w+=,.@-]{1,64}, as AWS constrains it — a suffix containing '/' previously
produced a role name outside RoleName's own pattern, leaving an ARN whose name
segment cannot be recovered. And a derived name over 64 characters is
rejected, because AWS caps RoleName at 64 on every action that takes one and
on the Role this action returns.

Document the three deviations that remain: the role name is derived locally
and will not match AWS for most services, deletion is synchronous so the
deletion status is always SUCCEEDED, and CreateRole accepts the
/aws-service-role/ path that AWS reserves.
2026-08-09 15:11:51 -04:00
..
2026-05-10 11:53:31 -05:00
2026-05-10 11:53:31 -05:00
2026-08-08 22:47:28 -04:00
2026-07-15 01:03:24 -04:00
2026-05-10 11:53:31 -05:00
2026-05-10 11:53:31 -05:00
2026-05-10 11:53:31 -05:00
2026-05-10 11:53:31 -05:00