mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
DeletePolicy read the attachment count alone, so a policy carrying a version beside its default was deleted along with its history and answered nothing. AWS refuses that delete with DeleteConflict 409 and three sentences of wholly fixed text, "This policy has more than one version. Before you delete a policy, you must delete the policy's versions. The default version is deleted with the policy.", recorded against a real account on 2026-10-29, and the operation's published description asks a caller for the same two steps: detach the policy from every user, group and role, then delete all of the policy's versions. The refusal reports an attachment first and the versions second, the order those steps are written in. Which of the two AWS names for a policy carrying both is not recorded, so the page marks that order as this package's reading rather than a recording, as it already does for attached ahead of inline. Nothing clears those versions on the caller's behalf, on AWS or here, so whoever wants the policy gone deletes them first. The CloudFormation provisioner for AWS::IAM::ManagedPolicy owns the policies its stacks create and publishes the new document as a new default version on every update, which leaves the version before it stored: the delete that brings such a stack down clears the other versions ahead of the policy, in the order the published steps give, so a stack cannot end up able to create and update a policy it can never take down again. The clearing asks the attachment question before a single version goes and answers it with the sentence the delete would, so a policy a principal the stack never recorded still holds keeps its history instead of spending it on a delete that was going to be refused anyway. The reads a delete decides on and the delete itself are under the lock every other IAM write takes, which the writes to a policy's versions now take as well, so a version published between the count and the delete is no longer deleted along with the policy it was added to, and the write back that ends a clearing cannot restore a policy another caller deleted in between. Inside it the version map keeps its own monitor, and SetDefaultPolicyVersion moves the default version id under that monitor beside the flags it already set there: between those two writes a clearing would have read the id this call had just replaced and dropped the version it had just made default. Covered over the API by the refusal, its precedence over the attachment and the control that deletes the other version and then the policy; at the service level by the clearing that keeps the default with its document, the attachment that refuses it with every version intact, and the version a SetDefault just chose being the one kept; by a trial loop over a delete racing a version publish; on the provisioner by the order its delete asks for; and end to end by a stack that is created, updated and then deleted, with the policy gone after it. One test fixture published a second version and tore the policy down with one call, which the refusal now blocks, so it deletes that version first.