Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions docs/self-host/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ The helper's role carries the boundary and can only do this (`helperPolicy()` in
- list and delete objects in buckets named `coderhelm-<name>-*` (to empty the data buckets on delete);
- delete an older release's progress bucket, `coderhelm-setup-<progress id>`: its policy, its files and the bucket (never write to it or make anything public);
- read and write the install's secret, `coderhelm/<name>/secrets`, and delete it (only on a stack delete with **KeepDataOnDelete** `false`);
- write items to, describe, update and delete the tables named `coderhelm-<name>` and `coderhelm-<name>-*` (the allowlist at launch; the tables on delete), and use the KMS keys tagged `coderhelm:install = coderhelm-<name>` to encrypt and decrypt for them;
- write items to, describe, update and delete the tables named `coderhelm-<name>` and `coderhelm-<name>-*` (the allowlist at launch; the tables on delete), and use the install's table key, named by its ARN, to encrypt and decrypt for them (a policy of its own, `table-key`, made once the Database part is: the helper is made before the key);
- invoke `coderhelm-<name>-updater` (the domain);
- describe the root stack and read its events;
- list log groups, and read the tags of and delete those named `/aws/lambda/coderhelm-<name>-*` or `/aws/codebuild/coderhelm-<name>-*`. The code deletes the exact names the parts declare, and otherwise only those tagged `coderhelm:install = coderhelm-<name>`;
Expand Down Expand Up @@ -314,7 +314,7 @@ Mark these as accepted in Security Hub (workflow status **Suppressed**, with the
| S3.9 | The release bucket and the log bucket | The release bucket is made before every other part (it holds their templates), so before the log bucket exists. Only the install helper may write to it (its bucket policy), and CloudTrail records each write. A log bucket that logged to itself would log forever. |
| Cognito.1, Cognito.4 | The user pool | Threat protection needs Cognito's Plus tier, billed for every monthly active user. The gateway rate-limits sign-in attempts itself. Turn it on in the console if your account requires it. |
| Cognito.5 | The user pool | Two-factor is optional, with an authenticator app. An admin can require it for everyone (the **RequireTwoFactor** launch parameter, or **Settings, Sign-in**), and CoderHelm enforces that at sign-in. Requiring it in Cognito would force it on every install, including those that chose not to. |
| KMS.2 | The roles `coderhelm-<name>-deploy-stack` and `coderhelm-<name>-install-helper` | Both allow `kms:Decrypt` only on keys tagged `coderhelm:install = coderhelm-<name>` (the install's own keys), but Security Hub reads only the resource, not the condition. The deploy role creates those keys, so their ids can't be known when its policy is written, and no update can change that role (see [Updates and the deploy role](#updates-and-the-deploy-role)). The helper is made before the part that makes the keys, for the same reason. |
| KMS.2 | The role `coderhelm-<name>-deploy-stack` | It allows `kms:Decrypt` only on keys tagged `coderhelm:install = coderhelm-<name>` (the install's own keys), but Security Hub reads only the resource, not the condition. The deploy role creates those keys, so their ids can't be known when its policy is written, and no update can change that role (see [Updates and the deploy role](#updates-and-the-deploy-role)). The install helper names its one key by ARN. |
| SecretsManager.1 | `coderhelm/<name>/secrets` | It holds the GitHub App's keys, which only GitHub can issue, and the session signing key: rotating that key signs everyone out. |
| SecretsManager.1 | `coderhelm-readonly-*` | You create these for a data source: a read-only database user of yours. Rotate them with your database's own rotation. |
| CloudFormation.3 | `coderhelm-<name>`, `coderhelm-<name>-access`, `CoderHelmLogReader*` | Uninstalling is deleting the stack. To protect it, turn termination protection on: `aws cloudformation update-termination-protection --enable-termination-protection --stack-name coderhelm-<name>`. Updates still apply. Turn it off with `--no-enable-termination-protection` before you uninstall. |
Expand Down
2 changes: 2 additions & 0 deletions infra/lib/database-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ export class DatabaseStack extends cdk.Stack {
// Outputs
new cdk.CfnOutput(this, "TableName", { value: this.table.tableName });
new cdk.CfnOutput(this, "TableArn", { value: this.table.tableArn });
// The table key, by ARN: a native install's helper may use only this key (native/parent.ts).
new cdk.CfnOutput(this, "TableKeyArn", { value: this.encryptionKey.keyArn });
new cdk.CfnOutput(this, "TeamsTableName", {
value: this.teamsTable.tableName,
});
Expand Down
21 changes: 20 additions & 1 deletion infra/lib/native/parent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -229,7 +229,6 @@ export function helperPolicy(): PolicyDocument {
// DeleteSecret: only on a stack delete with KeepDataOnDelete=false (Final).
{ Sid: "Secret", Effect: "Allow", Action: ["secretsmanager:GetSecretValue", "secretsmanager:PutSecretValue", "secretsmanager:DeleteSecret"], Resource: `${at("secretsmanager")}:secret:coderhelm/\${Stage}/secrets-??????` },
{ Sid: "AllowlistAndTablesOnDelete", Effect: "Allow", Action: ["dynamodb:BatchWriteItem", "dynamodb:DescribeTable", "dynamodb:DeleteTable", "dynamodb:UpdateTable"], Resource: [`${at("dynamodb")}:table/${p}`, `${at("dynamodb")}:table/${p}-*`] },
{ Sid: "TableKey", Effect: "Allow", Action: ["kms:Encrypt", "kms:Decrypt", "kms:GenerateDataKey*", "kms:DescribeKey"], Resource: "*", Condition: { StringEquals: { [`aws:ResourceTag/${INSTALL_TAG}`]: p } } },
{ Sid: "Domain", Effect: "Allow", Action: "lambda:InvokeFunction", Resource: `${at("lambda")}:function:${p}-updater` },
{ Sid: "RootStack", Effect: "Allow", Action: ["cloudformation:DescribeStacks", "cloudformation:DescribeStackEvents"], Resource: "arn:${AWS::Partition}:cloudformation:${AWS::Region}:${AWS::AccountId}:stack/${AWS::StackName}/*" },
// stage_held: the root stack's own deploy role and boundaries, read from its current template (read-only, that stack only).
Expand All @@ -254,6 +253,10 @@ export function helperPolicy(): PolicyDocument {
};
}

/** The helper's own policy on the install's table key, by its ARN (the Database part's output). */
export const HELPER_TABLE_KEY_POLICY = "table-key";
export const HELPER_TABLE_KEY_ACTIONS = ["kms:Encrypt", "kms:Decrypt", "kms:GenerateDataKey*", "kms:DescribeKey"];

/** The auto-update role's policy: the deploy policy, the parent stack, the release files. */
export function deployRolePolicy(n: AccessNames): PolicyDocument {
const base = deployPolicy(n);
Expand Down Expand Up @@ -487,8 +490,24 @@ export function buildParent(input: ParentInput): Json {
},
};
if (names.has("Database")) {
// The allowlist goes into a table encrypted with the install's table key.
// The helper is made before the parts, so it can't name the key in its
// own policy: this one, made once the Database part is, names that one
// key (never every key: Security Hub KMS.2).
R.HelperTableKey = {
Type: "AWS::IAM::RolePolicy",
Properties: {
RoleName: { Ref: "HelperRole" },
PolicyName: HELPER_TABLE_KEY_POLICY,
PolicyDocument: {
Version: "2012-10-17",
Statement: [{ Sid: "TableKey", Effect: "Allow", Action: HELPER_TABLE_KEY_ACTIONS, Resource: { "Fn::GetAtt": ["Database", "Outputs.TableKeyArn"] } }],
},
},
};
R.Allowlist = {
Type: "Custom::Allowlist",
DependsOn: ["HelperTableKey"],
Properties: { ...helper, Table: { "Fn::GetAtt": ["Database", "Outputs.SettingsTableName"] }, Admin: { Ref: "AdminEmail" }, Domain: { Ref: "SignupDomain" }, TwoFactor: { Ref: "RequireTwoFactor" } },
};
}
Expand Down
7 changes: 7 additions & 0 deletions infra/scripts/deploy-role-sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,8 @@ def resolve(self, v):
if attr == "ApiId": return self.ident(lid)[0]
if attr == "UserPoolId": return self.ident(lid)[0]
if attr == "Id" and ty == "AWS::CloudFront::Distribution": return self.ident(lid)[0]
# A function URL's function (the web part's OAC permissions name the streaming function).
if attr == "FunctionArn" and ty == "AWS::Lambda::Url": return self.resolve(self.res[lid]["Properties"]["TargetFunctionArn"])
return f"<{lid}.{attr}>"
if "Fn::Join" in v:
sep, parts = v["Fn::Join"]
Expand Down Expand Up @@ -310,6 +312,9 @@ def targets(st, lid, r, action):
"AWS::Cognito::UserPool": "email.cognito-idp.amazonaws.com/AWSServiceRoleForAmazonCognitoIdpEmailService",
"AWS::Cognito::UserPoolClient": "email.cognito-idp.amazonaws.com/AWSServiceRoleForAmazonCognitoIdpEmailService"}[ty]
return [(f"arn:aws:iam::{ACCT}:role/aws-service-role/{slr}", {"iam:AWSServiceName": slr.split("/")[0]})]
# One inline policy on one role (the native helper's table-key policy).
if svc == "iam" and ty == "AWS::IAM::RolePolicy":
return [(f"arn:aws:iam::{ACCT}:role/{st.resolve(p['RoleName'])}", {})]
if svc == "iam" and ty in ("AWS::IAM::Policy",):
roles = [st.resolve(x) for x in p.get("Roles", [])]
if action.startswith("iam:") and ("User" in action or "Group" in action):
Expand Down Expand Up @@ -738,6 +743,8 @@ def helper_rows():
("ssm:PutParameter", f"{at('ssm')}:parameter/{P}/uninstall/delete-data"), ("ssm:DeleteParameter", f"{at('ssm')}:parameter/{P}/public-url"),
("s3:DeleteBucket", f"{s3}someone-else"), ("s3:DeleteBucket", f"{s3}{P}-dashboard-{ACCT}"), ("kms:DeleteAlias", f"{at('kms')}:alias/my-app"),
("kms:ScheduleKeyDeletion", f"{at('kms')}:key/0f0f0f0f-1111-2222-3333-444455556666"),
# No key use in its own policy: the table key, by ARN, is its table-key policy (Security Hub KMS.2).
("kms:Decrypt", f"{at('kms')}:key/0f0f0f0f-1111-2222-3333-444455556666"), ("kms:Decrypt", "*"),
("cognito-idp:DeleteUserPool", f"{at('cognito-idp')}:userpool/us-east-1_someones"),
# Nothing public: progress goes to CoderHelm with the guide's key.
("s3:PutObject", f"{s3}coderhelm-setup-0123456789abcdef/status.json"), ("s3:PutBucketPolicy", f"{s3}coderhelm-setup-0123456789abcdef"),
Expand Down
Loading
Loading