Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate seccomp profile #223

Merged
merged 3 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"
nwneisen marked this conversation as resolved.
Show resolved Hide resolved

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"
nwneisen marked this conversation as resolved.
Show resolved Hide resolved
)

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
Loading