Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
695 changes: 695 additions & 0 deletions .github/scripts/Invoke-CredentialScan.ps1

Large diffs are not rendered by default.

51 changes: 50 additions & 1 deletion .github/workflows/quality-gates.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Quality gates for IntuneScriptLab.
#
# Five jobs, because the module makes claims that can only fail on different hosts:
# Six jobs. Five because the module makes claims that can only fail on different hosts, and one
# that scans the repository for credentials:
#
# tests Windows, PowerShell 7. PSScriptAnalyzer at Error and Warning over the module, the
# kit and the tests, the 115-character line limit, then the whole Pester suite (the
Expand Down Expand Up @@ -46,6 +47,17 @@
# and imports the staged copy in a new process. A release that would fail at the tag
# fails at the pull request instead.
#
# credentials Ubuntu. Every commit of every branch and tag, and the files of the checkout,
# scanned for credentials with gitleaks through .github/scripts/Invoke-CredentialScan.ps1,
# which the PowerShell standards install and keep current. A credential that was
# committed stays in the history after the commit that removes it. The job is here
# and not in a workflow of its own, so that a release cannot go out past it. It runs
# the configuration and the ignore file of the pull request itself, so a change can
# leave out the finding it adds. When they leave something out, the run writes how
# much under "Left out of this scan"; a run without that line left nothing out. The
# step runs verbose, so a passing run records the probe it found and the two scans
# it made. gitleaks writes REDACTED in place of each value, so the public log shows none.
#
# There is no Linux test job on purpose: the harness launches Windows PowerShell hosts, reads
# the registry and registers scheduled tasks, and the rules are about what happens on a Windows
# device. The module imports on Linux, which the help job proves.
Expand Down Expand Up @@ -393,3 +405,40 @@ jobs:
run: |
$ErrorActionPreference = 'Stop'
./Build/Publish-Module.ps1 -WhatIf

credentials:
Comment thread
fadwen-ai marked this conversation as resolved.
Resolved
name: 'Credential scan'
runs-on: ubuntu-latest

# The names of these values hold no word such as credential, key, or token. Beside a long
# value, a scanner takes such a name for the name of a key, and reports the hash below.
# The scanner is pinned by its version and by the SHA256 of its release archive for the
# runner, as the checksum file of that release gives it. Change the two together, and read
# what the new version reports in the same change: the built-in rules belong to the version.
env:
SCANNER: 'gitleaks'
SCANNER_VERSION: '8.30.1'
SCANNER_SHA256: '551f6fc83ea457d62a0d98237cbad105af8d557003051f41f3e7ca7b3f2470eb'

steps:
# Every commit of every branch and tag. The default is the one commit that is built, and
# the script refuses to scan such a checkout.
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
fetch-depth: 0
persist-credentials: false

- name: Scan the history and the files
shell: pwsh
run: |
$ErrorActionPreference = 'Stop'
$scan = @{
Scanner = $env:SCANNER
Version = $env:SCANNER_VERSION
Sha256 = $env:SCANNER_SHA256
# The verbose lines name the probe, the scans, rules and places, never a value.
# Without them a passing run leaves nothing in the log to show that it scanned.
Verbose = $true
}
./.github/scripts/Invoke-CredentialScan.ps1 @scan
Comment thread
fadwen-ai marked this conversation as resolved.
Resolved
3 changes: 2 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ permissions:

jobs:
# The same gates a pull request runs: analysis, the suites on Windows PowerShell 7 and 5.1
# and on ARM64, the command help gate on a case-sensitive filesystem, and the release rehearsal.
# and on ARM64, the command help gate on a case-sensitive filesystem, the release rehearsal,
# and the credential scan of every branch and tag.
gates:
name: 'Quality gates'
uses: ./.github/workflows/quality-gates.yml
Expand Down
18 changes: 18 additions & 0 deletions .gitleaks.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Configuration of the credential scan that .github/scripts/Invoke-CredentialScan.ps1 runs with
# gitleaks. The script passes this file with --config.
#
# The rules are the built-in rules of the gitleaks version that the scan uses, and this file adds
# nothing to them. Measured with gitleaks 8.30.1: an expression after a name such as $password,
# for example [System.Security.SecureString]::new(), is not reported in a PowerShell file.
#
# Written for gitleaks 8.x, the major version that the scan script supports.
#
# Add an exception here only for a form that is never a credential. An [[allowlists]] entry names
# the rules it applies to in targetRules, and gitleaks refuses a file that names a rule it does
# not have. A single finding that was read and is not a credential goes into .gitleaksignore by
# its fingerprint.

title = 'Credential scan'

[extend]
useDefault = true
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ entries are carried over from the manifest's release notes.

### Added

- A credential scan in CI: the `credentials` job of the quality gates, which the release runs too,
scans every commit of every branch and tag, and the files of the checkout, with gitleaks 8.30.1
pinned by hash. It writes `REDACTED` in place of each value it finds (CIC-12, #127).
- A performance gate in CI: the tests job runs the performance tests three times and fails when
the median time of a reader at 10,000 lines is more than twice its baseline for that runner
image, or its memory a quarter more, recorded in `Tests/Performance/Baselines.psd1` (#136).
Expand Down
7 changes: 7 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,17 @@ week and opens a pull request when they change:
- `.github/instructions/pester-supporting-docs/`
- `.claude/rules/powershell-standards/`
- the `powershell-*` skills under `.github/skills/`, `.claude/skills/` and `.agents/skills/`
- `.github/scripts/Invoke-CredentialScan.ps1`, the credential scan

**The next sync overwrites those files.** A local edit there is silently reverted, and a file the
standards stop producing is deleted. Changes belong upstream in the standards repository.

The scan's configuration, `.gitleaks.toml`, belongs to this repository, and so does the job that
runs it: the `credentials` job of `quality-gates.yml`, where the release runs it too, rather than the
`credential-scan.yml` the installer writes. The sync refreshes the script because the repository
has it. It does not pass `-IncludeCredentialScan`, which would write `credential-scan.yml` again and
run the scan twice.

This file is not one of them, so it is the right place for anything specific to this module.
[docs/StandardsDecisions.md](docs/StandardsDecisions.md) records the rules that are built later,
do not fit this module, or are a question for the standards repository, each with its reason.
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,5 +82,5 @@ explains the rounds.
- Add or update the tests that pin the behaviour, and a line in `CHANGELOG.md` under
`[Unreleased]`.
- The quality gates run on every pull request on PowerShell 7, Windows PowerShell 5.1, Windows on
ARM, and a case-sensitive filesystem for the help, and they rehearse the release as far as the
upload.
ARM, and a case-sensitive filesystem for the help, rehearse the release as far as the upload,
and scan every branch and tag for credentials with gitleaks.
2 changes: 1 addition & 1 deletion docs/StandardsDecisions.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@ Each decision is one of three:
| TST-47, unit tests in less than 30 seconds | Does not fit | The unit run takes 69 to 86 seconds locally and 72 seconds on the ARM runner, for 2,211 tests in 164 files. In the 86-second run that was 9 seconds of discovery, 16 of Pester's own work and 61 in the tests; in the 69-second run, 4, 14 and 50. It took 157 seconds, and 206 on the ARM runner, until the tests that start processes, read the real machine or run a script as a caller were tagged `Integration` ([#70](https://github.com/fadwen/IntuneScriptLab/issues/70)). The build and the ARM job run those in a second run; the tests and 5.1 jobs run every suite in one. What is left is spread out: no file takes more than 7 seconds. The slowest are the pre-flight, which mocks Graph and analyzes the scripts it returns, the diagnostic package, which writes real zip files from fixture logs, and the module contract, which imports the module anew and reads the help of every command. Pester's `Run.Parallel` brought the run to 50 seconds at best, at four or eight workers and never below, because each worker imports the module again, in about a second, for each file; and the workers share `$env:ProgramData` and the other variables the harness tests set, which failed 7 to 38 tests a run. Under 30 seconds would take fewer tests, not faster ones. |
| CIC-13, performance gate | Build after TST-43, as [#136](https://github.com/fadwen/IntuneScriptLab/issues/136) | `Build/Test-PerformanceBaseline.ps1` compares the median of three runs of `Tests/Performance` with the baselines in `Tests/Performance/Baselines.psd1`, recorded for each hosted runner image, PowerShell version and architecture, and fails a median above its margin. A runner without a baseline, such as a new image, is reported and not gated. |
| CIC-14, documentation gate for the README | Build, as [#137](https://github.com/fadwen/IntuneScriptLab/issues/137) | `Build/Test-MarkdownLink.ps1`, run by the `help` job, checks the anchors and relative links of the README and the other Markdown, as `docs/` is checked by `Build-Help.ps1 -ValidateOnly`. |
| CIC-12, credential and dependency scanning | Build, as [#127](https://github.com/fadwen/IntuneScriptLab/issues/127) | No workflow scans for credentials. The standards installer adds a scan with `-IncludeCredentialScan`; the module has no dependencies to scan. |
| CIC-12, credential and dependency scanning | Built for credentials, as [#127](https://github.com/fadwen/IntuneScriptLab/issues/127); does not fit for dependencies | The `credentials` job of `quality-gates.yml` scans every commit of every branch and tag, and the files of the checkout, with gitleaks 8.30.1 pinned by the SHA-256 of its archive, through the standards' `Invoke-CredentialScan.ps1` (CIC-23). It is in `quality-gates.yml` so that the release, which calls that workflow, runs it too. gitleaks was chosen because it writes `REDACTED` in place of each value and this repository's logs are public. The first scan of the full history found no credential, and `.gitleaks.toml` adds nothing to the built-in rules. The module has no dependencies to scan: `RequiredModules = @()`. |
| PLT-12, the help build in the normal local build | Build, as [#138](https://github.com/fadwen/IntuneScriptLab/issues/138) | `Build/Invoke-Build.ps1` rebuilds the help and `docs/Rules.md`, checks the links, analyzes and runs the unit suites on 7 and 5.1, and heads the "Checks" in `CLAUDE.md` and `CONTRIBUTING.md`. |