Repository navigation
feat(opentofu): add private-module-sources input - #65
Merged
Merged
Conversation
The tfm-oce-cell and tfm-oce-tenant modules call private tfm-oce modules through git@github.com: sources and the workflow had no credentials so they cannot adopt the tfm copier template. This adds an opt-in private-module-sources input to opentofu.yml that fetches private openCoreEMR module sources during tofu init with a keyless octo-sts token. When the input is true the job gets an oce-ci-bot contents: read token from octo-sts using the ci-tofu-modules identity and org scope. It rewrites ssh://git@github.com/ and git@github.com: to https with it and removes the rewrite after tofu init. Checkout now sets persist-credentials: false because nothing pushes and a persisted token would win over the URL token. A guard step fails with a clear message when the input is set but the caller did not grant id-token: write. The job no longer declares permissions and runs with exactly what the caller grants. A probe run showed GitHub fails the whole run at startup when a reusable job asks for id-token: write the caller did not grant, even when an if skips the job, so a job-level grant would break every existing caller. The org requires callers to declare permissions anyway. The selftest covers the guard and the rewrite and removal scripts with a fake token. The real exchange cannot run on a PR because the trust policy admits only release tags. Merge after openCoreEMR/.github#16 establishes the trust policy. Release this, then the tfm-copier-template change pins it. Refs #64. Assisted-by: Claude Code
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
|
Contributor
Author
|
A CodeRabbit CLI review of this PR at
CLI review events{
"type": "review_context",
"reviewType": "committed",
"currentBranch": "HEAD",
"baseBranch": "origin/main",
"baseCommit": "2854c3d5c41f931fa9f5a22d5a5f1ca2e8481480",
"expectedDuration": "Reviews usually take 2-6 minutes and can take up to 15. Keep this command running for at least 15 minutes or run it in the background; stopping it early discards the review."
}
{
"type": "complete",
"status": "review_completed",
"findings": 0,
"reviewedFiles": [
".github/workflows/opentofu-selftest.yml",
".github/workflows/opentofu.yml",
"README.md"
],
"outcome": "completed",
"message": "Review completed"
} |
Contributor
Author
|
@coderabbitai approve |
Action performed
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Merge order: openCoreEMR/.github#16 (the ci-tofu-modules trust policy) first, then this PR and its release, then the tfm-copier-template PR that pins the release.
opentofu.yml gains an opt-in private-module-sources input so modules with private git@github.com: sources can run tofu init in CI using a keyless octo-sts token. tfm-oce-cell (gke, cloudsql, pgcloudsql) and tfm-oce-tenant (service-agents) cannot adopt tfm-copier-template until CI can fetch their private module sources.
Callers that use the input must pin a release tag and grant id-token: write next to contents: read. The trust policy admits only opentofu.yml at refs/tags/X.Y.Z.
Behavior change for every caller
The job no longer declares its own permissions block. It runs with exactly what the caller grants. A probe run (https://github.com/openCoreEMR/github-workflows-public/actions/runs/47220042122) failed at startup with "The nested job 'oidc' is requesting 'id-token: write', but is only allowed 'id-token: none'" even though an if: skipped that job. A second probe (https://github.com/openCoreEMR/github-workflows-public/actions/runs/47220189879) showed a job with no permissions block gets contents: read only from a contents: read caller and gets the OIDC token when the caller grants it. The README already requires callers to declare permissions. The probe branch is deleted.
Security and cleanup
Checkout sets persist-credentials: false for all callers. Nothing in the workflow pushes.
The token is removed from git config right after tofu init, before validate and test run module code. octo-sts/action also revokes it at job end.
Documentation
The README documentation now covers the new input, the required permissions, and how the token exchange works.
Testing
It was tested with actionlint, and the selftest's scripts job (run locally too) covers the OIDC guard and the rewrite and cleanup with a fake token. The real octo-sts exchange is not tested. A PR cannot reach it because the policy admits only tags. First real proof is tfm-oce-cell adopting the template after the release.
Refs #64 (its "done when" also needs tfm-oce-cell and tfm-oce-tenant to adopt the template, so this does not close it)