Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
3bbdf9e
fix: check repo trusted when running privileged containers
plyr4 Oct 12, 2022
c23c6b9
revert: docker-compose local changes
plyr4 Oct 12, 2022
7b2b277
revert: docker-compose local changes
plyr4 Oct 12, 2022
7d94146
fix: add repo nil check
plyr4 Oct 12, 2022
4dca3ba
wip: enabling flag for trusted repo protection
plyr4 Oct 13, 2022
4982778
wip: enforcement runtime flag
plyr4 Oct 14, 2022
3dc2082
wip: moving flag to executor and remove changes from runtime
plyr4 Oct 14, 2022
751b5ee
wip: removing more changes from runtime
plyr4 Oct 14, 2022
b695195
wip: code cleanup
plyr4 Oct 14, 2022
36d1425
fix: golangci lint
plyr4 Oct 14, 2022
24a5c0c
fix: golangci lint
plyr4 Oct 14, 2022
f4d1665
fix: golangci lint
plyr4 Oct 14, 2022
245cea3
fix: improve comments
plyr4 Oct 14, 2022
11fbff9
fix: improve comments
plyr4 Oct 14, 2022
e73c88f
fix: improve comments
plyr4 Oct 14, 2022
baf7ebb
fix: improve comments
plyr4 Oct 14, 2022
573a223
fix: improve comments
plyr4 Oct 14, 2022
fa6cee2
fix: improve comments
plyr4 Oct 14, 2022
2264236
fix: golangci lint
plyr4 Oct 14, 2022
b844114
wip: code cleanup
plyr4 Oct 14, 2022
a83514d
wip: code cleanup
plyr4 Oct 14, 2022
9fa2e95
fix: golint goconst
plyr4 Oct 14, 2022
9cee4ba
fix: golint goconst
plyr4 Oct 14, 2022
6d07ba2
fix: golint goconst
plyr4 Oct 14, 2022
d6917a7
fix: golint goconst
plyr4 Oct 14, 2022
f793a7e
fix: return cuddle
plyr4 Oct 14, 2022
308e76e
fix: contextcheck
plyr4 Oct 14, 2022
f7b073e
fix: add var to docker-compose
plyr4 Oct 14, 2022
1f0fff4
fix: add var to docker-compose
plyr4 Oct 14, 2022
c367ac9
fix: change var default in docker-compose to false
plyr4 Oct 14, 2022
9934ce9
enhance: executor and opts tests
plyr4 Oct 14, 2022
3b0ea9d
enhance: executor and opts tests
plyr4 Oct 14, 2022
55ae629
enhance: executor and opts tests
plyr4 Oct 14, 2022
55b9519
enhance: executor and opts tests remove foobar list
plyr4 Oct 14, 2022
85e6643
enhance: add log for denials
plyr4 Oct 14, 2022
c9e24f9
enhance: move log for denials
plyr4 Oct 14, 2022
4db9f3a
fix: fullname access
plyr4 Oct 14, 2022
91e3074
enhance: fix log for denials
plyr4 Oct 14, 2022
e7a055f
fix: cleanup logs
plyr4 Oct 14, 2022
3748a75
fix: wording around log and error
plyr4 Oct 14, 2022
5e216ab
fix: apply logic to services and stages
plyr4 Oct 14, 2022
4e1974a
fix: apply logic to services and stages
plyr4 Oct 14, 2022
19bdcb7
fix: update stages when skipped
plyr4 Oct 17, 2022
6ec071d
revert: docker-compose local changes
plyr4 Oct 19, 2022
932aa6f
Merge branch 'main' into fix/trusted-repos
plyr4 Oct 26, 2022
6e64e43
alter: change default setting to TRUE
plyr4 Oct 28, 2022
92f13d8
Merge branch 'fix/trusted-repos' of github.com:go-vela/worker into fi…
plyr4 Oct 28, 2022
390d700
fix: match struct param order
plyr4 Oct 31, 2022
7847195
fix: skip init image, not name
plyr4 Nov 1, 2022
45855b7
fix: remove nolint:goconst directive
plyr4 Nov 2, 2022
4fe08b7
test: add init-named steps
plyr4 Nov 2, 2022
66300e9
test: add init-named steps
plyr4 Nov 2, 2022
c21e7a3
test: fix service tests comments
plyr4 Nov 2, 2022
7ef5ea6
Merge branch 'main' into fix/trusted-repos
wass3r Nov 9, 2022
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
Prev Previous commit
Next Next commit
wip: enforcement runtime flag
  • Loading branch information
plyr4 committed Oct 14, 2022
commit 498277816686690c6f19fefb6e80a9e2378cf74f
20 changes: 10 additions & 10 deletions cmd/vela-worker/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,16 @@ func (w *Worker) exec(index int) error {
//
// https://pkg.go.dev/github.com/go-vela/worker/runtime?tab=doc#New
w.Runtime, err = runtime.New(&runtime.Setup{
Logger: logger,
Mock: w.Config.Mock,
Driver: w.Config.Runtime.Driver,
ConfigFile: w.Config.Runtime.ConfigFile,
HostVolumes: w.Config.Runtime.HostVolumes,
Namespace: w.Config.Runtime.Namespace,
PodsTemplateName: w.Config.Runtime.PodsTemplateName,
PodsTemplateFile: w.Config.Runtime.PodsTemplateFile,
PrivilegedImages: w.Config.Runtime.PrivilegedImages,
EnableTrusted: w.Config.Runtime.EnableTrusted,
Logger: logger,
Mock: w.Config.Mock,
Driver: w.Config.Runtime.Driver,
ConfigFile: w.Config.Runtime.ConfigFile,
HostVolumes: w.Config.Runtime.HostVolumes,
Namespace: w.Config.Runtime.Namespace,
PodsTemplateName: w.Config.Runtime.PodsTemplateName,
PodsTemplateFile: w.Config.Runtime.PodsTemplateFile,
PrivilegedImages: w.Config.Runtime.PrivilegedImages,
EnforceTrustedRepos: w.Config.Runtime.EnforceTrustedRepos,
})
if err != nil {
return err
Expand Down
19 changes: 9 additions & 10 deletions cmd/vela-worker/run.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ func run(c *cli.Context) error {
},
// runtime configuration
Runtime: &runtime.Setup{
Driver: c.String("runtime.driver"),
ConfigFile: c.String("runtime.config"),
Namespace: c.String("runtime.namespace"),
PodsTemplateName: c.String("runtime.pods-template-name"),
PodsTemplateFile: c.Path("runtime.pods-template-file"),
HostVolumes: c.StringSlice("runtime.volumes"),
PrivilegedImages: c.StringSlice("runtime.privileged-images"),
EnableTrusted: c.Bool("runtime.enable-trusted"),
Driver: c.String("runtime.driver"),
ConfigFile: c.String("runtime.config"),
Namespace: c.String("runtime.namespace"),
PodsTemplateName: c.String("runtime.pods-template-name"),
PodsTemplateFile: c.Path("runtime.pods-template-file"),
HostVolumes: c.StringSlice("runtime.volumes"),
PrivilegedImages: c.StringSlice("runtime.privileged-images"),
EnforceTrustedRepos: c.Bool("runtime.enforce-trusted-repos"),
},
// queue configuration
Queue: &queue.Setup{
Expand All @@ -136,8 +136,7 @@ func run(c *cli.Context) error {
},
Executors: make(map[int]executor.Engine),
}
logrus.Tracef("runtime setup trusted flag: %v", w.Config.Runtime.EnableTrusted)
logrus.Tracef("runtime.enable-trusted flag picked up from CLI config: %v", c.Bool("runtime.enable-trusted"))

// set the worker address if no flag was provided
if len(w.Config.API.Address.String()) == 0 {
w.Config.API.Address, _ = url.Parse(fmt.Sprintf("http://%s", hostname))
Expand Down
5 changes: 1 addition & 4 deletions runtime/docker/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (

"github.com/go-vela/types/constants"
"github.com/go-vela/types/library"
"github.com/sirupsen/logrus"

"github.com/docker/docker/api/types"
"github.com/docker/docker/api/types/container"
Expand Down Expand Up @@ -149,11 +148,9 @@ func (c *client) RunContainer(ctx context.Context, ctn *pipeline.Container, b *p
return err
}

logrus.Tracef("running priv container with enableTrusted: %v", c.config.EnableTrusted)

if privileged {
// ensure repo is trusted and therefore allowed to run privileged containers
if c.config.EnableTrusted && (r == nil || !r.GetTrusted()) {
if c.config.EnforceTrustedRepos && (r == nil || !r.GetTrusted()) {
return errors.New("repo must be trusted to run privileged images")
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/docker/docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ const Version = "v1.40"
type config struct {
// specifies a list of privileged images to use for the Docker client
Images []string
// EnforceTrustedRepos sets whether to enforce trusted repo restrictions on privileged images for the Docker client
EnforceTrustedRepos bool
// specifies a list of host volumes to use for the Docker client
Volumes []string
// enable trusted repo restrictions
EnableTrusted bool
}

type client struct {
Expand Down
10 changes: 5 additions & 5 deletions runtime/docker/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ func WithPrivilegedImages(images []string) ClientOpt {
}
}

// WithEnableTrusted sets FILL ME.
func WithEnableTrusted(enable bool) ClientOpt {
// WithEnforceTrustedRepos sets whether to enforce trusted repo restrictions on privileged images in the runtime client for Docker.
func WithEnforceTrustedRepos(enforce bool) ClientOpt {
return func(c *client) error {
c.Logger.Trace("configuring privileged restrictions in docker runtime client")
c.Logger.Trace("configuring trusted repo restrictions on privileged images in docker runtime client")

// set the runtime privileged trusted restrictions in the docker client
c.config.EnableTrusted = enable
// set configuration for using trusted repo restrictions in the docker client
c.config.EnforceTrustedRepos = enforce

return nil
}
Expand Down
12 changes: 5 additions & 7 deletions runtime/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,11 @@ var Flags = []cli.Flag{
Name: "runtime.volumes",
Usage: "list of host volumes to mount for the runtime",
},
&cli.BoolFlag{ // overaching feature flag to enable trusted repo column to actually mean something
// enabling this will restrict privileged images to not run unless the repo 'trusted' field is 'true'
// protect privileged container execution using repo.trusted field
EnvVars: []string{"VELA_RUNTIME_ENABLE_TRUSTED", "RUNTIME_ENABLE_TRUSTED"},
FilePath: "/vela/runtime/enable_trusted",
Name: "runtime.enable-trusted",
Usage: "enable trusted repo restrictions for privileged images",
&cli.BoolFlag{
EnvVars: []string{"VELA_RUNTIME_ENFORCE_TRUSTED_REPOS", "RUNTIME_ENFORCE_TRUSTED_REPOS"},
FilePath: "/vela/runtime/enforce_trusted_repos",
Name: "runtime.enforce-trusted-repos",
Usage: "enforce trusted repo restrictions for privileged images",
Value: false,
},
}
2 changes: 1 addition & 1 deletion runtime/kubernetes/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ func (c *client) SetupContainer(ctx context.Context, ctn *pipeline.Container, r
}

// ensure repo is trusted and therefore allowed to run privileged containers
if c.config.EnableTrusted && (r == nil || !r.GetTrusted()) {
if c.config.EnforceTrustedRepos && (r == nil || !r.GetTrusted()) {
return errors.New("repo must be trusted to run privileged images")
}

Expand Down
4 changes: 2 additions & 2 deletions runtime/kubernetes/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ type config struct {
Namespace string
// specifies a list of privileged images to use for the Kubernetes client
Images []string
// EnableTrusted FILL ME
EnableTrusted bool
// EnforceTrustedRepos sets whether to enforce trusted repo restrictions on privileged images for the Kubernetes client
EnforceTrustedRepos bool
// specifies a list of host volumes to use for the Kubernetes client
Volumes []string
// PipelinePodsTemplateName has the name of the PipelinePodTemplate to retrieve from the Namespace
Expand Down
6 changes: 3 additions & 3 deletions runtime/kubernetes/opts.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,13 @@ func WithPrivilegedImages(images []string) ClientOpt {
}
}

// WithEnableTrusted sets FILL ME.
func WithEnableTrusted(enable bool) ClientOpt {
// WithEnforceTrustedRepos sets whether to enforce trusted repo restrictions on privileged images in the runtime client for Kubernetes.
func WithEnforceTrustedRepos(enable bool) ClientOpt {
return func(c *client) error {
c.Logger.Trace("configuring FILLME in kubernetes runtime client")

// set the runtime FILLME in the kubernetes client
c.config.EnableTrusted = enable
c.config.EnforceTrustedRepos = enable

return nil
}
Expand Down
10 changes: 4 additions & 6 deletions runtime/setup.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,21 +42,19 @@ type Setup struct {
PodsTemplateFile string
// specifies a list of privileged images to use for the runtime client
PrivilegedImages []string
// specifies settings for restrictions on trusted repos
EnableTrusted bool
// EnforceTrustedRepos sets whether to enforce trusted repo restrictions on privileged images for the runtime client
EnforceTrustedRepos bool
}

// Docker creates and returns a Vela engine capable of
// integrating with a Docker runtime environment.
func (s *Setup) Docker() (Engine, error) {
logrus.Trace("creating docker runtime client from setup")

logrus.Trace("creating docker runtime using enable trusted %v", s.EnableTrusted)

opts := []docker.ClientOpt{
docker.WithHostVolumes(s.HostVolumes),
docker.WithPrivilegedImages(s.PrivilegedImages),
docker.WithEnableTrusted(s.EnableTrusted),
docker.WithEnforceTrustedRepos(s.EnforceTrustedRepos),
docker.WithLogger(s.Logger),
}

Expand Down Expand Up @@ -84,7 +82,7 @@ func (s *Setup) Kubernetes() (Engine, error) {
kubernetes.WithNamespace(s.Namespace),
kubernetes.WithPodsTemplate(s.PodsTemplateName, s.PodsTemplateFile),
kubernetes.WithPrivilegedImages(s.PrivilegedImages),
kubernetes.WithEnableTrusted(s.EnableTrusted),
kubernetes.WithEnforceTrustedRepos(s.EnforceTrustedRepos),
kubernetes.WithLogger(s.Logger),
}

Expand Down