mirror of
https://github.com/containers/podman.git
synced 2025-06-22 18:08:11 +08:00
Merge pull request #10155 from pablofsf/fix-default-seccomp
Use seccomp_profile as default profile if defined in containers.conf
This commit is contained in:
@ -17,6 +17,7 @@ type SecurityInfo struct {
|
|||||||
DefaultCapabilities string `json:"capabilities"`
|
DefaultCapabilities string `json:"capabilities"`
|
||||||
Rootless bool `json:"rootless"`
|
Rootless bool `json:"rootless"`
|
||||||
SECCOMPEnabled bool `json:"seccompEnabled"`
|
SECCOMPEnabled bool `json:"seccompEnabled"`
|
||||||
|
SECCOMPProfilePath string `json:"seccompProfilePath"`
|
||||||
SELinuxEnabled bool `json:"selinuxEnabled"`
|
SELinuxEnabled bool `json:"selinuxEnabled"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,6 +87,12 @@ func (r *Runtime) hostInfo() (*define.HostInfo, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, errors.Wrapf(err, "error getting hostname")
|
return nil, errors.Wrapf(err, "error getting hostname")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
seccompProfilePath, err := DefaultSeccompPath()
|
||||||
|
if err != nil {
|
||||||
|
return nil, errors.Wrapf(err, "error getting Seccomp profile path")
|
||||||
|
}
|
||||||
|
|
||||||
info := define.HostInfo{
|
info := define.HostInfo{
|
||||||
Arch: runtime.GOARCH,
|
Arch: runtime.GOARCH,
|
||||||
BuildahVersion: buildah.Version,
|
BuildahVersion: buildah.Version,
|
||||||
@ -106,6 +112,7 @@ func (r *Runtime) hostInfo() (*define.HostInfo, error) {
|
|||||||
DefaultCapabilities: strings.Join(r.config.Containers.DefaultCapabilities, ","),
|
DefaultCapabilities: strings.Join(r.config.Containers.DefaultCapabilities, ","),
|
||||||
Rootless: rootless.IsRootless(),
|
Rootless: rootless.IsRootless(),
|
||||||
SECCOMPEnabled: seccomp.IsEnabled(),
|
SECCOMPEnabled: seccomp.IsEnabled(),
|
||||||
|
SECCOMPProfilePath: seccompProfilePath,
|
||||||
SELinuxEnabled: selinux.GetEnabled(),
|
SELinuxEnabled: selinux.GetEnabled(),
|
||||||
},
|
},
|
||||||
Slirp4NetNS: define.SlirpInfo{},
|
Slirp4NetNS: define.SlirpInfo{},
|
||||||
|
@ -194,7 +194,15 @@ func programVersion(mountProgram string) (string, error) {
|
|||||||
// if it exists, first it checks OverrideSeccomp and then default.
|
// if it exists, first it checks OverrideSeccomp and then default.
|
||||||
// If neither exist function returns ""
|
// If neither exist function returns ""
|
||||||
func DefaultSeccompPath() (string, error) {
|
func DefaultSeccompPath() (string, error) {
|
||||||
_, err := os.Stat(config.SeccompOverridePath)
|
def, err := config.Default()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
if def.Containers.SeccompProfile != "" {
|
||||||
|
return def.Containers.SeccompProfile, nil
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = os.Stat(config.SeccompOverridePath)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
return config.SeccompOverridePath, nil
|
return config.SeccompOverridePath, nil
|
||||||
}
|
}
|
||||||
|
@ -353,4 +353,23 @@ var _ = Describe("Podman run", func() {
|
|||||||
Expect(session.ExitCode()).To(Equal(0))
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
Expect(session.OutputToString()).To(ContainSubstring("test"))
|
Expect(session.OutputToString()).To(ContainSubstring("test"))
|
||||||
})
|
})
|
||||||
|
|
||||||
|
It("podman info seccomp profile path", func() {
|
||||||
|
configPath := filepath.Join(podmanTest.TempDir, "containers.conf")
|
||||||
|
os.Setenv("CONTAINERS_CONF", configPath)
|
||||||
|
|
||||||
|
profile := filepath.Join(podmanTest.TempDir, "seccomp.json")
|
||||||
|
containersConf := []byte(fmt.Sprintf("[containers]\nseccomp_profile=\"%s\"", profile))
|
||||||
|
err = ioutil.WriteFile(configPath, containersConf, os.ModePerm)
|
||||||
|
Expect(err).To(BeNil())
|
||||||
|
|
||||||
|
if IsRemote() {
|
||||||
|
podmanTest.RestartRemoteService()
|
||||||
|
}
|
||||||
|
|
||||||
|
session := podmanTest.Podman([]string{"info", "--format", "{{.Host.Security.SECCOMPProfilePath}}"})
|
||||||
|
session.WaitWithDefaultTimeout()
|
||||||
|
Expect(session.ExitCode()).To(Equal(0))
|
||||||
|
Expect(session.OutputToString()).To(Equal(profile))
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
Reference in New Issue
Block a user