Repository navigation
Description
OrganizationsPlugin.HandleRequest (emulator/organizations_plugin.go:41-58) dispatches five operations: DescribeOrganization, ListAccounts, DescribeAccount, ListRoots, CreateAccount. Everything else returns InvalidAction.
That covers reading an organization but not building one. The missing operations are the OU tree, the policy lifecycle, account placement, and tagging — which together are the entire surface a tool that vends and governs member accounts uses.
Operations
Grouped by what they make possible, since they are only useful in clusters.
OU tree — without these there is nowhere to put an account.
CreateOrganizationalUnitDescribeOrganizationalUnitListOrganizationalUnitsForParentListParentsListAccountsForParent
Account placement — CreateAccount exists but the account cannot be moved.
MoveAccountDescribeCreateAccountStatus
Policy lifecycle — nothing here exists today.
CreatePolicyUpdatePolicyDescribePolicyListPoliciesAttachPolicyListPoliciesForTargetEnablePolicyType
Tagging
TagResourceListTagsForResource
DescribeResourcePolicy is also absent; it is lower priority, since the delegation-policy case it serves is one where "the caller cannot read it" is the realistic answer anyway.
The behaviours matter more than the endpoints
An emulator that implements these as straightforward CRUD would let a whole class of bug pass. The specific behaviours worth having, roughly in order of how much they change a caller's code:
1. CreateAccount is asynchronous. Today it returns State: "SUCCEEDED" inline (:315). In AWS it returns IN_PROGRESS with a car-… request ID, and the caller polls DescribeCreateAccountStatus until SUCCEEDED or FAILED. A synchronous fake lets a missing poll loop pass, and the poll loop is the part that has to survive being interrupted — the request ID is the only handle a resumed run has on an account that may or may not exist yet.
2. A newly created account lands under the ROOT, not under a destination OU. CreateAccount takes no parent parameter; the account appears at the root and the caller must then MoveAccount. A tool that assumes otherwise silently leaves accounts unprotected, since the OU is where the policies are attached. Worth making explicit in the model rather than incidental.
3. CreateAccount fails asynchronously. The call returns 200 and the status later reports FAILED with a FailureReason — EMAIL_ALREADY_EXISTS, ACCOUNT_LIMIT_EXCEEDED, INVALID_EMAIL, CONCURRENT_ACCOUNT_MODIFICATION, GOVCLOUD_ACCOUNT_LIMIT_EXCEEDED, INTERNAL_FAILURE, and others. Code that only checks the immediate error believes a failed create succeeded. A seedable "fail the next create with reason X" knob covers this.
4. None of the mutating operations are idempotent, and each refuses differently. This is the single most valuable thing for a caller to test against, because the refusals are what "safely re-runnable" has to be built on:
| Second call | Refusal |
|---|---|
CreateOrganizationalUnit, same name under same parent |
DuplicateOrganizationalUnitException |
CreatePolicy, same name |
DuplicatePolicyException |
AttachPolicy, already attached |
DuplicatePolicyAttachmentException |
EnablePolicyType, already enabled |
PolicyTypeAlreadyEnabledException |
CreateOrganization, already in one |
AlreadyInOrganizationException |
5. MoveAccount to the account's current parent. Genuinely uncertain against the real API, and it is the case a resumed run hits every time. If substrate picks a reading, saying which in the plugin doc comment is enough; a knob for both is better.
6. The service control policy type can be disabled on the root. The dangerous state: organization in ALL features mode, SCP type off, CreatePolicy succeeds, AttachPolicy succeeds, nothing is enforced. A caller has to detect it before attaching anything, and can only test that if the fixture can start there. (ListRoots currently hardcodes ENABLED — see #577.)
7. Quotas that are reachable in ordinary use, not edge cases.
- 5 SCPs per target (
ConstraintViolationException/MAX_POLICY_TYPE_ATTACHMENT_LIMIT_EXCEEDED). Four is a normal working set, so this is one policy away. - 5 levels of OU below the root (
OU_DEPTH_LIMIT_EXCEEDED). - 5120 bytes per SCP document (
POLICY_CONTENT_LIMIT_EXCEEDED). - Org-wide unique account email (surfaces as the async
EMAIL_ALREADY_EXISTS, not as an error fromCreateAccount).
8. Pagination on every List*. A caller that ignores NextToken gets a truncated answer with no error, which for policy attachments means concluding a policy is not attached when it is. A small configurable page size makes that testable; a plugin that returns everything in one page makes it invisible.
9. aws:RequestTag / aws:ResourceTag on Organizations resources. authz.go already builds both condition keys, so this may be mostly wiring: the case that matters is CreatePolicy with a request tag and UpdatePolicy gated on a resource tag, which is how policy ownership gets enforced in a delegated setup. Tag-gated policy modification is a privilege boundary, and it is only testable if the tag is actually part of the authorization decision.
Context
This is what automat (a tool that vends compliance-baselined AWS sub-accounts) needs; it currently uses hand-rolled fakes for exactly these behaviours and would rather use substrate. Happy to contribute the plugin work or to review — say which. I can also share the hand-rolled fake's shape if useful as a spec for the refusal semantics, since it is already written against all nine points above.
Splitting into per-cluster issues is fine if that suits the milestone better; filed as one because the clusters are not independently useful.
Activity
scttfrdmn commentedon Aug 9, 2026
Scoped into milestone v0.97.0 and now underway. Four corrections and additions came out of checking the issue's specifics against the botocore model (
organizations/2016-11-28/service-2.json) and the User Guide, rather than against the numbers as written here:Two quotas in the issue are the RCP values, not the SCP ones. Quotas for AWS Organizations gives SCPs as 10 per root/OU/account and 10,240 characters per policy; the 5-per-target and 5,120-character figures belong to resource control policies. The implementation uses 10 and 10,240, so
MAX_POLICY_TYPE_ATTACHMENT_LIMIT_EXCEEDEDfires on the 11th attachment andPOLICY_CONTENT_LIMIT_EXCEEDEDabove 10,240 characters. OU depth 5 as stated here is correct; also pinned are max accounts 10, OUs per org 2,000, SCPs per org 10,000, tags per resource 50.Point 5 is settled by the API reference, so it needs no seed knob. The question was what a
MoveAccountto the account's current parent should do.MoveAccountdocumentsDuplicateAccountException— "That account is already present in the specified destination" — so it is a refusal, not a no-op. That is the better answer for the re-runnability case this issue is really about: a governance script re-run gets a distinguishable error instead of a silent success.Point 6 is unreachable as specified, so
DisablePolicyTypewas added. The point asks for an organization inALLmode with SCPs off, but lists onlyEnablePolicyType. AWS creates anALL-features organization withSERVICE_CONTROL_POLICYalready enabled, so the state only exists by disabling.DisablePolicyTypedetaches every SCP from every entity in the root (per the User Guide: "all SCPs are automatically detached… attachments from before are lost"), and re-enabling restores onlyFullAWSAccess.FullAWSAccesswas absent and is load-bearing. It had zero occurrences inemulator/. AWS auto-attachesp-FullAWSAccess(AwsManaged: true, ARNarn:aws:organizations::aws:policy/service_control_policy/p-FullAWSAccess) to the root, every OU and every account while SCPs are enabled, and the minimum-one-SCP rule is what makes detaching the last SCP refuse withMIN_POLICY_TYPE_ATTACHMENT_LIMIT_EXCEEDED. Without itListPoliciesandListPoliciesForTargetwere wrong on a fresh organization and the min-attachment refusal had nothing to fire on. It is synthesized rather than stored, so it exists in every organization and cannot be written to.Two smaller notes:
MaxResultscaps at 20 in the model, so the "configurable page size" this issue asks for needs no seed endpoint — honoringMaxResults(clamped to 1–20) makes a truncated read testable on its own.POST/DELETE /v1/organizations/feature-setreaches theCONSOLIDATED_BILLINGorganization where no SCP can exist, andPOST/DELETE /v1/organizations/create-account-failureseeds the asynchronousFAILEDoutcome with aFailureReasonfrom the model's 15-value enum, keyed by account name or"*". An unknown reason is refused with a 400 — a typo'd value would seed an outcome no SDK catch branch matches, so the caller's fallback path would go untested while the test still passed.Also fixed on the way through, both pre-existing fidelity bugs the work exposed: every Organizations exception is HTTP 400 (the model declares no 404 for any of them,
AccountNotFoundExceptionincluded, anddescribeAccountwas returning 404), and an unparseable request body returnedMalformedData, which is not an Organizations code — it isInvalidInputException.Work is split as a foundation PR (#606, closing #577 — the persisted root plus the shared storage layer) and four independent lanes: OU tree, policy lifecycle, account vending, tagging with the
authz.gocondition-key wiring.feat(organizations): make account vending asynchronous (#578) (#607)
feat(organizations): implement the organizational-unit tree (#578) (#608
feat(organizations): tag roots, OUs, accounts and policies, and let a…
feat(organizations): implement the service control policy lifecycle (#…
feat(organizations): validate inline tags on every create path (#613)
docs(organizations): document the service, and add the SDK-level jour…
feat(organizations): emulate CloseAccount, record the email decision,…