Open-sourcing one directory of a private monorepo
Copybara publishes the Driverforge SDK from a private monorepo. Keeping private references out of the public history takes checks beyond the file allowlist.
Our open-source SDK lets developers instrument Control4 drivers. We develop it in a private monorepo alongside the agent it communicates with and their shared libraries. Keeping that code together lets us change and test both sides without manually copying updates into a separate public repository.
We publish the SDK through Copybara, Google's code-transformation and sync tool. It reads a selected subtree and reproduces its commits in a public mirror. Our documentation site uses the same arrangement, and the CLI is next.
Only the selected subtree may reach the mirror. Restricting file paths is straightforward, but commits also carry messages written for an internal audience. PR titles and release notes can contain private references too, so we needed checks on the text as well as the files.
An allowlist is a security boundary
Each mirror has two Copybara workflows: an outbound sync and an inbound import. The outbound workflow restricts what it reads with an origin glob:
# ALLOWLIST: only the SDK subtree is ever read. Anything outside it
# is structurally incapable of reaching the mirror. Never make this a denylist.
origin_files = glob(["sdk/**"]),
A core.move transformation then moves that subtree to the public repository's root. The inbound workflow reverses the mapping: it reads a public PR and can write only inside the SDK subtree in the private repository. The Copybara configuration and the workflows that run it live outside the published subtree.
That boundary also determines where we put files that must stay private. A development signing key lives outside the published subtree, so the sync can't read it. Keeping it there avoids having to maintain an exclusion inside an otherwise public directory.
The mapping lets us keep public CI beside the code it tests. A file at <subtree>/.github/workflows/ is inactive in the monorepo because GitHub only runs workflows at the repository root. After the sync, it lands at .github/workflows/ and becomes the mirror's CI. Each mirror has a 32-line workflow that runs tests and a build in a public container image without secrets, allowing it to run on contributions from forks.
The gate that simulates the scrubbers
We plan work in Jira and put the issue number at the end of a commit subject, for example fix: retire unused heartbeat keys (ABC-890). Squash merges append a PR number, and code comments sometimes reference issues too. Within the team, those links provide context for a change.
Public readers can't open those issues. Leaving the references in place points them to an explanation they can't read, so we exclude private references from mirrored code and messages.
For commit subjects, the outbound sync strips the issue suffix and the PR number. Messages without either pass through unchanged.
References elsewhere need a separate check. An issue number in a PR body or halfway through a commit message can reach the squash-merge commit without matching either suffix scrubber. A title can also change after review. We want authors to fix those cases before merge, while the PR is still editable. The configuration records that requirement:
The sync is effectively a deploy; it must never be the first place a deterministic check fails.
A required CI job reads the PR title and body along with every commit message on the branch. It applies a sed equivalent of the Copybara scrubber expressions and fails if an internal reference remains, asking the author to move it into the parenthesised suffix or remove it. The job also runs on the PR edited event, so a title changed after a successful check is checked again.
Copybara provides a backstop for changes that arrive outside the PR workflow. It replaces any remaining bare internal reference with [internal], preserving the surrounding sentence.
Published files have a stricter rule: they must contain no internal references. CI checks before merge, a review bot scans added lines so it can identify the introducing PR, and a post-sync check scans the mirror. A persistent bot comment also lists which files a private PR will publish, making the public effect visible during review.
After each sync, and daily even when nothing changes, the pipeline clones the published mirror and audits it directly. It checks for forbidden paths, private references in files and recent commit history, and secrets anywhere in history. The forbidden-path list includes top-level private monorepo directories, catching a failed re-root that copied the raw tree. This audit can detect an error in the earlier checks because it inspects their published output.
Vendoring the tool that has write access
The sync runner uses our own container image with a pinned Copybara release jar. The image build verifies the download against a recorded SHA-256. Upgrading requires changing the version and hash, then rebuilding the image; sync workflows reference its version tag.
Third-party GitHub Actions are pinned to commit SHAs, and the secrets scanner is pinned by image digest. We make one documented exception for the build action we publish to customers: our workflows consume its floating v1 tag to exercise the same update behaviour customers receive.
Copybara returns exit code 4 when there's nothing new to migrate. That's common for the daily catch-up run, so the wrapper treats both 0 and 4 as success and logs which occurred. Otherwise an already-current mirror would produce a daily failure notification.
Contributions come back through the same machine
Contributors can open pull requests on the mirrors. An import workflow takes the public PR number and runs the inbound Copybara transformation, creating a private PR with the change moved into the SDK subtree. It uses the same pinned runner and accepts exit code 4.
Two Copybara behaviours needed explicit configuration. Branch-name templates substitute only ${CONTEXT_REFERENCE}, which is the PR number for a PR origin. They don't support the richer labels available in PR titles and bodies.
We also set set_rev_id = False on the inbound workflow. Without it, a contribution that synced back to the mirror carried two origin-revision trailers: one for the private commit and another for the original public PR commit. Removing the inbound trailer leaves an unambiguous mapping back to the private source.
Once the imported change lands privately and syncs back out, a finalize workflow closes the public PR with an accepted label and a link to the landed commit. GitHub displays it as closed because the original PR wasn't merged there. The bot comment and contributing guide explain that process.
The guide also identifies a vendored shared-library file whose canonical copy lives elsewhere in the monorepo. During import, edits to that file are re-rooted to its source location.
Releasing from the mirror
We create release tags, run release builds, and publish GitHub Releases on the public mirror.
This makes build provenance useful to someone outside the company. A build provenance attestation binds an artifact to the workflow run and source commit that produced it. A reader can check it with gh attestation verify and open the referenced repository. If the attestation pointed to our private monorepo, they couldn't inspect that source.
A mirror commit has a different SHA from its private original. Creating the release on the mirror also avoids having to map a private tag to the corresponding public commit.
What it takes to run
The figures below describe the SDK mirror. The documentation site uses the same machinery from a different monorepo; the CLI mirror is planned next.
| Item | Value |
|---|---|
| Copybara configuration | 2 workflows per mirror: one outbound, one inbound |
| Published surface | 22 files, ~1,000 lines of Lua, of 188 tracked files repo-wide |
| Leak defence layers | 4 (structure, pre-merge gates, sync scrubbers, post-sync mirror scan) |
| Pinned third-party actions / pinned scanners | 9 by commit SHA / 2 by digest or checksum |
| Sync cadence | on push to the subtree, plus a daily catch-up cron |
| Machinery commits, first sync to current form | 20, over 7 weeks |
Counts are from the current main branch of the private repository; the commit count covers the sync, import and finalize workflows plus the Copybara configuration.
We maintain the scrubber rules in two regex dialects, one for Copybara and one for the CI simulation. Changes need to keep them aligned. Each checking layer also needs maintenance, and the daily scan continues failing if a leak remains anywhere it checks in mirror history. A later clean sync doesn't resolve an earlier leak.
Working in private with a public history
The SDK stays beside the agent and shared libraries during development, with one test suite exercising them together. Merging a change triggers publication without a separate copy step.
On the public side, readers can follow individual commits and contribute through pull requests. Releases point to source they can inspect. Copybara handles the file and history transformations; the surrounding checks determine whether the result is suitable to publish.