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
49 changes: 47 additions & 2 deletions docs/self-host/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ order: 11

| From | To | How |
|---|---|---|
| People | CloudFront (your hostname) | HTTPS only, TLS 1.2+, HSTS |
| CloudFront | HTTP API, streaming function URL, dashboard bucket | HTTPS; the bucket is private and only CloudFront can read it |
| People | CloudFront (your hostname) | HTTPS only, TLS 1.2+ (CloudFront's `TLSv1.2_2025` policy on your own domain), HSTS |
| CloudFront | HTTP API, streaming function URL, dashboard bucket | HTTPS; the bucket is private and only CloudFront can read it; the streaming function URL takes only calls CloudFront signs (origin access control) |
| GitHub, Jira | `/webhooks/*` | Signed payloads, checked before use |
| Functions | GitHub, Anthropic, Bedrock, the services teams connect | HTTPS from Lambda (no VPC) |

Expand Down Expand Up @@ -276,6 +276,51 @@ CoderHelm **cannot** see: your code at rest, your runs, plans, reviews, memory,
- Messages from CoderHelm carry CoderHelm's own signature (Ed25519, key in AWS KMS), checked with public keys pinned in your signed release once a release pins them: a leaked relay key alone can't make an install accept a message. See hybrid.md, "How an install knows a message is from CoderHelm". The answers of the OAuth sign-in broker (Notion and the other OAuth integrations) are not signed yet; HTTPS and the install's client secret protect them.
- Install requests carry no one-time number, so someone who could break HTTPS could repeat one within its 5 minutes. They would already see the same traffic, tokens included.

## Security Hub

AWS Security Hub checks an install against AWS's best practices. This is what each check finds on an install, and why.

### What an install sets

| Control | What the stacks set |
|---|---|
| Lambda.1, CloudFront.16 | The chat stream's function URL takes only calls signed with AWS credentials (`AWS_IAM`), and only the install's CloudFront may call it: origin access control signs every request, and the function's policy allows `cloudfront.amazonaws.com` for that one distribution. The function still checks the person's short-lived stream token on every request. Because CloudFront's signature is the `Authorization` header, the dashboard sends the token in `x-coderhelm-stream-token`, and sends the body's SHA-256 in `x-amz-content-sha256`, which Lambda requires of a signed POST. Responses still stream. |
| S3.5 | Every bucket refuses requests without TLS, the release bucket included. |
| S3.9 | The data, dashboard and sandbox buckets write server access logs to the install's log bucket, `coderhelm-<name>-logs-<account>`, under `s3/<bucket>/`. |
| S3.13 | Every bucket has a lifecycle: access logs expire after 90 days, sandbox tarballs after a day, old versions of data after 30 days, and unfinished uploads after a day. |
| CloudFront.5 | The distribution writes standard logs to the log bucket, under `cloudfront/`, in every region AWS enables by default. CloudFront delivers no standard logs to a bucket in an opt-in region (Cape Town, Hong Kong, Milan, Spain, Zurich, Tel Aviv, the UAE, Bahrain, Hyderabad, Jakarta, Melbourne, Calgary, Mexico and newer), so an install there has the S3 access logs only. |
| CloudFront.15 | On your own domain, viewers need TLS 1.2 with modern ciphers, or TLS 1.3 (`TLSv1.2_2025`). |
| DynamoDB.2, DynamoDB.6 | Every table has point-in-time recovery and deletion protection. On a Launch Stack install, deletion protection follows **KeepDataOnDelete**, so an uninstall that deletes the data can delete the tables. |
| Cognito.3, Cognito.6 | Passwords need 8 characters with an upper-case and a lower-case letter, a digit and a symbol. Temporary passwords last 7 days. The user pool has deletion protection, which follows **KeepDataOnDelete** like the tables. |
| Lambda.2 | Every function runs on a supported runtime (the MCP proxy on Node.js 22). |
| SES.3 | The install's SES configuration set sends only over TLS: a receiving server that can't do TLS gets no mail. |

The log bucket uses SSE-S3 and has ACLs enabled with the bucket owner preferred: S3 log delivery can't write to an SSE-KMS bucket, and CloudFront's standard logging writes with an ACL. The install still owns every object, and the bucket blocks all public access. It is deleted with the stack: writes are refused first, then it is emptied.

### Accepted, and why

Mark these as accepted in Security Hub (workflow status **Suppressed**, with the reason below).

| Control | Resource | Why it stays |
|---|---|---|
| APIGateway.9 | The HTTP API's `$default` stage | Every request to the API comes through the install's CloudFront, whose standard logs record each one (CloudFront.5). Access logs on the stage itself need `logs:CreateLogDelivery` and `logs:PutResourcePolicy` on all resources, which the install's deploy role deliberately doesn't have, so an update could never turn them on. |
| CloudFront.4 | The distribution | Origin failover needs a second copy of each origin in another region. The API and the functions run in one region, and failover covers only GET, HEAD and OPTIONS. |
| CloudFront.6 | The distribution | AWS WAF is billed per web ACL, per rule and per request, and the boundary doesn't let an install create one. Every API route checks a session, a signed webhook or a stream token, and the HTTP API throttles each stage. Attach your own web ACL to the distribution if your account requires one. |
| CloudFront.17 | The distribution | Trusted key groups are for signed URLs and cookies. CoderHelm serves nothing private through CloudFront that way: the dashboard is public static files, and everything else checks its own session or signature. |
| CloudFront.15 | A distribution without your own domain | CloudFront's default certificate (`*.cloudfront.net`) allows only its own TLS policy. Add your own domain to get `TLSv1.2_2025`. |
| S3.15 | Every bucket | Object Lock would stop CoderHelm deleting what it must: data a team removes, a release's old files, the sandbox's tarballs, the dashboard's old build, and everything on uninstall with **KeepDataOnDelete** `false`. |
| S3.17 | The dashboard, release, sandbox and log buckets | They use SSE-S3 on purpose. The dashboard is public static files that CloudFront reads; the release bucket holds the signed release's public files, each checked against its sha256; the sandbox holds tarballs that live for a day; S3 log delivery can't write to an SSE-KMS bucket. The data bucket uses the install's KMS key. |
| S3.20 | Every bucket | Only the account's root user can turn on MFA delete, from the CLI with the root user's MFA device. A template can't. |
| 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. |
| 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. |
| CloudFormation.4 | `coderhelm-<name>-access`, `CoderHelmLogReader*` | An AWS admin creates these with their own permissions, because they write IAM roles and policies. A service role would need the same IAM permissions. The main stack `coderhelm-<name>` has its service role, the deploy role. |
| KMS.3 | Keys of an install already uninstalled | An uninstall with **KeepDataOnDelete** `false` schedules the install's keys for deletion after 7 days, on purpose. The finding goes away when they are deleted. |

## Reporting a problem

Report security issues privately, never in a public issue: email [support@coderhelm.com](mailto:support@coderhelm.com?subject=Security%20report) with "Security report" in the subject. The [Security](https://docs.coderhelm.com/security/) page says what to include.
1 change: 1 addition & 0 deletions docs/self-host/uninstall.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ The stack parameter **KeepDataOnDelete** does the same from AWS. It is `true` un
| CoderHelm's functions, roles, queues, API, CloudFront, dashboard, schedules, alarms, the permissions boundary, the install helper | deleted | deleted |
| The release bucket (`coderhelm-<name>-release-<account>`) and the install guide's progress bucket | emptied and deleted | emptied and deleted |
| Log groups the stack declares (every function's) | deleted | deleted |
| The access log bucket (`coderhelm-<name>-logs-<account>`: S3 and CloudFront access logs, 90 days) | writes stopped, emptied and deleted | writes stopped, emptied and deleted |
| Certificates the updater requested for your own domain | deleted | deleted |
| DNS records you added for the domain (the certificate's validation CNAME and the address CNAME) | kept: CoderHelm never changes your DNS. The uninstall's log names them so you can remove them | kept, the same |
| DynamoDB tables | kept | deleted |
Expand Down
10 changes: 8 additions & 2 deletions infra/lib/api-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ export class ApiStack extends cdk.Stack {
requireUppercase: true,
requireLowercase: true,
requireDigits: true,
requireSymbols: false,
// The gateway checks the same before it calls Cognito (routes/auth.rs password_fits).
requireSymbols: true,
tempPasswordValidity: cdk.Duration.days(7),
},
mfa: cognito.Mfa.OPTIONAL,
mfaSecondFactor: { sms: false, otp: true },
Expand All @@ -105,6 +107,10 @@ export class ApiStack extends cdk.Stack {
: {}),
})
: cognito.UserPoolEmail.withCognito(),
// Deleting the pool takes turning this off first: the uninstaller and a
// native install's helper do (KeepDataOnDelete=false); a native install
// follows KeepDataOnDelete (native/package.ts).
deletionProtection: cfg.retainData,
removalPolicy: cfg.retainData
? cdk.RemovalPolicy.RETAIN
: cdk.RemovalPolicy.DESTROY,
Expand Down Expand Up @@ -802,7 +808,7 @@ export class ApiStack extends cdk.Stack {

this.mcpProxyFunction = new lambda.Function(this, "McpProxy", {
functionName: `${prefix}-mcp-proxy`,
runtime: lambda.Runtime.NODEJS_20_X,
runtime: lambda.Runtime.NODEJS_22_X,
architecture: lambda.Architecture.ARM_64,
handler: "handler.handler",
// MCP_PROXY_DIR: a prebuilt proxy (release artifact) instead of a local build.
Expand Down
5 changes: 5 additions & 0 deletions infra/lib/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ export function buildApp(app: cdk.App, cfg: ResolvedConfig, opts: { accessStack?
: undefined,
});

// The sandbox bucket logs into the storage stack's log bucket (by name).
worker.addDependency(storage);

// --- Streaming (SSE via Lambda Function URL + Web Adapter) ---
// Created before email and log analyzer so a single-origin web stack can
// sit between them (those two link to the dashboard URL it creates).
Expand Down Expand Up @@ -110,6 +113,8 @@ export function buildApp(app: cdk.App, cfg: ResolvedConfig, opts: { accessStack?
streamingFunctionUrl: streaming.functionUrl,
crossRegionReferences: false,
});
// Its dashboard bucket and distribution log into the storage stack's log bucket (by name).
web.addDependency(storage);
}

/** The dashboard's URL: static when known, else the web stack's CloudFront URL. */
Expand Down
3 changes: 3 additions & 0 deletions infra/lib/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,8 @@ export interface ResolvedConfig {
/** Data bucket name. */
dataBucketName: string;
sandboxBucketName: string;
/** The access log bucket: S3 server access logs and CloudFront's logs (storage-stack.ts). */
logBucketName: string;
cognitoDomainPrefix: string;
/**
* A native release (infra/lib/native): one set of templates for every
Expand Down Expand Up @@ -742,6 +744,7 @@ export function resolveConfig(cfg: CoderhelmConfig, opts: { skipValidation?: boo
: null,
dataBucketName: `${prefix}-data${suffix}`,
sandboxBucketName: `${prefix}-sandbox${suffix}`,
logBucketName: `${prefix}-logs${suffix}`,
cognitoDomainPrefix: `${prefix}${suffix}`,
};
}
Expand Down
27 changes: 25 additions & 2 deletions infra/lib/database-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,9 @@ export class DatabaseStack extends cdk.Stack {
encryption: dynamodb.TableEncryptionV2.customerManagedKey(
this.encryptionKey
),
pointInTimeRecoverySpecification: {
pointInTimeRecoveryEnabled: true,
},
deletionProtection: isProd,
removalPolicy: isProd
? cdk.RemovalPolicy.RETAIN
Expand Down Expand Up @@ -529,7 +532,15 @@ export class DatabaseStack extends cdk.Stack {
encryption: dynamodb.TableEncryptionV2.customerManagedKey(
this.encryptionKey
),
removalPolicy: cdk.RemovalPolicy.DESTROY,
pointInTimeRecoverySpecification: {
pointInTimeRecoveryEnabled: true,
},
// Run history: deleting it is a person's choice (KeepDataOnDelete
// on a native install, retainData otherwise), like every other table.
deletionProtection: isProd,
removalPolicy: isProd
? cdk.RemovalPolicy.RETAIN
: cdk.RemovalPolicy.DESTROY,
timeToLiveAttribute: "ttl",
});

Expand All @@ -546,7 +557,15 @@ export class DatabaseStack extends cdk.Stack {
encryption: dynamodb.TableEncryptionV2.customerManagedKey(
this.encryptionKey
),
removalPolicy: cdk.RemovalPolicy.DESTROY,
pointInTimeRecoverySpecification: {
pointInTimeRecoveryEnabled: true,
},
// Run history: deleting it is a person's choice (KeepDataOnDelete
// on a native install, retainData otherwise), like every other table.
deletionProtection: isProd,
removalPolicy: isProd
? cdk.RemovalPolicy.RETAIN
: cdk.RemovalPolicy.DESTROY,
timeToLiveAttribute: "ttl",
});

Expand Down Expand Up @@ -596,6 +615,10 @@ export class DatabaseStack extends cdk.Stack {
partitionKey: { name: "pk", type: dynamodb.AttributeType.STRING },
sortKey: { name: "sk", type: dynamodb.AttributeType.STRING },
billing: dynamodb.Billing.onDemand(),
pointInTimeRecoverySpecification: {
pointInTimeRecoveryEnabled: true,
},
deletionProtection: isProd,
removalPolicy: cdk.RemovalPolicy.RETAIN,
});
new cdk.CfnOutput(this, "BillingTableName", {
Expand Down
2 changes: 2 additions & 0 deletions infra/lib/email-stack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ export class EmailStack extends cdk.Stack {
configurationSetName: `${prefix}-emails`,
reputationMetrics: true,
sendingEnabled: true,
// Never in the clear: a receiving server without TLS gets no mail.
tlsPolicy: ses.ConfigurationSetTlsPolicy.REQUIRE,
});
// A self-hosted install counts its own email by kind (Deliveries): every
// send, delivery, bounce, complaint and rejection goes to its worker
Expand Down
2 changes: 2 additions & 0 deletions infra/lib/mail-relay.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ export class MailRelay extends Construct {
reputationMetrics: true,
sendingEnabled: true,
suppressionReasons: ses.SuppressionReasons.BOUNCES_AND_COMPLAINTS,
// Never in the clear: a receiving server without TLS gets no mail.
tlsPolicy: ses.ConfigurationSetTlsPolicy.REQUIRE,
});
configSet.addEventDestination("BouncesAndComplaints", {
destination: ses.EventDestination.snsTopic(this.topic),
Expand Down
15 changes: 13 additions & 2 deletions infra/lib/native/parent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,9 +323,16 @@ export function buildParent(input: ParentInput): Json {
R.DeployBoundary = pinned.DeployBoundary;
R.AssetsBucket = {
Type: "AWS::S3::Bucket",
Properties: { BucketName: sub(ASSETS_BUCKET_NAME), ...s3Secure, Tags: [{ Key: INSTALL_TAG, Value: sub("coderhelm-${Stage}") }] },
Properties: {
BucketName: sub(ASSETS_BUCKET_NAME),
...s3Secure,
// The helper copies each file whole; nothing should keep half an upload.
LifecycleConfiguration: { Rules: [{ Id: "abort-uploads", Status: "Enabled", AbortIncompleteMultipartUpload: { DaysAfterInitiation: 1 } }] },
Tags: [{ Key: INSTALL_TAG, Value: sub("coderhelm-${Stage}") }],
},
};
// Only the helper may write or delete the release files (it checks each one).
// Only the helper may write or delete the release files (it checks each one),
// and only over TLS.
R.AssetsBucketPolicy = {
Type: "AWS::S3::BucketPolicy",
Properties: {
Expand All @@ -337,6 +344,10 @@ export function buildParent(input: ParentInput): Json {
Action: ["s3:PutObject", "s3:DeleteObject", "s3:DeleteObjectVersion", "s3:PutObjectAcl"],
Resource: { "Fn::Sub": "${AssetsBucket.Arn}/*" },
Condition: { ArnNotEquals: { "aws:PrincipalArn": { "Fn::GetAtt": ["HelperRole", "Arn"] } } },
}, {
Sid: "TlsOnly", Effect: "Deny", Principal: "*", Action: "s3:*",
Resource: [{ "Fn::GetAtt": ["AssetsBucket", "Arn"] }, { "Fn::Sub": "${AssetsBucket.Arn}/*" }],
Condition: { Bool: { "aws:SecureTransport": "false" } },
}],
},
},
Expand Down
Loading
Loading