diff --git a/docs/self-host/integrations.md b/docs/self-host/integrations.md index 30093b584..bb607d659 100644 --- a/docs/self-host/integrations.md +++ b/docs/self-host/integrations.md @@ -21,7 +21,7 @@ Teams connect their own AWS accounts so CoderHelm can read CloudWatch logs, alar - **Making the role by hand**\ The AWS page lists every action the role needs, grouped by what CoderHelm reads with it, and your install's account id. Create the role named `CoderHelmLogReader`, let your install's account assume it only with the team's External ID, and allow those actions. - **Reading the install's own account**\ - Nothing special: create the same role in that account. The install's functions may already take on `CoderHelmLogReader` in any account, their own included, so no permission on the install changes. It is also safer than widening the install's own roles to read every log group. + Connect it the same way: the `CoderHelmLogReader` role there, with the team's External ID, proves the team may read it. After that, the install reads its own account with its gateway's and worker's own roles, which the install's stack gives this release's read-only permissions (`infra/lib/own-account-read.ts`, the same list as the update template). Each version update brings any new permission, so the install's own account never shows **Update in AWS**; if a permission is still missing, the page says it comes with the next version update. - **When a release needs new permissions**\ Each AWS connection shows **Permissions up to date** or **Update needed: N new read-only permissions**. The check runs live: it asks IAM's policy simulator about the role (`iam:SimulatePrincipalPolicy` on that one role), or, for roles made before that, tries the cheapest read of each kind. **Update in AWS** opens a stack (`CoderHelmLogReaderUpdate-`) that adds exactly this release's permissions to the existing role. Sign in to the role's account, review it and press **Create stack**. When you come back, the page checks again by itself. If something went wrong, it names the reason and the fix: the stack failed, it isn't in the role's account, a permissions boundary or an organization policy (SCP) blocks the permissions. Once a day the install checks every account, and each team's Slack or Teams channel hears once per release that needs an update. Until then, features that need a missing permission say so where they are used, skip that step and keep working with the rest. - **Alert routes (SNS)**\ diff --git a/infra/lib/access.ts b/infra/lib/access.ts index 23ebfbf19..e13d018f9 100644 --- a/infra/lib/access.ts +++ b/infra/lib/access.ts @@ -150,7 +150,9 @@ export const LOG_ANALYZER_ROLE = "log-analyzer"; /** Every tag value the boundary lets take on the read roles in this account. */ export const READ_ROLE_CALLERS = [...RUNTIME_ROLES, LOG_ANALYZER_ROLE]; /** STS actions on a role in this account: all denied, except sts:AssumeRole on the read roles above. */ -const ROLE_SESSION_ACTIONS = ["sts:AssumeRole", "sts:AssumeRoleWithWebIdentity", "sts:AssumeRoleWithSAML", "sts:TagSession", "sts:SetSourceIdentity"]; +const ROLE_SESSION_ACTIONS = ["sts:AssumeRole*", "sts:TagSession", "sts:SetSourceIdentity"]; +/** The same, without sts:AssumeRole itself (AssumeRoleWithWebIdentity and AssumeRoleWithSAML). */ +const OTHER_SESSION_ACTIONS = ["sts:AssumeRoleWith*", "sts:TagSession", "sts:SetSourceIdentity"]; /** Role and policy writes: only with the boundary on the role. */ export const ROLE_WRITES = [ @@ -196,6 +198,15 @@ const POLICY_MANAGE = [ */ export const BOUNDARY_SERVICES = [ "acm:*", + // A self-hosted install reading its own account (own-account-read.ts): + // Airflow as a Viewer, ECS services and image manifests, read-only. + "airflow:Get*", + "airflow:List*", + "airflow:InvokeRestApi", + "ecs:Describe*", + "ecs:List*", + "ecr:BatchGetImage", + "ecr:List*", "apigateway:*", "bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream", @@ -339,7 +350,7 @@ export function guardrails(n: AccessNames, otherBoundaries: string[] = []): Stat // On the read roles: sts:AssumeRole only, no other STS action. Sid: "ReadRolesHereAssumeOnly", Effect: "Deny", - Action: ROLE_SESSION_ACTIONS.filter((x) => x !== "sts:AssumeRole"), + Action: OTHER_SESSION_ACTIONS, Resource: a.ownReadRoles, }, { @@ -376,7 +387,7 @@ export function boundaryPolicy(n: AccessNames, otherBoundaries: string[] = []): { Sid: "CoderHelmServices", Effect: "Allow", Action: BOUNDARY_SERVICES, Resource: "*" }, { Sid: "InstallRoleWrites", Effect: "Allow", Action: ROLE_WRITES, Resource: a.role, Condition: { StringEquals: { "iam:PermissionsBoundary": n.boundaryArn } } }, // The same calls as ROLE_MANAGE and POLICY_MANAGE, shorter (the boundary must fit IAM's 6,144 characters). - { Sid: "InstallRoles", Effect: "Allow", Action: ["iam:Get*", "iam:List*", "iam:DeleteRole", "iam:UpdateRole*", "iam:UpdateAssumeRolePolicy", "iam:TagRole", "iam:UntagRole", "iam:PassRole"], Resource: a.role }, + { Sid: "InstallRoles", Effect: "Allow", Action: ["iam:Get*", "iam:List*", "iam:Simulate*", "iam:DeleteRole", "iam:UpdateRole*", "iam:UpdateAssumeRolePolicy", "iam:TagRole", "iam:UntagRole", "iam:PassRole"], Resource: a.role }, { Sid: "InstallPolicies", Effect: "Allow", Action: ["iam:CreatePolicy*", "iam:DeletePolicy*", "iam:Get*", "iam:List*", "iam:TagPolicy", "iam:UntagPolicy"], Resource: a.policy }, ...guardrails(n, otherBoundaries), ]); diff --git a/infra/lib/api-stack.ts b/infra/lib/api-stack.ts index 516778aca..edc269074 100644 --- a/infra/lib/api-stack.ts +++ b/infra/lib/api-stack.ts @@ -21,6 +21,7 @@ import * as scheduler from "aws-cdk-lib/aws-scheduler"; import { Construct } from "constructs"; import { ResolvedConfig } from "./config"; import { repoPath } from "./paths"; +import { grantOwnAccountRead } from "./own-account-read"; import { Hybrid } from "./hybrid"; import { serviceEnvironment, modelPolicyStatements, publicUrlReadStatement, recordNameIn, setupEnvironment, setupStatements, updaterInvokeStatement, weeklySummaryScheduled } from "./service-env"; import { MailRelay, relaySendStatement } from "./mail-relay"; @@ -625,6 +626,9 @@ export class ApiStack extends cdk.Stack { ...serviceEnvironment(cfg, this.account), }, }); + // A self-hosted install reads its own AWS account with this role, whose + // read-only permissions arrive with each version update (own-account-read.ts). + if (cfg.layout === "single-origin") grantOwnAccountRead(this, "GatewayOwnAccountRead", this.gatewayFunction); for (const st of [...modelPolicyStatements(cfg, this), publicUrlReadStatement(cfg, this), updaterInvokeStatement(cfg, this), relaySendStatement(cfg, this.account)]) { if (st) this.gatewayFunction.addToRolePolicy(st); } diff --git a/infra/lib/own-account-read.ts b/infra/lib/own-account-read.ts new file mode 100644 index 000000000..666af75a7 --- /dev/null +++ b/infra/lib/own-account-read.ts @@ -0,0 +1,57 @@ +/** + * A self-hosted install reading its own AWS account (logs, metrics, Airflow, + * ECS and the rest): its gateway and worker read with their own roles, and + * this stack gives those roles the read-only permissions of the release. + * Every version update brings them along, so nobody launches an extra stack + * to grant the install what its own release needs. + * + * The permissions are the update template's (infra/cfn/coderhelm-log-reader-update.yaml), + * read from that file: the same one the services check a role against + * (services/common/src/log_reader.rs), so the two can't drift apart. + * + * Connecting the account still proves the team's own CoderHelmLogReader role + * with its private ID (routes/log_analyzer.rs); only reading uses the + * install's role (services/common/src/live/aws.rs, install_target). + */ +import * as cdk from "aws-cdk-lib"; +import * as iam from "aws-cdk-lib/aws-iam"; +import { CfnInclude } from "aws-cdk-lib/cloudformation-include"; +import { Construct } from "constructs"; +import { repoPath } from "./paths"; + +/** The environment variable naming the function's own role (live/aws.rs, OWN_ROLE_ENV). */ +export const OWN_ROLE_ENV = "INSTALL_OWN_ROLE_ARN"; +const UPDATE_TEMPLATE = "infra/cfn/coderhelm-log-reader-update.yaml"; +const UPDATE_POLICY_ID = "CoderHelmReadOnlyUpdate"; +const ROLE_NAME_MARK = "__CODERHELM_ROLE__"; + +type Statement = { Sid?: string; Effect: string; Action: string | string[]; Resource: unknown }; + +/** The update template's statements, as the template has them. */ +export function updateTemplateStatements(): Statement[] { + const scratch = new cdk.Stack(new cdk.App(), "Scratch"); + const inc = new CfnInclude(scratch, "T", { templateFile: repoPath(UPDATE_TEMPLATE), parameters: { RoleName: ROLE_NAME_MARK } }); + const p = inc.getResource(UPDATE_POLICY_ID) as iam.CfnPolicy; + return scratch.resolve(p.policyDocument).Statement as Statement[]; +} + +/** + * The statements for `roleArn`: the template's, with the one statement that + * names the role (the permission check on itself) pointed at `roleArn`. + */ +export function ownAccountStatements(roleArn: string): Statement[] { + return updateTemplateStatements().map((s) => + JSON.stringify(s.Resource).includes(ROLE_NAME_MARK) ? { ...s, Resource: roleArn } : s, + ); +} + +/** Gives `fn`'s role this release's read-only permissions in its own account, and tells it so. */ +export function grantOwnAccountRead(scope: Construct, id: string, fn: cdk.aws_lambda.Function): void { + const role = fn.role!; + new iam.CfnManagedPolicy(scope, id, { + description: "CoderHelm: reads this install's own AWS account (logs, metrics, Airflow, ECS), read-only; kept current by each version update", + roles: [role.roleName], + policyDocument: { Version: "2012-10-17", Statement: ownAccountStatements(role.roleArn) }, + }); + fn.addEnvironment(OWN_ROLE_ENV, role.roleArn); +} diff --git a/infra/lib/worker-stack.ts b/infra/lib/worker-stack.ts index b6f2d207d..8b4846a13 100644 --- a/infra/lib/worker-stack.ts +++ b/infra/lib/worker-stack.ts @@ -16,6 +16,7 @@ import { Construct } from "constructs"; import { ResolvedConfig } from "./config"; import { HYBRID_SIGNER_TAG, grantHybridMaster, grantNameRecords, hybridSigningAlias } from "./hybrid"; import { repoPath } from "./paths"; +import { grantOwnAccountRead } from "./own-account-read"; import * as path from "path"; import { relaySendStatement } from "./mail-relay"; import { serviceEnvironment, modelPolicyStatements, publicUrlReadStatement, weeklySummaryScheduled } from "./service-env"; @@ -141,6 +142,9 @@ export class WorkerStack extends cdk.Stack { ...serviceEnvironment(cfg, this.account), }, }); + // A self-hosted install reads its own AWS account with this role, whose + // read-only permissions arrive with each version update (own-account-read.ts). + if (cfg.layout === "single-origin") grantOwnAccountRead(this, "WorkerOwnAccountRead", this.workerFunction); for (const st of [...modelPolicyStatements(cfg, this), publicUrlReadStatement(cfg, this), relaySendStatement(cfg, this.account)]) { if (st) this.workerFunction.addToRolePolicy(st); } diff --git a/infra/scripts/deploy-role-sim.py b/infra/scripts/deploy-role-sim.py index 31d9a1f6f..343f136ae 100644 --- a/infra/scripts/deploy-role-sim.py +++ b/infra/scripts/deploy-role-sim.py @@ -321,6 +321,10 @@ def targets(st, lid, r, action): if action in ("iam:AttachRolePolicy", "iam:DetachRolePolicy"): return [(f"arn:aws:iam::{ACCT}:role/{st.resolve(x)}", {}) for x in p.get("Roles", [])] return [(arn, {})] + # A bulk operation is its own resource (bulk-operation/), described only + # while one runs; the install's tables never start one (no import source). + if action == "dynamodb:DescribeBulkOperation" and not p.get("ImportSourceSpecification"): + return [("UNUSED:no bulk operation", {})] if svc == "iam" and ty == "AWS::SNS::Topic": return [("UNUSED:no delivery status logging role", {})] if svc == "sns" and action in ("sns:Subscribe", "sns:Unsubscribe", "sns:ListSubscriptionsByTopic") and not p.get("Subscription"): diff --git a/infra/test/fixtures/native-sim.json b/infra/test/fixtures/native-sim.json index db070a3a2..e359b07a5 100644 --- a/infra/test/fixtures/native-sim.json +++ b/infra/test/fixtures/native-sim.json @@ -477,6 +477,13 @@ "Effect": "Allow", "Action": [ "acm:*", + "airflow:Get*", + "airflow:List*", + "airflow:InvokeRestApi", + "ecs:Describe*", + "ecs:List*", + "ecr:BatchGetImage", + "ecr:List*", "apigateway:*", "bedrock:InvokeModel", "bedrock:InvokeModelWithResponseStream", @@ -528,6 +535,7 @@ "Action": [ "iam:Get*", "iam:List*", + "iam:Simulate*", "iam:DeleteRole", "iam:UpdateRole*", "iam:UpdateAssumeRolePolicy", @@ -713,9 +721,7 @@ "Sid": "NoOtherRolesHere", "Effect": "Deny", "Action": [ - "sts:AssumeRole", - "sts:AssumeRoleWithWebIdentity", - "sts:AssumeRoleWithSAML", + "sts:AssumeRole*", "sts:TagSession", "sts:SetSourceIdentity" ], @@ -733,8 +739,7 @@ "Sid": "ReadRolesHereAssumeOnly", "Effect": "Deny", "Action": [ - "sts:AssumeRoleWithWebIdentity", - "sts:AssumeRoleWithSAML", + "sts:AssumeRoleWith*", "sts:TagSession", "sts:SetSourceIdentity" ], @@ -906,6 +911,9 @@ {"actions": {"cloudwatch:PutMetricAlarm": "allowed", "cloudwatch:TagResource": "allowed"}, "calls": ["AWS::CloudWatch::Alarm create", "AWS::CloudWatch::Alarm tag", "AWS::CloudWatch::Alarm update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:ResourceTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:cloudwatch:us-east-1:111122223333:alarm:coderhelm-prod-review-gave-up"}, {"actions": {"cloudwatch:PutMetricAlarm": "allowed"}, "calls": ["AWS::CloudWatch::Alarm create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:cloudwatch:us-east-1:111122223333:alarm:coderhelm-prod-review-gave-up"}, {"actions": {"cloudwatch:DeleteAlarms": "allowed", "cloudwatch:DescribeAlarms": "allowed", "cloudwatch:ListTagsForResource": "allowed", "cloudwatch:UntagResource": "allowed"}, "calls": ["AWS::CloudWatch::Alarm create", "AWS::CloudWatch::Alarm delete", "AWS::CloudWatch::Alarm read", "AWS::CloudWatch::Alarm tag", "AWS::CloudWatch::Alarm update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:cloudwatch:us-east-1:111122223333:alarm:coderhelm-prod-review-gave-up"}, + {"actions": {"cloudwatch:PutMetricAlarm": "allowed", "cloudwatch:TagResource": "allowed"}, "calls": ["AWS::CloudWatch::Alarm create", "AWS::CloudWatch::Alarm tag", "AWS::CloudWatch::Alarm update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:ResourceTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:cloudwatch:us-east-1:111122223333:alarm:coderhelm-prod-run-waiting-unasked"}, + {"actions": {"cloudwatch:PutMetricAlarm": "allowed"}, "calls": ["AWS::CloudWatch::Alarm create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:cloudwatch:us-east-1:111122223333:alarm:coderhelm-prod-run-waiting-unasked"}, + {"actions": {"cloudwatch:DeleteAlarms": "allowed", "cloudwatch:DescribeAlarms": "allowed", "cloudwatch:ListTagsForResource": "allowed", "cloudwatch:UntagResource": "allowed"}, "calls": ["AWS::CloudWatch::Alarm create", "AWS::CloudWatch::Alarm delete", "AWS::CloudWatch::Alarm read", "AWS::CloudWatch::Alarm tag", "AWS::CloudWatch::Alarm update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:cloudwatch:us-east-1:111122223333:alarm:coderhelm-prod-run-waiting-unasked"}, {"actions": {"cloudwatch:PutMetricAlarm": "allowed", "cloudwatch:TagResource": "allowed"}, "calls": ["AWS::CloudWatch::Alarm create", "AWS::CloudWatch::Alarm tag", "AWS::CloudWatch::Alarm update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:ResourceTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:cloudwatch:us-east-1:111122223333:alarm:coderhelm-prod-worker-errors"}, {"actions": {"cloudwatch:PutMetricAlarm": "allowed"}, "calls": ["AWS::CloudWatch::Alarm create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:cloudwatch:us-east-1:111122223333:alarm:coderhelm-prod-worker-errors"}, {"actions": {"cloudwatch:DeleteAlarms": "allowed", "cloudwatch:DescribeAlarms": "allowed", "cloudwatch:ListTagsForResource": "allowed", "cloudwatch:UntagResource": "allowed"}, "calls": ["AWS::CloudWatch::Alarm create", "AWS::CloudWatch::Alarm delete", "AWS::CloudWatch::Alarm read", "AWS::CloudWatch::Alarm tag", "AWS::CloudWatch::Alarm update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:cloudwatch:us-east-1:111122223333:alarm:coderhelm-prod-worker-errors"}, @@ -1092,6 +1100,9 @@ {"actions": {"events:PutRule": "allowed"}, "calls": ["AWS::Events::Rule create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:events:us-east-1:111122223333:rule/coderhelm-prod-weekly-summary"}, {"actions": {"events:DeleteRule": "allowed", "events:DescribeRule": "allowed", "events:ListTagsForResource": "allowed", "events:ListTargetsByRule": "allowed", "events:PutTargets": "allowed", "events:RemoveTargets": "allowed", "events:UntagResource": "allowed"}, "calls": ["AWS::Events::Rule create", "AWS::Events::Rule delete", "AWS::Events::Rule read", "AWS::Events::Rule tag", "AWS::Events::Rule update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:events:us-east-1:111122223333:rule/coderhelm-prod-weekly-summary"}, {"actions": {"events:PutTargets": "allowed"}, "calls": ["AWS::Events::Rule create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack"}, "resource": "arn:aws:events:us-east-1:111122223333:rule/coderhelm-prod-weekly-summary"}, + {"actions": {"iam:TagPolicy": "allowed"}, "calls": ["AWS::IAM::ManagedPolicy create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:ResourceTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:iam::111122223333:policy/coderhelm-prod-GatewayOwnAccountRead-aa934871"}, + {"actions": {"iam:CreatePolicy": "allowed"}, "calls": ["AWS::IAM::ManagedPolicy create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:iam::111122223333:policy/coderhelm-prod-GatewayOwnAccountRead-aa934871"}, + {"actions": {"iam:CreatePolicyVersion": "allowed", "iam:DeletePolicy": "allowed", "iam:DeletePolicyVersion": "allowed", "iam:GetPolicy": "allowed", "iam:GetPolicyVersion": "allowed", "iam:ListEntitiesForPolicy": "allowed", "iam:ListPolicyVersions": "allowed"}, "calls": ["AWS::IAM::ManagedPolicy delete", "AWS::IAM::ManagedPolicy read", "AWS::IAM::ManagedPolicy update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:iam::111122223333:policy/coderhelm-prod-GatewayOwnAccountRead-aa934871"}, {"actions": {"iam:TagPolicy": "allowed"}, "calls": ["AWS::IAM::ManagedPolicy create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:ResourceTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:iam::111122223333:policy/coderhelm-prod-OverflowPolicy1-2ccac3d5"}, {"actions": {"iam:CreatePolicy": "allowed"}, "calls": ["AWS::IAM::ManagedPolicy create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:iam::111122223333:policy/coderhelm-prod-OverflowPolicy1-2ccac3d5"}, {"actions": {"iam:CreatePolicyVersion": "allowed", "iam:DeletePolicy": "allowed", "iam:DeletePolicyVersion": "allowed", "iam:GetPolicy": "allowed", "iam:GetPolicyVersion": "allowed", "iam:ListEntitiesForPolicy": "allowed", "iam:ListPolicyVersions": "allowed"}, "calls": ["AWS::IAM::ManagedPolicy delete", "AWS::IAM::ManagedPolicy read", "AWS::IAM::ManagedPolicy update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:iam::111122223333:policy/coderhelm-prod-OverflowPolicy1-2ccac3d5"}, @@ -1104,6 +1115,9 @@ {"actions": {"iam:TagPolicy": "allowed"}, "calls": ["AWS::IAM::ManagedPolicy create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:ResourceTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:iam::111122223333:policy/coderhelm-prod-OverflowPolicy2-e68ee111"}, {"actions": {"iam:CreatePolicy": "allowed"}, "calls": ["AWS::IAM::ManagedPolicy create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:iam::111122223333:policy/coderhelm-prod-OverflowPolicy2-e68ee111"}, {"actions": {"iam:CreatePolicyVersion": "allowed", "iam:DeletePolicy": "allowed", "iam:DeletePolicyVersion": "allowed", "iam:GetPolicy": "allowed", "iam:GetPolicyVersion": "allowed", "iam:ListEntitiesForPolicy": "allowed", "iam:ListPolicyVersions": "allowed"}, "calls": ["AWS::IAM::ManagedPolicy delete", "AWS::IAM::ManagedPolicy read", "AWS::IAM::ManagedPolicy update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:iam::111122223333:policy/coderhelm-prod-OverflowPolicy2-e68ee111"}, + {"actions": {"iam:TagPolicy": "allowed"}, "calls": ["AWS::IAM::ManagedPolicy create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:ResourceTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:iam::111122223333:policy/coderhelm-prod-WorkerOwnAccountRead-e10f242c"}, + {"actions": {"iam:CreatePolicy": "allowed"}, "calls": ["AWS::IAM::ManagedPolicy create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:iam::111122223333:policy/coderhelm-prod-WorkerOwnAccountRead-e10f242c"}, + {"actions": {"iam:CreatePolicyVersion": "allowed", "iam:DeletePolicy": "allowed", "iam:DeletePolicyVersion": "allowed", "iam:GetPolicy": "allowed", "iam:GetPolicyVersion": "allowed", "iam:ListEntitiesForPolicy": "allowed", "iam:ListPolicyVersions": "allowed"}, "calls": ["AWS::IAM::ManagedPolicy delete", "AWS::IAM::ManagedPolicy read", "AWS::IAM::ManagedPolicy update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:iam::111122223333:policy/coderhelm-prod-WorkerOwnAccountRead-e10f242c"}, {"actions": {"iam:TagPolicy": "explicitDeny"}, "calls": ["AWS::IAM::ManagedPolicy create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:ResourceTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:iam::111122223333:policy/coderhelm-prod-boundary-stack"}, {"actions": {"iam:CreatePolicy": "explicitDeny"}, "calls": ["AWS::IAM::ManagedPolicy create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:iam::111122223333:policy/coderhelm-prod-boundary-stack"}, {"actions": {"iam:CreatePolicyVersion": "explicitDeny", "iam:DeletePolicy": "explicitDeny", "iam:DeletePolicyVersion": "explicitDeny", "iam:GetPolicy": "allowed", "iam:GetPolicyVersion": "allowed", "iam:ListEntitiesForPolicy": "allowed", "iam:ListPolicyVersions": "allowed"}, "calls": ["AWS::IAM::ManagedPolicy delete", "AWS::IAM::ManagedPolicy read", "AWS::IAM::ManagedPolicy update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:iam::111122223333:policy/coderhelm-prod-boundary-stack"}, @@ -1335,8 +1349,8 @@ {"actions": {"logs:PutDataProtectionPolicy": "allowed", "logs:PutRetentionPolicy": "allowed"}, "calls": ["AWS::Logs::LogGroup create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack"}, "resource": "arn:aws:logs:us-east-1:111122223333:log-group:/aws/lambda/coderhelm-prod-streaming"}, {"actions": {"logs:TagLogGroup": "allowed", "logs:TagResource": "allowed"}, "calls": ["AWS::Logs::LogGroup create", "AWS::Logs::LogGroup tag", "AWS::Logs::LogGroup update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:ResourceTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:logs:us-east-1:111122223333:log-group:/aws/lambda/coderhelm-prod-stuck-run-cleanup"}, {"actions": {"logs:CreateLogGroup": "allowed"}, "calls": ["AWS::Logs::LogGroup create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:logs:us-east-1:111122223333:log-group:/aws/lambda/coderhelm-prod-stuck-run-cleanup"}, - {"actions": {"logs:AssociateKmsKey": "allowed", "logs:DeleteDataProtectionPolicy": "allowed", "logs:DeleteLogGroup": "allowed", "logs:DeleteRetentionPolicy": "allowed", "logs:DisassociateKmsKey": "allowed", "logs:GetDataProtectionPolicy": "allowed", "logs:ListTagsForResource": "allowed", "logs:PutDataProtectionPolicy": "allowed", "logs:PutLogGroupDeletionProtection": "allowed", "logs:PutRetentionPolicy": "allowed", "logs:UntagResource": "allowed"}, "calls": ["AWS::Logs::LogGroup create", "AWS::Logs::LogGroup delete", "AWS::Logs::LogGroup read", "AWS::Logs::LogGroup tag", "AWS::Logs::LogGroup update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:logs:us-east-1:111122223333:log-group:/aws/lambda/coderhelm-prod-stuck-run-cleanup"}, - {"actions": {"logs:PutDataProtectionPolicy": "allowed", "logs:PutRetentionPolicy": "allowed"}, "calls": ["AWS::Logs::LogGroup create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack"}, "resource": "arn:aws:logs:us-east-1:111122223333:log-group:/aws/lambda/coderhelm-prod-stuck-run-cleanup"}, + {"actions": {"logs:AssociateKmsKey": "allowed", "logs:DeleteDataProtectionPolicy": "allowed", "logs:DeleteLogGroup": "allowed", "logs:DeleteMetricFilter": "allowed", "logs:DeleteRetentionPolicy": "allowed", "logs:DescribeMetricFilters": "allowed", "logs:DisassociateKmsKey": "allowed", "logs:GetDataProtectionPolicy": "allowed", "logs:ListTagsForResource": "allowed", "logs:PutDataProtectionPolicy": "allowed", "logs:PutLogGroupDeletionProtection": "allowed", "logs:PutMetricFilter": "allowed", "logs:PutRetentionPolicy": "allowed", "logs:UntagResource": "allowed"}, "calls": ["AWS::Logs::LogGroup create", "AWS::Logs::LogGroup delete", "AWS::Logs::LogGroup read", "AWS::Logs::LogGroup tag", "AWS::Logs::LogGroup update", "AWS::Logs::MetricFilter create", "AWS::Logs::MetricFilter delete", "AWS::Logs::MetricFilter read", "AWS::Logs::MetricFilter update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:logs:us-east-1:111122223333:log-group:/aws/lambda/coderhelm-prod-stuck-run-cleanup"}, + {"actions": {"logs:PutDataProtectionPolicy": "allowed", "logs:PutMetricFilter": "allowed", "logs:PutRetentionPolicy": "allowed"}, "calls": ["AWS::Logs::LogGroup create", "AWS::Logs::MetricFilter create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack"}, "resource": "arn:aws:logs:us-east-1:111122223333:log-group:/aws/lambda/coderhelm-prod-stuck-run-cleanup"}, {"actions": {"logs:TagLogGroup": "allowed", "logs:TagResource": "allowed"}, "calls": ["AWS::Logs::LogGroup create", "AWS::Logs::LogGroup tag", "AWS::Logs::LogGroup update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:ResourceTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:logs:us-east-1:111122223333:log-group:/aws/lambda/coderhelm-prod-updater"}, {"actions": {"logs:CreateLogGroup": "allowed"}, "calls": ["AWS::Logs::LogGroup create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:logs:us-east-1:111122223333:log-group:/aws/lambda/coderhelm-prod-updater"}, {"actions": {"logs:AssociateKmsKey": "allowed", "logs:DeleteDataProtectionPolicy": "allowed", "logs:DeleteLogGroup": "allowed", "logs:DeleteRetentionPolicy": "allowed", "logs:DisassociateKmsKey": "allowed", "logs:GetDataProtectionPolicy": "allowed", "logs:ListTagsForResource": "allowed", "logs:PutDataProtectionPolicy": "allowed", "logs:PutLogGroupDeletionProtection": "allowed", "logs:PutRetentionPolicy": "allowed", "logs:UntagResource": "allowed"}, "calls": ["AWS::Logs::LogGroup create", "AWS::Logs::LogGroup delete", "AWS::Logs::LogGroup read", "AWS::Logs::LogGroup tag", "AWS::Logs::LogGroup update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:logs:us-east-1:111122223333:log-group:/aws/lambda/coderhelm-prod-updater"}, @@ -1359,14 +1373,14 @@ {"actions": {"s3:CreateBucket": "allowed", "s3:PutBucketTagging": "allowed"}, "calls": ["AWS::S3::Bucket create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:RequestTag/coderhelm:install": "coderhelm-prod", "aws:TagKeys": ["coderhelm:install"]}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333"}, {"actions": {"s3:BypassGovernanceRetention": "allowed", "s3:CreateBucketMetadataTableConfiguration": "allowed", "s3:DeleteBucket": "allowed", "s3:DeleteBucketAnalyticsConfiguration": "allowed", "s3:DeleteBucketCors": "allowed", "s3:DeleteBucketEncryption": "allowed", "s3:DeleteBucketLifecycle": "allowed", "s3:DeleteBucketMetadataTableConfiguration": "allowed", "s3:DeleteBucketMetricsConfiguration": "allowed", "s3:DeleteBucketPolicy": "allowed", "s3:DeleteBucketReplication": "allowed", "s3:DeleteBucketTagging": "allowed", "s3:DeleteBucketWebsite": "allowed", "s3:DeleteObject": "allowed", "s3:DeleteObjectVersion": "allowed", "s3:GetAccelerateConfiguration": "allowed", "s3:GetAnalyticsConfiguration": "allowed", "s3:GetBucketAbac": "allowed", "s3:GetBucketAcl": "allowed", "s3:GetBucketCORS": "allowed", "s3:GetBucketDefaultStorageClass": "allowed", "s3:GetBucketLogging": "allowed", "s3:GetBucketMetadataTableConfiguration": "allowed", "s3:GetBucketNotification": "allowed", "s3:GetBucketObjectLockConfiguration": "allowed", "s3:GetBucketOwnershipControls": "allowed", "s3:GetBucketPolicy": "allowed", "s3:GetBucketPublicAccessBlock": "allowed", "s3:GetBucketTagging": "allowed", "s3:GetBucketVersioning": "allowed", "s3:GetBucketWebsite": "allowed", "s3:GetEncryptionConfiguration": "allowed", "s3:GetIntelligentTieringConfiguration": "allowed", "s3:GetInventoryConfiguration": "allowed", "s3:GetLifecycleConfiguration": "allowed", "s3:GetMetricsConfiguration": "allowed", "s3:GetReplicationConfiguration": "allowed", "s3:ListBucket": "allowed", "s3:ListTagsForResource": "allowed", "s3:PutAccelerateConfiguration": "allowed", "s3:PutAnalyticsConfiguration": "allowed", "s3:PutBucketAbac": "allowed", "s3:PutBucketAcl": "allowed", "s3:PutBucketCORS": "allowed", "s3:PutBucketDefaultStorageClass": "allowed", "s3:PutBucketLogging": "allowed", "s3:PutBucketNotification": "allowed", "s3:PutBucketObjectLockConfiguration": "allowed", "s3:PutBucketOwnershipControls": "allowed", "s3:PutBucketPolicy": "allowed", "s3:PutBucketPublicAccessBlock": "allowed", "s3:PutBucketReplication": "allowed", "s3:PutBucketVersioning": "allowed", "s3:PutBucketWebsite": "allowed", "s3:PutEncryptionConfiguration": "allowed", "s3:PutIntelligentTieringConfiguration": "allowed", "s3:PutInventoryConfiguration": "allowed", "s3:PutLifecycleConfiguration": "allowed", "s3:PutMetricsConfiguration": "allowed", "s3:PutObjectLockConfiguration": "allowed", "s3:PutReplicationConfiguration": "allowed", "s3:UntagResource": "allowed", "s3:UpdateBucketMetadataAnnotationTableConfiguration": "allowed", "s3:UpdateBucketMetadataInventoryTableConfiguration": "allowed", "s3:UpdateBucketMetadataJournalTableConfiguration": "allowed"}, "calls": ["AWS::S3::Bucket create", "AWS::S3::Bucket delete", "AWS::S3::Bucket read", "AWS::S3::Bucket tag", "AWS::S3::Bucket update", "AWS::S3::BucketPolicy create", "AWS::S3::BucketPolicy delete", "AWS::S3::BucketPolicy read", "AWS::S3::BucketPolicy update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333"}, {"actions": {"s3:CreateBucketMetadataTableConfiguration": "allowed", "s3:PutAccelerateConfiguration": "allowed", "s3:PutAnalyticsConfiguration": "allowed", "s3:PutBucketAbac": "allowed", "s3:PutBucketAcl": "allowed", "s3:PutBucketCORS": "allowed", "s3:PutBucketDefaultStorageClass": "allowed", "s3:PutBucketLogging": "allowed", "s3:PutBucketNotification": "allowed", "s3:PutBucketObjectLockConfiguration": "allowed", "s3:PutBucketOwnershipControls": "allowed", "s3:PutBucketPolicy": "allowed", "s3:PutBucketPublicAccessBlock": "allowed", "s3:PutBucketReplication": "allowed", "s3:PutBucketVersioning": "allowed", "s3:PutBucketWebsite": "allowed", "s3:PutEncryptionConfiguration": "allowed", "s3:PutIntelligentTieringConfiguration": "allowed", "s3:PutInventoryConfiguration": "allowed", "s3:PutLifecycleConfiguration": "allowed", "s3:PutMetricsConfiguration": "allowed", "s3:PutObjectAcl": "allowed", "s3:PutObjectLockConfiguration": "allowed", "s3:PutObjectVersionAcl": "allowed", "s3:PutReplicationConfiguration": "allowed"}, "calls": ["AWS::S3::Bucket create", "AWS::S3::BucketPolicy create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack"}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333"}, + {"actions": {"s3:GetObject": "allowed", "s3:GetObjectVersion": "allowed"}, "calls": ["AWS::Lambda::Function create", "AWS::Lambda::Function update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333/assets/11f131d7e6e4bcb0bc0bf25345465d4aed0de4295e3f1d4e4b628dcafc64a464.zip"}, {"actions": {"s3:GetObject": "allowed", "s3:GetObjectVersion": "allowed"}, "calls": ["AWS::Lambda::Function create", "AWS::Lambda::Function update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333/assets/2819175352ad1ce0dae768e83fc328fb70fb5f10b4a8ff0ccbcb791f02b0716d.zip"}, {"actions": {"s3:GetObject": "allowed", "s3:GetObjectVersion": "allowed"}, "calls": ["AWS::Lambda::Function create", "AWS::Lambda::Function update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333/assets/3423a042b818e31c1e34a19d6689ab2e5f9b70fcbe9e71df66f241b20a200bd9.zip"}, - {"actions": {"s3:GetObject": "allowed", "s3:GetObjectVersion": "allowed"}, "calls": ["AWS::Lambda::Function create", "AWS::Lambda::Function update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333/assets/53eada20248e9d1494fc00c7310a9df9f3647025d008c2562adb60bf7ac88f2d.zip"}, + {"actions": {"s3:GetObject": "allowed", "s3:GetObjectVersion": "allowed"}, "calls": ["AWS::Lambda::Function create", "AWS::Lambda::Function update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333/assets/3c7ee2b1963d304a27fa0796383c8924fe298b4dd2c3730fc94af6b62be134b7.zip"}, + {"actions": {"s3:GetObject": "allowed", "s3:GetObjectVersion": "allowed"}, "calls": ["AWS::Lambda::Function create", "AWS::Lambda::Function update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333/assets/4a591e9289d3102697d4a891189fc90352ce38222e0b201ae637147e5fd55142.zip"}, {"actions": {"s3:GetObject": "allowed", "s3:GetObjectVersion": "allowed"}, "calls": ["AWS::Lambda::Function create", "AWS::Lambda::Function update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333/assets/a77bb41544bf739e532a3faedb5ecda0bba5d9e19ab56eaa0fc6ec92f1bf5827.zip"}, {"actions": {"s3:GetObject": "allowed", "s3:GetObjectVersion": "allowed"}, "calls": ["AWS::Lambda::Function create", "AWS::Lambda::Function update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333/assets/ae46d59f832d7b7e8ed231a7a3af7955b7585bf1cef81350968eb356db6a79e0.zip"}, {"actions": {"s3:GetObject": "allowed", "s3:GetObjectVersion": "allowed"}, "calls": ["AWS::Lambda::Function create", "AWS::Lambda::Function update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333/assets/bc4e026165204dddfc22a4d9b0dd1cc9b8f53c37b8575a9c4638b289303f2da4.zip"}, - {"actions": {"s3:GetObject": "allowed", "s3:GetObjectVersion": "allowed"}, "calls": ["AWS::Lambda::Function create", "AWS::Lambda::Function update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333/assets/c6a0d267ee8fc5537ab8911079af833d5135b8ba2dada7bb2046cb9b7cab6902.zip"}, - {"actions": {"s3:GetObject": "allowed", "s3:GetObjectVersion": "allowed"}, "calls": ["AWS::Lambda::Function create", "AWS::Lambda::Function update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333/assets/dfa2ec5066963bca8a1394faef4ceafca564232d628b3cfc0815a5d3d6a9140c.zip"}, {"actions": {"s3:GetObject": "allowed", "s3:GetObjectVersion": "allowed"}, "calls": ["AWS::Lambda::Function create", "AWS::Lambda::Function update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333/assets/e2323f040b88a4c0ffdb662a75b62cad20b096cc1a873043f7b71c3927548590.zip"}, {"actions": {"s3:GetObject": "allowed", "s3:GetObjectVersion": "allowed"}, "calls": ["AWS::Lambda::LayerVersion create"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333/assets/e2659170a0721541efa761a8d5d04d5e36cbbf691c4b15a9053002b7c825055d.zip"}, {"actions": {"s3:GetObject": "allowed", "s3:GetObjectVersion": "allowed"}, "calls": ["AWS::Lambda::Function create", "AWS::Lambda::Function update"], "context": {"aws:PrincipalArn": "arn:aws:iam::111122223333:role/coderhelm-prod-deploy-stack", "aws:ResourceTag/coderhelm:install": "coderhelm-prod"}, "resource": "arn:aws:s3:::coderhelm-prod-release-111122223333/assets/faa95a81ae7d7373f3e1f242268f904eb748d8d0fdd306e8a6fe515a1905a7d6.zip"}, @@ -1582,6 +1596,7 @@ {"action": "application-autoscaling:PutScheduledAction", "calls": ["AWS::DynamoDB::GlobalTable create", "AWS::DynamoDB::GlobalTable delete", "AWS::DynamoDB::GlobalTable update"], "reason": "application-autoscaling"}, {"action": "application-autoscaling:RegisterScalableTarget", "calls": ["AWS::DynamoDB::GlobalTable create", "AWS::DynamoDB::GlobalTable delete", "AWS::DynamoDB::GlobalTable update"], "reason": "application-autoscaling"}, {"action": "cloudfront:UpdateDistribution", "calls": ["AWS::Cognito::UserPoolDomain create", "AWS::Cognito::UserPoolDomain update"], "reason": "prefix domain, no custom domain"}, + {"action": "dynamodb:DescribeBulkOperation", "calls": ["AWS::DynamoDB::GlobalTable create", "AWS::DynamoDB::GlobalTable delete", "AWS::DynamoDB::GlobalTable read", "AWS::DynamoDB::GlobalTable update"], "reason": "no bulk operation"}, {"action": "ec2:DescribeNetworkInterfaces", "calls": ["AWS::Lambda::Function delete"], "reason": "ec2"}, {"action": "ec2:DescribeSecurityGroups", "calls": ["AWS::Lambda::Function create", "AWS::Lambda::Function update"], "reason": "ec2"}, {"action": "ec2:DescribeSubnets", "calls": ["AWS::Lambda::Function create", "AWS::Lambda::Function update"], "reason": "ec2"}, diff --git a/infra/test/synth.test.ts b/infra/test/synth.test.ts index 08e1da1da..3ca8c59fb 100644 --- a/infra/test/synth.test.ts +++ b/infra/test/synth.test.ts @@ -176,6 +176,47 @@ test("fresh self-host config without a domain: nothing hosted-specific, one Clou assert.ok(json(t["coderhelm-prod-email"]).includes("Fn::ImportValue"), "email templates link to the web stack's URL"); }); +test("self-host: the gateway and worker read the install's own account with this release's read-only permissions", () => { + const t = synth(selfHost()); + // Every permission the services check a role against (services/common/src/log_reader.rs ABILITIES). + const rs = fs.readFileSync(path.join(INFRA, "..", "services", "common", "src", "log_reader.rs"), "utf8"); + const abilities = rs.slice(rs.indexOf("pub const ABILITIES"), rs.indexOf("];", rs.indexOf("pub const ABILITIES"))); + const needed = [...new Set([...abilities.matchAll(/"([a-z0-9-]+:[A-Za-z]+)"/g)].map((m) => m[1]))]; + assert.ok(needed.length > 20, `${needed.length} actions`); + for (const [stack, fn] of [ + ["coderhelm-prod-api", "coderhelm-prod-gateway"], + ["coderhelm-prod-worker", "coderhelm-prod-worker"], + ]) { + const policies = Object.values(t[stack].findResources("AWS::IAM::ManagedPolicy")).filter((p: any) => + String(p.Properties.Description ?? "").includes("this install's own AWS account"), + ) as any[]; + assert.equal(policies.length, 1, `${fn}: one read policy`); + const doc = JSON.stringify(policies[0].Properties.PolicyDocument); + for (const a of needed) assert.ok(doc.includes(`"${a}"`), `${fn} lacks ${a}`); + // Only reads: list, describe, get, query, never a write. + const actions: string[] = policies[0].Properties.PolicyDocument.Statement.flatMap((s: any) => ([] as string[]).concat(s.Action)); + for (const a of actions) assert.match(a, /^[a-z0-9-]+:(List|Describe|Get|Filter|Start(Query)?$|Stop(Query)?$|BatchGet|Simulate|InvokeRestApi)/, a); + // It checks its own permissions on its own role only. + const sim = policies[0].Properties.PolicyDocument.Statement.find((s: any) => ([] as string[]).concat(s.Action).includes("iam:SimulatePrincipalPolicy")); + assert.ok(JSON.stringify(sim.Resource).includes("Fn::GetAtt"), "its own role's ARN"); + // The function knows its role, so it reads its own account with it. + const env = envOf(t[stack], fn); + assert.ok(env.INSTALL_OWN_ROLE_ARN, `${fn} names its own role`); + } +}); + +test("hosted: no read policy for an own account and no own role", () => { + const cfg = loadConfigFile(path.join(INFRA, "config", "hosted.prod.json"), { CDK_DEFAULT_ACCOUNT: "654654210434" }); + const t = synth(cfg, zoneContext("654654210434", "us-east-1", "coderhelm.com")); + for (const [stack, fn] of [ + ["coderhelm-prod-api", "coderhelm-prod-gateway"], + ["coderhelm-prod-worker", "coderhelm-prod-worker"], + ]) { + assert.ok(!json(t[stack]).includes("this install's own AWS account"), stack); + assert.equal(envOf(t[stack], fn).INSTALL_OWN_ROLE_ARN, undefined, fn); + } +}); + test("self-host with a domain in another region and Bedrock", () => { const cfg = selfHost({ region: "eu-west-1", diff --git a/services/common/src/live/aws.rs b/services/common/src/live/aws.rs index 62f748edb..66d7b223a 100644 --- a/services/common/src/live/aws.rs +++ b/services/common/src/live/aws.rs @@ -557,14 +557,85 @@ fn session_name(actor: &str) -> String { crate::truncate_str(&name, 64).to_string() } +/// On a self-hosted install, the gateway's and worker's own role +/// (infra/lib/own-account-read.ts): its stack gives it this release's +/// read-only permissions in the install's own account. +pub const OWN_ROLE_ENV: &str = "INSTALL_OWN_ROLE_ARN"; + +/// The function's own role, when its stack gave it the read-only +/// permissions for the install's own account. +pub fn install_read_role() -> Option { + std::env::var(OWN_ROLE_ENV) + .ok() + .map(|s| s.trim().to_string()) + .filter(|s| !s.is_empty()) +} + +fn account_of(role_arn: &str) -> &str { + role_arn.split(':').nth(4).unwrap_or("") +} + +/// `role_arn` is in the same account as the install's own role `own`. +pub fn in_install_account(role_arn: &str, own: Option<&str>) -> bool { + own.is_some_and(|o| { + let a = account_of(o); + a.len() == 12 && a == account_of(role_arn) + }) +} + +/// What to read through instead of `target`, when `target` is the log +/// reader a person created in the install's own account: the install's own +/// role, whose permissions arrive with each version update. `None` for any +/// other role or account (the data-source role, another account, the +/// hosted deployment). Connecting still proves the person's role with the +/// team's private ID; this only changes how a connected account is read. +pub fn install_target(target: &AwsTarget, own: Option<&str>) -> Option { + let own = own?; + let name = target.role_arn.rsplit('/').next().unwrap_or(""); + (name == LOG_READER_ROLE && in_install_account(&target.role_arn, Some(own))).then(|| { + AwsTarget { + role_arn: own.to_string(), + ..target.clone() + } + }) +} + +/// A session on the function's own role (its environment's credentials), +/// in `region`. `None` outside Lambda. +pub fn own_session(region: &str) -> Option { + let get = |k: &str| std::env::var(k).ok().filter(|v| !v.is_empty()); + Some(Session { + access_key_id: get("AWS_ACCESS_KEY_ID")?, + secret_access_key: get("AWS_SECRET_ACCESS_KEY")?, + session_token: get("AWS_SESSION_TOKEN").unwrap_or_default(), + region: region.to_string(), + }) +} + /// Takes on a team's role. `actor` names the session in the team's AWS -/// records (`reviewer`, `planner`, a person's email). +/// records (`reviewer`, `planner`, a person's email). In a self-hosted +/// install's own account the log reader is read with the install's own role +/// ([`install_target`]). pub async fn assume( sts: &aws_sdk_sts::Client, target: &AwsTarget, actor: &str, ) -> Result { check_target(target)?; + if install_target(target, install_read_role().as_deref()).is_some() { + if let Some(s) = own_session(&target.region) { + return Ok(s); + } + } + assume_exact(sts, target, actor).await +} + +/// Takes on exactly `target`'s role (already checked by the caller). +pub async fn assume_exact( + sts: &aws_sdk_sts::Client, + target: &AwsTarget, + actor: &str, +) -> Result { let external_id = target.external_id.as_str(); if external_id.is_empty() { return Err(StepError::new( @@ -681,6 +752,48 @@ mod tests { const ROLE: &str = "arn:aws:iam::123456789012:role/CoderhelmReadOnly"; + const OWN: &str = "arn:aws:iam::111122223333:role/coderhelm-prod-gateway-1a2b3c4d"; + + fn reader(account: &str) -> AwsTarget { + AwsTarget { + role_arn: format!("arn:aws:iam::{account}:role/{LOG_READER_ROLE}"), + external_id: "team-id".into(), + region: "us-east-1".into(), + ..Default::default() + } + } + + #[test] + fn the_install_account_reads_with_the_install_role() { + let t = install_target(&reader("111122223333"), Some(OWN)).expect("swapped"); + assert_eq!(t.role_arn, OWN); + // The team's private ID and region carry over. + assert_eq!(t.external_id, "team-id"); + assert_eq!(t.region, "us-east-1"); + } + + #[test] + fn other_accounts_roles_and_installs_keep_their_role() { + // Another account keeps the person's log reader and its update flow. + assert!(install_target(&reader("444455556666"), Some(OWN)).is_none()); + // The data-source role is never swapped. + let data = AwsTarget { + role_arn: "arn:aws:iam::111122223333:role/CoderhelmReadOnly".into(), + ..reader("111122223333") + }; + assert!(install_target(&data, Some(OWN)).is_none()); + // No install role (the hosted deployment, or an install not updated yet). + assert!(install_target(&reader("111122223333"), None).is_none()); + assert!(!in_install_account( + "arn:aws:iam::111122223333:role/x", + None + )); + assert!(!in_install_account( + "arn:aws:iam::111122223333:role/x", + Some("not-an-arn") + )); + } + #[test] fn log_groups_must_be_names_or_real_prefixes() { let v = diff --git a/services/common/src/live/permissions.rs b/services/common/src/live/permissions.rs index 91f9067a0..caea40a4b 100644 --- a/services/common/src/live/permissions.rs +++ b/services/common/src/live/permissions.rs @@ -17,7 +17,9 @@ use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; -use super::aws::{assume, AwsTarget, Session}; +use super::aws::{ + assume_exact, install_read_role, install_target, own_session, AwsTarget, Session, +}; use crate::log_reader::{self, ABILITIES}; /// What the simulator said about one action. @@ -62,6 +64,14 @@ pub struct PermissionCheck { pub scp_blocks: Vec, pub update_stack: UpdateStack, pub error: String, + /// The account is the self-hosted install's own: its read-only + /// permissions arrive with the install's version updates, never from a + /// stack a person launches. + #[serde(default)] + pub install_account: bool, + /// Checked on the install's own read role (its stack keeps it current). + #[serde(default)] + pub install_role: bool, } /// What the page shows for one account. @@ -86,6 +96,8 @@ impl PermissionCheck { scp_blocks: Vec::new(), update_stack: UpdateStack::Unknown, error: String::new(), + install_account: false, + install_role: false, } } @@ -132,6 +144,20 @@ impl PermissionCheck { if self.missing.is_empty() { return None; } + if self.install_account && self.scp_blocks.is_empty() { + // Nothing for a person to launch in AWS: the install's own stack + // grants these with its next version update. + return Some(Problem { + code: "install_update", + message: format!( + "{} read-only permission{} of this release {} not on this install's read role yet.", + self.missing.len(), + if self.missing.len() == 1 { "" } else { "s" }, + if self.missing.len() == 1 { "is" } else { "are" }, + ), + fix: "They arrive with this install's next version update (Settings, Version and updates). Nothing is needed in AWS.".into(), + }); + } if !self.scp_blocks.is_empty() { return Some(Problem { code: "scp", @@ -225,7 +251,7 @@ impl PermissionCheck { }) }) .collect(); - let update = (self.status() == "update_needed") + let update = (self.status() == "update_needed" && !self.install_account) .then(|| log_reader::update_template_url(template_url)) .flatten() .map(|t| { @@ -250,6 +276,7 @@ impl PermissionCheck { "missing_abilities": self.missing_abilities(), "abilities": abilities, "update": update, + "install_account": self.install_account, "problem": self.problem(pressed), }) } @@ -484,14 +511,34 @@ pub async fn check( actor: &str, now: &str, ) -> PermissionCheck { + let own = install_read_role(); + let install_account = super::aws::in_install_account(&target.role_arn, own.as_deref()); + if let Some(t) = install_target(target, own.as_deref()) { + if let Some(session) = own_session(&t.region) { + // The install's own role, checked as the role it is. + let mut c = check_with(session, &t, now).await; + c.install_account = true; + c.install_role = true; + return c; + } + } let mut c = PermissionCheck::new(target, now); - let session = match assume(sts, target, actor).await { + let session = match assume_exact(sts, target, actor).await { Ok(s) => s, Err(e) => { c.error = e.message; + c.install_account = install_account; return c; } }; + let mut c = check_with(session, target, now).await; + c.install_account = install_account; + c +} + +/// [`check`] with a session on `target`'s role. +async fn check_with(session: Session, target: &AwsTarget, now: &str) -> PermissionCheck { + let mut c = PermissionCheck::new(target, now); c.works = true; match simulate(&session, target).await { Ok(results) => apply_simulation(&mut c, &results), @@ -547,6 +594,46 @@ mod tests { assert_eq!(c.method, "simulate"); } + #[test] + fn the_install_account_is_never_offered_an_update_stack() { + let mut c = checked(); + c.install_account = true; + apply_simulation(&mut c, &[sim("ecs:DescribeTasks", false)]); + assert_eq!(c.status(), "update_needed"); + let v = c.view( + true, + "https://example.com/launch/v1.2.3/coderhelm-log-reader.yaml", + ); + assert!(v["update"].is_null(), "no stack to launch: {v}"); + assert_eq!(v["install_account"], true); + let p = c.problem(true).expect("says what happens"); + assert_eq!(p.code, "install_update"); + assert!(p.fix.contains("next version update")); + assert!(!p.fix.contains("Update in AWS")); + } + + #[test] + fn another_account_still_gets_the_update_stack() { + let mut c = checked(); + apply_simulation(&mut c, &[sim("ecs:DescribeTasks", false)]); + let v = c.view( + false, + "https://example.com/launch/v1.2.3/coderhelm-log-reader.yaml", + ); + assert_eq!(v["install_account"], false); + assert_eq!(v["status"], "update_needed"); + } + + #[test] + fn a_check_saved_before_the_install_fields_still_reads() { + let mut v = serde_json::to_value(checked()).unwrap(); + let o = v.as_object_mut().unwrap(); + o.remove("install_account"); + o.remove("install_role"); + let c: PermissionCheck = serde_json::from_value(v).unwrap(); + assert!(!c.install_account && !c.install_role); + } + #[test] fn missing_actions_are_listed_in_template_order() { let mut c = checked(); diff --git a/services/gateway/src/routes/connectors.rs b/services/gateway/src/routes/connectors.rs index 1eeef9819..d2225f1f2 100644 --- a/services/gateway/src/routes/connectors.rs +++ b/services/gateway/src/routes/connectors.rs @@ -849,7 +849,17 @@ pub async fn aws_check( Ok(Json(json!({ "check": check, "missing": missing, - "update_url": if missing.is_empty() { None } else { update_stack_url(&t.region) }, + // The install's own account gets these with its version updates. + "update_url": if missing.is_empty() + || common::live::aws::in_install_account( + &t.role_arn, + common::live::aws::install_read_role().as_deref(), + ) + { + None + } else { + update_stack_url(&t.region) + }, "stack_name": common::log_reader::update_stack_name(), "template_url": common::log_reader::update_template_url(&template), }))) diff --git a/services/gateway/src/routes/integrations.rs b/services/gateway/src/routes/integrations.rs index 4a7ae8034..6474038b4 100644 --- a/services/gateway/src/routes/integrations.rs +++ b/services/gateway/src/routes/integrations.rs @@ -249,6 +249,24 @@ pub fn aws_missing(a: &AwsAccount) -> Vec<&'static str> { out } +/// The account is the self-hosted install's own. Its read-only permissions +/// arrive with the install's version updates, so no update stack is offered. +pub fn install_account(a: &AwsAccount) -> bool { + a.permissions.as_ref().is_some_and(|p| p.install_account) + || common::live::aws::in_install_account( + &a.role_arn, + common::live::aws::install_read_role().as_deref(), + ) +} + +/// The one-click update stack's link, when the role lacks something and a +/// person can add it (never in the install's own account). +fn update_stack_link(a: &AwsAccount) -> Option { + (!install_account(a) && (!aws_missing(a).is_empty() || needs_update(a))) + .then(|| super::connectors::update_stack_url(&a.region)) + .flatten() +} + /// The last live check found permissions of this release missing. pub fn needs_update(a: &AwsAccount) -> bool { a.permissions @@ -511,11 +529,6 @@ pub async fn list( )); // AWS accounts: one card each (or one to connect the first). - let stack_url = |a: &AwsAccount| { - (!aws_missing(a).is_empty() || needs_update(a)) - .then(|| super::connectors::update_stack_url(&a.region)) - .flatten() - }; if accounts.is_empty() { items.push(card( "aws", @@ -530,7 +543,8 @@ pub async fn list( for a in &accounts { let mut detail = a.public_json(); detail["missing"] = json!(aws_missing(a)); - detail["update_url"] = json!(stack_url(a)); + detail["update_url"] = json!(update_stack_link(a)); + detail["install_account"] = json!(install_account(a)); detail["stack_name"] = json!(common::log_reader::update_stack_name()); items.push(card( &format!("aws-{}", a.account), @@ -731,9 +745,8 @@ async fn load_account( fn account_reply(a: &AwsAccount) -> Value { let mut detail = a.public_json(); detail["missing"] = json!(aws_missing(a)); - detail["update_url"] = json!((!aws_missing(a).is_empty() || needs_update(a)) - .then(|| super::connectors::update_stack_url(&a.region)) - .flatten()); + detail["update_url"] = json!(update_stack_link(a)); + detail["install_account"] = json!(install_account(a)); detail["stack_name"] = json!(common::log_reader::update_stack_name()); let st = aws_state(a); json!({ "account": detail, "status": st.status, "reason": st.reason, "last_check": a.abilities.checked_at })