-
Notifications
You must be signed in to change notification settings - Fork 40k
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
Fix the wrong localhost seccomp path of CRI #55450
Conversation
/assign @yujuhong |
/retest |
1 similar comment
/retest |
@@ -62,7 +62,8 @@ func getSeccompDockerOpts(seccompProfile string) ([]dockerOpt, error) { | |||
return nil, fmt.Errorf("unknown seccomp profile option: %s", seccompProfile) | |||
} | |||
|
|||
fname := strings.TrimPrefix(seccompProfile, "localhost/") // by pod annotation validation, name is a valid subpath | |||
// get the full path of seccomp profile when prefixed with 'localhost/'. | |||
fname := strings.TrimPrefix(seccompProfile, "localhost/") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure you end up with an absolute path here. TrimPrefix
will cut the /
too, and you're left with a path that has no leading /
. From what I can tell, filepath.FromSlash
does not add a leading /
. https://play.golang.org/p/_A6DBoSG1V
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mtaufen yep, it doesn't add a leading '/'. And there are indeed issues about seccomp path.
localhost/
is missing because of following code:
kubernetes/pkg/kubelet/kuberuntime/helpers.go
Lines 278 to 282 in 72a2b0b
if strings.HasPrefix(profile, "localhost/") { | |
name := strings.TrimPrefix(profile, "localhost/") | |
fname := filepath.Join(m.seccompProfileRoot, filepath.FromSlash(name)) | |
return fname | |
} |
will add a new commit to fix this.
Removing label |
@@ -62,7 +62,8 @@ func getSeccompDockerOpts(seccompProfile string) ([]dockerOpt, error) { | |||
return nil, fmt.Errorf("unknown seccomp profile option: %s", seccompProfile) | |||
} | |||
|
|||
fname := strings.TrimPrefix(seccompProfile, "localhost/") // by pod annotation validation, name is a valid subpath | |||
// get the full path of seccomp profile when prefixed with 'localhost/'. | |||
fname := strings.TrimPrefix(seccompProfile, "localhost/") | |||
file, err := ioutil.ReadFile(filepath.FromSlash(fname)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also add validation that fname
is absolute, and return an error if it is not?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something like this
import "path/filepath"
if !filepath.IsAbs(fname) {
return nil, fmt.Errorf("seccomp profile path must be absolute, but got relative path %q", fname)
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mtaufen Good catch. Will add.
f2d58e8
to
d03629a
Compare
/retest |
1 similar comment
/retest |
@feiskyer what's the expected format of the annotation value? Is it |
@yujuhong The path in the kubernetes annotation is a relative path, and root directory is set by kubelet's |
/retest |
@@ -55,26 +58,26 @@ func TestGetSeccompSecurityOpts(t *testing.T) { | |||
} | |||
|
|||
func TestLoadSeccompLocalhostProfiles(t *testing.T) { | |||
tmpdir, err := ioutil.TempDir("", "seccomp-local-profile-test") | |||
assert.NoError(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/assert/require
assert is not fatal and the test will continue.
defer os.RemoveAll(tmpdir) | ||
testProfile := `{"foo": "bar"}` | ||
err = ioutil.WriteFile(filepath.Join(tmpdir, "test"), []byte(testProfile), 0644) | ||
assert.NoError(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/assert/require
seccompProfile: "localhost/fixtures/seccomp/sub/subtest", | ||
expectedOpts: []string{`seccomp={"abc":"def"}`}, | ||
expectErr: false, | ||
msg: "Non-exist profile should return error", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/Non-exist/Non-existent
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ack
|
||
func TestGetSeccompProfileFromAnnotations(t *testing.T) { | ||
_, _, m, err := createTestRuntimeManager() | ||
assert.NoError(t, err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
s/assert/require
/unassign |
f6fa52b
to
b8469e4
Compare
@yujuhong Addressed comments. PTAL |
/lgtm |
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: feiskyer, yujuhong Associated issue: 55359 The full list of commands accepted by this bot can be found here.
Needs approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
/priority critical-urgent /remove-priority important-soon adjusting priorities for code freeze |
[MILESTONENOTIFIER] Milestone Pull Request Current @Random-Liu @feiskyer @yujuhong Note: This pull request is marked as Example update:
Pull Request Labels
|
Automatic merge from submit-queue (batch tested with PRs 55952, 49112, 55450, 56178, 56151). If you want to cherry-pick this change to another branch, please follow the instructions here. |
What this PR does / why we need it:
Fix the wrong seccomp path comment.
Which issue(s) this PR fixes (optional, in
fixes #<issue number>(, fixes #<issue_number>, ...)
format, will close the issue(s) when PR gets merged):Fixes #55359
Special notes for your reviewer:
Release note: