Files
floci/docs
Priamo Germosen 82fdb36228 fix(iam): answer a blocked delete with the sentence for the dependency that blocks it (#9220)
IAM names exactly one blocking dependent and words each class with its own
wholly fixed sentence, no entity name and no count, because a cleanup loop
reads the sentence to choose its next step. Four of those recordings bear on
this package and three of them diverged.

- DeleteRole read a role's attached and inline policies together and answered
  the detach sentence for both, so an inline policy was told to detach
  something. The two are reported apart now: "Cannot delete entity, must
  detach all policies first." for a managed attachment and "Cannot delete
  entity, must delete policies first." for an embedded policy, which is the
  remedy that clears what is there. DeleteGroup conflated them the same way
  and selects the same two sentences now; DeleteUser already did and is the
  model both follow.
- DeleteRole never looked at instance profiles, so a role a profile held was
  deleted and left the profile naming nothing. A role an instance profile
  holds is "Cannot delete entity, must remove roles from instance profile
  first." and the profile has to let go of it first, as on AWS. The profile
  is reported ahead of an attached policy, which is recorded for a role that
  is both held and carrying attachments, and is what a cleanup loop needs,
  since detaching changes nothing while the pairing is there.
- DeleteInstanceProfile wording its own refusal now carries that same
  sentence, which is AWS's for both ends of the pairing.

The new membership check and the emptiness check it joins are both
check-then-act, so AddRoleToInstanceProfile takes the lock the deletes decide
under, outside the profile's own monitor as every path here already does: one
order throughout, and no pairing can land between a delete's read and what it
does with it.

Nothing takes a role out of a profile on the caller's behalf, on AWS or here.
The CloudFormation role provisioner keeps clearing the policies its stack owns
and lets the conflict reach the stack, with a provisioner case for it; a stack
owning both resources deletes the profile first, since dependents go before
what they depend on. The test fixture that tears a role down removes it from
any profile first, ahead of its policies, so teardown asks for the remedies in
the order the refusals name. The tolerance behind RemoveRoleFromInstanceProfile
stays for state reached another way, and the test that reached it by deleting
the role first now asserts the refusal and clears the pairing before the role.

Which profiles hold a role is kept as an index beside the profiles themselves,
written in the same two places a pairing is and read only under that lock, so
the check costs a lookup rather than a read of every profile in the account
while the lock is held. A scope is filled from storage the first time it is
asked about, so a pairing a restart inherited is in it before the first answer.

The two callers that delete a role of their own clear its policies first, so
each asks about the profile before it clears anything: otherwise a role that
turns out not to be deletable would be left in place with its permissions
stripped by a delete that could not finish.
2026-11-22 15:14:52 -04:00
..
2026-03-15 17:43:56 -05:00