Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
7e211460
Commit
7e211460
authored
Nov 22, 2017
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Verify seccomp absolute path in dockershim
parent
2a2a8756
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
24 additions
and
11 deletions
+24
-11
helpers_linux.go
pkg/kubelet/dockershim/helpers_linux.go
+5
-1
helpers_linux_test.go
pkg/kubelet/dockershim/helpers_linux_test.go
+19
-10
No files found.
pkg/kubelet/dockershim/helpers_linux.go
View file @
7e211460
...
...
@@ -62,7 +62,11 @@ 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/"
)
if
!
filepath
.
IsAbs
(
fname
)
{
return
nil
,
fmt
.
Errorf
(
"seccomp profile path must be absolute, but got relative path %q"
,
fname
)
}
file
,
err
:=
ioutil
.
ReadFile
(
filepath
.
FromSlash
(
fname
))
if
err
!=
nil
{
return
nil
,
fmt
.
Errorf
(
"cannot load seccomp profile %q: %v"
,
fname
,
err
)
...
...
pkg/kubelet/dockershim/helpers_linux_test.go
View file @
7e211460
...
...
@@ -20,9 +20,13 @@ package dockershim
import
(
"fmt"
"io/ioutil"
"os"
"path/filepath"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
func
TestGetSeccompSecurityOpts
(
t
*
testing
.
T
)
{
...
...
@@ -55,26 +59,31 @@ func TestGetSeccompSecurityOpts(t *testing.T) {
}
func
TestLoadSeccompLocalhostProfiles
(
t
*
testing
.
T
)
{
tmpdir
,
err
:=
ioutil
.
TempDir
(
""
,
"seccomp-local-profile-test"
)
require
.
NoError
(
t
,
err
)
defer
os
.
RemoveAll
(
tmpdir
)
testProfile
:=
`{"foo": "bar"}`
err
=
ioutil
.
WriteFile
(
filepath
.
Join
(
tmpdir
,
"test"
),
[]
byte
(
testProfile
),
0644
)
require
.
NoError
(
t
,
err
)
tests
:=
[]
struct
{
msg
string
seccompProfile
string
expectedOpts
[]
string
expectErr
bool
}{{
msg
:
"Seccomp localhost/test profile"
,
// We are abusing localhost for loading test seccomp profiles.
// The profile should be an absolute path while we are using a relative one.
seccompProfile
:
"localhost/fixtures/seccomp/test"
,
msg
:
"Seccomp localhost/test profile should return correct seccomp profiles"
,
seccompProfile
:
"localhost/"
+
filepath
.
Join
(
tmpdir
,
"test"
),
expectedOpts
:
[]
string
{
`seccomp={"foo":"bar"}`
},
expectErr
:
false
,
},
{
msg
:
"
Seccomp localhost/sub/subtest profile
"
,
seccompProfile
:
"localhost/
fixtures/seccomp/sub/subtest"
,
expectedOpts
:
[]
string
{
`seccomp={"abc":"def"}`
}
,
expectErr
:
fals
e
,
msg
:
"
Non-existent profile should return error
"
,
seccompProfile
:
"localhost/
"
+
filepath
.
Join
(
tmpdir
,
"fixtures/non-existent"
)
,
expectedOpts
:
nil
,
expectErr
:
tru
e
,
},
{
msg
:
"
Seccomp non-existent
"
,
seccompProfile
:
"localhost/fixtures/
seccomp/non-existen
t"
,
msg
:
"
Relative profile path should return error
"
,
seccompProfile
:
"localhost/fixtures/
tes
t"
,
expectedOpts
:
nil
,
expectErr
:
true
,
}}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment