Update vendor github.com/opencontainers/runtime-tools

This will change mount of /dev within container to noexec, making
containers slightly more secure.

[NO NEW TESTS NEEDED]

Signed-off-by: Daniel J Walsh <dwalsh@redhat.com>
This commit is contained in:
Daniel J Walsh
2021-10-25 07:22:11 -04:00
parent dbe770e3ce
commit a42c131c80
9 changed files with 93 additions and 20 deletions

2
go.mod
View File

@ -50,7 +50,7 @@ require (
github.com/opencontainers/image-spec v1.0.2-0.20210819154149-5ad6f50d6283 github.com/opencontainers/image-spec v1.0.2-0.20210819154149-5ad6f50d6283
github.com/opencontainers/runc v1.0.2 github.com/opencontainers/runc v1.0.2
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
github.com/opencontainers/runtime-tools v0.9.0 github.com/opencontainers/runtime-tools v0.9.1-0.20211020193359-09d837bf40a7
github.com/opencontainers/selinux v1.9.1 github.com/opencontainers/selinux v1.9.1
github.com/pkg/errors v0.9.1 github.com/pkg/errors v0.9.1
github.com/pmezard/go-difflib v1.0.0 github.com/pmezard/go-difflib v1.0.0

3
go.sum
View File

@ -786,8 +786,9 @@ github.com/opencontainers/runtime-spec v1.0.3-0.20200929063507-e6143ca7d51d/go.m
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 h1:3snG66yBm59tKhhSPQrQ/0bCrv1LQbKt40LnUPiUxdc= github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 h1:3snG66yBm59tKhhSPQrQ/0bCrv1LQbKt40LnUPiUxdc=
github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0= github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417/go.mod h1:jwyrGlmzljRJv/Fgzds9SsS/C5hL+LL3ko9hs6T5lQ0=
github.com/opencontainers/runtime-tools v0.0.0-20181011054405-1d69bd0f9c39/go.mod h1:r3f7wjNzSs2extwzU3Y+6pKfobzPh+kKFJ3ofN+3nfs= github.com/opencontainers/runtime-tools v0.0.0-20181011054405-1d69bd0f9c39/go.mod h1:r3f7wjNzSs2extwzU3Y+6pKfobzPh+kKFJ3ofN+3nfs=
github.com/opencontainers/runtime-tools v0.9.0 h1:FYgwVsKRI/H9hU32MJ/4MLOzXWodKK5zsQavY8NPMkU=
github.com/opencontainers/runtime-tools v0.9.0/go.mod h1:r3f7wjNzSs2extwzU3Y+6pKfobzPh+kKFJ3ofN+3nfs= github.com/opencontainers/runtime-tools v0.9.0/go.mod h1:r3f7wjNzSs2extwzU3Y+6pKfobzPh+kKFJ3ofN+3nfs=
github.com/opencontainers/runtime-tools v0.9.1-0.20211020193359-09d837bf40a7 h1:6JHkPc2wUOsj2XBpYzyvmCL5Y/fA3TFaomYv/Iggt1g=
github.com/opencontainers/runtime-tools v0.9.1-0.20211020193359-09d837bf40a7/go.mod h1:r3f7wjNzSs2extwzU3Y+6pKfobzPh+kKFJ3ofN+3nfs=
github.com/opencontainers/selinux v1.5.1/go.mod h1:yTcKuYAh6R95iDpefGLQaPaRwJFwyzAJufJyiTt7s0g= github.com/opencontainers/selinux v1.5.1/go.mod h1:yTcKuYAh6R95iDpefGLQaPaRwJFwyzAJufJyiTt7s0g=
github.com/opencontainers/selinux v1.6.0/go.mod h1:VVGKuOLlE7v4PJyT6h7mNWvq1rzqiriPsEqVhc+svHE= github.com/opencontainers/selinux v1.6.0/go.mod h1:VVGKuOLlE7v4PJyT6h7mNWvq1rzqiriPsEqVhc+svHE=
github.com/opencontainers/selinux v1.8.0/go.mod h1:RScLhm78qiWa2gbVCcGkC7tCGdgk3ogry1nUQF8Evvo= github.com/opencontainers/selinux v1.8.0/go.mod h1:RScLhm78qiWa2gbVCcGkC7tCGdgk3ogry1nUQF8Evvo=

View File

@ -322,7 +322,7 @@ func (c *Container) generateSpec(ctx context.Context) (*spec.Spec, error) {
return nil, err return nil, err
} }
g := generate.Generator{Config: c.config.Spec} g := generate.NewFromSpec(c.config.Spec)
// If network namespace was requested, add it now // If network namespace was requested, add it now
if c.config.CreateNetNS { if c.config.CreateNetNS {
@ -1219,7 +1219,8 @@ func (c *Container) importCheckpoint(input string) error {
} }
// Make sure the newly created config.json exists on disk // Make sure the newly created config.json exists on disk
g := generate.Generator{Config: c.config.Spec} g := generate.NewFromSpec(c.config.Spec)
if err := c.saveSpec(g.Config); err != nil { if err := c.saveSpec(g.Config); err != nil {
return errors.Wrap(err, "saving imported container specification for restore failed") return errors.Wrap(err, "saving imported container specification for restore failed")
} }

View File

@ -969,7 +969,7 @@ func WithUserNSFrom(nsCtr *Container) CtrCreateOption {
if err := JSONDeepCopy(nsCtr.IDMappings(), &ctr.config.IDMappings); err != nil { if err := JSONDeepCopy(nsCtr.IDMappings(), &ctr.config.IDMappings); err != nil {
return err return err
} }
g := generate.Generator{Config: ctr.config.Spec} g := generate.NewFromSpec(ctr.config.Spec)
g.ClearLinuxUIDMappings() g.ClearLinuxUIDMappings()
for _, uidmap := range nsCtr.config.IDMappings.UIDMap { for _, uidmap := range nsCtr.config.IDMappings.UIDMap {

View File

@ -389,7 +389,7 @@ func (r *Runtime) setupContainer(ctx context.Context, ctr *Container) (_ *Contai
if ctr.restoreFromCheckpoint { if ctr.restoreFromCheckpoint {
// Remove information about bind mount // Remove information about bind mount
// for new container from imported checkpoint // for new container from imported checkpoint
g := generate.Generator{Config: ctr.config.Spec} g := generate.NewFromSpec(ctr.config.Spec)
g.RemoveMount("/dev/shm") g.RemoveMount("/dev/shm")
ctr.config.ShmDir = "" ctr.config.ShmDir = ""
g.RemoveMount("/etc/resolv.conf") g.RemoveMount("/etc/resolv.conf")

View File

@ -29,6 +29,9 @@ var (
type Generator struct { type Generator struct {
Config *rspec.Spec Config *rspec.Spec
HostSpecific bool HostSpecific bool
// This is used to keep a cache of the ENVs added to improve
// performance when adding a huge number of ENV variables
envMap map[string]int
} }
// ExportOptions have toggles for exporting only certain parts of the specification // ExportOptions have toggles for exporting only certain parts of the specification
@ -179,7 +182,7 @@ func New(os string) (generator Generator, err error) {
Destination: "/dev", Destination: "/dev",
Type: "tmpfs", Type: "tmpfs",
Source: "tmpfs", Source: "tmpfs",
Options: []string{"nosuid", "strictatime", "mode=755", "size=65536k"}, Options: []string{"nosuid", "noexec", "strictatime", "mode=755", "size=65536k"},
}, },
{ {
Destination: "/dev/pts", Destination: "/dev/pts",
@ -236,7 +239,12 @@ func New(os string) (generator Generator, err error) {
} }
} }
return Generator{Config: &config}, nil envCache := map[string]int{}
if config.Process != nil {
envCache = createEnvCacheMap(config.Process.Env)
}
return Generator{Config: &config, envMap: envCache}, nil
} }
// NewFromSpec creates a configuration Generator from a given // NewFromSpec creates a configuration Generator from a given
@ -246,8 +254,14 @@ func New(os string) (generator Generator, err error) {
// //
// generator := Generator{Config: config} // generator := Generator{Config: config}
func NewFromSpec(config *rspec.Spec) Generator { func NewFromSpec(config *rspec.Spec) Generator {
envCache := map[string]int{}
if config != nil && config.Process != nil {
envCache = createEnvCacheMap(config.Process.Env)
}
return Generator{ return Generator{
Config: config, Config: config,
envMap: envCache,
} }
} }
@ -273,11 +287,27 @@ func NewFromTemplate(r io.Reader) (Generator, error) {
if err := json.NewDecoder(r).Decode(&config); err != nil { if err := json.NewDecoder(r).Decode(&config); err != nil {
return Generator{}, err return Generator{}, err
} }
envCache := map[string]int{}
if config.Process != nil {
envCache = createEnvCacheMap(config.Process.Env)
}
return Generator{ return Generator{
Config: &config, Config: &config,
envMap: envCache,
}, nil }, nil
} }
// createEnvCacheMap creates a hash map with the ENV variables given by the config
func createEnvCacheMap(env []string) map[string]int {
envMap := make(map[string]int, len(env))
for i, val := range env {
envMap[val] = i
}
return envMap
}
// SetSpec sets the configuration in the Generator g. // SetSpec sets the configuration in the Generator g.
// //
// Deprecated: Replace with: // Deprecated: Replace with:
@ -414,6 +444,13 @@ func (g *Generator) SetProcessUsername(username string) {
g.Config.Process.User.Username = username g.Config.Process.User.Username = username
} }
// SetProcessUmask sets g.Config.Process.User.Umask.
func (g *Generator) SetProcessUmask(umask uint32) {
g.initConfigProcess()
u := umask
g.Config.Process.User.Umask = &u
}
// SetProcessGID sets g.Config.Process.User.GID. // SetProcessGID sets g.Config.Process.User.GID.
func (g *Generator) SetProcessGID(gid uint32) { func (g *Generator) SetProcessGID(gid uint32) {
g.initConfigProcess() g.initConfigProcess()
@ -456,21 +493,44 @@ func (g *Generator) ClearProcessEnv() {
return return
} }
g.Config.Process.Env = []string{} g.Config.Process.Env = []string{}
// Clear out the env cache map as well
g.envMap = map[string]int{}
} }
// AddProcessEnv adds name=value into g.Config.Process.Env, or replaces an // AddProcessEnv adds name=value into g.Config.Process.Env, or replaces an
// existing entry with the given name. // existing entry with the given name.
func (g *Generator) AddProcessEnv(name, value string) { func (g *Generator) AddProcessEnv(name, value string) {
if name == "" {
return
}
g.initConfigProcess()
g.addEnv(fmt.Sprintf("%s=%s", name, value), name)
}
// AddMultipleProcessEnv adds multiple name=value into g.Config.Process.Env, or replaces
// existing entries with the given name.
func (g *Generator) AddMultipleProcessEnv(envs []string) {
g.initConfigProcess() g.initConfigProcess()
env := fmt.Sprintf("%s=%s", name, value) for _, val := range envs {
for idx := range g.Config.Process.Env { split := strings.SplitN(val, "=", 2)
if strings.HasPrefix(g.Config.Process.Env[idx], name+"=") { g.addEnv(val, split[0])
g.Config.Process.Env[idx] = env }
return }
}
// addEnv looks through adds ENV to the Process and checks envMap for
// any duplicates
// This is called by both AddMultipleProcessEnv and AddProcessEnv
func (g *Generator) addEnv(env, key string) {
if idx, ok := g.envMap[key]; ok {
// The ENV exists in the cache, so change its value in g.Config.Process.Env
g.Config.Process.Env[idx] = env
} else {
// else the env doesn't exist, so add it and add it's index to g.envMap
g.Config.Process.Env = append(g.Config.Process.Env, env)
g.envMap[key] = len(g.Config.Process.Env) - 1
} }
g.Config.Process.Env = append(g.Config.Process.Env, env)
} }
// AddProcessRlimits adds rlimit into g.Config.Process.Rlimits. // AddProcessRlimits adds rlimit into g.Config.Process.Rlimits.
@ -1442,9 +1502,6 @@ func (g *Generator) AddDevice(device rspec.LinuxDevice) {
g.Config.Linux.Devices[i] = device g.Config.Linux.Devices[i] = device
return return
} }
if dev.Type == device.Type && dev.Major == device.Major && dev.Minor == device.Minor {
fmt.Fprintln(os.Stderr, "WARNING: The same type, major and minor should not be used for multiple devices.")
}
} }
g.Config.Linux.Devices = append(g.Config.Linux.Devices, device) g.Config.Linux.Devices = append(g.Config.Linux.Devices, device)

View File

@ -566,6 +566,20 @@ func DefaultProfile(rs *specs.Spec) *rspec.LinuxSeccomp {
}, },
}...) }...)
/* Flags parameter of the clone syscall is the 2nd on s390 */ /* Flags parameter of the clone syscall is the 2nd on s390 */
syscalls = append(syscalls, []rspec.LinuxSyscall{
{
Names: []string{"clone"},
Action: rspec.ActAllow,
Args: []rspec.LinuxSeccompArg{
{
Index: 1,
Value: 2080505856,
ValueTwo: 0,
Op: rspec.OpMaskedEqual,
},
},
},
}...)
} }
return &rspec.LinuxSeccomp{ return &rspec.LinuxSeccomp{

View File

@ -144,7 +144,7 @@ func JSONSchemaURL(version string) (url string, err error) {
func (v *Validator) CheckJSONSchema() (errs error) { func (v *Validator) CheckJSONSchema() (errs error) {
logrus.Debugf("check JSON schema") logrus.Debugf("check JSON schema")
url, err := JSONSchemaURL(v.spec.Version) url, err := JSONSchemaURL(strings.TrimSuffix(v.spec.Version, "-dev"))
if err != nil { if err != nil {
errs = multierror.Append(errs, err) errs = multierror.Append(errs, err)
return errs return errs

2
vendor/modules.txt vendored
View File

@ -517,7 +517,7 @@ github.com/opencontainers/runc/libcontainer/userns
github.com/opencontainers/runc/libcontainer/utils github.com/opencontainers/runc/libcontainer/utils
# github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417 # github.com/opencontainers/runtime-spec v1.0.3-0.20210326190908-1c3f411f0417
github.com/opencontainers/runtime-spec/specs-go github.com/opencontainers/runtime-spec/specs-go
# github.com/opencontainers/runtime-tools v0.9.0 # github.com/opencontainers/runtime-tools v0.9.1-0.20211020193359-09d837bf40a7
github.com/opencontainers/runtime-tools/error github.com/opencontainers/runtime-tools/error
github.com/opencontainers/runtime-tools/filepath github.com/opencontainers/runtime-tools/filepath
github.com/opencontainers/runtime-tools/generate github.com/opencontainers/runtime-tools/generate