Skip to content

Organizations: state is keyed by caller account, so a member account cannot observe its own organization #623

Closed

Description

@scttfrdmn

Split out of #619, which asked for it as one of its suggested behaviours. #619 ships the three resource-policy operations scoped to the caller's own organization; the cross-account asymmetry it also describes needs a change to how Organizations stores state, so it is tracked here.

What cannot be observed today

From #619:

DescribeResourcePolicy from a member account of the same organization returns what management set — that asymmetry is the interesting thing to be able to test.

There is no way to reach that. Organizations state is keyed by the caller's account:

// emulator/organizations_state.go
func orgKey(acct string) string     { return "org:" + acct }
func orgRootKey(acct string) string { return "root:" + acct }

and ensureOrganization auto-creates a whole organization — root, management account, FullAWSAccess attachments — for any account ID it has not seen:

func (p *OrganizationsPlugin) ensureOrganization(ctx context.Context, acct string) (*Organization, error) {
	var org Organization
	found, err := p.orgGetJSON(ctx, orgKey(acct), &org)
	...
	if found {
		return &org, nil
	}
	// Auto-create.

So a member account that calls any Organizations operation does not see the organization it belongs to. It silently gets a brand-new one, with a different org ID, a different root, and no resource policy. Every read succeeds; every answer is about the wrong organization.

That auto-create is deliberate and load-bearing — it is what makes a fresh emulator usable with no setup call — so this is not a bug in it, but it does mean "the organization the caller is a member of" is not a question the state layer can currently answer.

What it would take

Two pieces, neither of which belongs inside a single operation:

  1. A member → organization reverse index. Accounts are stored under orgAccountKey(id) = "account:" + id with a per-management-account index at orgAccountIDsKey(masterAcct), but there is no mapping from a member account ID back to its management account. ensureOrganization would need to consult that index before deciding to auto-create, so a known member resolves to its existing organization instead of getting a new one. Note CreateAccount mints member IDs via generateOrganizationAccountID(), so the index can be written at vend time.
  2. A way for a test to authenticate as a member. reqCtx.AccountID comes from the credential registry (emulator/server.go, step 1.5) or an STS session account. Driving a journey as a member account means registering a credential for a vended account ID — worth confirming that path works end to end before designing the index.

Why it is worth doing

It is the difference between "delegation is in place" and "cannot tell" for any tool that classifies where it stands in an organization before acting — #619's original motivation. It also generalizes well beyond resource policies: the same index would make DescribeOrganization, ListParents and ListPoliciesForTarget answer correctly for a member caller, and would let AccessDeniedException for a caller outside the organization be modelled at all (also deferred from #619, for the same reason).

Once the index exists, the resource-policy half is small: DescribeResourcePolicy resolves the management account and reads resource_policy:<mgmt>.

Acceptance criteria

  • A member→management reverse index, written when an account is vended or otherwise joined
  • ensureOrganization resolves a known member to its existing organization rather than auto-creating
  • A test can authenticate as a vended member account through the credential registry
  • DescribeResourcePolicy from a member account returns what management set
  • A caller outside the organization gets AccessDeniedException
  • The no-setup auto-create path still works for an unseen account that is not a known member
  • An e2e journey covering the asymmetry through the SDK

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: organizationspriority: mediumtype: feature

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions