restrict volumes used with plugins

This commit is contained in:
Brad Rydzewski
2020-11-17 08:36:06 -05:00
parent c8b3a362a2
commit 2335394161
2 changed files with 25 additions and 1 deletions

View File

@@ -1,6 +1,11 @@
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## 1.6.1
### Changed
- restrict temporary volumes used with docker plugins
- restrict environment variables used with docker plugins
## 1.6.0 ## 1.6.0
### Added ### Added
- experimental support for remote debugging with tmate, disabled by default - experimental support for remote debugging with tmate, disabled by default

View File

@@ -123,6 +123,14 @@ func (c *Compiler) Compile(ctx context.Context, args runtime.CompilerArgs) runti
// create the workspace paths // create the workspace paths
base, path, full := createWorkspace(pipeline) base, path, full := createWorkspace(pipeline)
// reset the workspace path if attempting to mount
// volumes that are internal use only.
if isRestrictedVolume(full) {
base = "/drone/src"
path = ""
full = "/drone/src"
}
// if the source code is mounted from the host, the // if the source code is mounted from the host, the
// target mount path inside the container must be the // target mount path inside the container must be the
// full workspace path. // full workspace path.
@@ -504,13 +512,24 @@ func (c *Compiler) isPrivileged(step *resource.Step) bool {
if len(step.Entrypoint) > 0 { if len(step.Entrypoint) > 0 {
return false return false
} }
if len(step.Volumes) > 0 {
return false
}
// privileged-by-default mode is disabled if the // privileged-by-default mode is disabled if the
// pipeline step mounts a restricted volume. // pipeline step mounts a volume restricted for
// internal use only.
// note: this is deprecated.
for _, mount := range step.Volumes { for _, mount := range step.Volumes {
if isRestrictedVolume(mount.MountPath) { if isRestrictedVolume(mount.MountPath) {
return false return false
} }
} }
// privileged-by-default mode is disabled if the
// pipeline step attempts to use an environment
// variable restricted for internal use only.
if isRestrictedVariable(step.Environment) {
return false
}
// if the container image matches any image // if the container image matches any image
// in the whitelist, return true. // in the whitelist, return true.
for _, img := range c.Privileged { for _, img := range c.Privileged {