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
bcd939cb
Commit
bcd939cb
authored
Dec 07, 2016
by
Euan Kemp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
kuberuntime: set privileged for sandboxes
parent
62148a76
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
67 additions
and
64 deletions
+67
-64
helpers.go
pkg/kubelet/container/helpers.go
+12
-0
helpers_test.go
pkg/kubelet/container/helpers_test.go
+41
-0
kubelet_pods.go
pkg/kubelet/kubelet_pods.go
+1
-13
kubelet_pods_test.go
pkg/kubelet/kubelet_pods_test.go
+0
-41
kuberuntime_sandbox.go
pkg/kubelet/kuberuntime/kuberuntime_sandbox.go
+13
-10
No files found.
pkg/kubelet/container/helpers.go
View file @
bcd939cb
...
...
@@ -261,3 +261,15 @@ func GetContainerSpec(pod *v1.Pod, containerName string) *v1.Container {
}
return
nil
}
// HasPrivilegedContainer returns true if any of the containers in the pod are privileged.
func
HasPrivilegedContainer
(
pod
*
v1
.
Pod
)
bool
{
for
_
,
c
:=
range
pod
.
Spec
.
Containers
{
if
c
.
SecurityContext
!=
nil
&&
c
.
SecurityContext
.
Privileged
!=
nil
&&
*
c
.
SecurityContext
.
Privileged
{
return
true
}
}
return
false
}
pkg/kubelet/container/helpers_test.go
View file @
bcd939cb
...
...
@@ -211,3 +211,44 @@ func TestShouldContainerBeRestarted(t *testing.T) {
}
}
}
func
TestHasPrivilegedContainer
(
t
*
testing
.
T
)
{
newBoolPtr
:=
func
(
b
bool
)
*
bool
{
return
&
b
}
tests
:=
map
[
string
]
struct
{
securityContext
*
v1
.
SecurityContext
expected
bool
}{
"nil security context"
:
{
securityContext
:
nil
,
expected
:
false
,
},
"nil privileged"
:
{
securityContext
:
&
v1
.
SecurityContext
{},
expected
:
false
,
},
"false privileged"
:
{
securityContext
:
&
v1
.
SecurityContext
{
Privileged
:
newBoolPtr
(
false
)},
expected
:
false
,
},
"true privileged"
:
{
securityContext
:
&
v1
.
SecurityContext
{
Privileged
:
newBoolPtr
(
true
)},
expected
:
true
,
},
}
for
k
,
v
:=
range
tests
{
pod
:=
&
v1
.
Pod
{
Spec
:
v1
.
PodSpec
{
Containers
:
[]
v1
.
Container
{
{
SecurityContext
:
v
.
securityContext
},
},
},
}
actual
:=
HasPrivilegedContainer
(
pod
)
if
actual
!=
v
.
expected
{
t
.
Errorf
(
"%s expected %t but got %t"
,
k
,
v
.
expected
,
actual
)
}
}
}
pkg/kubelet/kubelet_pods.go
View file @
bcd939cb
...
...
@@ -1441,25 +1441,13 @@ func (kl *Kubelet) cleanupOrphanedPodCgroups(
// or it will not have the correct capabilities in the namespace. This means that host user namespace
// is enabled per pod, not per container.
func
(
kl
*
Kubelet
)
enableHostUserNamespace
(
pod
*
v1
.
Pod
)
bool
{
if
h
asPrivilegedContainer
(
pod
)
||
hasHostNamespace
(
pod
)
||
if
kubecontainer
.
H
asPrivilegedContainer
(
pod
)
||
hasHostNamespace
(
pod
)
||
hasHostVolume
(
pod
)
||
hasNonNamespacedCapability
(
pod
)
||
kl
.
hasHostMountPVC
(
pod
)
{
return
true
}
return
false
}
// hasPrivilegedContainer returns true if any of the containers in the pod are privileged.
func
hasPrivilegedContainer
(
pod
*
v1
.
Pod
)
bool
{
for
_
,
c
:=
range
pod
.
Spec
.
Containers
{
if
c
.
SecurityContext
!=
nil
&&
c
.
SecurityContext
.
Privileged
!=
nil
&&
*
c
.
SecurityContext
.
Privileged
{
return
true
}
}
return
false
}
// hasNonNamespacedCapability returns true if MKNOD, SYS_TIME, or SYS_MODULE is requested for any container.
func
hasNonNamespacedCapability
(
pod
*
v1
.
Pod
)
bool
{
for
_
,
c
:=
range
pod
.
Spec
.
Containers
{
...
...
pkg/kubelet/kubelet_pods_test.go
View file @
bcd939cb
...
...
@@ -1266,47 +1266,6 @@ func TestMakeDevices(t *testing.T) {
}
}
func
TestHasPrivilegedContainer
(
t
*
testing
.
T
)
{
newBoolPtr
:=
func
(
b
bool
)
*
bool
{
return
&
b
}
tests
:=
map
[
string
]
struct
{
securityContext
*
v1
.
SecurityContext
expected
bool
}{
"nil sc"
:
{
securityContext
:
nil
,
expected
:
false
,
},
"nil privleged"
:
{
securityContext
:
&
v1
.
SecurityContext
{},
expected
:
false
,
},
"false privleged"
:
{
securityContext
:
&
v1
.
SecurityContext
{
Privileged
:
newBoolPtr
(
false
)},
expected
:
false
,
},
"true privleged"
:
{
securityContext
:
&
v1
.
SecurityContext
{
Privileged
:
newBoolPtr
(
true
)},
expected
:
true
,
},
}
for
k
,
v
:=
range
tests
{
pod
:=
&
v1
.
Pod
{
Spec
:
v1
.
PodSpec
{
Containers
:
[]
v1
.
Container
{
{
SecurityContext
:
v
.
securityContext
},
},
},
}
actual
:=
hasPrivilegedContainer
(
pod
)
if
actual
!=
v
.
expected
{
t
.
Errorf
(
"%s expected %t but got %t"
,
k
,
v
.
expected
,
actual
)
}
}
}
func
TestHasHostMountPVC
(
t
*
testing
.
T
)
{
tests
:=
map
[
string
]
struct
{
pvError
error
...
...
pkg/kubelet/kuberuntime/kuberuntime_sandbox.go
View file @
bcd939cb
...
...
@@ -130,23 +130,21 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxConfig(pod *v1.Pod, attemp
// generatePodSandboxLinuxConfig generates LinuxPodSandboxConfig from v1.Pod.
func
(
m
*
kubeGenericRuntimeManager
)
generatePodSandboxLinuxConfig
(
pod
*
v1
.
Pod
,
cgroupParent
string
)
*
runtimeapi
.
LinuxPodSandboxConfig
{
if
pod
.
Spec
.
SecurityContext
==
nil
&&
cgroupParent
==
""
{
return
nil
lc
:=
&
runtimeapi
.
LinuxPodSandboxConfig
{
SecurityContext
:
&
runtimeapi
.
LinuxSandboxSecurityContext
{},
}
lc
:=
&
runtimeapi
.
LinuxPodSandboxConfig
{}
if
cgroupParent
!=
""
{
lc
.
CgroupParent
=
&
cgroupParent
}
if
pod
.
Spec
.
SecurityContext
!=
nil
{
sc
:=
pod
.
Spec
.
SecurityContext
lc
.
SecurityContext
=
&
runtimeapi
.
LinuxSandboxSecurityContext
{
NamespaceOptions
:
&
runtimeapi
.
NamespaceOption
{
HostNetwork
:
&
pod
.
Spec
.
HostNetwork
,
HostIpc
:
&
pod
.
Spec
.
HostIPC
,
HostPid
:
&
pod
.
Spec
.
HostPID
,
},
RunAsUser
:
sc
.
RunAsUser
,
lc
.
SecurityContext
.
RunAsUser
=
sc
.
RunAsUser
lc
.
SecurityContext
.
NamespaceOptions
=
&
runtimeapi
.
NamespaceOption
{
HostNetwork
:
&
pod
.
Spec
.
HostNetwork
,
HostIpc
:
&
pod
.
Spec
.
HostIPC
,
HostPid
:
&
pod
.
Spec
.
HostPID
,
}
if
sc
.
FSGroup
!=
nil
{
...
...
@@ -168,6 +166,11 @@ func (m *kubeGenericRuntimeManager) generatePodSandboxLinuxConfig(pod *v1.Pod, c
}
}
if
kubecontainer
.
HasPrivilegedContainer
(
pod
)
{
privileged
:=
true
lc
.
SecurityContext
.
Privileged
=
&
privileged
}
return
lc
}
...
...
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