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
e1493c9c
Unverified
Commit
e1493c9c
authored
Jun 07, 2017
by
Jess Frazelle
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allowPrivilegeEscalation: apply to correct docker api versions
Signed-off-by:
Jess Frazelle
<
acidburn@google.com
>
parent
0f349cc6
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
72 additions
and
0 deletions
+72
-0
kubelet.go
pkg/kubelet/kubelet.go
+1
-0
handlers.go
pkg/kubelet/lifecycle/handlers.go
+71
-0
No files found.
pkg/kubelet/kubelet.go
View file @
e1493c9c
...
@@ -811,6 +811,7 @@ func NewMainKubelet(kubeCfg *componentconfig.KubeletConfiguration, kubeDeps *Dep
...
@@ -811,6 +811,7 @@ func NewMainKubelet(kubeCfg *componentconfig.KubeletConfiguration, kubeDeps *Dep
klet
.
appArmorValidator
=
apparmor
.
NewValidator
(
kubeCfg
.
ContainerRuntime
)
klet
.
appArmorValidator
=
apparmor
.
NewValidator
(
kubeCfg
.
ContainerRuntime
)
klet
.
softAdmitHandlers
.
AddPodAdmitHandler
(
lifecycle
.
NewAppArmorAdmitHandler
(
klet
.
appArmorValidator
))
klet
.
softAdmitHandlers
.
AddPodAdmitHandler
(
lifecycle
.
NewAppArmorAdmitHandler
(
klet
.
appArmorValidator
))
klet
.
softAdmitHandlers
.
AddPodAdmitHandler
(
lifecycle
.
NewNoNewPrivsAdmitHandler
(
klet
.
containerRuntime
))
if
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
Accelerators
)
{
if
utilfeature
.
DefaultFeatureGate
.
Enabled
(
features
.
Accelerators
)
{
if
kubeCfg
.
ContainerRuntime
==
kubetypes
.
DockerContainerRuntime
{
if
kubeCfg
.
ContainerRuntime
==
kubetypes
.
DockerContainerRuntime
{
if
klet
.
gpuManager
,
err
=
nvidia
.
NewNvidiaGPUManager
(
klet
,
kubeDeps
.
DockerClient
);
err
!=
nil
{
if
klet
.
gpuManager
,
err
=
nvidia
.
NewNvidiaGPUManager
(
klet
,
kubeDeps
.
DockerClient
);
err
!=
nil
{
...
...
pkg/kubelet/lifecycle/handlers.go
View file @
e1493c9c
...
@@ -165,3 +165,74 @@ func (a *appArmorAdmitHandler) Admit(attrs *PodAdmitAttributes) PodAdmitResult {
...
@@ -165,3 +165,74 @@ func (a *appArmorAdmitHandler) Admit(attrs *PodAdmitAttributes) PodAdmitResult {
Message
:
fmt
.
Sprintf
(
"Cannot enforce AppArmor: %v"
,
err
),
Message
:
fmt
.
Sprintf
(
"Cannot enforce AppArmor: %v"
,
err
),
}
}
}
}
func
NewNoNewPrivsAdmitHandler
(
runtime
kubecontainer
.
Runtime
)
PodAdmitHandler
{
return
&
noNewPrivsAdmitHandler
{
Runtime
:
runtime
,
}
}
type
noNewPrivsAdmitHandler
struct
{
kubecontainer
.
Runtime
}
func
(
a
*
noNewPrivsAdmitHandler
)
Admit
(
attrs
*
PodAdmitAttributes
)
PodAdmitResult
{
// If the pod is already running or terminated, no need to recheck NoNewPrivs.
if
attrs
.
Pod
.
Status
.
Phase
!=
v1
.
PodPending
{
return
PodAdmitResult
{
Admit
:
true
}
}
// If the containers in a pod do not require no-new-privs, admit it.
if
!
noNewPrivsRequired
(
attrs
.
Pod
)
{
return
PodAdmitResult
{
Admit
:
true
}
}
// Make sure it is either docker or rkt runtimes.
if
a
.
Runtime
.
Type
()
!=
kubetypes
.
DockerContainerRuntime
&&
a
.
Runtime
.
Type
()
!=
kubetypes
.
RktContainerRuntime
{
return
PodAdmitResult
{
Admit
:
false
,
Reason
:
"NoNewPrivs"
,
Message
:
fmt
.
Sprintf
(
"Cannot enforce NoNewPrivs: %s runtime not supported"
,
a
.
Runtime
.
Type
()),
}
}
if
a
.
Runtime
.
Type
()
!=
kubetypes
.
DockerContainerRuntime
{
// Make sure docker api version is valid.
rversion
,
err
:=
a
.
Runtime
.
APIVersion
()
if
err
!=
nil
{
return
PodAdmitResult
{
Admit
:
false
,
Reason
:
"NoNewPrivs"
,
Message
:
fmt
.
Sprintf
(
"Cannot enforce NoNewPrivs: %v"
,
err
),
}
}
v
,
err
:=
rversion
.
Compare
(
"1.23"
)
if
err
!=
nil
{
return
PodAdmitResult
{
Admit
:
false
,
Reason
:
"NoNewPrivs"
,
Message
:
fmt
.
Sprintf
(
"Cannot enforce NoNewPrivs: %v"
,
err
),
}
}
// If the version is less than 1.23 it will return -1 above.
if
v
==
-
1
{
return
PodAdmitResult
{
Admit
:
false
,
Reason
:
"NoNewPrivs"
,
Message
:
fmt
.
Sprintf
(
"Cannot enforce NoNewPrivs: docker runtime API version %q must be greater than or equal to 1.23"
,
rversion
.
String
()),
}
}
}
return
PodAdmitResult
{
Admit
:
true
}
}
func
noNewPrivsRequired
(
pod
*
v1
.
Pod
)
bool
{
// Iterate over pod containers and check if we added no-new-privs.
for
_
,
c
:=
range
pod
.
Spec
.
Containers
{
if
c
.
SecurityContext
!=
nil
&&
c
.
SecurityContext
.
AllowPrivilegeEscalation
!=
nil
&&
!*
c
.
SecurityContext
.
AllowPrivilegeEscalation
{
return
true
}
}
return
false
}
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