Repository navigation
feat(organizations): implement the service control policy lifecycle (#578) - #612
Merged
Merged
Conversation
…578) 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.
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
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.
Part of #578. This is the service control policy lane of the v0.97.0
Organizations work; the OU, account and tagging clusters land separately, so
Closesis deliberately not used.What this covers
Points 2 (SCP CRUD), 3 (attach/detach with the quotas), 5
(
ListPoliciesForTarget/ListTargetsForPolicy) and 6(
EnablePolicyType/DisablePolicyType, and the unenforced state betweenthem) of #578, plus the parts of point 9 that belong to policies —
PolicyInUseException,IMMUTABLE_POLICY, the min/max attachment limits andthe content limit.
Eleven operations:
CreatePolicy,UpdatePolicy,DeletePolicy,DescribePolicy,ListPolicies,AttachPolicy,DetachPolicy,ListPoliciesForTarget,ListTargetsForPolicy,EnablePolicyType,DisablePolicyType.Why the refusals are the point
A governance script's real behaviour is what it does when a call is refused,
and each of these distinguishes a case the caller must handle differently:
PolicyTypeNotEnabledExceptionCreatePolicystill succeeds, so a caller treating create-then-attach as atomic would record a guardrail as applied while nothing evaluates it.ConstraintViolationException/MIN_POLICY_TYPE_ATTACHMENT_LIMIT_EXCEEDEDConstraintViolationException/MAX_POLICY_TYPE_ATTACHMENT_LIMIT_EXCEEDEDp-FullAWSAccessInvalidInputException/IMMUTABLE_POLICYPolicyInUseExceptionDuplicatePolicyExceptionDuplicatePolicyAttachmentExceptionPolicyNotAttachedExceptionPolicyNotFoundException/TargetNotFoundExceptionConstraintViolationException/POLICY_CONTENT_LIMIT_EXCEEDEDMalformedPolicyDocumentExceptionPolicyTypeAlreadyEnabledExceptionPolicyTypeNotEnabledExceptionDisablePolicyType's error list declares; all three mean "nothing here to turn off".RootNotFoundExceptionPolicyTypeNotAvailableForOrganizationExceptionCreatePolicyandEnablePolicyType— see below.InvalidInputException/INVALID_SYNTAX_POLICY_ID,INVALID_PATTERN_TARGET_ID,INVALID_ENUM_POLICY_TYPEConstraintViolationException/POLICY_NUMBER_LIMIT_EXCEEDEDTwo model-vs-brief discrepancies, resolved toward the model
PolicyTypeNotAvailableForOrganizationExceptionis narrower than thelane brief said. The brief called for it on any policy operation under
CONSOLIDATED_BILLING. The API model declares it onCreatePolicyandEnablePolicyTypeonly. Availability is therefore modeled asvisibility: while SCPs are unavailable no policy is visible, so each
other operation answers with the not-found code its own error list carries
(
PolicyNotFoundException,TargetNotFoundException) and the two listingsanswer an empty page, which they declare no code to refuse with. Emitting
an undeclared exception would hand a caller something its SDK cannot catch
by type — worse than a truthful "no such policy".
Generated policy IDs use a ten-character suffix, not eight. The model
gives two patterns for one identity:
PolicyIdadmitsp-[0-9a-zA-Z_]{8,128},while
PolicyArnrequiresp-[0-9a-z]{10,32}in the org-owned ARN form.Eight would emit an ARN invalid against the model's own pattern, so ten
satisfies both.
Also wired
PolicyNotAttachedExceptiononDetachPolicy, which the modeldeclares and the brief's refusal list omitted.
The disable/enable round trip
DisablePolicyTypedetaches every SCP from every entity in the root — theroot, every OU and every account — and does not remember them.
EnablePolicyTyperestoresp-FullAWSAccessand nothing else. That is whatthe User Guide documents, and helpfully restoring the prior attachments would
hide a destructive round trip from a caller that disabled the type to make a
change. Clearing only the root would leave an account carrying an SCP the root
no longer evaluates — a state no sequence of API calls can reach, so no caller
has handling for it.
Deliberate omissions
ListPolicies/ListPoliciesForTargetfilters beyond the requiredFilter; the model has no others.SERVICE_CONTROL_POLICYis modeled. Other enum members(
TAG_POLICY,BACKUP_POLICY, …) are refused on create/enable withPolicyTypeNotAvailableForOrganizationExceptionand return an empty pagefrom the listings, which declare no refusal for it. A value outside the enum
is
INVALID_ENUM_POLICY_TYPE— a typo and an unsupported feature call fordifferent action from the caller.
PENDING_ENABLE/PENDING_DISABLEpolicy-type status. The modeldeclares them, but a transition whose end no caller can observe would make a
poll loop wait for a state change that never arrives. Clock-driven
transitions are EC2: every instance state transition is instantaneous, so pending, stopping and shutting-down are never observable #514.
statement semantics is modeling the authorization engine, not the API.
CHANGELOG.mdis untouched — PR 6 of this series owns it.New unexported helpers, for later hoisting
All live in
emulator/organizations_policy.goso the parallel lanes do notconflict; several are candidates to move into
organizations_state.gooncethe lanes have merged:
policyTypeAvailable,loadVisiblePolicy,scpEnabledOnStoredRoot,rootSubtree,orgRootWithPolicyTypes,orgPolicyNotFound,orgTargetNotFound,orgPolicyArn,orgPolicyTypesand the
orgCheck*validators.Verification
gofmt -l emulator/,go build ./...,go vet ./...,golangci-lint run ./emulator/(0 issues), andmake test(race detector)are all clean. Per-function statement coverage of
emulator/organizations_policy.goaverages 97%.