Skip to content

feat(#1582, #1583): IAM ListEntitiesForPolicy, UpdateUser/UpdateGroup renames, login profiles, force_destroy listings - #1711

Merged
scttfrdmn merged 2 commits into
mainfrom
feat/v0134-iam-extras
Nov 25, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
feat/v0134-iam-extras

Conversation

@scttfrdmn

@scttfrdmn scttfrdmn commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Fixes #1582
Fixes #1583
Part of #1613. This adds ListEntitiesForPolicy. The rest of #1613 is the other v0.134.0 workstreams, and GetFederationToken is #1694.

This PR was stacked on #1700, which has merged (1b9c19f). It is rebased onto main, so the diff is F2 alone.

  • ListEntitiesForPolicy. It reuses iamPolicyAttachedEntities, the attachment reader that DeletePolicy and AttachmentCount share. It adds the users and roles using the policy as a permissions boundary, unless PolicyUsageFilter=PermissionsPolicy.

    • EntityFilter: User, Role and Group narrow the kinds. LocalManagedPolicy and AWSManagedPolicy have no published meaning for this operation. Substrate's reading, marked as its own, is that they select by the policy's own kind: naming the other kind returns nothing.
    • PathPrefix uses the pattern the page documents.
    • Paging: one Marker resumes across groups, roles and users, through iamMarker/paginateIAMKeys (pageAfter).
    • A missing policy is NoSuchEntity.
  • UpdateUser / UpdateGroup (iam: route UpdateUser and UpdateGroup so a CloudFormation user or group Path change applies in place #1582). These rename and re-path. Everything stored under the name is re-keyed:

    • the record, with its ARN rebuilt;
    • the attached-policy list;
    • the inline-policy names and each document;
    • the access-key list, and each key record's UserName, so a signed request resolves to the new name;
    • both sides of each group membership;
    • the login profile;
    • the user's GetSessionToken sessions (AWS ties a session to the user, not its name).

    Ordering and atomicity. A rename runs as an iamTxn. The new name's dependents are written first, then its entity record. Next, the pointers are flipped (access keys, group lists, STS sessions), and only then is the old entity record deleted, followed by the old dependents. So a reader outside IAM (principal resolution, the authz gate, STS) sees one name or the other, whole. Every write records what it replaced, and a failure part way through rolls back, leaving the entity wholly under its old name. A fault-injection test fails each state write in turn and asserts the old name is fully intact. A copy onto a key that already holds a stale record deletes the stale record first.

    Locking. The rename holds IAMPlugin.entityMu for writing, and every other IAM operation holds it for reading. The tagging API's writes to IAM records now go through IAM (resourceTagger: tagResourceByARN/tagRecord under the read lock), so a concurrent tag write cannot recreate a ghost record under the removed name. Race-mode tests interleave a rename with a signed request and with a tagging-API write. The rename also authorizes the target ARN ("permissions on both the source object and the target object"). Errors are EntityAlreadyExists/409, NoSuchEntity/404, and ValidationError for a bad NewPath. Neither operation has an output shape in the model, so both answer the empty envelope.

  • Login profiles (iam: route the login-profile operations so AWS::IAM::User LoginProfile is applied #1583). Create, Get, Update and DeleteLoginProfile.

    • The record stores CreateDate and PasswordResetRequired only. The password is never stored, and a test asserts it never reaches a response.
    • UserName defaults to the caller where the page says so.
    • DeleteUser now refuses with DeleteConflict while the user has a login profile, access keys, inline or attached policies, or group memberships ("Cannot delete entity, must delete login profile first.", "... access keys first.", "... policies first."; observed wording).
  • CloudFormation.

    • AWS::IAM::User LoginProfile is created on deploy and created, updated or deleted on update. A stack delete removes it before DeleteUser, and calls DeleteLoginProfile only when the template declared one.
    • A changed user or group Path is applied through UpdateUser/UpdateGroup, replacing cfnIAMPathRefusal. The record's ARN is refreshed, so Fn::GetAtt Arn reports the new path.
    • docs/reference/iam.md's "not applied" and "InvalidAction" paragraphs are fixed.
  • force_destroy listings. Terraform's aws_iam_user force_destroy reads ListMFADevices, ListSSHPublicKeys, ListSigningCertificates, ListServiceSpecificCredentials and ListVirtualMFADevices. None was routed. Each now answers an empty list: substrate models none of these credentials, so empty is the true answer. The per-user four answer NoSuchEntity for an absent user, and all five validate MaxItems. No follow-up issue is needed.

The routed-operation catalog goes from 1,211 to 1,223 (IAM 97 → 109). The wire-model snapshot was refetched.

Provenance

The DeleteConflict "must delete login profile first" wording and the NoSuchEntity "Login Profile for User … cannot be found." wording are observed through the AWS CLI and Terraform. The path, Password is required and login-profile EntityAlreadyExists messages, and the ListEntitiesForPolicy EntityFilter reading, are substrate's own; the CHANGELOG lists them.

Compatibility

  • DeleteUser refuses a user that still has a login profile, access keys, inline policies, attached policies or group memberships, as AWS does.
  • A CloudFormation Path change on a user or group now updates in place instead of failing the update.

Review fixes (rebased onto main at 1b9c19f)

These are the nine review items: tagging writes go through IAM, under the lock; the CFN GetAtt Arn refresh after a path change; the transactional rename with rollback, and its fault test; GetSessionToken sessions follow the user; the DeleteUser conflicts, and a stale destination deleted on copy; DeleteLoginProfile only when one was declared; the EntityFilter reading marked as substrate's own; the login-profile message marked as substrate's own; and substrate's own messages listed in the CHANGELOG. All gates below were re-run after the rebase.

Final review round (ac584ec)

  1. A request is decided against one side of a rename.
    • The server holds IAM's entity lock for reading across resolvePrincipal and the pre-plugin gates, and releases it before the latency sleep and the plugin call.
    • The server reaches the lock through the registry (iamEntityLocker, PluginRegistry.iamEntityReadLock), not a global.
    • IAM's own handlers run after the gate has released, so HandleRequest looks the caller up again under its lock by unique ID (iamRefreshedPrincipal). The handler doesn't re-take the gate's read lock, so there is no recursive RLock. This is what lets authorizeWith, GetUser with no name and the login-profile defaults see a renamed user.
    • Defence in depth: a principal built from an IAM access key or session record (Principal.iamCredential) whose user or role no longer exists is refused in CheckAccess and in authorizeWith, instead of going unenforced. The message is substrate's own, in AWS's implicit-deny shape.
    • Race test: bob has an Allow on * and a Deny on sqs:*, attached either to him or to his group, while renames run concurrently. No signed sqs:ListQueues succeeds.
    • Mutation check: with the gate lock disabled, the user-rename, group-rename and GetSessionToken race tests all fail.
  2. GetSessionToken resolves its caller and writes the session under the same read lock, using the refreshed user. A user that has vanished is refused.
  3. Tag mutex. IAMPlugin.tagMu covers the read-merge-write in TagUser, UntagUser, TagRole, UntagRole, TagInstanceProfile, UntagInstanceProfile and tagRecord. The mergeResourceTags comment is corrected.
    • Test: 24 concurrent writes, split between TagUser and TagResources, all land.
  4. Nit: CFN dr.ARN refreshes right after applyIAMPath succeeds, for both users and groups.

Behaviour change. A deleted role's sessions are now refused, where before they were unenforced and narrowed only by their session policies. Two F1 tests that asserted the old behaviour are renamed and now assert the refusal.

Coverage. I added tests for the refusal branches, the store faults (a new failList on the shared fault store) and the CFN out-of-band paths. I also folded the unreachable marshal-error branches into iamTxn.putJSON and a generic iamRetag. Patch-line coverage from the emulator package's own tests is 97.5% (960 of 985). What's left is unreachable: marshal errors, and branches shadowed by an earlier read of the same key.

CHANGELOG. New entries under Fixed and Compatibility. I also removed a stale duplicate from #1700, a round-2 line saying an unbundled AWS managed policy is "accepted and not applied"; the "allows nothing" line beside it stays.

Gates run locally

  • make lint (0 issues), make test and make e2e.
  • Both drift sets, docs-versions, docs-counts-check, cfn-schema-check, and the VitePress build (with node_modules removed afterwards).
  • SUBSTRATE_IAC=1 make iac-e2e: Terraform and CDK pass.
  • Scratch Terraform check with provider 6.73.0 against a built binary. The config was aws_iam_user with force_destroy plus a group membership, a policy attachment and aws_iam_user_login_profile.
    • Apply succeeded, and the next plan was empty.
    • Renaming the user and changing its path ran as an in-place update of the user (its dependents are ForceNew in the provider), and the next plan was empty.
    • Destroy succeeded with the login profile present, and the server log had no unrouted calls.

@scttfrdmn scttfrdmn added this to the v0.134.0 milestone Nov 25, 2026
@scttfrdmn
scttfrdmn force-pushed the feat/v0134-federation branch 2 times, most recently from a469592 to de10810 Compare November 25, 2026 01:16
@scttfrdmn
scttfrdmn force-pushed the feat/v0134-iam-extras branch from efb136c to 60db32b Compare November 25, 2026 01:46
Base automatically changed from feat/v0134-federation to main November 25, 2026 01:50
… renames, login profiles, force_destroy listings

- ListEntitiesForPolicy reuses the attachment reader, adds the boundary users and
  roles, and pages one Marker across groups, roles and users with EntityFilter,
  PathPrefix and PolicyUsageFilter.
- UpdateUser and UpdateGroup rename and re-path under a write lock every other IAM
  request reads under, moving the record, attached and inline policies, both sides
  of each membership, access keys (and each key's UserName) and the login profile.
- Login profiles store CreateDate and PasswordResetRequired, never the password;
  DeleteUser refuses a user with one.
- CloudFormation applies AWS::IAM::User LoginProfile and user/group Path in place.
- ListMFADevices, ListSSHPublicKeys, ListSigningCertificates,
  ListServiceSpecificCredentials and ListVirtualMFADevices answer empty lists.
@scttfrdmn
scttfrdmn force-pushed the feat/v0134-iam-extras branch from 60db32b to 967ead5 Compare November 25, 2026 01:53
@codecov

codecov Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.37587% with 14 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
emulator/iam_rename.go 97.95% 7 Missing ⚠️
emulator/cfn_resources_iam.go 95.58% 3 Missing ⚠️
emulator/iam_list_entities_for_policy.go 98.44% 2 Missing ⚠️
emulator/iam_tagging.go 98.43% 1 Missing ⚠️
emulator/iam_user_credentials.go 99.39% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

… serialized; vanished credentials refused

The server holds IAM's entity lock for reading across principal resolution
and the authorization gate, reached through the registry (iamEntityLocker),
so a rename cannot run between resolving a caller and deciding its request.
IAM's handlers and GetSessionToken look a caller resolved before they took
the lock up again by its unique ID; sessions follow a renamed user by that
ID. A key or session whose user or role is gone is refused rather than
unenforced. Tag writes to users, roles and instance profiles, through IAM
or the tagging API, take one tag mutex. The CFN Arn refreshes as soon as a
Path change applies. Coverage for the rollback, store-fault and refusal
branches.
@scttfrdmn
scttfrdmn merged commit 5c58695 into main Nov 25, 2026
22 of 23 checks passed
@scttfrdmn
scttfrdmn deleted the feat/v0134-iam-extras branch November 25, 2026 02:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant