Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove all default privileged plugins #4053

Merged
merged 11 commits into from
Sep 2, 2024
5 changes: 4 additions & 1 deletion cli/exec/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,9 +185,12 @@ func execWithAxis(ctx context.Context, c *cli.Command, file, repoPath string, ax
volumes = append(volumes, repoPath+":"+path.Join(workspaceBase, workspacePath))
}

privilegedPlugins := c.StringSlice("plugins-privileged")

// lint the yaml file
err = linter.New(
linter.WithTrusted(true),
linter.PrivilegedPlugins(privilegedPlugins),
linter.WithTrustedClonePlugins(constant.TrustedClonePlugins),
).Lint([]*linter.WorkflowConfig{{
File: path.Base(file),
Expand All @@ -205,7 +208,7 @@ func execWithAxis(ctx context.Context, c *cli.Command, file, repoPath string, ax
// compiles the yaml file
compiled, err := compiler.New(
compiler.WithEscalated(
c.StringSlice("privileged")...,
privilegedPlugins...,
),
compiler.WithVolumes(volumes...),
compiler.WithWorkspace(
Expand Down
8 changes: 3 additions & 5 deletions cli/exec/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@ import (
"time"

"github.com/urfave/cli/v3"

"go.woodpecker-ci.org/woodpecker/v2/shared/constant"
)

var flags = []cli.Flag{
Expand Down Expand Up @@ -58,9 +56,9 @@ var flags = []cli.Flag{
Hidden: true,
},
&cli.StringSliceFlag{
Name: "privileged",
Usage: "privileged plugins",
Value: constant.PrivilegedPlugins,
Sources: cli.EnvVars("WOODPECKER_PLUGINS_PRIVILEGED"),
Name: "plugins-privileged",
Usage: "Allow plugins to run in privileged mode, if environment variable is defined but empty there will be none",
},
&cli.StringFlag{
Sources: cli.EnvVars("WOODPECKER_BACKEND"),
Expand Down
6 changes: 6 additions & 0 deletions cli/lint/lint.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,11 @@ var Command = &cli.Command{
ArgsUsage: "[path/to/.woodpecker.yaml]",
Action: lint,
Flags: []cli.Flag{
&cli.StringSliceFlag{
Sources: cli.EnvVars("WOODPECKER_PLUGINS_PRIVILEGED"),
Name: "plugins-privileged",
Usage: "Allow plugins to run in privileged mode, if environment variable is defined but empty there will be none",
},
&cli.StringSliceFlag{
Sources: cli.EnvVars("WOODPECKER_PLUGINS_TRUSTED_CLONE"),
Name: "plugins-trusted-clone",
Expand Down Expand Up @@ -106,6 +111,7 @@ func lintFile(_ context.Context, c *cli.Command, file string) error {
// TODO: lint multiple files at once to allow checks for sth like "depends_on" to work
err = linter.New(
linter.WithTrusted(true),
linter.PrivilegedPlugins(c.StringSlice("plugins-privileged")),
linter.WithTrustedClonePlugins(c.StringSlice("plugins-trusted-clone")),
).Lint([]*linter.WorkflowConfig{config})
if err != nil {
Expand Down
5 changes: 2 additions & 3 deletions cmd/server/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,10 +160,9 @@ var flags = append([]cli.Flag{
Value: time.Hour * 72,
},
&cli.StringSliceFlag{
Sources: cli.EnvVars("WOODPECKER_ESCALATE"),
Name: "escalate",
Sources: cli.EnvVars("WOODPECKER_PLUGINS_PRIVILEGED"),
Name: "plugins-privileged",
Usage: "Allow plugins to run in privileged mode, if environment variable is defined but empty there will be none",
Value: constant.PrivilegedPlugins,
},
&cli.StringSliceFlag{
Sources: cli.EnvVars("WOODPECKER_PLUGINS_TRUSTED_CLONE"),
Expand Down
7 changes: 1 addition & 6 deletions cmd/server/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -224,12 +224,7 @@ func setupEvilGlobals(ctx context.Context, c *cli.Command, s store.Store) error
server.Config.Pipeline.Volumes = c.StringSlice("volume")
server.Config.WebUI.EnableSwagger = c.Bool("enable-swagger")
server.Config.WebUI.SkipVersionCheck = c.Bool("skip-version-check")

// list has default value but should be able to be set to zero
server.Config.Pipeline.PrivilegedPlugins = c.StringSlice("escalate")
if val, set := os.LookupEnv("WOODPECKER_ESCALATE"); set && val == "" {
server.Config.Pipeline.PrivilegedPlugins = []string{}
}
server.Config.Pipeline.PrivilegedPlugins = c.StringSlice("plugins-privileged")

// prometheus
server.Config.Prometheus.AuthToken = c.String("prometheus-auth-token")
Expand Down
4 changes: 1 addition & 3 deletions docs/docs/30-administration/10-server-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -348,9 +348,7 @@ Context: when someone does log into Woodpecker, a temporary session token is cre
As long as the session is valid (until it expires or log-out),
a user can log into Woodpecker, without re-authentication.

### `WOODPECKER_ESCALATE`

> Defaults are defined in [shared/constant/constant.go](https://github.com/woodpecker-ci/woodpecker/blob/main/shared/constant/constant.go)
### `WOODPECKER_PLUGINS_PRIVILEGED`

Docker images to run in privileged mode. Only change if you are sure what you do!

Expand Down
3 changes: 2 additions & 1 deletion docs/docs/91-migrations.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ Some versions need some changes to the server configuration or the pipeline conf

## `next`

- Rename server environment variable `WOODPECKER_ESCALATE` to `WOODPECKER_PLUGINS_PRIVILEGED`
- Remove all default privileged plugins ([re-add plugins to the list via config if needed](./30-administration/10-server-config.md#woodpecker_plugins_privileged)).
6543 marked this conversation as resolved.
Show resolved Hide resolved
- `WOODPECKER_DEFAULT_CLONE_IMAGE` got depricated use `WOODPECKER_DEFAULT_CLONE_PLUGIN`
- Check trusted-clone- and privileged-plugins by image name and tag (if tag is set)
- Remove `plugins/docker`, `plugins/gcr` and `plugins/ecr` from the default list of privileged plugins ([modify the list via config if needed](./30-administration/10-server-config.md#woodpecker_escalate)).
- Secret filters for plugins now check against tag if specified
- Removed `WOODPECKER_DEV_OAUTH_HOST` and `WOODPECKER_DEV_GITEA_OAUTH_URL` use `WOODPECKER_EXPERT_FORGE_OAUTH_HOST`
- Compatibility mode of deprecated `pipeline:`, `platform:` and `branches:` pipeline config options are now removed and pipeline will now fail if still in use.
Expand Down
4 changes: 2 additions & 2 deletions pipeline/frontend/yaml/linter/linter.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,8 +168,8 @@ func (l *Linter) lintImage(config *WorkflowConfig, c *types.Container, area stri

func (l *Linter) lintPrivilegedPlugins(config *WorkflowConfig, c *types.Container, area string) error {
// lint for conflicts of https://github.com/woodpecker-ci/woodpecker/pull/3918
if utils.MatchImage(c.Image, "plugins/docker", "plugins/gcr", "plugins/ecr") {
msg := "Cannot use once privileged plugins removed from WOODPECKER_ESCALATE, use 'woodpeckerci/plugin-docker-buildx' instead"
if utils.MatchImage(c.Image, "plugins/docker", "plugins/gcr", "plugins/ecr", "woodpeckerci/plugin-docker-buildx") {
msg := "Cannot use once by default privileged plugins, if needed add it too WOODPECKER_PLUGINS_PRIVILEGED"
// check first if user did not add them back
if l.privilegedPlugins != nil && !utils.MatchImage(c.Image, *l.privilegedPlugins...) {
return newLinterError(msg, config.File, fmt.Sprintf("%s.%s", area, c.Name), false)
Expand Down
2 changes: 1 addition & 1 deletion pipeline/frontend/yaml/linter/linter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ func TestLintErrors(t *testing.T) {
},
{
from: "{steps: { build: { image: plugins/docker, settings: { test: 'true' } } }, when: { branch: main, event: push } } }",
want: "Cannot use once privileged plugins removed from WOODPECKER_ESCALATE, use 'woodpeckerci/plugin-docker-buildx' instead",
want: "Cannot use once by default privileged plugins, if needed add it too WOODPECKER_PLUGINS_PRIVILEGED",
},
{
from: "{steps: { build: { image: golang, settings: { test: 'true' } } }, when: { branch: main, event: push }, clone: { git: { image: some-other/plugin-git:v1.1.0 } } }",
Expand Down
6 changes: 0 additions & 6 deletions shared/constant/constant.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,6 @@

package constant

// PrivilegedPlugins can be changed by 'WOODPECKER_ESCALATE' at runtime.
var PrivilegedPlugins = []string{
"docker.io/woodpeckerci/plugin-docker-buildx",
"codeberg.org/woodpecker-plugins/docker-buildx",
}

// DefaultConfigOrder represent the priority in witch woodpecker search for a pipeline config by default
// folders are indicated by supplying a trailing slash.
var DefaultConfigOrder = [...]string{
Expand Down