Skip to content

feat(opentofu): add private-module-sources input - #65

Merged
kojiromike merged 1 commit into
mainfrom
opentofu-private-module-sources
Dec 4, 2026
Merged

kojiromike merged 1 commit into
mainfrom
opentofu-private-module-sources

Conversation

@kojiromike

Copy link
Copy Markdown
Contributor

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)

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
@coderabbitai

coderabbitai Bot commented Dec 3, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central YAML (base), Organization UI (inherited)
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 4b2c9c47-dbcd-4b70-afa3-546b0e70a32e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@kojiromike

Copy link
Copy Markdown
Contributor Author

A CodeRabbit CLI review of this PR at 6bb8d62 found nothing to fix.

Head reviewed 6bb8d6298363737c6e37e766935e7efe38aa7b14
Base 2854c3d5c41f931fa9f5a22d5a5f1ca2e8481480 (merge base with main)
Command coderabbit review --agent --deep --fresh --committed --base-commit 2854c3d5c41f931fa9f5a22d5a5f1ca2e8481480
CLI 0.9.7
Finished 2026-12-04 02:13 UTC
Findings 0, actionable 0
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"
}

@kojiromike

Copy link
Copy Markdown
Contributor Author

@coderabbitai approve

@coderabbitai

coderabbitai Bot commented Dec 4, 2026

Copy link
Copy Markdown
Action performed

Comments resolved and changes approved.

@kojiromike
kojiromike merged commit fc45922 into main Dec 4, 2026
6 checks passed
@kojiromike
kojiromike deleted the opentofu-private-module-sources branch December 4, 2026 02:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant