Skip to content

Commit

Permalink
api: implement seccomp adjustment via json string
Browse files Browse the repository at this point in the history
a much less boilerplate-y version of seccomp policy adjustment

Signed-off-by: Tycho Andersen <tycho@tycho.pizza>
  • Loading branch information
tych0 committed Nov 22, 2024
1 parent 6d486ac commit a70547a
Show file tree
Hide file tree
Showing 5 changed files with 459 additions and 334 deletions.
32 changes: 32 additions & 0 deletions pkg/adaptation/result.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,9 @@ func (r *result) adjust(rpl *ContainerAdjustment, plugin string) error {
if err := r.adjustOomScoreAdj(rpl.Linux.OomScoreAdj, plugin); err != nil {
return err
}
if err := r.adjustSeccompPolicy(rpl.Linux.SeccompPolicy, plugin); err != nil {
return err
}
}
if err := r.adjustRlimits(rpl.Rlimits, plugin); err != nil {
return err
Expand Down Expand Up @@ -738,6 +741,22 @@ func (r *result) adjustOomScoreAdj(OomScoreAdj *OptionalInt, plugin string) erro
return nil
}

func (r *result) adjustSeccompPolicy(adjustment *OptionalString, plugin string) error {
if adjustment == nil {
return nil
}
create, id := r.request.create, r.request.create.Container.Id

if err := r.owners.claimSeccompPolicy(id, plugin); err != nil {
return err
}

create.Container.Linux.SeccompPolicy = adjustment.Value
r.reply.adjust.Linux.SeccompPolicy = adjustment

return nil
}

func (r *result) adjustRlimits(rlimits []*POSIXRlimit, plugin string) error {
create, id, adjust := r.request.create, r.request.create.Container.Id, r.reply.adjust
for _, l := range rlimits {
Expand Down Expand Up @@ -976,6 +995,7 @@ type owners struct {
unified map[string]string
cgroupsPath string
oomScoreAdj string
seccompPolicy string
rlimits map[string]string
}

Expand Down Expand Up @@ -1096,6 +1116,10 @@ func (ro resultOwners) claimOomScoreAdj(id, plugin string) error {
return ro.ownersFor(id).claimOomScoreAdj(plugin)
}

func (ro resultOwners) claimSeccompPolicy(id, plugin string) error {
return ro.ownersFor(id).claimSeccompPolicy(plugin)
}

func (ro resultOwners) claimRlimits(id, typ, plugin string) error {
return ro.ownersFor(id).claimRlimit(typ, plugin)
}
Expand Down Expand Up @@ -1349,6 +1373,14 @@ func (o *owners) claimOomScoreAdj(plugin string) error {
return nil
}

func (o *owners) claimSeccompPolicy(plugin string) error {
if other := o.seccompPolicy; other != "" {
return conflict(plugin, other, "seccomp policy")
}
o.seccompPolicy = plugin
return nil
}

func (ro resultOwners) clearAnnotation(id, key string) {
ro.ownersFor(id).clearAnnotation(key)
}
Expand Down
Loading

0 comments on commit a70547a

Please sign in to comment.