Skip to content

A self-hosted install reads its own AWS account with its own roles - #516

Merged
nambok merged 1 commit into
mainfrom
selfhost-own-account-read
Nov 7, 2026
Merged

nambok merged 1 commit into
mainfrom
selfhost-own-account-read

Conversation

@nambok

@nambok nambok commented Nov 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

A self-hosted install connected to its own AWS account showed "Update needed: N new read-only permissions" with an Update in AWS button. That button launches a second stack, CoderHelmLogReaderUpdate-<id>, to add permissions to a CoderHelmLogReader role a person created by hand. An install runs inside that same account, and its own stack already deploys there. So whatever a release reads should arrive with the version update, without a person launching a stack.

With this change, the install reads its own account with its gateway's and worker's own roles. The install's stack gives those roles this release's read-only permissions. The card never shows Update in AWS for the install's own account.

Changes

Infra

  • infra/lib/own-account-read.ts adds a managed policy to the gateway's and worker's roles, on self-hosted installs only (layout: single-origin).
    • The policy holds this release's read-only permissions, read from infra/cfn/coderhelm-log-reader-update.yaml. That is the same template the services check roles against, so the two lists can't drift apart.
    • The one statement that names a role (iam:SimulatePrincipalPolicy) is pointed at the function's own role.
    • Each function gets INSTALL_OWN_ROLE_ARN.
  • infra/lib/access.ts: the boundary now allows the read-only Airflow (Get*, List*, InvokeRestApi), ECS (Describe*, List*) and ECR (BatchGetImage, List*) calls, and iam:Simulate* on the install's own roles.
    • To stay within IAM's 6,144-character limit, its STS session lists are written as sts:AssumeRole* and sts:AssumeRoleWith*. These cover the same actions as before.

Services

  • live/aws.rs: install_target swaps a connected CoderHelmLogReader in the install's own account for the function's own role, and assume then uses the function's own credentials. Nothing else is swapped:
    • the data-source role;
    • other accounts;
    • the hosted deployment, which has no INSTALL_OWN_ROLE_ARN.
  • Connecting an account still proves the team's own role, with its External ID (routes/log_analyzer.rs, which calls STS directly). So reading with the install's role happens only for an account the team was granted.
  • live/permissions.rs: the check runs on the function's own role and marks install_account.
    • In that account it never returns an update stack.
    • If a permission is still missing, the problem says it comes with the next version update, and that nothing is needed in AWS.
    • Checks saved before this change still parse.
  • routes/integrations.rs and routes/connectors.rs: no update_url for the install's own account, and the card carries install_account.

Docs: docs/self-host/integrations.md describes how the install reads its own account.

The dashboard counterpart is linked below. It shows "These read-only permissions come with the next version update" with a link to Version and updates, and no Update in AWS button.

Verification

  • cargo test -p common --lib -- live::aws live::permissions: 39 passed. New tests:
    • the_install_account_reads_with_the_install_role and other_accounts_roles_and_installs_keep_their_role;
    • the_install_account_is_never_offered_an_update_stack, another_account_still_gets_the_update_stack and a_check_saved_before_the_install_fields_still_reads.
  • infra: tsc is clean. New synth tests:
    • On self-host, the gateway and worker each get one read policy that covers every action in log_reader::ABILITIES. That policy is read-only, checks permissions only on the function's own role, and the function names its role.
    • The hosted deployment gets neither the policy nor the variable.
    • The boundary size tests pass for both the config-file install and the native one.
  • infra/test/fixtures/native-sim.json regenerated with python3 infra/scripts/deploy-role-sim.py --native (read-only: DescribeType, SimulateCustomPolicy). 3,204 (action, resource) pairs simulated, 63 registry calls not simulated. Two fixes to the script were needed, neither caused by this change:
    • The updates part now takes DeployRoleArn from a parent resource (Fn::GetAtt DeployRole.Arn). The script assumed every GetAtt pointed at a child stack, so its synth step crashed before any AWS call. It now resolves a parent role's ARN.
    • AWS added dynamodb:DescribeBulkOperation to the table's handler permissions. That action acts on its own bulk-operation/<id> resource, and the install's tables never start one (no import source). It is now recorded as unused, the way the script already handles calls a template never triggers.
  • npm test in infra: 147 passed, 0 failed.

A self-hosted install connected to its own AWS account read it through the
CoderHelmLogReader role a person created, so every release that read a
little more asked that person to launch an update stack in AWS ("Update in
AWS"). The install's own stack already deploys into that account and can
carry those permissions itself.

- The gateway's and worker's roles get this release's read-only
  permissions in their own account as a managed policy, read from the
  update template the services check roles against, so the list can't
  drift. Each version update brings any new permission.
- In the install's own account the log reader is read with the function's
  own role (live/aws.rs install_target). Connecting still proves the
  team's CoderHelmLogReader role with its External ID; other accounts and
  the hosted deployment keep the role and its update flow.
- The permissions check marks the install's own account. It never offers
  the update stack there; a missing permission says it arrives with the
  next version update.
- The boundary allows the read-only Airflow, ECS and ECR calls and the
  role's check of its own permissions, and writes its session actions as
  wildcards to stay within IAM's size limit.
- The native policy simulation is regenerated. Its script resolves a
  parent role's ARN passed to a part, and records the table handler's new
  bulk-operation call as unused (the tables never start one).
@nambok
nambok force-pushed the selfhost-own-account-read branch from 1d2dea9 to ba1b2da Compare November 7, 2026 18:37
@nambok
nambok merged commit b25ce7b into main Nov 7, 2026
10 checks passed
@nambok
nambok deleted the selfhost-own-account-read branch November 7, 2026 18:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant