Skip to content

Commit db67fed

Browse files
Merge pull request #10155 from pablofsf/fix-default-seccomp
Use seccomp_profile as default profile if defined in containers.conf
2 parents 928dce5 + 18cb17f commit db67fed

File tree

4 files changed

+36
-1
lines changed

4 files changed

+36
-1
lines changed

libpod/define/info.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type SecurityInfo struct {
1717
DefaultCapabilities string `json:"capabilities"`
1818
Rootless bool `json:"rootless"`
1919
SECCOMPEnabled bool `json:"seccompEnabled"`
20+
SECCOMPProfilePath string `json:"seccompProfilePath"`
2021
SELinuxEnabled bool `json:"selinuxEnabled"`
2122
}
2223

libpod/info.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,12 @@ func (r *Runtime) hostInfo() (*define.HostInfo, error) {
8787
if err != nil {
8888
return nil, errors.Wrapf(err, "error getting hostname")
8989
}
90+
91+
seccompProfilePath, err := DefaultSeccompPath()
92+
if err != nil {
93+
return nil, errors.Wrapf(err, "error getting Seccomp profile path")
94+
}
95+
9096
info := define.HostInfo{
9197
Arch: runtime.GOARCH,
9298
BuildahVersion: buildah.Version,
@@ -106,6 +112,7 @@ func (r *Runtime) hostInfo() (*define.HostInfo, error) {
106112
DefaultCapabilities: strings.Join(r.config.Containers.DefaultCapabilities, ","),
107113
Rootless: rootless.IsRootless(),
108114
SECCOMPEnabled: seccomp.IsEnabled(),
115+
SECCOMPProfilePath: seccompProfilePath,
109116
SELinuxEnabled: selinux.GetEnabled(),
110117
},
111118
Slirp4NetNS: define.SlirpInfo{},

libpod/util.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,15 @@ func programVersion(mountProgram string) (string, error) {
194194
// if it exists, first it checks OverrideSeccomp and then default.
195195
// If neither exist function returns ""
196196
func DefaultSeccompPath() (string, error) {
197-
_, err := os.Stat(config.SeccompOverridePath)
197+
def, err := config.Default()
198+
if err != nil {
199+
return "", err
200+
}
201+
if def.Containers.SeccompProfile != "" {
202+
return def.Containers.SeccompProfile, nil
203+
}
204+
205+
_, err = os.Stat(config.SeccompOverridePath)
198206
if err == nil {
199207
return config.SeccompOverridePath, nil
200208
}

test/e2e/containers_conf_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,4 +353,23 @@ var _ = Describe("Podman run", func() {
353353
Expect(session.ExitCode()).To(Equal(0))
354354
Expect(session.OutputToString()).To(ContainSubstring("test"))
355355
})
356+
357+
It("podman info seccomp profile path", func() {
358+
configPath := filepath.Join(podmanTest.TempDir, "containers.conf")
359+
os.Setenv("CONTAINERS_CONF", configPath)
360+
361+
profile := filepath.Join(podmanTest.TempDir, "seccomp.json")
362+
containersConf := []byte(fmt.Sprintf("[containers]\nseccomp_profile=\"%s\"", profile))
363+
err = ioutil.WriteFile(configPath, containersConf, os.ModePerm)
364+
Expect(err).To(BeNil())
365+
366+
if IsRemote() {
367+
podmanTest.RestartRemoteService()
368+
}
369+
370+
session := podmanTest.Podman([]string{"info", "--format", "{{.Host.Security.SECCOMPProfilePath}}"})
371+
session.WaitWithDefaultTimeout()
372+
Expect(session.ExitCode()).To(Equal(0))
373+
Expect(session.OutputToString()).To(Equal(profile))
374+
})
356375
})

0 commit comments

Comments
 (0)