Skip to content

Commit ef57d6c

Browse files
claude[bot]claude
andauthored
Run PR previews in a separate preview environment (#255)
The production environment now only deploys from main, so it rejects the pull request refs that preview.yml runs on and the Preview job fails before its first step. Point the job at a `preview` environment instead and document which environment holds which credentials. The secret and variable names are unchanged. The `preview` environment is meant to hold a read-only GitHub App rather than the deploy App, the follow-up noted in #238. Claude-Session: https://claude.ai/code/session_016HDqNdz6KVjegQzqngoZKa Co-authored-by: Claude <noreply@anthropic.com>
1 parent 56e5b5e commit ef57d6c

2 files changed

Lines changed: 21 additions & 7 deletions

File tree

‎.github/workflows/preview.yml‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ jobs:
1818
runs-on: ubuntu-latest
1919
# Skip preview for fork PRs and Dependabot - they don't have access to Actions secrets
2020
if: github.event.pull_request.head.repo.full_name == github.repository && github.actor != 'dependabot[bot]'
21-
environment: production
21+
# `production` only deploys from main, so it rejects pull request refs.
22+
# `preview` accepts them and holds its own credentials. See README.md
23+
# "Required GitHub Secrets (for CI/CD)".
24+
environment: preview
2225
steps:
2326
- name: Checkout code
2427
uses: actions/checkout@v4

‎README.md‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ Channels listed in [`src/config/channels.ts`](src/config/channels.ts) are manage
120120
### One-time setup
121121

122122
1. In the Cloudflare dashboard for the **MCP Domain Account**, create a token dedicated to Access policy role management. Give it a descriptive name so it does not read as a generic API token, e.g. `mcp-access: Access policy role management`, and scope it to only **Account → Access: Apps and Policies → Edit** on the MCP Domain Account. Do not reuse this token for anything else.
123-
2. Add it as the GitHub Actions secret `CLOUDFLARE_ROLE_MANAGEMENT_TOKEN` in the `production` environment (repository settings → Environments → production). The deploy workflow passes it to Pulumi as `cloudflare:roleManagementToken`. Until the secret exists, the Cloudflare module logs "Cloudflare integration disabled: roleManagementToken not configured" and creates nothing, so previews stay green.
123+
2. Add it as the GitHub Actions secret `CLOUDFLARE_ROLE_MANAGEMENT_TOKEN` in the `production` and `preview` environments (repository settings → Environments). The deploy workflow passes it to Pulumi as `cloudflare:roleManagementToken`. Until the secret exists, the Cloudflare module logs "Cloudflare integration disabled: roleManagementToken not configured" and creates nothing, so previews stay green.
124124
3. The account ID and GitHub identity-provider ID are non-secret and live in [`Pulumi.prod.yaml`](Pulumi.prod.yaml).
125125
4. **Adopting the existing policy.** Pulumi's `import` resource option only succeeds when the program's inputs match the live resource, so adoption is two deploys:
126126
- With `cloudflare:importExistingPolicies: "true"` in `Pulumi.prod.yaml`, the first deploy imports the existing `Maintainers` policy (by its `cloudflarePolicyId`) as-is, ignoring its rule lists.
@@ -199,15 +199,26 @@ The private key is equivalent to organization admin. Store it as an environment
199199
gh secret set DEPLOY_APP_PRIVATE_KEY --env production -R modelcontextprotocol/access < key.pem
200200
```
201201

202+
Preview runs in the `preview` environment and reads `DEPLOY_APP_CLIENT_ID` and `DEPLOY_APP_PRIVATE_KEY` from there. That environment accepts pull request branches, so give it the credentials of a separate App that has only **Metadata: read** and **Custom organization roles: read**, not the deploy App's. The token Preview requests is limited to those two permissions, but the private key behind it is not.
203+
202204
Do not use a refresh (`make refresh`, `pulumi preview --refresh`) as a read-only check: the Discord member sync corrects role drift during `read()`, so any refresh can change live Discord roles.
203205

204206
### Required GitHub Secrets (for CI/CD)
205207

206-
The following secrets must be configured in GitHub Actions for automated deployments:
208+
The workflows run in two GitHub environments (repository settings → Environments):
209+
210+
| Environment | Used by | Deployment branches |
211+
| ------------ | --------------------------------------------------------------- | --------------------------------------------------------------------------------------------------- |
212+
| `production` | [`deploy.yml`](.github/workflows/deploy.yml) on `main` | `main` only |
213+
| `preview` | [`preview.yml`](.github/workflows/preview.yml) on pull requests | No restriction. Pull request runs use `refs/pull/<number>/merge`, which a `main`-only rule rejects. |
214+
215+
A secret or variable stored in an environment is visible only to jobs that declare that environment. One stored at repository level is visible to both. Anyone who can push a branch to this repository can run a workflow in `preview`, so keep the deploy App's private key out of it.
216+
217+
The following secrets must be configured in GitHub Actions for automated deployments. Both workflows read all of them. Apart from the App credentials, Preview needs the same values as Deploy: it fails without the billing email, and it shows the Discord and Cloudflare resources as deletes when their values are missing.
207218

208-
- **`DEPLOY_APP_PRIVATE_KEY`** (secret, `production` environment): private key of the deploy GitHub App
219+
- **`DEPLOY_APP_PRIVATE_KEY`** (secret, set in each environment): private key of the deploy GitHub App in `production`, and of the read-only preview App in `preview`
209220

210-
- **`DEPLOY_APP_CLIENT_ID`** (a **variable**, not a secret, `production` environment): client ID of the deploy GitHub App
221+
- **`DEPLOY_APP_CLIENT_ID`** (a **variable**, not a secret, set in each environment): client ID of the App whose private key that environment holds
211222

212223
- **`ORG_BILLING_EMAIL`**, **`DISCORD_BOT_TOKEN`**, **`DISCORD_GUILD_ID`**: passed to Pulumi config by the workflows
213224

@@ -220,7 +231,7 @@ The following secrets must be configured in GitHub Actions for automated deploym
220231
- Used to decrypt encrypted values in Pulumi stack configuration
221232
- Keep this secure - if lost, you cannot decrypt your Pulumi state
222233

223-
- **`CLOUDFLARE_ROLE_MANAGEMENT_TOKEN`** (optional, `production` environment): Cloudflare token dedicated to Access policy role management, scoped only to **Account → Access: Apps and Policies → Edit** on the MCP Domain Account (not a general-purpose API token)
234+
- **`CLOUDFLARE_ROLE_MANAGEMENT_TOKEN`** (optional, `production` and `preview` environments): Cloudflare token dedicated to Access policy role management, scoped only to **Account → Access: Apps and Policies → Edit** on the MCP Domain Account (not a general-purpose API token)
224235
- Used to manage the Cloudflare Access policy for `securityroom.modelcontextprotocol.io` (see [Cloudflare Access (security-room)](#cloudflare-access-security-room))
225236

226237
## Initial Setup
@@ -284,4 +295,4 @@ Add the CI/CD secrets to GitHub Actions (repository settings → Secrets and var
284295

285296
- `GCP_PROD_SERVICE_ACCOUNT_KEY`: Content of `sa-key.json`
286297
- `PULUMI_PROD_PASSPHRASE`: The passphrase you set above
287-
- `DEPLOY_APP_CLIENT_ID` and `DEPLOY_APP_PRIVATE_KEY` (in the `production` environment, not at repository level): see [Deploy GitHub App](#deploy-github-app)
298+
- `DEPLOY_APP_CLIENT_ID` and `DEPLOY_APP_PRIVATE_KEY` (in the `production` and `preview` environments, not at repository level): see [Deploy GitHub App](#deploy-github-app)

0 commit comments

Comments
 (0)