Skip to content

Commit

Permalink
Move cri-tools SHA and migrate seccomp profile
Browse files Browse the repository at this point in the history
  • Loading branch information
nwneisen committed Aug 18, 2023
1 parent b9f52ee commit 613f80a
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ jobs:
with:
repository: kubernetes-sigs/cri-tools
path: src/sigs.k8s.io/cri-tools
ref: e3c99451faee42de2fcf4568bdd81be8bb29e40f
ref: 5fd98895f3bbf8a3ba2d25e93fa95ba1e2ae0923

- name: Build cri-tools
working-directory: src/sigs.k8s.io/cri-tools
Expand Down
2 changes: 1 addition & 1 deletion core/container_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func (ds *dockerService) CreateContainer(
hc.Resources.Devices = devices

securityOpts, err := ds.getSecurityOpts(
config.GetLinux().GetSecurityContext().GetSeccompProfilePath(),
config.GetLinux().GetSecurityContext().GetSeccomp(),
securityOptSeparator,
)
if err != nil {
Expand Down
21 changes: 12 additions & 9 deletions core/security_context.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ import (
"crypto/md5"
"encoding/json"
"fmt"
"github.com/Mirantis/cri-dockerd/config"
"io/ioutil"
"path/filepath"
"strconv"
"strings"

"github.com/Mirantis/cri-dockerd/config"

dockercontainer "github.com/docker/docker/api/types/container"

runtimeapi "k8s.io/cri-api/pkg/apis/runtime/v1"
v1 "k8s.io/cri-api/pkg/apis/runtime/v1"

knetwork "github.com/Mirantis/cri-dockerd/network"
)
Expand Down Expand Up @@ -248,24 +250,25 @@ func modifyHostOptionsForContainer(
}
}

func getSeccompDockerOpts(seccompProfile string) ([]DockerOpt, error) {
if seccompProfile == "" || seccompProfile == config.SeccompProfileNameUnconfined {
func getSeccompDockerOpts(seccomp *v1.SecurityProfile) ([]DockerOpt, error) {

if seccomp == nil || seccomp.GetProfileType() == v1.SecurityProfile_Unconfined {
// return early the default
return defaultSeccompOpt, nil
}

if seccompProfile == config.SeccompProfileRuntimeDefault ||
seccompProfile == config.DeprecatedSeccompProfileDockerDefault {
if seccomp.GetProfileType() == v1.SecurityProfile_RuntimeDefault ||
seccomp.GetProfileType().String() == config.DeprecatedSeccompProfileDockerDefault {
// return nil so docker will load the default seccomp profile
return nil, nil
}

if !strings.HasPrefix(seccompProfile, config.SeccompLocalhostProfileNamePrefix) {
return nil, fmt.Errorf("unknown seccomp profile option: %s", seccompProfile)
if seccomp.GetProfileType() != v1.SecurityProfile_Localhost {
return nil, fmt.Errorf("unknown seccomp profile option: %s", seccomp)
}

// get the full path of seccomp profile when prefixed with 'localhost/'.
fname := strings.TrimPrefix(seccompProfile, config.SeccompLocalhostProfileNamePrefix)
fname := seccomp.GetLocalhostRef()
if !filepath.IsAbs(fname) {
return nil, fmt.Errorf(
"seccomp profile path must be absolute, but got relative path %q",
Expand All @@ -289,7 +292,7 @@ func getSeccompDockerOpts(seccompProfile string) ([]DockerOpt, error) {

// getSeccompSecurityOpts gets container seccomp options from container seccomp profile.
// It is an experimental feature and may be promoted to official runtime api in the future.
func getSeccompSecurityOpts(seccompProfile string, separator rune) ([]string, error) {
func getSeccompSecurityOpts(seccompProfile *v1.SecurityProfile, separator rune) ([]string, error) {
seccompOpts, err := getSeccompDockerOpts(seccompProfile)
if err != nil {
return nil, err
Expand Down
6 changes: 4 additions & 2 deletions core/security_context_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@ package core

import (
"fmt"

v1 "k8s.io/cri-api/pkg/apis/runtime/v1"
)

func (ds *dockerService) getSecurityOpts(seccompProfile string, separator rune) ([]string, error) {
func (ds *dockerService) getSecurityOpts(seccomp *v1.SecurityProfile, separator rune) ([]string, error) {
// Apply seccomp options.
seccompSecurityOpts, err := getSeccompSecurityOpts(seccompProfile, separator)
seccompSecurityOpts, err := getSeccompSecurityOpts(seccomp, separator)
if err != nil {
return nil, fmt.Errorf("failed to generate seccomp security options for container: %v", err)
}
Expand Down

0 comments on commit 613f80a

Please sign in to comment.