Skip to content
Closed
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
10 changes: 9 additions & 1 deletion .plumber.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,7 @@ github:
# 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) is absent does not run.
# 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.
Expand Down Expand Up @@ -1372,6 +1372,14 @@ mise:
# 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
Expand Down
3 changes: 3 additions & 0 deletions cmd/config_slim.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ func pinAbsentMiseChecks(m map[interface{}]interface{}, base *configuration.Mise
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
}

Expand Down
11 changes: 10 additions & 1 deletion cmd/config_slim_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,8 +786,10 @@ func TestPinAbsentMiseChecks(t *testing.T) {
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{}
Expand All @@ -798,7 +800,7 @@ func TestPinAbsentMiseChecks(t *testing.T) {
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},
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",
Expand All @@ -808,8 +810,15 @@ func TestPinAbsentMiseChecks(t *testing.T) {
"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{}{},
Expand Down
14 changes: 13 additions & 1 deletion cmd/testdata/catalog_golden.json
Original file line number Diff line number Diff line change
Expand Up @@ -1196,7 +1196,7 @@
"gitlab",
"github"
],
"description": "Verifies the mise files of the repository: that every config has a committed, up to date lockfile whose downloads carry checksums and trusted provenance, that no tool requests a forbidden version such as latest, that tools come from authorized sources, and, when required, that the repository uses mise at all.",
"description": "Verifies the mise files of the repository: that every config has a committed, up to date lockfile whose downloads carry checksums and trusted provenance, that no tool requests a forbidden version such as latest, that tools come from authorized sources, that every mise project declares the required tasks, and, when required, that the repository uses mise at all.",
"requiresConfig": false,
"issueCodes": [
"ISSUE-1001",
Expand All @@ -1215,6 +1215,7 @@
"ISSUE-1014",
"ISSUE-1015",
"ISSUE-1016",
"ISSUE-1017",
"ISSUE-1018",
"ISSUE-1019"
],
Expand All @@ -1235,6 +1236,7 @@
"ISSUE-1014": "hygiene",
"ISSUE-1015": "hygiene",
"ISSUE-1016": "hygiene",
"ISSUE-1017": "hygiene",
"ISSUE-1018": "hygiene",
"ISSUE-1019": "hygiene"
},
Expand Down Expand Up @@ -2682,6 +2684,16 @@
"controlName": "mise-en-place",
"subject": "sources"
},
{
"code": "ISSUE-1017",
"severity": "medium",
"title": "mise: a project misses required tasks",
"description": "A mise project (a directory holding a mise config) does not declare the tasks `mise.tasks.required` asks for. When CI runs `mise run \u003ctask\u003e`, the tasks the organization expects (lint, test, a security scan) are the steps that actually run, so a project without them skips those steps. Tasks count from `[tasks]` tables, TOML task files, executable files of the task directories, and parent directories, as `mise run` sees them. Tasks from a remote (`git::`, `oci::`, `zip::`) or templated include are not read, so they never satisfy the requirement.",
"remediation": "Declare the missing tasks in the project's `mise.toml` (`[tasks.lint]`) or as executable files in `mise-tasks/`, or list the project's path in `exemptPaths` if it is not meant to run them.",
"docUrl": "https://getplumber.io/docs/cli/issues/ISSUE-1017",
"controlName": "mise-en-place",
"subject": "tasks"
},
{
"code": "ISSUE-1018",
"severity": "high",
Expand Down
44 changes: 42 additions & 2 deletions configuration/packagemanagers.go
Comment thread
Exypte marked this conversation as resolved.
Resolved
Comment thread
Exypte marked this conversation as resolved.
Resolved
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ type MiseConfig struct {
// the download location. An absent block does not run.
Sources *MiseSourcesCheckConfig `yaml:"sources,omitempty"`

// Tasks checks that every mise project declares the required tasks.
// An absent block does not run.
Tasks *MiseTasksCheckConfig `yaml:"tasks,omitempty"`

// ExemptPackages lists tool keys exempted from every mise check
// (globs allowed, e.g. "aqua:my-org/*").
ExemptPackages []string `yaml:"exemptPackages,omitempty"`
Expand All @@ -47,7 +51,7 @@ type MiseConfig struct {

// UnmarshalYAML rejects unknown mise keys.
func (c *MiseConfig) UnmarshalYAML(unmarshal func(any) error) error {
if err := rejectUnknownKeys(unmarshal, "mise", "enabled", "required", "lockfile", "versions", "sources", "exemptPackages", "exemptPaths"); err != nil {
if err := rejectUnknownKeys(unmarshal, "mise", "enabled", "required", "lockfile", "versions", "sources", "tasks", "exemptPackages", "exemptPaths"); err != nil {
return err
}
type plain MiseConfig
Expand All @@ -63,7 +67,13 @@ func (c *MiseConfig) IsEnabled() bool {
// AnyCheckEnabled reports whether at least one mise check is on: a check
// block, or `required`. An enabled mise block with none asserts nothing.
func (c *MiseConfig) AnyCheckEnabled() bool {
return c != nil && (c.Required || c.LockfileCheckEnabled() || c.VersionsCheckEnabled() || c.SourcesCheckEnabled())
return c != nil && (c.Required || c.LockfileCheckEnabled() || c.VersionsCheckEnabled() || c.SourcesCheckEnabled() || c.TasksCheckEnabled())
}

// TasksCheckEnabled reports whether the tasks check runs: its block is
// present and does not say enabled: false.
func (c *MiseConfig) TasksCheckEnabled() bool {
return c != nil && c.Tasks != nil && (c.Tasks.Enabled == nil || *c.Tasks.Enabled)
}

// LockfileCheckEnabled reports whether the lockfile check runs: its block
Expand Down Expand Up @@ -226,6 +236,36 @@ func (c *MiseSourcesCheckConfig) UnmarshalYAML(unmarshal func(any) error) error
return nil
}

// MiseTasksCheckConfig configures the mise tasks check: every mise
// project must declare each task of Required (ISSUE-1017).
type MiseTasksCheckConfig struct {
// Enabled turns the check off when false. A present block is enabled.
Enabled *bool `yaml:"enabled,omitempty"`

// Required lists the tasks every mise project must declare. Each
// entry is a task name or alias, globs allowed (`lint:*`).
Required []string `yaml:"required,omitempty"`
}

// UnmarshalYAML rejects unknown tasks check keys, an empty requirement
// and invalid globs.
func (c *MiseTasksCheckConfig) UnmarshalYAML(unmarshal func(any) error) error {
if err := rejectUnknownKeys(unmarshal, "mise.tasks", "enabled", "required"); err != nil {
return err
}
type plain MiseTasksCheckConfig
if err := unmarshal((*plain)(c)); err != nil {
return fmt.Errorf("mise.tasks.required must be a list of task names: %w", err)
}
if c.Enabled != nil && !*c.Enabled {
return nil
}
if len(c.Required) == 0 {
return fmt.Errorf("mise.tasks: set 'required', the list of tasks every mise project must declare")
}
return validateGlobs("mise.tasks.required", c.Required)
}

// validateGlobs rejects a pattern the Rego rules cannot match. They use
// glob.match, which fails on a bad pattern and then matches nothing, so a
// typo would silently change what the check passes. Each pattern is
Expand Down
131 changes: 129 additions & 2 deletions configuration/packagemanagers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,18 @@ func TestMiseConfigDecoding(t *testing.T) {
wantLockfile bool
wantVersions bool
wantSources bool
wantTasks bool

wantExemptPaths []string
wantRequired bool
wantAnyCheck bool
// wantTrustedProvenance is TrustedProvenanceOrDefault, checked
// when the lockfile check is on.
wantTrustedProvenance []string
// The lockfile check keys, checked when the lockfile check is on.
wantRequireProvenance []string
wantRequiredPlatforms []string
wantMinimumLockfileVersion *int
}{
{name: "a missing mise block is off", block: ""},
{
Expand All @@ -45,6 +50,22 @@ mise:
wantAnyCheck: true,
wantTrustedProvenance: DefaultTrustedProvenance,
},
{
name: "the lockfile check keys decode",
block: `
mise:
lockfile:
requireProvenance: ["aqua:*"]
requiredPlatforms: [linux-x64, linux-arm64]
minimumLockfileVersion: 2`,
wantEnabled: true,
wantLockfile: true,
wantAnyCheck: true,
wantTrustedProvenance: DefaultTrustedProvenance,
wantRequireProvenance: []string{"aqua:*"},
wantRequiredPlatforms: []string{"linux-x64", "linux-arm64"},
wantMinimumLockfileVersion: new(2),
},
{
name: "trustedProvenance replaces the default list",
block: `
Expand Down Expand Up @@ -175,11 +196,68 @@ mise:
wantErr: `unknown key(s) "trustedSources" in mise.sources`,
},
{
name: "an unknown mise key is a config error",
name: "a tasks block with a list is on",
block: `
mise:
tasks:
required: [lint, "test:*"]`,
wantEnabled: true,
wantTasks: true,
wantAnyCheck: true,
},
{
name: "a disabled tasks block needs no requirement",
block: `
mise:
tasks:
enabled: false`,
wantEnabled: true,
},
{
name: "a tasks block with no requirement is a config error",
block: `
mise:
tasks: {}`,
wantErr: `unknown key(s) "tasks" in mise;`,
wantErr: `mise.tasks: set 'required'`,
},
{
name: "an empty list is a config error",
block: `
mise:
tasks:
required: []`,
wantErr: `mise.tasks: set 'required'`,
},
{
name: "the old expression form is a config error",
block: `
mise:
tasks:
required: lint AND test`,
wantErr: `mise.tasks.required must be a list of task names`,
},
{
name: "the old requiredGroups key is a config error",
block: `
mise:
tasks:
requiredGroups: [[lint]]`,
wantErr: `unknown key(s) "requiredGroups" in mise.tasks`,
},
{
name: "an invalid task glob is a config error",
block: `
mise:
tasks:
required: ["lint:["]`,
wantErr: `invalid pattern "lint:[" in mise.tasks.required`,
},
{
name: "an unknown mise key is a config error",
block: `
mise:
npm: {}`,
wantErr: `unknown key(s) "npm" in mise;`,
},
{
name: "an invalid forbiddenVersions glob is a config error",
Expand Down Expand Up @@ -228,6 +306,9 @@ mise:
if got := pc.Mise.VersionsCheckEnabled(); got != tc.wantVersions {
t.Errorf("VersionsCheckEnabled = %v, want %v", got, tc.wantVersions)
}
if got := pc.Mise.TasksCheckEnabled(); got != tc.wantTasks {
t.Errorf("TasksCheckEnabled = %v, want %v", got, tc.wantTasks)
}
if got := pc.Mise.SourcesCheckEnabled(); got != tc.wantSources {
t.Errorf("SourcesCheckEnabled = %v, want %v", got, tc.wantSources)
}
Expand All @@ -249,6 +330,17 @@ mise:
if !slices.Equal(got, tc.wantTrustedProvenance) || (got == nil) != (tc.wantTrustedProvenance == nil) {
t.Errorf("TrustedProvenanceOrDefault = %#v, want %#v", got, tc.wantTrustedProvenance)
}
lf := pc.Mise.Lockfile
if !slices.Equal(lf.RequireProvenance, tc.wantRequireProvenance) {
t.Errorf("RequireProvenance = %#v, want %#v", lf.RequireProvenance, tc.wantRequireProvenance)
}
if !slices.Equal(lf.RequiredPlatforms, tc.wantRequiredPlatforms) {
t.Errorf("RequiredPlatforms = %#v, want %#v", lf.RequiredPlatforms, tc.wantRequiredPlatforms)
}
if (lf.MinimumLockfileVersion == nil) != (tc.wantMinimumLockfileVersion == nil) ||
(lf.MinimumLockfileVersion != nil && *lf.MinimumLockfileVersion != *tc.wantMinimumLockfileVersion) {
t.Errorf("MinimumLockfileVersion = %v, want %v", lf.MinimumLockfileVersion, tc.wantMinimumLockfileVersion)
}
}
})
}
Expand Down Expand Up @@ -288,3 +380,38 @@ func TestMiseConfigYAMLRoundTrip(t *testing.T) {
})
}
}

// An empty trustedRegistries trusts no URL and an absent one checks none:
// a YAML round trip must not turn the first into the second.
func TestMiseSourcesConfigYAMLRoundTrip(t *testing.T) {
cases := []struct {
name string
block string
want []string
wantSet bool
}{
{name: "an empty trustedRegistries stays set and empty", block: "trustedRegistries: []\n", want: []string{}, wantSet: true},
{name: "an absent trustedRegistries stays unset", block: "trustedTools: [\"core:*\"]\n"},
{name: "a set trustedRegistries is kept", block: "trustedRegistries: [\"https://github.com/*\"]\n", want: []string{"https://github.com/*"}, wantSet: true},
}
for _, tc := range cases {
t.Run(tc.name, func(t *testing.T) {
var c MiseSourcesCheckConfig
if err := yaml.Unmarshal([]byte(tc.block), &c); err != nil {
t.Fatal(err)
}
out, err := yaml.Marshal(&c)
if err != nil {
t.Fatal(err)
}
var back MiseSourcesCheckConfig
if err := yaml.Unmarshal(out, &back); err != nil {
t.Fatal(err)
}
got, set := back.TrustedRegistriesList()
if set != tc.wantSet || !slices.Equal(got, tc.want) || (got == nil) != (tc.want == nil) {
t.Errorf("after a round trip (%q): TrustedRegistriesList = %#v, %v, want %#v, %v", out, got, set, tc.want, tc.wantSet)
}
})
}
}
2 changes: 1 addition & 1 deletion configuration/registry.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ var controlsMeta = map[string]ControlMeta{
DisplayName: "mise-en-place",
Category: CategoryPackageManagers,
ID: "CTRL-1001",
Description: "Verifies the mise files of the repository: that every config has a committed, up to date lockfile whose downloads carry checksums and trusted provenance, that no tool requests a forbidden version such as latest, that tools come from authorized sources, and, when required, that the repository uses mise at all.",
Description: "Verifies the mise files of the repository: that every config has a committed, up to date lockfile whose downloads carry checksums and trusted provenance, that no tool requests a forbidden version such as latest, that tools come from authorized sources, that every mise project declares the required tasks, and, when required, that the repository uses mise at all.",
},
"dockerfilesMustPinBaseImageByDigest": {
Providers: []string{ProviderGitHub},
Expand Down
Loading
Loading