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
2 changes: 1 addition & 1 deletion docs/api/openapi.json
Original file line number Diff line number Diff line change
Expand Up @@ -4973,7 +4973,7 @@
},
"/webhooks/relay": {
"post": {
"description": "On a hybrid self-hosted install, where CoderHelm's hosted relay forwards the events of CoderHelm's GitHub App (and Jira app) after checking the provider's own signature. Each request is signed with the install's relay key: `X-CoderHelm-Relay-Signature: t=<unix seconds>,d=<delivery id>,v1=<hex>`, the HMAC-SHA256 of `<t>.<d>.<raw body>`. Requests older than 5 minutes are refused, and so is a delivery id the install has already taken (`409`). `X-CoderHelm-Relay-Source` is `github` or `jira`; for GitHub, `X-CoderHelm-Relay-Event` is GitHub's event type and the body is GitHub's payload, unchanged.",
"description": "On a hybrid self-hosted install, where CoderHelm's hosted relay forwards the events of CoderHelm's GitHub App (and Jira app) after checking the provider's own signature. Each request is signed with the install's relay key: `X-CoderHelm-Relay-Signature: t=<unix seconds>,d=<delivery id>,v1=<hex>,v2=<hex>`, where `v1` is the HMAC-SHA256 of `<t>.<d>.<raw body>` and `v2` of `v2.<t>.<d>.<source>.<event>.<raw body>` (so the two headers below are signed too). Requests older than 5 minutes are refused, and so is a delivery id the install has already taken (`409`). `X-CoderHelm-Relay-Source` is `github` or `jira`; for GitHub, `X-CoderHelm-Relay-Event` is GitHub's event type and the body is GitHub's payload, unchanged.",
"operationId": "receiveRelayedEvent",
"parameters": [
{
Expand Down
18 changes: 11 additions & 7 deletions docs/self-host/hybrid.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,18 @@ How the pieces are protected:

- **Registration.** Your install registers once and gets an id, a secret and a relay key. Both keys are derived from a key on CoderHelm's side, so CoderHelm stores no copy of them; your install keeps them in its own Secrets Manager secret.
- **Proof of ownership.** Before a name or an app is linked, CoderHelm asks your install's CloudFront address to answer a challenge with its secret. Names only ever point at a verified install's own CloudFront distribution.
- **Signed both ways.** Every call from your install is signed (`X-CoderHelm-Signature`), and every relayed event is signed with your relay key (`X-CoderHelm-Relay-Signature: t=,d=,v1=`). Your install refuses anything older than 5 minutes and any delivery id it has already taken.
- **Linking proves both sides.** Linking CoderHelm's GitHub App needs your install (its setup key in the guide, or an install admin in Settings) and a GitHub sign-in that shows the installation is yours. A GitHub redirect alone can't link anything.
- **Scoped tokens.** The broker mints tokens only for installations linked to your install, narrowed to the repositories you chose.
- **Revocable.** CoderHelm can turn an install's access off (its name and records go, the relay and broker refuse it), and every action is in an audit log.
- **Same-site safety.** Every address under coderhelm.com is a different site to the browser: CoderHelm's own cookies are host-only (`__Host-`, no Domain attribute) and its CORS lists exact origins, so an install's pages can't read or change coderhelm.com sessions.
- **Signed both ways.** Every call from your install is signed (`X-CoderHelm-Signature`), and every relayed event is signed with your relay key (`X-CoderHelm-Relay-Signature: t=,d=,v1=,v2=`; `v2` also covers the source and event headers). Your install refuses anything older than 5 minutes and any delivery id it has already taken, and refuses an event it couldn't record as taken.
- **Linking proves both sides.** Linking CoderHelm's GitHub App needs your install (its setup key in the guide, or an install admin in Settings), a GitHub sign-in that shows the installation is yours, and a press of **Link** on a CoderHelm page that names your install's address. A GitHub redirect or a link someone sends you can't link anything by itself.
- **Scoped tokens.** The broker mints tokens only for installations linked to your install, narrowed to the repositories you chose and, within those, to the repositories the person who linked it can push to on GitHub. GitHub itself enforces both: they are part of the token request.
- **Sign-ins are yours only once your install takes them.** A Notion, Confluence or Google Drive sign-in is held apart until your install redeems it with its secret and its PKCE verifier, so nobody else can put their account in place of yours.
- **Revocable.** CoderHelm can turn an install's access off (its name and records go, its GitHub links are removed, the relay and broker refuse it, and the same CloudFront can't register again), and every action is in an audit log.
- **Same-site safety.** Addresses under coderhelm.com are the same site as app.coderhelm.com and api.coderhelm.com to a browser, so CoderHelm doesn't rely on that: its cookies are host-only (`__Host-`, no Domain attribute), its CORS lists exact origins, and the API refuses any change sent with cookies from another page on the same site. An install's pages can't read or change coderhelm.com sessions.

The full threat model, with each attack and what stops it, is in [Security model](./security.md#hybrid-threat-model).

## A CoderHelm address

Pick a name in the guide or in **Settings, System, Domain**. The page checks it as you type: lowercase letters, digits and hyphens, 3 to 40 characters, not reserved (CoderHelm's own hosts such as `app`, `api`, `docs` and `auth`, and names such as `admin`, `support` or `status`), and not taken.
Pick a name in the guide or in **Settings, System, Domain**. The page checks it as you type: lowercase letters, digits and hyphens, 3 to 40 characters, not reserved (CoderHelm's own hosts such as `app`, `api`, `docs` and `auth`, and names such as `admin`, `support` or `status`), not reading as CoderHelm's own (no `coderhelm` in it, even spelled with digits, and no part such as `app`, `login`, `billing` or `support`, as in `app2` or `acme-login`), and not taken.

Then everything happens by itself:

Expand All @@ -58,7 +61,8 @@ A name can change five times a day. Uninstalling with `npx github:CoderHelm/code

1. In the guide (or **Settings, System, Hybrid**), choose **Use CoderHelm's GitHub App**.
2. Press **Install on GitHub**, pick the organization and repositories, and sign in to GitHub when it asks. That sign-in proves the installation is yours.
3. You come back linked. From then on GitHub sends events to CoderHelm, which forwards each one to `https://<your CloudFront>/webhooks/relay`, and your install asks the broker for tokens when it works on a repository.
3. CoderHelm shows which install the organization is about to be linked to. Check the address and press **Link**.
4. You come back linked. Tokens reach only the repositories you can push to on GitHub; someone with more access can link it again to widen that. From then on GitHub sends events to CoderHelm, which forwards each one to `https://<your CloudFront>/webhooks/relay`, and your install asks the broker for tokens when it works on a repository.

A forward that fails is retried with growing waits for about 24 hours. Both sides show it on their **Deliveries** page with each attempt, the answer and the next retry. Choose your own GitHub App again any time; signing in with GitHub on your install needs your own app.

Expand Down
56 changes: 56 additions & 0 deletions docs/self-host/security.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,62 @@ order: 11

Releases are built by GitHub Actions from a tag, with checksums and build provenance attestations (Sigstore, through GitHub). The installer checks both. You can also deploy from source (`--source`) after reviewing the code.

## Hybrid threat model

This part covers a [hybrid](./hybrid.md) install: one that uses CoderHelm's address, GitHub App or integration apps. A fully private install talks to none of what follows.

### What is worth protecting

- **Your code and repositories.** CoderHelm's GitHub App can read and change code. Its installation tokens are the most valuable thing the hybrid side hands out.
- **Your install's identity**: its id, its registration secret and its relay key. Whoever holds them can act as your install toward CoderHelm.
- **Your provider sign-ins** (Notion, Confluence, Google Drive): what your agents read as knowledge.
- **Your events**: GitHub and Jira payloads, which can contain code, titles and comments.
- **Your address**, `yourname.coderhelm.com`, and CoderHelm's own hosts in the same zone (`app`, `api`, `auth`, `docs`).
- **Sessions on app.coderhelm.com and api.coderhelm.com** of people who also use the hosted service.

### Who might attack

1. Someone who runs their own hybrid install (and so controls its code, its CloudFront and its address).
2. Anyone on the internet, with no account.
3. Someone who controls one `{name}.coderhelm.com` address and the pages it serves.
4. Someone who can see one install's network traffic.

### Attacks and what stops them

| Attack | What stops it |
|---|---|
| Register an install, or act as another one | Anyone may register, but a registration does nothing until CoderHelm's challenge is answered from the install's own CloudFront address with that install's secret. Every later call is signed with the install's secret (HMAC-SHA256 over the time, method, path and body, compared in constant time, at most 5 minutes old). Ids have one fixed shape, so no id can be built to collide with another install's keys. |
| Work out an install's keys | Each install's secret and relay key are HMAC-SHA256 of CoderHelm's master key with a fixed label (`install:` or `relay:`) and the install id. The labels differ, so no install's secret can equal another install's relay key, and a key is useless without the master key. |
| Keep working after CoderHelm turns an install off | Every signed call, token request, sign-in and relayed event checks that the install is active. Revoking also removes its name and its GitHub links, and its CloudFront address can't register again. |
| Send a forged GitHub event | The hosted side checks GitHub's own signature (`X-Hub-Signature-256`) before it looks at anything else, and forwards only to the install that installation is linked to. |
| Send a forged or replayed relayed event to an install | The install checks the relay signature (time, delivery id, body, and from `v2` the source and event headers), refuses anything older than 5 minutes, and takes each delivery id once in its own database. If it can't record the delivery id, it refuses the event and the relay tries again. |
| Forge a Jira event through the relay | The install checks the Forge app's own secret, which CoderHelm forwards but doesn't decide. |
| Get events or tokens for someone else's GitHub organization | A link needs a GitHub sign-in that sees that installation of CoderHelm's app (another app's installation never counts), and a press of **Link** on a CoderHelm page that names the install's address and can't be shown inside another page. One installation links to one install, never to one a hosted team already uses. Tokens reach only the repositories the person who linked it can push to, so read access to one repository can't become write access to all. |
| Mint a wider token | The broker asks GitHub for the token with an explicit list of repositories and permissions, never more than the link allows and never more than the app's own permissions. GitHub refuses anything outside that list. Tokens last at most an hour. |
| Take over someone's Notion, Confluence or Google Drive sign-in | The sign-in is finished in a holding place of its own and becomes the install's only when the install redeems the one-time code with its secret and the PKCE verifier (S256), at the return address it registered. Starting sign-ins is limited per address. |
| Send people somewhere else after linking or signing in | Return addresses are compared host by host against the install's own CloudFront address and name (and the docs install guide); anything else goes to the install's settings page. Sign-in returns must be the install's own callback page, over HTTPS, with no port or user name. |
| Make CoderHelm's servers call something inside AWS | CoderHelm calls an install only at the CloudFront address it proved at registration, which never changes afterwards. Those calls never follow a redirect and read at most 16 KB of the answer. CloudFront's own names can't be pointed at other addresses. |
| Claim a reserved or misleading name | Names are lowercase letters, digits and single hyphens (so no punycode, other alphabets or trailing dots), 3 to 40 characters. CoderHelm's own hosts and a blocklist are refused, and so is any name that reads as CoderHelm's own: `coderhelm` anywhere, digits standing in for letters included, or a part such as `app`, `api`, `login`, `billing` or `support` (`app2`, `acme-login`). |
| Take over another install's name, or point a name elsewhere | A claim is a write that fails when the name exists. The address record must point at the install's own verified CloudFront, proved again just before it is written; the certificate record must have the exact shape ACM uses and point at `acm-validations.aws`. |
| Make CoderHelm write any other DNS record | The code writes only two CNAMEs per name (the name and `_<token>.<name>`) plus the setup page's alias while the name is new, and never overwrites a record it didn't write. Its AWS permissions are a second fence: CNAME, A and AAAA only, in that one zone, never the apex, the wildcard or a reserved name, never anything under CoderHelm's own hosts, never mail or certificate-authority records (`_domainkey`, `_dmarc`, `_mta-sts`, `_acme-challenge`) and never anything three labels deep. |
| Use a customer address against CoderHelm's own sites | Every address under coderhelm.com is the same site as app.coderhelm.com and api.coderhelm.com to a browser, so nothing relies on that. Cookies are `__Host-` (no Domain attribute), so a customer page can neither read nor set them. CORS answers only exact origins, never `*.coderhelm.com`. A change sent with cookies from any other page on the same site is refused. Sign-in messages between windows check the exact origin. |
| Show other content on the "no CoderHelm here yet" page | The wildcard site has one origin, CoderHelm's own fallback page, which shows one of two fixed pages and nothing from the request but whether the name is being set up. |
| Read through the public name check | It answers only whether a name is free (claimed names are public in DNS anyway), carries no cookies, and is limited to 30 checks a minute per address. The install guide's setup routes need the install's one-time setup key. |
| Read other teams' deliveries | Deliveries are read by team, by admins only. An install reads only its own relay and broker records, with its own signature. Stored headers have every secret-looking value removed, and the relay keeps no payload in its records. |
| Read traffic between an install and CoderHelm | Everything is HTTPS. The keys never travel after registration: requests carry only signatures, which are bound to the time, the path and the body. |

### What CoderHelm can and cannot see

CoderHelm **can** see: each relayed event's payload while it forwards it (and holds it for up to 24 hours only while retrying), the Forge app's secret as it passes, delivery metadata for 14 days, the installation tokens it mints as it hands them out, your provider sign-ins (sealed with a key only its services can use), your name, your CloudFront address and your two DNS records, and failed-delivery metadata you chose to share.

CoderHelm **cannot** see: your code at rest, your runs, plans, reviews, memory, knowledge or secrets, your model calls, your AWS account, or your people's sign-ins. It can't sign in to your install.

### Known limits

- A link made before the **Link** confirmation and the push-permission limit existed keeps the repositories it had. Link it again to bring it under both.
- Someone who controls CoderHelm's hosted side could mint tokens for linked installations, read relayed events and act as the relay. Choose your own GitHub App and apps (fully private) if that is outside what you accept.
- 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.

## Reporting a problem

Report security issues privately to the support address in the CoderHelm repository rather than in a public issue.
28 changes: 28 additions & 0 deletions infra/lib/hybrid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,34 @@ export class Hybrid extends Construct {
},
}),
);
// IAM's `*` crosses dots, so the allow above also matches deeper names.
// A separate deny (conditions inside one statement would AND together)
// fences what the code never writes: anything under a host CoderHelm serves
// (such as `_acme-challenge.app.<zone>`, which could get a certificate
// for the dashboard), mail and certificate-authority records anywhere in
// the zone, and names three or more labels deep.
fn_.addToRolePolicy(
new iam.PolicyStatement({
sid: "HybridNeverDeeper",
effect: iam.Effect.DENY,
actions: ["route53:ChangeResourceRecordSets"],
resources: [zoneArn],
conditions: {
"ForAnyValue:StringLike": {
"route53:ChangeResourceRecordSetsNormalizedRecordNames": [
`*.*.*.${h.zone}`,
"*_domainkey*",
"*_dmarc*",
"*_mta-sts*",
"*_smtp*",
"*_acme-challenge*",
"*_spf*",
...reserved.zoneRecords.map((n) => `*.${n}.${h.zone}`),
],
},
},
}),
);
fn_.addEnvironment("HYBRID_ZONE_ID", zone.hostedZoneId);
fn_.addEnvironment("HYBRID_FALLBACK_DOMAIN", this.fallback.distributionDomainName);

Expand Down
Loading
Loading