- How the pieces fit together
- One-time setup
- Releasing
- Updating Betterleaks
- Changing the ruleset
- Other dependencies
- Adding a check
- Local development
- Repository layout
This repository is the only source. A release publishes, from one version number:
| Artifact | Where | Built from | Consumed by |
|---|---|---|---|
ngchecks_<version>_<os>_<arch>.tar.gz + checksums.txt |
GitHub release v<version> |
scripts/build-release.sh |
the Composer plugin |
netgen/ngchecks |
Packagist (reads the v<version> tag of this repository) |
composer.json, composer/ |
PHP projects |
@netgen/ngchecks + @netgen/ngchecks-<os>-<arch> |
npm | npm/, scripts/build-npm.sh |
Node projects |
ghcr.io/netgen/ngchecks:<version>, :<major>.<minor>, :<major> |
GitHub Container Registry | Dockerfile |
CI pipelines |
Every archive, npm platform package and image contains the same two binaries:
ngchecks (built from cmd/ and internal/, with ruleset/betterleaks.toml embedded)
and the Betterleaks release pinned in betterleaks.env (downloaded from the Betterleaks
GitHub release and verified against the checksums in betterleaks.env).
How each package gets the binaries:
- Composer: the package on Packagist contains only the plugin (
composer/) and thevendor/bin/ngcheckswrapper (everything else isexport-ignored in.gitattributes). Aftercomposer install/composer update, the plugin downloads the GitHub release archive of the installed version for the current platform intovendor/netgen/ngchecks/var/<os>_<arch>/, after checking it against the release'schecksums.txt. That's why the GitHub release is created together with the tag: Packagist can't offer a version before its binaries exist. Aftercomposer require/composer updatein an interactive terminal, when the package was not invendor/before (not listed invendor/composer/installed.jsonwhen the plugin is activated), the plugin also runsngchecks init. It never does oncomposer install, so a fresh clone or a CI install never changes project files. - npm:
@netgen/ngcheckscontains a small Node launcher (npm/bin/ngchecks.js) and lists the four platform packages as optional dependencies, which the package managers install only for the matchingos/cpu. No install scripts are involved, so it works with pnpm and Yarn setups that block them. - Docker: the image compiles ngchecks from source and downloads Betterleaks, both for the target architecture.
Projects run it from their hook managers with the same command: a CaptainHook action
vendor/bin/ngchecks secrets --staged, or ngchecks secrets --staged in .husky/pre-commit.
ngchecks init (internal/setup/) writes these and the GitHub Actions workflow, and prints
the Bitbucket and GitLab steps.
No credentials are stored in GitHub. Each service authenticates the release workflow on its own:
| Service | Secret in GitHub | How publishing is authorized |
|---|---|---|
| GitHub release and tag | none | the workflow's automatic GITHUB_TOKEN (contents: write) |
| ghcr.io Docker image | none | the workflow's automatic GITHUB_TOKEN (packages: write) |
| Packagist | none | Packagist reads the public repository itself; a GitHub webhook tells it about new tags |
| npm | none | trusted publishing: each npm package trusts the release.yml workflow of netgen/ngchecks (OIDC, id-token: write) |
npm trusted publishing can only be configured for packages that already exist, so the first npm release is published by hand (step 5). npm no longer offers long-lived tokens that could do this from CI instead: tokens that skip 2FA lose direct publishing in 2027.
The repository is github.com/netgen/ngchecks. It must stay public: Packagist and npm provenance need a public repository.
- Settings → Actions → General → Workflow permissions: the workflows declare the
permissions they need per job (
contents: write,packages: write,id-token: write), which works with the default "Read repository contents" setting. Check that the organization allows members to create public packages (organization Settings → Packages), for the Docker image. - Protect
masterand make the CI checks required.
The netgen vendor name is protected on Packagist: only maintainers of an existing
netgen/* package can submit packages under it.
- Log in to packagist.org with such an account, preferably
through GitHub ("Login with GitHub"), and submit
https://github.com/netgen/ngchecks. - Make Packagist update on every push, so a release is available within a minute:
- with a GitHub login: make sure the Packagist application has access to the
netgenorganization (GitHub → Settings → Applications → Authorized OAuth Apps → Packagist), then use "trigger a manual account sync" on Packagist; - or add the webhook by hand: repository Settings → Webhooks → Add webhook, Payload URL
https://packagist.org/api/github?username=<packagist username>, Content typeapplication/json, Secret: the API token from the Packagist profile page, event "Just the push event".
- with a GitHub login: make sure the Packagist application has access to the
- The package page must not show a warning about not being auto-updated.
- Add the other maintainers on the package page.
Publishing the first version by hand (step 5) needs an npm account that is a member
of the @netgen organization, allowed to publish packages in it, and with two-factor
authentication enabled. Nothing is configured in GitHub.
The first release creates the ngchecks container package in the netgen organization,
private by default. On GitHub: organization → Packages → ngchecks → Package settings →
Change visibility → Public. Pipelines on Bitbucket and GitLab pull it without credentials.
-
Release
1.0.0-rc.1with the Release workflow (see Releasing). The GitHub release, Packagist and Docker work; the npm job fails, because the packages don't exist yet. -
Publish the npm packages of that release by hand, from the release archives:
gh release download v1.0.0-rc.1 --repo netgen/ngchecks --dir dist scripts/build-npm.sh 1.0.0-rc.1 npm login for package in dist/npm/ngchecks-* dist/npm/ngchecks; do npm publish "$package" --access public --tag next # asks for a 2FA code done
The platform packages go first,
dist/npm/ngchecks(the launcher) last. -
For each of the five packages (
@netgen/ngchecks,@netgen/ngchecks-darwin-arm64,-darwin-x64,-linux-arm64,-linux-x64): npmjs.com → the package → Settings → Trusted publishing → GitHub Actions, with organizationnetgen, repositoryngchecks, workflow filenamerelease.yml, no environment, and allownpm publish. -
Within 2 days (npm expires trusted publisher configurations that were never used), release the next version, e.g.
1.0.0-rc.2or1.0.0, and check that the npm job publishes all packages. If a configuration expired, delete it, add it again and release. -
Recommended: in the same package settings, Publishing access → "Require two-factor authentication and disallow tokens", so only the workflow and 2FA-authenticated maintainers can publish.
-
Try the release candidate on a PHP and a Node project, following installation.md. Composer installs pre-releases with
composer require --dev netgen/ngchecks:^1.0@rc, npm with@netgen/ngchecks@next. -
Release
1.0.0.
Versions follow semver, one version for all artifacts:
- patch: bug fixes, fewer false positives;
- minor: new rules, new options. New rules can report findings in code that passed before, but only for new commits (pull requests and hooks scan new changes only);
- major: breaking CLI or config changes, e.g. a Betterleaks major version.
Steps:
- Make sure
masteris green and contains what should be released. - GitHub → Actions → Release → Run workflow on
master, version1.2.3(nov). Pre-releases like1.3.0-rc.1are marked as such on GitHub, published with thenexttag on npm and only get their exact tag on Docker. - The workflow:
- runs the linters and tests;
- builds the archives and creates the GitHub release
v1.2.3with them (this creates the tag, Packagist picks it up within minutes); - builds and pushes the Docker image for amd64 and arm64;
- builds and publishes the npm packages, platform packages first.
- Check: the GitHub release has 4 archives and
checksums.txt; Packagist lists the version;npm view @netgen/ngchecks version;docker pull ghcr.io/netgen/ngchecks:1.2.3.
Projects pick up the release with composer update netgen/ngchecks or
npm update @netgen/ngchecks; CI images on :1 get it on their next run.
If a release job fails:
- GitHub release job: nothing was published, fix the problem and run the workflow again.
- Docker or npm job: the GitHub release (and the Composer package) exists. Use "Re-run
failed jobs". If some npm packages were already published, the re-run fails on them:
publish the remaining ones by hand from the release archives, as in
step 5.2 of the first release
(
--tag nextonly for pre-releases). - A bad release: release a fixed version. Don't delete tags or GitHub releases:
Composer installs of that version would break. On npm, prefer
npm deprecateover unpublishing.
The Betterleaks update check workflow runs weekly and opens an issue when a new Betterleaks release exists. Read its release notes, then:
-
Pin the new version (rewrites
betterleaks.envwith the published checksums):scripts/update-betterleaks.sh 1.10.2
-
Run the tests:
make testTestRulesetContainsBuiltInGlobalExpressionsfails when the built-in globalprefilterorfilterchanged. The ruleset contains copies of them because extending a config replaces these expressions. Print the new ones with.cache/betterleaks/<os>_<arch>/betterleaks config show | head -60and update the copies at the top ofruleset/betterleaks.toml.TestRulesetIgnoresNonLeaksfails when new built-in rules report something in the Symfony / Node defaults; adjust the ruleset filters.
-
Scan a few real projects with the new version (see Local development) and compare the findings with the previous release.
-
Open a pull request, then release (minor version: new built-in rules mean new findings).
A new Betterleaks major version (v2 is in release candidates) changes the CLI
(--staged and --log-opts are replaced, the JUnit and SARIF reports and baselines are
removed), the config format and the ignore file format. Plan it as an ngchecks major
release: update the arguments in internal/secrets/scanner.go, the report parsing in
internal/secrets/finding.go, the ruleset and the tests.
ruleset/betterleaks.toml applies to every project on its next update, so false
positives cost everyone time. Project-specific rules belong in the project's
.betterleaks.toml.
- Edit
ruleset/betterleaks.toml. Rules use the Betterleaks config format; always setkeywords(lowercase) so the regex only runs on candidate content. - Add cases to
internal/secrets/ruleset_test.go: at least one leak the rule must find (TestRulesetDetectsLeaks) and the common legitimate values it must not report (TestRulesetIgnoresNonLeaks). Never use real secrets in tests; the repository's own.betterleaks.tomlexcludes_test.gofiles from its scan. make test, try it on real projects, open a pull request, release.
Dependabot opens weekly pull requests for:
- Go modules (
go.mod); - the Docker base images, pinned by digest in the
Dockerfile; - the GitHub Actions used in the workflows.
Merge them when CI is green; they are released with the next release. To move to a new
Go version, update the go line in go.mod and the golang image in the Dockerfile.
For example ngchecks cve:
- Implement it in a new package under
internal/and register the command ininternal/cli/cli.go, following the exit codes0passed,1problems found,2error. - If it needs an external tool, bundle it like Betterleaks: pin it with checksums, download
it in
scripts/build-release.shand theDockerfile, add it to the archive file list and to the npm platform packages (scripts/build-npm.sh), and to the files checked bycomposer/src/BinaryInstaller.php. - Document it in the README and
docs/installation.md.
Requirements: Go (version in go.mod), git, a POSIX shell; Node.js for the npm packages,
Docker for the image.
make test # downloads the pinned Betterleaks into .cache/, runs all tests
make lint # gofmt + go vet
make build # bin/ngchecks + bin/betterleaks for this machine
bin/ngchecks secrets --history ../some-project
make release VERSION=1.2.3 # dist/ngchecks_1.2.3_<platform>.tar.gz + checksums.txt
make npm VERSION=1.2.3 # dist/npm/*, needs the archives
make docker VERSION=1.2.3 # image for this machinego run ./cmd/ngchecks needs NGCHECKS_BETTERLEAKS=.cache/betterleaks/<os>_<arch>/betterleaks,
because the binary is looked up next to the ngchecks executable.
Testing the distributions without publishing:
- Composer: serve the
dist/archives in av<version>/directory over HTTP, require the package from a path repository with"versions": {"netgen/ngchecks": "<version>"}, and runcomposer requirewithNGCHECKS_DOWNLOAD_URL=http://<host>(setconfig.secure-httptofalsefor plain HTTP).NGCHECKS_VERSIONmakes the plugin download another release, e.g. for a development version. The plugin only runsngchecks initin an interactive terminal; from a script, useprintf 'y\n' | script -qec "composer require --dev netgen/ngchecks:<version>" /dev/null(Linuxscript) to get one and answer the trust prompt. - npm: publish
dist/npm/*to a local registry such as Verdaccio (raise itsmax_body_size, the platform packages are about 11 MB) and install from it with--registry.
| Path | Content |
|---|---|
cmd/ngchecks/ |
entry point |
internal/cli/ |
command line parsing and output |
internal/secrets/ |
the secrets scan: Betterleaks invocation, config composition, ignore file, suppressions |
internal/setup/ |
ngchecks init: CaptainHook / Husky hooks and CI pipelines of a project |
internal/git/, internal/ci/, internal/report/ |
git commands, CI platform detection, JUnit / JSON / GitHub annotation output |
internal/betterleaks/ |
locating the bundled Betterleaks binary |
ruleset/betterleaks.toml |
the built-in ruleset, embedded in the binary |
betterleaks.env |
pinned Betterleaks version and checksums |
composer.json, composer/ |
the Composer package: plugin and vendor/bin/ngchecks wrapper |
npm/ |
the @netgen/ngchecks package (launcher); platform packages are generated |
scripts/ |
fetching Betterleaks, building release archives and npm packages, updating Betterleaks |
Dockerfile |
the CI image |
.github/workflows/ |
CI, release, Betterleaks update check |