diff --git a/cli/exec/exec.go b/cli/exec/exec.go index 79994e6b9..c59df519f 100644 --- a/cli/exec/exec.go +++ b/cli/exec/exec.go @@ -41,6 +41,7 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/yaml/linter" "go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/yaml/matrix" pipelineLog "go.woodpecker-ci.org/woodpecker/v2/pipeline/log" + "go.woodpecker-ci.org/woodpecker/v2/shared/constant" "go.woodpecker-ci.org/woodpecker/v2/shared/utils" ) @@ -185,7 +186,10 @@ func execWithAxis(ctx context.Context, c *cli.Command, file, repoPath string, ax } // lint the yaml file - err = linter.New(linter.WithTrusted(true)).Lint([]*linter.WorkflowConfig{{ + err = linter.New( + linter.WithTrusted(true), + linter.WithTrustedClonePlugins(constant.TrustedClonePlugins), + ).Lint([]*linter.WorkflowConfig{{ File: path.Base(file), RawConfig: confStr, Workflow: conf, diff --git a/cli/lint/lint.go b/cli/lint/lint.go index 1e053369d..0f324f14c 100644 --- a/cli/lint/lint.go +++ b/cli/lint/lint.go @@ -27,6 +27,7 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/cli/common" "go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/yaml" "go.woodpecker-ci.org/woodpecker/v2/pipeline/frontend/yaml/linter" + "go.woodpecker-ci.org/woodpecker/v2/shared/constant" ) // Command exports the info command. @@ -35,6 +36,14 @@ var Command = &cli.Command{ Usage: "lint a pipeline configuration file", ArgsUsage: "[path/to/.woodpecker.yaml]", Action: lint, + Flags: []cli.Flag{ + &cli.StringSliceFlag{ + Sources: cli.EnvVars("WOODPECKER_PLUGINS_TRUSTED_CLONE"), + Name: "plugins-trusted-clone", + Usage: "Plugins witch are trusted to handle the netrc info in clone steps", + Value: constant.TrustedClonePlugins, + }, + }, } func lint(ctx context.Context, c *cli.Command) error { @@ -69,7 +78,7 @@ func lintDir(ctx context.Context, c *cli.Command, dir string) error { return nil } -func lintFile(_ context.Context, _ *cli.Command, file string) error { +func lintFile(_ context.Context, c *cli.Command, file string) error { fi, err := os.Open(file) if err != nil { return err @@ -83,7 +92,7 @@ func lintFile(_ context.Context, _ *cli.Command, file string) error { rawConfig := string(buf) - c, err := yaml.ParseString(rawConfig) + parsedConfig, err := yaml.ParseString(rawConfig) if err != nil { return err } @@ -91,11 +100,14 @@ func lintFile(_ context.Context, _ *cli.Command, file string) error { config := &linter.WorkflowConfig{ File: path.Base(file), RawConfig: rawConfig, - Workflow: c, + Workflow: parsedConfig, } // TODO: lint multiple files at once to allow checks for sth like "depends_on" to work - err = linter.New(linter.WithTrusted(true)).Lint([]*linter.WorkflowConfig{config}) + err = linter.New( + linter.WithTrusted(true), + linter.WithTrustedClonePlugins(c.StringSlice("plugins-trusted-clone")), + ).Lint([]*linter.WorkflowConfig{config}) if err != nil { str, err := FormatLintError(config.File, err) diff --git a/cmd/server/flags.go b/cmd/server/flags.go index 1f2400aca..f29071d98 100644 --- a/cmd/server/flags.go +++ b/cmd/server/flags.go @@ -135,10 +135,11 @@ var flags = append([]cli.Flag{ Value: []string{"push", "pull_request"}, }, &cli.StringFlag{ - Sources: cli.EnvVars("WOODPECKER_DEFAULT_CLONE_IMAGE"), - Name: "default-clone-image", + Sources: cli.EnvVars("WOODPECKER_DEFAULT_CLONE_PLUGIN", "WOODPECKER_DEFAULT_CLONE_IMAGE"), + Name: "default-clone-plugin", + Aliases: []string{"default-clone-image"}, Usage: "The default docker image to be used when cloning the repo", - Value: constant.DefaultCloneImage, + Value: constant.DefaultClonePlugin, }, &cli.IntFlag{ Sources: cli.EnvVars("WOODPECKER_DEFAULT_PIPELINE_TIMEOUT"), @@ -164,6 +165,12 @@ var flags = append([]cli.Flag{ 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"), + Name: "plugins-trusted-clone", + Usage: "Plugins witch are trusted to handle the netrc info in clone steps", + Value: constant.TrustedClonePlugins, + }, &cli.StringSliceFlag{ Sources: cli.EnvVars("WOODPECKER_VOLUME"), Name: "volume", diff --git a/cmd/server/setup.go b/cmd/server/setup.go index 375df7a90..3b67c0ca6 100644 --- a/cmd/server/setup.go +++ b/cmd/server/setup.go @@ -43,7 +43,6 @@ import ( "go.woodpecker-ci.org/woodpecker/v2/server/store" "go.woodpecker-ci.org/woodpecker/v2/server/store/datastore" "go.woodpecker-ci.org/woodpecker/v2/server/store/types" - "go.woodpecker-ci.org/woodpecker/v2/shared/constant" ) const ( @@ -165,8 +164,9 @@ func setupEvilGlobals(ctx context.Context, c *cli.Command, s store.Store) error server.Config.Pipeline.AuthenticatePublicRepos = c.Bool("authenticate-public-repos") // Cloning - server.Config.Pipeline.DefaultCloneImage = c.String("default-clone-image") - constant.TrustedCloneImages = append(constant.TrustedCloneImages, server.Config.Pipeline.DefaultCloneImage) + server.Config.Pipeline.DefaultClonePlugin = c.String("default-clone-plugin") + server.Config.Pipeline.TrustedClonePlugins = c.StringSlice("plugins-trusted-clone") + server.Config.Pipeline.TrustedClonePlugins = append(server.Config.Pipeline.TrustedClonePlugins, server.Config.Pipeline.DefaultClonePlugin) // Execution _events := c.StringSlice("default-cancel-previous-pipeline-events") diff --git a/docs/docs/30-administration/10-server-config.md b/docs/docs/30-administration/10-server-config.md index ed624bf6e..c11d91f52 100644 --- a/docs/docs/30-administration/10-server-config.md +++ b/docs/docs/30-administration/10-server-config.md @@ -319,11 +319,13 @@ Always use authentication to clone repositories even if they are public. Needed List of event names that will be canceled when a new pipeline for the same context (tag, branch) is created. -### `WOODPECKER_DEFAULT_CLONE_IMAGE` +### `WOODPECKER_DEFAULT_CLONE_PLUGIN` > Default is defined in [shared/constant/constant.go](https://github.com/woodpecker-ci/woodpecker/blob/main/shared/constant/constant.go) -The default docker image to be used when cloning the repo +The default docker image to be used when cloning the repo. + +It is also added to the trusted clone plugin list. ### `WOODPECKER_DEFAULT_PIPELINE_TIMEOUT` @@ -352,6 +354,15 @@ a user can log into Woodpecker, without re-authentication. Docker images to run in privileged mode. Only change if you are sure what you do! +### WOODPECKER_PLUGINS_TRUSTED_CLONE + +> Defaults are defined in [shared/constant/constant.go](https://github.com/woodpecker-ci/woodpecker/blob/main/shared/constant/constant.go) + +Plugins witch are trusted to handle the netrc info in clone steps. +If a clone step use an image not in this list, the netrc will not be injected and an user has to use other methods (e.g. secrets) to clone non public repos. + +You should specify the tag of your images too, as this enforces exact matches. +