Repository navigation
feat(organizations): persist the root and add the shared storage layer (#577) - #606
Merged
Merged
Conversation
#577) ListRoots minted a fresh r- ID per call and never persisted it, so two calls disagreed and nothing could reference the root — a caller that attached a policy to it and re-read would conclude the attachment had vanished. The root is now created once with the organization and persisted under root:<account>. Alongside it, the storage layer the remaining Organizations operations are built on: the hierarchy in both directions, OUs, policies, attachments, tags, and CreateAccount statuses, plus pagination that honors the model's MaxResults ceiling and a target resolver the policy and tagging clusters share. The per-operation dispatch switch is replaced by a chain of per-cluster claim functions so each cluster owns one file. p-FullAWSAccess is synthesized rather than stored — so it is immutable — and attached to the root and every account and OU while the SCP type is enabled, as AWS does. Two control-plane seeds ship with it: the organization feature set, which makes the no-SCPs-possible state reachable, and the asynchronous CreateAccount failure, whose reason is validated against the model enum so a typo cannot seed an outcome no SDK catch branch matches. Two fidelity fixes fall out: every Organizations exception is HTTP 400 (the model declares no 404, so DescribeAccount's was unreproducible against AWS), and an unparseable body is InvalidInputException rather than MalformedData, which is not an Organizations code. Closes #577
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
The foundation shipped storage helpers reachable only from the four lanes that follow, so codecov/patch reported them uncovered on #606. Each is tested directly rather than merged past: a lane inherits tested storage instead of assuming it. Covers saveRoot/loadStoredRoot as the pair DisablePolicyType writes through, the OU index a listing pages over, detachPolicyFrom clearing both directions of the attachment index, the tag store's ordering and per-resource scoping, the create-account-status store including the unknown-ID answer, and the ConstraintViolationException and empty-body shapes.
Every read helper distinguishes three answers a caller must not confuse: the entity exists, it does not, or the store could not be read. The last is retryable and the middle is terminal, so collapsing one into the other sends a consumer down the wrong path — and for the root specifically, a swallowed read failure has the caller mint a new root, which is the unstable identity #577 was about. Adds a prefix-scoped fault state manager and a corrupt-record one, and covers: auto-creation refusing on a failure at any of its writes; both halves of every save (record and index), since a save reported successful with only one written is invisible to a listing or names an ID no Describe resolves; both directions of an attachment write; the seed reads, where a swallowed failure silently exercises the nominal path the seed exists to avoid; and the wire result, a 500 InternalFailure the SDK retries rather than a 400 it treats as terminal. Also pins the operation-level guards the lanes will inherit: a stale NextToken is refused rather than restarting a paging loop, an unparseable body is refused per operation, an empty body is not (the CLI sends none for ListRoots), a vanished record is skipped rather than listed as an empty account, and the depth walk terminates on a cycle.
This was referenced Aug 9, 2026
scttfrdmn
added a commit
that referenced
this pull request
Aug 9, 2026
…578) (#612) Implements the eleven SCP operations — CreatePolicy, UpdatePolicy, DeletePolicy, DescribePolicy, ListPolicies, AttachPolicy, DetachPolicy, ListPoliciesForTarget, ListTargetsForPolicy, EnablePolicyType and DisablePolicyType — over the storage layer PR #606 landed. Every request/response shape, error code and quota is verified against the Organizations API model rather than recall. The point of the lane is the refusals, because a governance script is built on them: - PolicyTypeNotEnabledException on AttachPolicy is #578 point 6. An all-features organization with SCPs disabled still accepts CreatePolicy and refuses the attach, so a caller that treats create-then-attach as one atomic step finds out here rather than recording a guardrail as applied while nothing evaluates it. - MIN_POLICY_TYPE_ATTACHMENT_LIMIT_EXCEEDED on the last DetachPolicy. An entity with the type enabled and no SCP attached denies everything in real AWS, so a detach that emptied the set would produce the reverse of what the caller intended, silently. - IMMUTABLE_POLICY on writes to p-FullAWSAccess. A teardown that deletes every policy it can list must not be able to remove the one the minimum-attachment rule depends on, and must not get a not-found it would read as "already cleaned up". - PolicyInUseException rather than a cascade on DeletePolicy: a cascade would strip a guardrail from every entity it was attached to, and a teardown running in the wrong order would look like it worked. - DuplicatePolicyException, DuplicatePolicyAttachmentException and PolicyNotAttachedException, so a re-run can tell "I already made this" from "I made it now" and a stale local record from a quota. - MAX_POLICY_TYPE_ATTACHMENT_LIMIT_EXCEEDED at ten SCPs per target — the SCP quota, not the five that belongs to resource control policies — and POLICY_CONTENT_LIMIT_EXCEEDED at 10,240 characters, measured in runes because the quota is stated in characters. - MalformedPolicyDocumentException separately from the size limit: an oversize document has to be split and an unparseable one corrected, and one code cannot say which. DisablePolicyType detaches every SCP from every entity in the root and does not remember them; re-enabling restores only FullAWSAccess. That is what the User Guide documents, and modeling it as a toggle would hide a destructive round trip from a caller that disabled the type to make a change. Availability is modeled as visibility. Under CONSOLIDATED_BILLING no SCP is visible, so each operation answers with the not-found code its own error list declares; only CreatePolicy and EnablePolicyType name the feature set, because they are the only two operations whose model error list declares PolicyTypeNotAvailableForOrganizationException. Emitting it elsewhere would hand a caller an exception its SDK cannot catch by type. Generated policy IDs use a ten-character suffix: the model's PolicyId pattern admits eight, but the PolicyArn pattern requires ten to thirty-two in the ARN it embeds, so a shorter suffix would produce an ARN invalid against the model's own pattern. Touches only this cluster's files, so the other v0.97.0 Organizations lanes do not conflict.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
ListRootsminted a freshr-ID on every call and never persisted it:Two calls disagreed, the ARN built from it moved with them, and nothing could
reference the root. The failure mode is not an error — a caller attaches a policy
to the root, re-reads, sees a different ID, and concludes the attachment
vanished. That is a determinism defect in the one property substrate exists to
provide.
The root is now created once alongside the organization and the management
account, persisted under
root:<account>, and returned unchanged for the life ofthe state store.
The storage layer
Every control #578 adds attaches to that root, so this PR also lands the shared
storage the remaining Organizations work is built on — deliberately as one
serial change, so the operation clusters that follow add operations rather than
data structures and can be written independently:
parent:<child>,children:<parent>), withnew accounts and the management account placed in the root so a
ListParentswalk has somewhere to start
CreateAccount-status stores with their indicesresolveOrgTarget, which names what an ID refers to — the policy and taggingclusters both branch on it
orgPaginate, honoring the model'sMaxResultsceiling of 20Reasonthe model documentsThe per-operation dispatch
switchis replaced by a chain of per-cluster claimfunctions, four of them currently empty, so each cluster owns one file rather
than contending for one statement.
p-FullAWSAccessAWS attaches this AWS-managed SCP to the root, every OU and every account when
the SCP type is enabled, and the minimum-one-SCP rule then prevents detaching
it without a replacement. It had zero occurrences in
emulator/but isload-bearing: without it a fresh organization reports no attached policies, which
is wrong, and the minimum-attachment rule has nothing to hold. It is synthesized
rather than stored, so it cannot be updated or deleted, and its ARN is owned by
awsrather than by the management account.Seeds
POST/DELETE /v1/organizations/feature-set— sets the feature set, making aCONSOLIDATED_BILLINGorganization (one in which no SCP can exist at all)reachable. The seed wins over the stored value, so a test can flip an
already-observed organization rather than having to arrange the seed before the
first request.
POST/DELETE /v1/organizations/create-account-failure— seeds theasynchronous
CreateAccountoutcome, keyed by account name or"*". Anunknown
failureReasonis refused with a 400, for the reason the Price Listseed already gives: a typo'd value would seed a
FAILEDstatus carryingsomething no SDK catch branch matches, so the caller's fallback path would go
untested while the test still passed.
Two fidelity fixes in the same code
AccountNotFoundExceptionis now 400, not 404. The API model declares no404 for any Organizations error, so the status was one a caller could not
reproduce against AWS. Updates the assertion in
organizations_plugin_test.go.InvalidInputException, notMalformedData, whichis not an Organizations code — so an SDK caller's catch branch never matched
it. The
InvalidInputExceptionReasonis carried in the message, since theJSON-RPC error document has nowhere else to put it.
Compatibility
A fresh organization now reports
FullAWSAccessattached to the root and toevery account, so a test asserting an empty policy list will see one entry.
AccountNotFoundExceptionis 400 rather than 404.Verification
All green. Sources for every code, status and quota: the botocore Organizations
model at
2016-11-28, and Quotas for AWS Organizations.Two figures #578 states are corrected against that page — an SCP limit is 10
per target and 10,240 characters; 5/5120 are the RCP values.
Closes #577