Skip to content

Organizations: OUs, policies, and account placement are unimplemented, so the whole account-vending surface is unreachable #578

Closed

Description

@scttfrdmn

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.

  • CreateOrganizationalUnit
  • DescribeOrganizationalUnit
  • ListOrganizationalUnitsForParent
  • ListParents
  • ListAccountsForParent

Account placement — CreateAccount exists but the account cannot be moved.

  • MoveAccount
  • DescribeCreateAccountStatus

Policy lifecycle — nothing here exists today.

  • CreatePolicy
  • UpdatePolicy
  • DescribePolicy
  • ListPolicies
  • AttachPolicy
  • ListPoliciesForTarget
  • EnablePolicyType

Tagging

  • TagResource
  • ListTagsForResource

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 from CreateAccount).

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

  1. added
    type: feature
    priority: high
    on Aug 5, 2026
  2. added this to the v0.97.0 milestone on Aug 9, 2026
  3. scttfrdmn commented on Aug 9, 2026

    @scttfrdmn
    OwnerAuthor

    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_EXCEEDED fires on the 11th attachment and POLICY_CONTENT_LIMIT_EXCEEDED above 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 MoveAccount to the account's current parent should do. MoveAccount documents DuplicateAccountException — "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 DisablePolicyType was added. The point asks for an organization in ALL mode with SCPs off, but lists only EnablePolicyType. AWS creates an ALL-features organization with SERVICE_CONTROL_POLICY already enabled, so the state only exists by disabling. DisablePolicyType detaches 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 only FullAWSAccess.

    FullAWSAccess was absent and is load-bearing. It had zero occurrences in emulator/. AWS auto-attaches p-FullAWSAccess (AwsManaged: true, ARN arn: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 with MIN_POLICY_TYPE_ATTACHMENT_LIMIT_EXCEEDED. Without it ListPolicies and ListPoliciesForTarget were 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:

    • MaxResults caps at 20 in the model, so the "configurable page size" this issue asks for needs no seed endpoint — honoring MaxResults (clamped to 1–20) makes a truncated read testable on its own.
    • The seed surface is two endpoints, both landed with the foundation: POST/DELETE /v1/organizations/feature-set reaches the CONSOLIDATED_BILLING organization where no SCP can exist, and POST/DELETE /v1/organizations/create-account-failure seeds the asynchronous FAILED outcome with a FailureReason from 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, AccountNotFoundException included, and describeAccount was returning 404), and an unparseable request body returned MalformedData, which is not an Organizations code — it is InvalidInputException.

    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.go condition-key wiring.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: organizationspriority: hightype: feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions