From 874182ca6e52f5e239591d7ba14a526f062f927a Mon Sep 17 00:00:00 2001 From: fadwen <110697945+fadwen@users.noreply.github.com> Date: Tue, 24 Nov 2026 07:41:54 +0000 Subject: [PATCH] chore: sync PowerShell standards 2.0.0 --- .../skills/powershell-ci-pipeline/SKILL.md | 4 +- .../powershell-credential-scan/SKILL.md | 122 ++++++++++++++++++ .../skills/powershell-ci-pipeline/SKILL.md | 4 +- .../powershell-credential-scan/SKILL.md | 122 ++++++++++++++++++ .../powershell-cicd.instructions.md | 63 ++++++++- .../skills/powershell-ci-pipeline/SKILL.md | 4 +- .../powershell-credential-scan/SKILL.md | 122 ++++++++++++++++++ 7 files changed, 437 insertions(+), 4 deletions(-) create mode 100644 .agents/skills/powershell-credential-scan/SKILL.md create mode 100644 .claude/skills/powershell-credential-scan/SKILL.md create mode 100644 .github/skills/powershell-credential-scan/SKILL.md diff --git a/.agents/skills/powershell-ci-pipeline/SKILL.md b/.agents/skills/powershell-ci-pipeline/SKILL.md index 470932a..af7b69c 100644 --- a/.agents/skills/powershell-ci-pipeline/SKILL.md +++ b/.agents/skills/powershell-ci-pipeline/SKILL.md @@ -35,4 +35,6 @@ holds the rules, a pull request workflow, and a publishing workflow. Say which files you added or changed, what each job runs, and what you were able to run locally. A workflow is not verified until it has run on the CI system; say so, and do not claim that it passes. -Do not add publishing, signing, or deployment steps unless the user asked for them. +Do not add publishing, signing, or deployment steps unless the user asked for them. When the +project has no credential scan (CIC-23), say so and name the `powershell-credential-scan` skill. Do +not add a scan unasked: it uses the project's CI time, and the user chooses the scanner. diff --git a/.agents/skills/powershell-credential-scan/SKILL.md b/.agents/skills/powershell-credential-scan/SKILL.md new file mode 100644 index 0000000..89b264b --- /dev/null +++ b/.agents/skills/powershell-credential-scan/SKILL.md @@ -0,0 +1,122 @@ +--- +name: powershell-credential-scan +description: Add a credential scan to the CI of a PowerShell project with betterleaks, gitleaks, or trufflehog, and deal with what it reports. Use when asked to add, set up, or repair secret scanning, credential scanning, or leak detection, or to handle the findings of such a scan. +--- + +# Add a credential scan + +A credential that was committed stays in the repository after the commit that removes it. This +skill adds a scan of the history and the files to the project's CI (CIC-23), with the scanner that +the user chooses, and deals with what the first run reports. + +Read these first, unless they are already loaded: + +- `.github/copilot-instructions.md`, or `AGENTS.md` if the repository has no such file +- `.github/instructions/powershell-cicd.instructions.md` +- `.github/instructions/powershell-security.instructions.md` + +Every statement about a scanner below was measured with betterleaks 1.10.1, gitleaks 8.30.1, and +trufflehog 3.99.9 on Linux, macOS, and Windows. + +## Steps + +1. Look for a scan that the project already has: a workflow job or a hook that runs betterleaks, + gitleaks, trufflehog, or another scanner, and files such as `.betterleaks.toml`, + `.gitleaks.toml`, and `.gitleaksignore`. A scan that works is left as it is. Do not replace it, + add a second one beside it, or move it to the form below unless the user asks for that. +2. Ask the user which scanner to use, and say that the scan runs on every pull request and every + push to the default branch, which uses the project's CI time. Do not choose for them. The + three differ in what they report: + + | | betterleaks | gitleaks | trufflehog | + | --- | --- | --- | --- | + | A quoted word after such a name, as in `$password = 'qwerty'` | Reported | Not reported | Not reported | + | A quoted random value after such a name | Reported | Reported for some values and not for others | Not reported | + | `$password = [System.Security.SecureString]::new()` | Reported without the installed configuration | Not reported | Not reported | + | A key in the form of a known service | Reported | Reported | Reported | + | Leaving out one finding | Fingerprint in `.betterleaksignore` | Fingerprint in `.gitleaksignore` | Fingerprint in `.trufflehogignore`, which the scan script reads | + +3. Install the scan with the installer of the standards repository, from a clone at the reference + that the project's sync workflow names (`STANDARDS_REPO` and `STANDARDS_REF`), or `main`. Give + the path of the project and the scanner that the user chose, here gitleaks: + + ```powershell + ./Tools/Install-CopilotStandards.ps1 -ProjectPath '../MyModule' -IncludeCredentialScan gitleaks + ``` + + It writes `.github/scripts/Invoke-CredentialScan.ps1`, `.github/workflows/credential-scan.yml`, + and the configuration of the scanner in the root of the project. The script belongs to the + standards and later updates replace it. The workflow and the configuration belong to the + project, and a file that is already there is not replaced. +4. When the project has one workflow that its release also runs, move the job from + `credential-scan.yml` into that workflow with its three `env` values and remove the separate + file, so that a release cannot go out past the scan. Keep `fetch-depth: 0`: the script refuses + a clone that does not hold the whole history. +5. Say that the ignore file, the configuration, the scan script, and the workflow decide what the + scan reports, and that a pull request runs its own copies of them, so a change can leave out + the finding that it adds. When the project has more than one maintainer, offer to require a + review for those paths with entries in its CODEOWNERS file, here for gitleaks: + + ```text + /.gitleaks.toml @owner + /.gitleaksignore @owner + /.github/scripts/Invoke-CredentialScan.ps1 @owner + /.github/workflows/credential-scan.yml @owner + ``` + + Put them after the other lines, because the last pattern that matches a file decides, and say + that the entries require nothing until the branch rule "Require review from Code Owners" is + on. Do not turn that rule on unasked. When the project has one maintainer, say that no such + rule binds the author of a change, and that the warning which the scan writes in every run, + "Left out of this scan", is the check to read. +6. Run the scan. On a computer where the scanner may run: + + ```powershell + ./.github/scripts/Invoke-CredentialScan.ps1 -Scanner gitleaks + ``` + + The script downloads the scanner, and an application control policy can refuse to start a + downloaded program. Do not look for a way around the policy: push the branch and read the + result of the workflow instead. +7. Read every finding, as the next section says, until the scan passes. Then report. + +## Reading a finding + +The scan reports a place, never a value: the rule, the file, the line, the commit for a finding in +the history, and a fingerprint. Look at the place itself, with `git show :` for the +history. + +- **A real credential.** Tell the user at once, and that it has to be revoked at the service that + issued it before anything else. Removing it from the file does not remove it from the history, + and everyone who can read the repository can read it there. Only after it is revoked does its + fingerprint go into the ignore file, with a comment that says so. Rewriting the history is the + user's decision, not a step of this skill. +- **A placeholder in a file**, such as a password in a test or a sample. Prefer changing the value + so that the scanner no longer reports it: build it at run time, or use a value that is not in + the form of a credential. +- **A placeholder in the history.** A commit does not change, so the value cannot be changed + there. Its fingerprint goes into the ignore file, under a comment that says what it is. +- **A form that is never a credential**, reported in many places. For betterleaks and gitleaks, + add an `[[allowlists]]` entry to the configuration that names the rule and the form. gitleaks + refuses a configuration that names a rule which it does not have. For trufflehog, leave a path + out in `.trufflehog-exclude.txt` only when nothing in that path can be a credential. + +An entry in an ignore file or an exception in a configuration MUST NOT be added to make the scan +pass. Each one is a finding that was read. A rule MUST NOT be switched off with `disabledRules`, +replaced by a rule of the same name, or filtered for that either: the scan runs again without the +configuration, and its warning counts every place that the configuration leaves out. Show the +user the list before it is committed: the user decides what is left out. + +To change the scanner later, change the three `env` values of the workflow to the name, the +version, and the SHA-256 of the archive for the runner, as the checksum file of that release gives +it, and add the configuration of the new scanner. To change the version, change the version and +the hash together and read what the new version reports: its built-in rules belong to it. The +script supports betterleaks 1.x, gitleaks 8.x, and trufflehog 3.x. + +## Report + +Say which scanner the user chose and which files were added or changed. List every finding of the +first run with its place and what was done about it: revoked, changed, or left out, with the +reason. Quote the "Left out of this scan" warning of the last run, so that the user sees how much +the scan does not report. Say whether the scan was run on this computer or only in the workflow, and what its last +run reported. If a real credential was found, say so first. diff --git a/.claude/skills/powershell-ci-pipeline/SKILL.md b/.claude/skills/powershell-ci-pipeline/SKILL.md index 470932a..af7b69c 100644 --- a/.claude/skills/powershell-ci-pipeline/SKILL.md +++ b/.claude/skills/powershell-ci-pipeline/SKILL.md @@ -35,4 +35,6 @@ holds the rules, a pull request workflow, and a publishing workflow. Say which files you added or changed, what each job runs, and what you were able to run locally. A workflow is not verified until it has run on the CI system; say so, and do not claim that it passes. -Do not add publishing, signing, or deployment steps unless the user asked for them. +Do not add publishing, signing, or deployment steps unless the user asked for them. When the +project has no credential scan (CIC-23), say so and name the `powershell-credential-scan` skill. Do +not add a scan unasked: it uses the project's CI time, and the user chooses the scanner. diff --git a/.claude/skills/powershell-credential-scan/SKILL.md b/.claude/skills/powershell-credential-scan/SKILL.md new file mode 100644 index 0000000..89b264b --- /dev/null +++ b/.claude/skills/powershell-credential-scan/SKILL.md @@ -0,0 +1,122 @@ +--- +name: powershell-credential-scan +description: Add a credential scan to the CI of a PowerShell project with betterleaks, gitleaks, or trufflehog, and deal with what it reports. Use when asked to add, set up, or repair secret scanning, credential scanning, or leak detection, or to handle the findings of such a scan. +--- + +# Add a credential scan + +A credential that was committed stays in the repository after the commit that removes it. This +skill adds a scan of the history and the files to the project's CI (CIC-23), with the scanner that +the user chooses, and deals with what the first run reports. + +Read these first, unless they are already loaded: + +- `.github/copilot-instructions.md`, or `AGENTS.md` if the repository has no such file +- `.github/instructions/powershell-cicd.instructions.md` +- `.github/instructions/powershell-security.instructions.md` + +Every statement about a scanner below was measured with betterleaks 1.10.1, gitleaks 8.30.1, and +trufflehog 3.99.9 on Linux, macOS, and Windows. + +## Steps + +1. Look for a scan that the project already has: a workflow job or a hook that runs betterleaks, + gitleaks, trufflehog, or another scanner, and files such as `.betterleaks.toml`, + `.gitleaks.toml`, and `.gitleaksignore`. A scan that works is left as it is. Do not replace it, + add a second one beside it, or move it to the form below unless the user asks for that. +2. Ask the user which scanner to use, and say that the scan runs on every pull request and every + push to the default branch, which uses the project's CI time. Do not choose for them. The + three differ in what they report: + + | | betterleaks | gitleaks | trufflehog | + | --- | --- | --- | --- | + | A quoted word after such a name, as in `$password = 'qwerty'` | Reported | Not reported | Not reported | + | A quoted random value after such a name | Reported | Reported for some values and not for others | Not reported | + | `$password = [System.Security.SecureString]::new()` | Reported without the installed configuration | Not reported | Not reported | + | A key in the form of a known service | Reported | Reported | Reported | + | Leaving out one finding | Fingerprint in `.betterleaksignore` | Fingerprint in `.gitleaksignore` | Fingerprint in `.trufflehogignore`, which the scan script reads | + +3. Install the scan with the installer of the standards repository, from a clone at the reference + that the project's sync workflow names (`STANDARDS_REPO` and `STANDARDS_REF`), or `main`. Give + the path of the project and the scanner that the user chose, here gitleaks: + + ```powershell + ./Tools/Install-CopilotStandards.ps1 -ProjectPath '../MyModule' -IncludeCredentialScan gitleaks + ``` + + It writes `.github/scripts/Invoke-CredentialScan.ps1`, `.github/workflows/credential-scan.yml`, + and the configuration of the scanner in the root of the project. The script belongs to the + standards and later updates replace it. The workflow and the configuration belong to the + project, and a file that is already there is not replaced. +4. When the project has one workflow that its release also runs, move the job from + `credential-scan.yml` into that workflow with its three `env` values and remove the separate + file, so that a release cannot go out past the scan. Keep `fetch-depth: 0`: the script refuses + a clone that does not hold the whole history. +5. Say that the ignore file, the configuration, the scan script, and the workflow decide what the + scan reports, and that a pull request runs its own copies of them, so a change can leave out + the finding that it adds. When the project has more than one maintainer, offer to require a + review for those paths with entries in its CODEOWNERS file, here for gitleaks: + + ```text + /.gitleaks.toml @owner + /.gitleaksignore @owner + /.github/scripts/Invoke-CredentialScan.ps1 @owner + /.github/workflows/credential-scan.yml @owner + ``` + + Put them after the other lines, because the last pattern that matches a file decides, and say + that the entries require nothing until the branch rule "Require review from Code Owners" is + on. Do not turn that rule on unasked. When the project has one maintainer, say that no such + rule binds the author of a change, and that the warning which the scan writes in every run, + "Left out of this scan", is the check to read. +6. Run the scan. On a computer where the scanner may run: + + ```powershell + ./.github/scripts/Invoke-CredentialScan.ps1 -Scanner gitleaks + ``` + + The script downloads the scanner, and an application control policy can refuse to start a + downloaded program. Do not look for a way around the policy: push the branch and read the + result of the workflow instead. +7. Read every finding, as the next section says, until the scan passes. Then report. + +## Reading a finding + +The scan reports a place, never a value: the rule, the file, the line, the commit for a finding in +the history, and a fingerprint. Look at the place itself, with `git show :` for the +history. + +- **A real credential.** Tell the user at once, and that it has to be revoked at the service that + issued it before anything else. Removing it from the file does not remove it from the history, + and everyone who can read the repository can read it there. Only after it is revoked does its + fingerprint go into the ignore file, with a comment that says so. Rewriting the history is the + user's decision, not a step of this skill. +- **A placeholder in a file**, such as a password in a test or a sample. Prefer changing the value + so that the scanner no longer reports it: build it at run time, or use a value that is not in + the form of a credential. +- **A placeholder in the history.** A commit does not change, so the value cannot be changed + there. Its fingerprint goes into the ignore file, under a comment that says what it is. +- **A form that is never a credential**, reported in many places. For betterleaks and gitleaks, + add an `[[allowlists]]` entry to the configuration that names the rule and the form. gitleaks + refuses a configuration that names a rule which it does not have. For trufflehog, leave a path + out in `.trufflehog-exclude.txt` only when nothing in that path can be a credential. + +An entry in an ignore file or an exception in a configuration MUST NOT be added to make the scan +pass. Each one is a finding that was read. A rule MUST NOT be switched off with `disabledRules`, +replaced by a rule of the same name, or filtered for that either: the scan runs again without the +configuration, and its warning counts every place that the configuration leaves out. Show the +user the list before it is committed: the user decides what is left out. + +To change the scanner later, change the three `env` values of the workflow to the name, the +version, and the SHA-256 of the archive for the runner, as the checksum file of that release gives +it, and add the configuration of the new scanner. To change the version, change the version and +the hash together and read what the new version reports: its built-in rules belong to it. The +script supports betterleaks 1.x, gitleaks 8.x, and trufflehog 3.x. + +## Report + +Say which scanner the user chose and which files were added or changed. List every finding of the +first run with its place and what was done about it: revoked, changed, or left out, with the +reason. Quote the "Left out of this scan" warning of the last run, so that the user sees how much +the scan does not report. Say whether the scan was run on this computer or only in the workflow, and what its last +run reported. If a real credential was found, say so first. diff --git a/.github/instructions/powershell-cicd.instructions.md b/.github/instructions/powershell-cicd.instructions.md index a83c461..1bfc202 100644 --- a/.github/instructions/powershell-cicd.instructions.md +++ b/.github/instructions/powershell-cicd.instructions.md @@ -47,6 +47,10 @@ repository that contains PowerShell code. the code that has performance tests (TST-43). - **CIC-14** A documentation gate validates the README. The pipeline SHOULD also generate a status report and a deployment summary for each run, and keep the runbooks current. +- **CIC-23** A credential scan reads the history of every branch and tag as well as the files of + the checkout. It runs a scanner at a fixed version whose download is checked against a hash, + first finds a value that the job plants outside the repository, and writes no value that it + finds to the log. ### Jobs and triggers @@ -266,7 +270,7 @@ Windows PowerShell 5.1 both read such files. The security gate is made of these scans: -- Credential scanning, so that no secret is committed (SEC-01). +- Credential scanning, so that no secret is committed (SEC-01, CIC-23). - Static analysis for security issues. - Dependency vulnerability scanning. - Container scanning, when the build runs in containers. @@ -285,6 +289,63 @@ The documentation gate validates the README and the other documentation the proj reports that the pipeline generates are a status report for each run, a deployment summary, and updates to the runbooks. +### Credential scan (CIC-23) + +Each part of the rule answers a scan that passes while a credential is in the repository. Measured +with betterleaks 1.10.1, gitleaks 8.30.1, and trufflehog 3.99.9 on Linux, macOS, and Windows: + +- A credential stays in the history after the commit that removes it. All three scanners find it + there, also on a branch that was never merged and on a commit that only a tag holds. A checkout + of one commit hides it, so the job checks out with `fetch-depth: 0`. +- No scanner's history scan reads what a merge commit itself added. The scan of the files does. +- betterleaks and trufflehog end with exit code 0 for a folder that does not exist, and a + configuration can leave out more than was meant. The job therefore first has to find a value + in the form of a key that it makes outside the repository, put together from parts so that no + file holds it. +- A scanner does not report every value that has the form of a key. On Linux, trufflehog left out + 6 of 1,500 random values in the form of a Stripe key and 1 of 1,500 in the form of a GitHub + token, and reported each of them with `filtered_unverified` among its `--results`. Such a value + holds a word: with `code`, `user`, or `hash` in it, in any letter case, none of 100 values was + reported, and each of 3,000 values in which no three letters stand together was. The job + therefore makes several values of each form, and a rule has to report one of them. +- An exception is not the only setting that leaves a value out. In a configuration of betterleaks + or gitleaks, `disabledRules` switches a built-in rule off, a rule that the file defines + replaces the built-in rule of the same name, and a file that it extends brings exceptions of + its own. betterleaks also takes a `filter`. Under each of them the scan passed over a value + while it still found the planted ones. TOML spells each in several ways, as a quoted key or + under a header with spaces, so the scan does not read the configuration for them: it scans + again without it and counts the places that only that scan reports. +- A scanner is a release archive and not a module. Pin it by its version and by the SHA-256 of + the archive, because a release tag can be moved to other content. +- trufflehog writes every value that it finds into its output, as text and as JSON. betterleaks + and gitleaks write `REDACTED` in its place when `--redact` is given. The log of a public + repository is public (CIC-06). +- trufflehog reads the `.git` folder as files unless that folder is left out, and then reports + again what its history scan reports. + +betterleaks and trufflehog can check a value against the service that it seems to belong to, with +`--validation` and by default. The scan switches that off, with `--no-verification` for +trufflehog. What such a check sends was not measured. + +The scan reads its ignore file, its configuration, and its own script from the commit that it +scans, which on a pull request is the pull request's own copy. A change can therefore leave out +the finding that it adds. The scan guards against an accident, not against an author who means to +get past it. Two things keep what is left out in view. The scan says in every run how much the +ignore file and the configuration leave out. And a change to one of those files, or to the +workflow, is reviewed as a change to what the scan reports: where a project has a second reader, +it requires one for those paths, for example with CODEOWNERS entries and the branch rule "Require +review from Code Owners". GitHub's documentation says that an entry requires nothing without that +rule, that the code owners are taken from the base branch, and that an author cannot approve +their own pull request. In a repository with one maintainer no rule binds the author, and the +line that the scan writes is the check to read. + +The standards ship a scan that does all of this, for whichever of the three scanners the project +chooses. It is installed only on request, because its workflow uses the project's CI time: +`Install-CopilotStandards.ps1 -IncludeCredentialScan ` writes +`.github/scripts/Invoke-CredentialScan.ps1`, a workflow that runs it, and a configuration for the +scanner. The `powershell-credential-scan` skill adds the scan to a project and reads what its +first run reports. A project whose own scan works keeps it. + ### A workflow with several jobs (CIC-15 to CIC-17) ```yaml diff --git a/.github/skills/powershell-ci-pipeline/SKILL.md b/.github/skills/powershell-ci-pipeline/SKILL.md index 470932a..af7b69c 100644 --- a/.github/skills/powershell-ci-pipeline/SKILL.md +++ b/.github/skills/powershell-ci-pipeline/SKILL.md @@ -35,4 +35,6 @@ holds the rules, a pull request workflow, and a publishing workflow. Say which files you added or changed, what each job runs, and what you were able to run locally. A workflow is not verified until it has run on the CI system; say so, and do not claim that it passes. -Do not add publishing, signing, or deployment steps unless the user asked for them. +Do not add publishing, signing, or deployment steps unless the user asked for them. When the +project has no credential scan (CIC-23), say so and name the `powershell-credential-scan` skill. Do +not add a scan unasked: it uses the project's CI time, and the user chooses the scanner. diff --git a/.github/skills/powershell-credential-scan/SKILL.md b/.github/skills/powershell-credential-scan/SKILL.md new file mode 100644 index 0000000..89b264b --- /dev/null +++ b/.github/skills/powershell-credential-scan/SKILL.md @@ -0,0 +1,122 @@ +--- +name: powershell-credential-scan +description: Add a credential scan to the CI of a PowerShell project with betterleaks, gitleaks, or trufflehog, and deal with what it reports. Use when asked to add, set up, or repair secret scanning, credential scanning, or leak detection, or to handle the findings of such a scan. +--- + +# Add a credential scan + +A credential that was committed stays in the repository after the commit that removes it. This +skill adds a scan of the history and the files to the project's CI (CIC-23), with the scanner that +the user chooses, and deals with what the first run reports. + +Read these first, unless they are already loaded: + +- `.github/copilot-instructions.md`, or `AGENTS.md` if the repository has no such file +- `.github/instructions/powershell-cicd.instructions.md` +- `.github/instructions/powershell-security.instructions.md` + +Every statement about a scanner below was measured with betterleaks 1.10.1, gitleaks 8.30.1, and +trufflehog 3.99.9 on Linux, macOS, and Windows. + +## Steps + +1. Look for a scan that the project already has: a workflow job or a hook that runs betterleaks, + gitleaks, trufflehog, or another scanner, and files such as `.betterleaks.toml`, + `.gitleaks.toml`, and `.gitleaksignore`. A scan that works is left as it is. Do not replace it, + add a second one beside it, or move it to the form below unless the user asks for that. +2. Ask the user which scanner to use, and say that the scan runs on every pull request and every + push to the default branch, which uses the project's CI time. Do not choose for them. The + three differ in what they report: + + | | betterleaks | gitleaks | trufflehog | + | --- | --- | --- | --- | + | A quoted word after such a name, as in `$password = 'qwerty'` | Reported | Not reported | Not reported | + | A quoted random value after such a name | Reported | Reported for some values and not for others | Not reported | + | `$password = [System.Security.SecureString]::new()` | Reported without the installed configuration | Not reported | Not reported | + | A key in the form of a known service | Reported | Reported | Reported | + | Leaving out one finding | Fingerprint in `.betterleaksignore` | Fingerprint in `.gitleaksignore` | Fingerprint in `.trufflehogignore`, which the scan script reads | + +3. Install the scan with the installer of the standards repository, from a clone at the reference + that the project's sync workflow names (`STANDARDS_REPO` and `STANDARDS_REF`), or `main`. Give + the path of the project and the scanner that the user chose, here gitleaks: + + ```powershell + ./Tools/Install-CopilotStandards.ps1 -ProjectPath '../MyModule' -IncludeCredentialScan gitleaks + ``` + + It writes `.github/scripts/Invoke-CredentialScan.ps1`, `.github/workflows/credential-scan.yml`, + and the configuration of the scanner in the root of the project. The script belongs to the + standards and later updates replace it. The workflow and the configuration belong to the + project, and a file that is already there is not replaced. +4. When the project has one workflow that its release also runs, move the job from + `credential-scan.yml` into that workflow with its three `env` values and remove the separate + file, so that a release cannot go out past the scan. Keep `fetch-depth: 0`: the script refuses + a clone that does not hold the whole history. +5. Say that the ignore file, the configuration, the scan script, and the workflow decide what the + scan reports, and that a pull request runs its own copies of them, so a change can leave out + the finding that it adds. When the project has more than one maintainer, offer to require a + review for those paths with entries in its CODEOWNERS file, here for gitleaks: + + ```text + /.gitleaks.toml @owner + /.gitleaksignore @owner + /.github/scripts/Invoke-CredentialScan.ps1 @owner + /.github/workflows/credential-scan.yml @owner + ``` + + Put them after the other lines, because the last pattern that matches a file decides, and say + that the entries require nothing until the branch rule "Require review from Code Owners" is + on. Do not turn that rule on unasked. When the project has one maintainer, say that no such + rule binds the author of a change, and that the warning which the scan writes in every run, + "Left out of this scan", is the check to read. +6. Run the scan. On a computer where the scanner may run: + + ```powershell + ./.github/scripts/Invoke-CredentialScan.ps1 -Scanner gitleaks + ``` + + The script downloads the scanner, and an application control policy can refuse to start a + downloaded program. Do not look for a way around the policy: push the branch and read the + result of the workflow instead. +7. Read every finding, as the next section says, until the scan passes. Then report. + +## Reading a finding + +The scan reports a place, never a value: the rule, the file, the line, the commit for a finding in +the history, and a fingerprint. Look at the place itself, with `git show :` for the +history. + +- **A real credential.** Tell the user at once, and that it has to be revoked at the service that + issued it before anything else. Removing it from the file does not remove it from the history, + and everyone who can read the repository can read it there. Only after it is revoked does its + fingerprint go into the ignore file, with a comment that says so. Rewriting the history is the + user's decision, not a step of this skill. +- **A placeholder in a file**, such as a password in a test or a sample. Prefer changing the value + so that the scanner no longer reports it: build it at run time, or use a value that is not in + the form of a credential. +- **A placeholder in the history.** A commit does not change, so the value cannot be changed + there. Its fingerprint goes into the ignore file, under a comment that says what it is. +- **A form that is never a credential**, reported in many places. For betterleaks and gitleaks, + add an `[[allowlists]]` entry to the configuration that names the rule and the form. gitleaks + refuses a configuration that names a rule which it does not have. For trufflehog, leave a path + out in `.trufflehog-exclude.txt` only when nothing in that path can be a credential. + +An entry in an ignore file or an exception in a configuration MUST NOT be added to make the scan +pass. Each one is a finding that was read. A rule MUST NOT be switched off with `disabledRules`, +replaced by a rule of the same name, or filtered for that either: the scan runs again without the +configuration, and its warning counts every place that the configuration leaves out. Show the +user the list before it is committed: the user decides what is left out. + +To change the scanner later, change the three `env` values of the workflow to the name, the +version, and the SHA-256 of the archive for the runner, as the checksum file of that release gives +it, and add the configuration of the new scanner. To change the version, change the version and +the hash together and read what the new version reports: its built-in rules belong to it. The +script supports betterleaks 1.x, gitleaks 8.x, and trufflehog 3.x. + +## Report + +Say which scanner the user chose and which files were added or changed. List every finding of the +first run with its place and what was done about it: revoked, changed, or left out, with the +reason. Quote the "Left out of this scan" warning of the last run, so that the user sees how much +the scan does not report. Say whether the scan was run on this computer or only in the workflow, and what its last +run reported. If a real credential was found, say so first.