Skip to content

Commit 99d2437

Browse files
committed
api: add seccomp adjustment
This adds an adjustment for seccomp policies. The intent is that people can wholesale replace policies, or parse them, make some changes, and then send them back. Sending them *to* NRI via containerd requires some containerd patches as well, those are here: https://github.com/tych0/containerd/commits/nri-seccomp/ Specifically, we are interested in making the listenerPath of the policy dynamic based on a k8s pod spec, so we can't use the Localhost custom policy (well, we can use most of it, except for listenerPath, which we have an NRI plugin to change based on this code). This patch is a lot of boilerplate, which is unfortunate. There is a much smaller but similar patch: tych0@a70547a but it involves directly serializing a runtime-spec string Finally, note the comment in generate.go: the runtime-tools generate code does not have complete coverage for seccomp stuff, so I opted to not use any of it, vs. adding more stuff to runtime-tools. The fact that there are human and computer names is also confusing, it seems like we should stick to the computer names for this particular interface. Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
1 parent 6d486ac commit 99d2437

File tree

7 files changed

+965
-368
lines changed

7 files changed

+965
-368
lines changed

pkg/adaptation/api.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ type (
7878
LinuxMemory = api.LinuxMemory
7979
LinuxDevice = api.LinuxDevice
8080
LinuxDeviceCgroup = api.LinuxDeviceCgroup
81+
LinuxSeccomp = api.LinuxSeccomp
8182
CDIDevice = api.CDIDevice
8283
HugepageLimit = api.HugepageLimit
8384
Hooks = api.Hooks

pkg/adaptation/result.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,9 @@ func (r *result) adjust(rpl *ContainerAdjustment, plugin string) error {
219219
if err := r.adjustOomScoreAdj(rpl.Linux.OomScoreAdj, plugin); err != nil {
220220
return err
221221
}
222+
if err := r.adjustSeccompPolicy(rpl.Linux.SeccompPolicy, plugin); err != nil {
223+
return err
224+
}
222225
}
223226
if err := r.adjustRlimits(rpl.Rlimits, plugin); err != nil {
224227
return err
@@ -738,6 +741,22 @@ func (r *result) adjustOomScoreAdj(OomScoreAdj *OptionalInt, plugin string) erro
738741
return nil
739742
}
740743

744+
func (r *result) adjustSeccompPolicy(adjustment *LinuxSeccomp, plugin string) error {
745+
if adjustment == nil {
746+
return nil
747+
}
748+
create, id := r.request.create, r.request.create.Container.Id
749+
750+
if err := r.owners.claimSeccompPolicy(id, plugin); err != nil {
751+
return err
752+
}
753+
754+
create.Container.Linux.SeccompPolicy = adjustment
755+
r.reply.adjust.Linux.SeccompPolicy = adjustment
756+
757+
return nil
758+
}
759+
741760
func (r *result) adjustRlimits(rlimits []*POSIXRlimit, plugin string) error {
742761
create, id, adjust := r.request.create, r.request.create.Container.Id, r.reply.adjust
743762
for _, l := range rlimits {
@@ -976,6 +995,7 @@ type owners struct {
976995
unified map[string]string
977996
cgroupsPath string
978997
oomScoreAdj string
998+
seccompPolicy string
979999
rlimits map[string]string
9801000
}
9811001

@@ -1096,6 +1116,10 @@ func (ro resultOwners) claimOomScoreAdj(id, plugin string) error {
10961116
return ro.ownersFor(id).claimOomScoreAdj(plugin)
10971117
}
10981118

1119+
func (ro resultOwners) claimSeccompPolicy(id, plugin string) error {
1120+
return ro.ownersFor(id).claimSeccompPolicy(plugin)
1121+
}
1122+
10991123
func (ro resultOwners) claimRlimits(id, typ, plugin string) error {
11001124
return ro.ownersFor(id).claimRlimit(typ, plugin)
11011125
}
@@ -1349,6 +1373,14 @@ func (o *owners) claimOomScoreAdj(plugin string) error {
13491373
return nil
13501374
}
13511375

1376+
func (o *owners) claimSeccompPolicy(plugin string) error {
1377+
if other := o.seccompPolicy; other != "" {
1378+
return conflict(plugin, other, "seccomp policy")
1379+
}
1380+
o.seccompPolicy = plugin
1381+
return nil
1382+
}
1383+
13521384
func (ro resultOwners) clearAnnotation(id, key string) {
13531385
ro.ownersFor(id).clearAnnotation(key)
13541386
}

0 commit comments

Comments
 (0)