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
97 changes: 97 additions & 0 deletions .plumber.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1301,3 +1301,100 @@ github:
- ACTIONS_STEP_DEBUG
- ACTIONS_RUNNER_DEBUG

# ============================================================================
# mise (mise-en-place)
# ============================================================================
# Top level, like gitlab and github: mise does not depend on the provider,
# the same block applies to a GitHub or a GitLab repository. It drives the
# mise-en-place control. Remove the block, or set
# `enabled: false`, and nothing is scanned or reported. A check whose
# block (lockfile, versions, sources, tasks) is absent does not run.
#
# The files are read from the local checkout. A run without one (a remote
# --project run) reports the control as not evaluated.
#
# Best practice: commit mise.lock with a checksum for every download, and
# install with `mise install --locked` in CI.
mise:
# Set to false to disable every mise check
enabled: true
# Set to true to report a repository that commits no mise config
# (ISSUE-1010). A .tool-versions file alone does not count.
required: false
# Every mise config that declares tools has its lockfile committed
# (mise.toml -> mise.lock, mise.<env>.toml -> mise.<env>.lock), every tool
# request has a matching lock entry, and every locked download carries a
# checksum. A request Plumber cannot read statically (a template) or a
# format 0 lockfile is reported as not locked. A mise file that cannot
# be read or parsed stops the run with an error listing every such
# file.
lockfile:
enabled: true
requireChecksums: true
# Backends whose locked downloads must record a provenance
# (SLSA, cosign, minisign, GitHub attestations), globs allowed.
# requireProvenance: ["aqua:*"]
# Provenance kinds a locked download may record; any other kind is
# reported. Defaults to every kind mise records.
# trustedProvenance: [slsa, github-attestations, cosign, minisign]
# Platforms every tool that locks downloads must lock.
# requiredPlatforms: [linux-x64, linux-arm64]
# Oldest accepted lockfile_version.
# minimumLockfileVersion: 1
# No tool request in a mise config uses a forbidden version (globs).
# The request as written is what people review: with `latest`, the
# lockfile pins a version, but `mise lock --bump` or `mise upgrade` moves
# it with no change in mise.toml (ISSUE-1011). A request Plumber cannot
# read statically (a template) is ISSUE-1012. A bare major such as "24" is
# not caught by this list. "ref:*" is left out: a ref pinned to a commit
# SHA cannot move. Add it to forbid every git ref.
versions:
enabled: true
forbiddenVersions:
- latest
- lts
- "lts/*"
- "lts-*"
- stable
- nightly
- beta
- "branch:*"
- "path:*"
- system
- "sub-*"
- "prefix:*"
# Where tools are fetched from. Off by default: write the block to turn
# it on. Globs allowed in every list.
# trustedTools: the tools that may be installed, by full mise name
# (`aqua:jqlang/jq`; a shorthand such as `terraform` takes the
# backend its mise.lock entry records, and with no entry it is
# reported). ISSUE-1013.
# trustedRegistries: the download URLs mise.lock may record, the ones
# `mise install --locked` downloads. Leave it out and they are not
# checked; [] trusts none. ISSUE-1014.
# trustedReplacement: where [settings] url_replacements may send
# downloads. Absent or [] trusts none. ISSUE-1015.
# trustedOptions: the URLs a tool option may set (api_url, url,
# platforms.<p>.url, pip indexes). Absent or [] trusts none.
# ISSUE-1016.
# sources:
# enabled: true
# trustedTools: ["core:*", "aqua:*", "github:my-org/*"]
# trustedRegistries: ["https://github.com/*", "https://nodejs.org/*"]
# trustedReplacement: []
# trustedOptions: []
# Every mise project (a directory holding a mise config) declares the
# tasks CI is expected to run, as `mise run` sees them there (its own,
# its task directories', its parents'). Off by default. `required` is a
# list; each entry matches a task name or alias, globs allowed. A project
# missing any of them is ISSUE-1017.
# tasks:
# enabled: true
# required: [lint, test]
# Tool keys exempted from every mise check, globs allowed.
exemptPackages: []
# Repository paths whose mise files are not checked, for example
# fixtures ("examples/**", "testdata/**"). A file there that cannot be
# read does not stop the run. `*` stays within a directory, `**`
# crosses directories.
exemptPaths: []
1 change: 1 addition & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -461,6 +461,7 @@ Skip if your rule only reads fields the IR already exposes (jobs, scripts, trigg
- `7xx` reserved for GitHub-specific supply-chain
- `8xx` reserved for GitHub-specific triggers
- `9xx` reserved for repo / dependabot artefacts
- `10xx` and up: package managers, one hundred-block per package manager (`10xx` is mise, under the `mise-en-place` control). Inside a block, codes take the next number in sequence whatever check raises them, and each one sets a `subject` (for mise: `lockfile`, `presence`, `versions`, `sources`, `tasks`) so the codes of one check can be filtered together. A new package manager takes the next free block, in the "Package Managers and Lockfiles" category. Its config is a top-level key of `.plumber.yaml` named after the package manager (`mise:`), not a block under `gitlab.controls` or `github.controls`: a package manager does not depend on the provider.
Pick the next free number; existing assignments live in the constants block at the top of `codes.go`.
- [ ] **Registry entry** — `errorCodeRegistry` map entry:
```go
Expand Down
38 changes: 38 additions & 0 deletions cmd/config_slim.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ func slimToOverlay(src string) ([]byte, error) {
overlay[p] = map[interface{}]interface{}{"controls": diff}
}
}
// mise is top level, not under a provider: an overlay source keeps
// its block as written, merged onto the base like any overlay key.
if m, ok := rawMap["mise"]; ok {
overlay["mise"] = m
}
return yaml.Marshal(overlay)
}

Expand Down Expand Up @@ -145,9 +150,42 @@ func slimToOverlay(src string) ([]byte, error) {
overlay[p] = map[interface{}]interface{}{"controls": diff}
}
}
// mise is top level. A legacy source is a full config, so its mise
// block is kept as written, and a source without one turned mise off:
// the overlay says so, or it would inherit the base's enabled block.
if m, ok := userMap["mise"].(map[interface{}]interface{}); ok {
overlay["mise"] = pinAbsentMiseChecks(m, baseCfg.Mise)
} else if baseCfg.Mise.IsEnabled() {
overlay["mise"] = map[interface{}]interface{}{"enabled": false}
}
return yaml.Marshal(overlay)
}

// pinAbsentMiseChecks returns a copy of a legacy source's mise block with
// every check block the source leaves out written as `{enabled: false}`.
// In a full config an absent check block does not run, but the overlay is
// deep-merged onto the base on resolve, so an absent key would inherit the
// base's enabled block and turn the check on.
func pinAbsentMiseChecks(m map[interface{}]interface{}, base *configuration.MiseConfig) map[interface{}]interface{} {
out := make(map[interface{}]interface{})
for k, v := range m {
out[k] = v
}
if _, ok := out["lockfile"]; !ok && base.LockfileCheckEnabled() {
out["lockfile"] = map[interface{}]interface{}{"enabled": false}
}
if _, ok := out["versions"]; !ok && base.VersionsCheckEnabled() {
out["versions"] = map[interface{}]interface{}{"enabled": false}
}
if _, ok := out["sources"]; !ok && base.SourcesCheckEnabled() {
out["sources"] = map[interface{}]interface{}{"enabled": false}
}
if _, ok := out["tasks"]; !ok && base.TasksCheckEnabled() {
out["tasks"] = map[interface{}]interface{}{"enabled": false}
}
return out
}

// normalizeConfigToMap marshals a loaded *configuration.PlumberConfig back
// to YAML and unmarshals it into a generic map, so it can be diffed with
// diffControls/controlsSubmap the same way a raw source map is. Routing
Expand Down
144 changes: 144 additions & 0 deletions cmd/config_slim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cmd
import (
"os"
"path/filepath"
"reflect"
"strings"
"testing"

Expand Down Expand Up @@ -671,6 +672,94 @@ github:
}
}

// TestSlimToOverlay_MiseSurvivesResolve pins the top-level mise block
// through slim -> resolve: a legacy source without mise turned it off, and
// a mise block the source writes is kept.
func TestSlimToOverlay_MiseSurvivesResolve(t *testing.T) {
cases := []struct {
name string
src string
wantEnabled bool
wantLockfile bool
wantVersions bool
// wantForbidden, when set, is the resolved forbiddenVersions list.
wantForbidden []string
wantExempt []string
}{
{
name: "a legacy source without mise stays off",
src: "version: \"2.0\"\ngithub:\n controls: {}\n",
wantEnabled: false,
},
{
name: "a legacy source keeps its mise block",
src: "version: \"2.0\"\ngithub:\n controls: {}\nmise:\n lockfile: {}\n exemptPackages: [node]\n",
wantEnabled: true,
wantLockfile: true,
wantExempt: []string{"node"},
},
{
name: "a legacy source keeps its versions block and pins the absent lockfile off",
src: "version: \"2.0\"\ngithub:\n controls: {}\nmise:\n versions:\n forbiddenVersions: [latest]\n",
wantEnabled: true,
wantVersions: true,
wantForbidden: []string{"latest"},
wantExempt: []string{},
},
{
name: "a legacy source without a lockfile block keeps the check off",
src: "version: \"2.0\"\ngithub:\n controls: {}\nmise:\n enabled: true\n",
wantEnabled: true,
wantLockfile: false,
wantExempt: []string{},
},
{
name: "an overlay source keeps enabled: false",
src: "extends: plumber:default\nversion: \"2.0\"\nmise:\n enabled: false\n",
wantEnabled: false,
},
{
name: "an overlay source without mise inherits the base",
src: "extends: plumber:default\nversion: \"2.0\"\n",
wantEnabled: true,
wantLockfile: true,
wantVersions: true,
wantExempt: []string{},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
path := filepath.Join(t.TempDir(), "src.yaml")
if err := os.WriteFile(path, []byte(tc.src), 0o600); err != nil {
t.Fatal(err)
}
out, err := slimToOverlay(path)
if err != nil {
t.Fatalf("slim: %v", err)
}
resolved, _, _, err := configuration.LoadPlumberConfigFromBytes(out, "slim-output-for-test")
if err != nil {
t.Fatalf("resolve slim overlay: %v\n%s", err, out)
}
if got := resolved.Mise.IsEnabled(); got != tc.wantEnabled {
t.Fatalf("mise enabled = %v, want %v\n%s", got, tc.wantEnabled, out)
}
if got := resolved.Mise.LockfileCheckEnabled(); tc.wantEnabled && got != tc.wantLockfile {
t.Errorf("lockfile check enabled = %v, want %v\n%s", got, tc.wantLockfile, out)
}
if got := resolved.Mise.VersionsCheckEnabled(); tc.wantEnabled && got != tc.wantVersions {
t.Errorf("versions check enabled = %v, want %v\n%s", got, tc.wantVersions, out)
}
if tc.wantForbidden != nil && !equalStringSlices(resolved.Mise.Versions.ForbiddenVersions, tc.wantForbidden) {
t.Errorf("forbiddenVersions = %v, want %v\n%s", resolved.Mise.Versions.ForbiddenVersions, tc.wantForbidden, out)
}
if tc.wantEnabled && !equalStringSlices(resolved.Mise.ExemptPackages, tc.wantExempt) {
t.Errorf("exemptPackages = %v, want %v", resolved.Mise.ExemptPackages, tc.wantExempt)
}
})
}
}

func equalStringSlices(a, b []string) bool {
if len(a) != len(b) {
return false
Expand All @@ -691,3 +780,58 @@ func containsString(list []string, s string) bool {
}
return false
}

func TestPinAbsentMiseChecks(t *testing.T) {
on := &configuration.MiseConfig{
Lockfile: &configuration.MiseLockfileCheckConfig{},
Versions: &configuration.MiseVersionsCheckConfig{},
Sources: &configuration.MiseSourcesCheckConfig{},
Tasks: &configuration.MiseTasksCheckConfig{Required: []string{"lint"}},
}
off := map[interface{}]interface{}{"enabled": false}
disabled := false
cases := []struct {
name string
src map[interface{}]interface{}
base *configuration.MiseConfig
want map[interface{}]interface{}
}{
{
name: "every check the source leaves out is pinned off when the base enables it",
src: map[interface{}]interface{}{"exemptPackages": []interface{}{"node"}},
base: on,
want: map[interface{}]interface{}{"exemptPackages": []interface{}{"node"}, "lockfile": off, "versions": off, "sources": off, "tasks": off},
},
{
name: "a check the source writes is kept as written",
src: map[interface{}]interface{}{"sources": map[interface{}]interface{}{"trustedTools": []interface{}{"aqua:*"}}},
base: on,
want: map[interface{}]interface{}{
"sources": map[interface{}]interface{}{"trustedTools": []interface{}{"aqua:*"}},
"lockfile": off,
"versions": off,
"tasks": off,
},
},
{
name: "a check the base turns off is not pinned",
src: map[interface{}]interface{}{},
base: &configuration.MiseConfig{Tasks: &configuration.MiseTasksCheckConfig{Enabled: &disabled}},
want: map[interface{}]interface{}{},
},
{
name: "nothing is pinned when the base enables no check",
src: map[interface{}]interface{}{},
base: &configuration.MiseConfig{},
want: map[interface{}]interface{}{},
},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
got := pinAbsentMiseChecks(tc.src, tc.base)
if !reflect.DeepEqual(got, tc.want) {
t.Errorf("got %#v\nwant %#v", got, tc.want)
}
})
}
}
9 changes: 8 additions & 1 deletion cmd/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ const (
compScripts = "Detect unverified script execution (curl|bash, base64|bash, |sh, …)"
compJobVars = "Detect sensitive variables overridden in pipeline YAML"
compDinD = "Detect Docker-in-Docker (dind) usage"
compPackageManagers = "Require committed package manager lockfiles with checksums and pinned versions (mise)"

// GitHub-applicable composition checks (new). The cross-provider ones
// (security jobs, DinD) reuse compSecurity / compDinD above.
Expand Down Expand Up @@ -903,7 +904,7 @@ func compositionOptionsForProviders(providers []string) []string {
if hasGitLab {
out = append(out, compHardcoded, compUpToDate, compForbidden, compRefCollision, compAuthorizedComponents, compAuthorizedFunctions)
}
out = append(out, compSecurity, compDinD)
out = append(out, compSecurity, compDinD, compPackageManagers)
if hasGitLab {
out = append(out, compScripts, compJobVars)
}
Expand Down Expand Up @@ -1550,6 +1551,12 @@ func (st *initWizardState) toPlumberConfig() *configuration.PlumberConfig {
}
}

// Provider-independent: mise is a top-level block. It is the
// shipped default's, so the wizard and the default cannot drift.
if compSelected(st, compPackageManagers) {
Comment thread
Exypte marked this conversation as resolved.
Resolved
cfg.Mise = embeddedDefault().Mise
}

// GitHub-only composition checks.
if gh != nil {
if compSelected(st, compActionPin) {
Expand Down
Loading