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
3027d9ba
Commit
3027d9ba
authored
Jul 13, 2017
by
Pengfei Ni
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add e2e test for privileged containers
parent
1bc56825
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
61 additions
and
0 deletions
+61
-0
security_context_test.go
test/e2e_node/security_context_test.go
+61
-0
No files found.
test/e2e_node/security_context_test.go
View file @
3027d9ba
...
@@ -459,4 +459,65 @@ var _ = framework.KubeDescribe("Security Context", func() {
...
@@ -459,4 +459,65 @@ var _ = framework.KubeDescribe("Security Context", func() {
})
})
})
})
Context
(
"When creating a pod with privileged"
,
func
()
{
makeUserPod
:=
func
(
podName
,
image
string
,
command
[]
string
,
privileged
bool
)
*
v1
.
Pod
{
return
&
v1
.
Pod
{
ObjectMeta
:
metav1
.
ObjectMeta
{
Name
:
podName
,
},
Spec
:
v1
.
PodSpec
{
RestartPolicy
:
v1
.
RestartPolicyNever
,
Containers
:
[]
v1
.
Container
{
{
Image
:
image
,
Name
:
podName
,
Command
:
command
,
SecurityContext
:
&
v1
.
SecurityContext
{
Privileged
:
&
privileged
,
},
},
},
},
}
}
createAndWaitUserPod
:=
func
(
privileged
bool
)
string
{
podName
:=
fmt
.
Sprintf
(
"busybox-privileged-%v-%s"
,
privileged
,
uuid
.
NewUUID
())
podClient
.
Create
(
makeUserPod
(
podName
,
"gcr.io/google_containers/busybox:1.24"
,
[]
string
{
"sh"
,
"-c"
,
"ip link add dummy0 type dummy || true"
},
privileged
,
))
podClient
.
WaitForSuccess
(
podName
,
framework
.
PodStartTimeout
)
return
podName
}
It
(
"should run the container as privileged when true"
,
func
()
{
podName
:=
createAndWaitUserPod
(
true
)
logs
,
err
:=
framework
.
GetPodLogs
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
podName
,
podName
)
if
err
!=
nil
{
framework
.
Failf
(
"GetPodLogs for pod %q failed: %v"
,
podName
,
err
)
}
framework
.
Logf
(
"Got logs for pod %q: %q"
,
podName
,
logs
)
if
strings
.
Contains
(
logs
,
"Operation not permitted"
)
{
framework
.
Failf
(
"privileged container should be able to create dummy device"
)
}
})
It
(
"should run the container as unprivileged when false"
,
func
()
{
podName
:=
createAndWaitUserPod
(
false
)
logs
,
err
:=
framework
.
GetPodLogs
(
f
.
ClientSet
,
f
.
Namespace
.
Name
,
podName
,
podName
)
if
err
!=
nil
{
framework
.
Failf
(
"GetPodLogs for pod %q failed: %v"
,
podName
,
err
)
}
framework
.
Logf
(
"Got logs for pod %q: %q"
,
podName
,
logs
)
if
!
strings
.
Contains
(
logs
,
"Operation not permitted"
)
{
framework
.
Failf
(
"unprivileged container shouldn't be able to create dummy device"
)
}
})
})
})
})
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