Skip to content

Commit 31a8103

Browse files
committed
Harden cpflow workflow secret forwarding
1 parent 8e2722f commit 31a8103

13 files changed

Lines changed: 58 additions & 30 deletions

.controlplane/controlplane.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ apps:
5454
<<: *common
5555
# QA Apps are like Heroku review apps, but the use `prefix` so you can run a commmand like
5656
# this to create a QA app for the tutorial app.
57-
# `cpflow setup gvc postgres redis rails -a qa-react-webpack-rails-tutorial-pr-1234`
57+
# `cpflow setup gvc postgres redis rails -a qa-react-webpack-rails-tutorial-1234`
5858
qa-react-webpack-rails-tutorial:
5959
<<: *common
6060
# Order matters!

.controlplane/docs/testing-cpflow-github-actions.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,8 @@ examples such as `${{ vars.SOME_VALUE }}` can fail action loading before any
151151
shell step starts. The wrapper runs `cpflow github-flow-readiness`, parses the
152152
generated YAML, checks action input descriptions for literal GitHub expressions,
153153
checks that every generated wrapper keeps `uses:` and `control_plane_flow_ref`
154-
on the same upstream ref across all `cpflow-*` wrappers, checks that any
155-
secret-inheriting reusable workflow passes `control_plane_flow_ref`, and runs
154+
on the same upstream ref across all `cpflow-*` wrappers, rejects broad `secrets: inherit` in generated cpflow wrappers, checks that
155+
any secret-passing reusable workflow passes `control_plane_flow_ref`, and runs
156156
`actionlint -ignore 'SC2129' .github/workflows/cpflow-*.yml`.
157157

158158
## PR Checks

.controlplane/readme.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ or similarly trusted maintainers should be able to approve the promotion job.
7474
The promotion workflow uses that environment before it can access
7575
`CPLN_TOKEN_PRODUCTION`, so the production token is not exposed to ordinary
7676
review-app or staging runs.
77+
Generated caller workflows pass only the named secrets each upstream workflow
78+
needs. They do not use `secrets: inherit`; `CPLN_TOKEN_PRODUCTION` is supplied
79+
only by the protected `production` Environment after approval.
7780

7881
Advanced optional variables:
7982

@@ -499,6 +502,7 @@ The GitHub settings and Control Plane resources must match the app names in
499502
`REVIEW_APP_PREFIX` unset and let the workflow infer
500503
`qa-react-webpack-rails-tutorial`; generated review apps are named
501504
`qa-react-webpack-rails-tutorial-<PR number>`.
505+
If you have older review apps from the previous `qa-react-webpack-rails-tutorial-pr-<PR number>` naming, delete them manually after this flow lands; cleanup targets the current prefix convention.
502506

503507
This allows teams to:
504508
- Preview changes in a production-like environment

.controlplane/shakacode-team.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,6 @@ Required repository variables for staging deploys:
3939
- `CPLN_ORG_STAGING=shakacode-open-source-examples-staging`
4040
- `STAGING_APP_NAME=react-webpack-rails-tutorial-staging`
4141
- `STAGING_APP_BRANCH=master`
42-
- `PRIMARY_WORKLOAD=rails`
4342

4443
Review apps infer `CPLN_ORG_STAGING`, `REVIEW_APP_PREFIX`, and
4544
`PRIMARY_WORKLOAD` from `.controlplane/controlplane.yml` and workflow defaults,
@@ -56,9 +55,13 @@ Production promotion uses a protected GitHub Environment named `production`:
5655
Protect the `production` environment with required reviewers, enable prevent
5756
self-review, and consider disabling administrator bypass. Do not store
5857
`CPLN_TOKEN_PRODUCTION` as a repository or organization secret.
58+
Generated caller workflows pass only the named secrets each upstream workflow
59+
needs. They do not use `secrets: inherit`; `CPLN_TOKEN_PRODUCTION` is supplied
60+
only by the protected `production` Environment after approval.
5961

6062
Optional repository settings:
6163

64+
- `PRIMARY_WORKLOAD`: public workload used for review URLs and promote health checks; defaults to `rails`.
6265
- `DOCKER_BUILD_SSH_KEY`: secret for private SSH dependencies during Docker builds.
6366
- `DOCKER_BUILD_EXTRA_ARGS`: newline-delimited Docker build tokens, such as `--build-arg=FOO=bar`.
6467
- `DOCKER_BUILD_SSH_KNOWN_HOSTS`: custom `known_hosts` entries when SSH build hosts are not GitHub.com.

.github/cpflow-help.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ You asked for review app help. These commands are generated by [cpflow](https://
3535
| Name | Required | Notes |
3636
| --- | --- | --- |
3737
| `CPLN_TOKEN_STAGING` | yes | Service-account token scoped to the staging Control Plane org on controlplane.com. |
38-
| `CPLN_TOKEN_PRODUCTION` | yes (for promote) | Store this as a secret on the protected `production` GitHub Environment, not as a repository or organization secret. |
38+
| `CPLN_TOKEN_PRODUCTION` | yes for promote, as an environment secret | Store this as a secret on the protected `production` GitHub Environment, not as a repository or organization secret. |
3939
| `DOCKER_BUILD_SSH_KEY` | optional | Private SSH key used when Docker builds fetch private deps via `RUN --mount=type=ssh`. |
4040

4141
For normal generated review apps, `CPLN_TOKEN_STAGING` is the only required
@@ -54,15 +54,18 @@ For production promotion, create a GitHub Environment named `production`, add
5454
required reviewers, enable prevent self-review, and store
5555
`CPLN_TOKEN_PRODUCTION` as an environment secret there. The generated promotion
5656
workflow uses that environment before it can access production secrets.
57+
Generated caller workflows pass only the named secrets each upstream workflow
58+
needs. They do not use `secrets: inherit`; the production token is supplied by
59+
the protected `production` Environment after approval.
5760

5861
### GitHub Actions variables
5962

6063
| Name | Required | Notes |
6164
| --- | --- | --- |
6265
| `CPLN_ORG_STAGING` | optional for review apps; yes for staging | Override the staging/review Control Plane org inferred from `controlplane.yml`. |
63-
| `CPLN_ORG_PRODUCTION` | yes (for promote) | Control Plane org on controlplane.com for production. Prefer a `production` environment variable. |
66+
| `CPLN_ORG_PRODUCTION` | yes for promote, preferably as environment variable | Control Plane org on controlplane.com for production. Prefer a `production` environment variable. |
6467
| `STAGING_APP_NAME` | yes | App name in `controlplane.yml` used as the staging deploy target. |
65-
| `PRODUCTION_APP_NAME` | yes (for promote) | App name in `controlplane.yml` used as the production deploy target. Prefer a `production` environment variable. |
68+
| `PRODUCTION_APP_NAME` | yes for promote, preferably as environment variable | App name in `controlplane.yml` used as the production deploy target. Prefer a `production` environment variable. |
6669
| `REVIEW_APP_PREFIX` | optional | Override the review-app app key inferred from the `match_if_app_name_starts_with: true` entry in `controlplane.yml`. |
6770
| `REVIEW_APP_DEPLOYING_ICON_URL` | optional, advanced | Cosmetic custom image URL for the animated deploying icon in review-app PR comments. Set to `none` to use the text fallback icon. |
6871
| `STAGING_APP_BRANCH` | optional | Custom staging branch. Custom branches must also appear in `cpflow-deploy-staging.yml`'s push filter. |
@@ -75,6 +78,11 @@ workflow uses that environment before it can access production secrets.
7578

7679
</details>
7780

81+
Generated review app names use `<review-app-prefix>-<PR number>`, for example
82+
`my-app-review-123`. If you are migrating from older local workflow glue that
83+
created names like `<review-app-prefix>-pr-123`, delete those old review apps
84+
manually after merging this flow.
85+
7886
<details>
7987
<summary>Advanced: testing unreleased control-plane-flow changes</summary>
8088

.github/workflows/cpflow-cleanup-stale-review-apps.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,8 @@ permissions:
1010

1111
jobs:
1212
cleanup:
13-
uses: shakacode/control-plane-flow/.github/workflows/cpflow-cleanup-stale-review-apps.yml@cfe494bf32925d49508380e03856d97bd71f6689
13+
uses: shakacode/control-plane-flow/.github/workflows/cpflow-cleanup-stale-review-apps.yml@7d9b80dcb55b243d0cc78b0a85bcb3d568ce8e02
1414
with:
15-
control_plane_flow_ref: cfe494bf32925d49508380e03856d97bd71f6689
16-
secrets: inherit
15+
control_plane_flow_ref: 7d9b80dcb55b243d0cc78b0a85bcb3d568ce8e02
16+
secrets:
17+
CPLN_TOKEN_STAGING: ${{ secrets.CPLN_TOKEN_STAGING }}

.github/workflows/cpflow-delete-review-app.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ jobs:
2626
contains(fromJson('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)) ||
2727
(github.event_name == 'pull_request_target' && github.event.action == 'closed') ||
2828
github.event_name == 'workflow_dispatch'
29-
uses: shakacode/control-plane-flow/.github/workflows/cpflow-delete-review-app.yml@cfe494bf32925d49508380e03856d97bd71f6689
29+
uses: shakacode/control-plane-flow/.github/workflows/cpflow-delete-review-app.yml@7d9b80dcb55b243d0cc78b0a85bcb3d568ce8e02
3030
with:
31-
control_plane_flow_ref: cfe494bf32925d49508380e03856d97bd71f6689
32-
secrets: inherit
31+
control_plane_flow_ref: 7d9b80dcb55b243d0cc78b0a85bcb3d568ce8e02
32+
secrets:
33+
CPLN_TOKEN_STAGING: ${{ secrets.CPLN_TOKEN_STAGING }}

.github/workflows/cpflow-deploy-review-app.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,9 @@ jobs:
3030
github.event.issue.pull_request &&
3131
contains(fromJson('["+review-app-deploy","+review-app-deploy\n","+review-app-deploy\r\n"]'), github.event.comment.body) &&
3232
contains(fromJson('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association))
33-
uses: shakacode/control-plane-flow/.github/workflows/cpflow-deploy-review-app.yml@cfe494bf32925d49508380e03856d97bd71f6689
33+
uses: shakacode/control-plane-flow/.github/workflows/cpflow-deploy-review-app.yml@7d9b80dcb55b243d0cc78b0a85bcb3d568ce8e02
3434
with:
35-
control_plane_flow_ref: cfe494bf32925d49508380e03856d97bd71f6689
36-
secrets: inherit
35+
control_plane_flow_ref: 7d9b80dcb55b243d0cc78b0a85bcb3d568ce8e02
36+
secrets:
37+
CPLN_TOKEN_STAGING: ${{ secrets.CPLN_TOKEN_STAGING }}
38+
DOCKER_BUILD_SSH_KEY: ${{ secrets.DOCKER_BUILD_SSH_KEY }}

.github/workflows/cpflow-deploy-staging.yml

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ permissions:
1616

1717
jobs:
1818
deploy-staging:
19-
uses: shakacode/control-plane-flow/.github/workflows/cpflow-deploy-staging.yml@cfe494bf32925d49508380e03856d97bd71f6689
19+
uses: shakacode/control-plane-flow/.github/workflows/cpflow-deploy-staging.yml@7d9b80dcb55b243d0cc78b0a85bcb3d568ce8e02
2020
with:
21-
control_plane_flow_ref: cfe494bf32925d49508380e03856d97bd71f6689
21+
control_plane_flow_ref: 7d9b80dcb55b243d0cc78b0a85bcb3d568ce8e02
2222
staging_app_branch_default: ""
23-
secrets: inherit
23+
secrets:
24+
CPLN_TOKEN_STAGING: ${{ secrets.CPLN_TOKEN_STAGING }}
25+
DOCKER_BUILD_SSH_KEY: ${{ secrets.DOCKER_BUILD_SSH_KEY }}

.github/workflows/cpflow-help-command.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ jobs:
2323
contains(fromJson('["+review-app-help","+review-app-help\n","+review-app-help\r\n"]'), github.event.comment.body) &&
2424
contains(fromJson('["OWNER","MEMBER","COLLABORATOR"]'), github.event.comment.author_association)) ||
2525
github.event_name == 'workflow_dispatch'
26-
uses: shakacode/control-plane-flow/.github/workflows/cpflow-help-command.yml@cfe494bf32925d49508380e03856d97bd71f6689
26+
uses: shakacode/control-plane-flow/.github/workflows/cpflow-help-command.yml@7d9b80dcb55b243d0cc78b0a85bcb3d568ce8e02
27+
with:
28+
control_plane_flow_ref: 7d9b80dcb55b243d0cc78b0a85bcb3d568ce8e02

0 commit comments

Comments
 (0)