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
307d677e
Commit
307d677e
authored
May 11, 2015
by
Victor Marmol
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #8022 from ddysher/kubelet-privilege
Check Pod privileged container
parents
c1b412d5
2f7183cb
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
65 additions
and
13 deletions
+65
-13
manager.go
pkg/kubelet/dockertools/manager.go
+0
-5
kubelet_test.go
pkg/kubelet/kubelet_test.go
+53
-0
rkt.go
pkg/kubelet/rkt/rkt.go
+3
-7
util.go
pkg/kubelet/util.go
+9
-1
No files found.
pkg/kubelet/dockertools/manager.go
View file @
307d677e
...
@@ -30,7 +30,6 @@ import (
...
@@ -30,7 +30,6 @@ import (
"sync"
"sync"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
kubecontainer
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
kubecontainer
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/lifecycle"
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/lifecycle"
...
@@ -542,10 +541,6 @@ func (dm *DockerManager) runContainer(pod *api.Pod, container *api.Container, op
...
@@ -542,10 +541,6 @@ func (dm *DockerManager) runContainer(pod *api.Pod, container *api.Container, op
}
}
}
}
if
!
capabilities
.
Get
()
.
AllowPrivileged
&&
securitycontext
.
HasPrivilegedRequest
(
container
)
{
return
""
,
fmt
.
Errorf
(
"container requested privileged mode, but it is disallowed globally."
)
}
hc
:=
&
docker
.
HostConfig
{
hc
:=
&
docker
.
HostConfig
{
PortBindings
:
portBindings
,
PortBindings
:
portBindings
,
Binds
:
opts
.
Binds
,
Binds
:
opts
.
Binds
,
...
...
pkg/kubelet/kubelet_test.go
View file @
307d677e
...
@@ -3754,6 +3754,59 @@ func TestHostNetworkDisallowed(t *testing.T) {
...
@@ -3754,6 +3754,59 @@ func TestHostNetworkDisallowed(t *testing.T) {
}
}
}
}
func
TestPrivilegeContainerAllowed
(
t
*
testing
.
T
)
{
testKubelet
:=
newTestKubelet
(
t
)
kubelet
:=
testKubelet
.
kubelet
capabilities
.
SetForTests
(
capabilities
.
Capabilities
{
AllowPrivileged
:
true
,
})
privileged
:=
true
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"12345678"
,
Name
:
"foo"
,
Namespace
:
"new"
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"foo"
,
SecurityContext
:
&
api
.
SecurityContext
{
Privileged
:
&
privileged
}},
},
},
}
kubelet
.
podManager
.
SetPods
([]
*
api
.
Pod
{
pod
})
err
:=
kubelet
.
syncPod
(
pod
,
nil
,
container
.
Pod
{})
if
err
!=
nil
{
t
.
Errorf
(
"expected pod infra creation to succeed: %v"
,
err
)
}
}
func
TestPrivilegeContainerDisallowed
(
t
*
testing
.
T
)
{
testKubelet
:=
newTestKubelet
(
t
)
kubelet
:=
testKubelet
.
kubelet
capabilities
.
SetForTests
(
capabilities
.
Capabilities
{
AllowPrivileged
:
false
,
})
privileged
:=
true
pod
:=
&
api
.
Pod
{
ObjectMeta
:
api
.
ObjectMeta
{
UID
:
"12345678"
,
Name
:
"foo"
,
Namespace
:
"new"
,
},
Spec
:
api
.
PodSpec
{
Containers
:
[]
api
.
Container
{
{
Name
:
"foo"
,
SecurityContext
:
&
api
.
SecurityContext
{
Privileged
:
&
privileged
}},
},
},
}
err
:=
kubelet
.
syncPod
(
pod
,
nil
,
container
.
Pod
{})
if
err
==
nil
{
t
.
Errorf
(
"expected pod infra creation to fail"
)
}
}
func
TestSyncPodsWithRestartPolicy
(
t
*
testing
.
T
)
{
func
TestSyncPodsWithRestartPolicy
(
t
*
testing
.
T
)
{
testKubelet
:=
newTestKubelet
(
t
)
testKubelet
:=
newTestKubelet
(
t
)
testKubelet
.
fakeCadvisor
.
On
(
"MachineInfo"
)
.
Return
(
&
cadvisorApi
.
MachineInfo
{},
nil
)
testKubelet
.
fakeCadvisor
.
On
(
"MachineInfo"
)
.
Return
(
&
cadvisorApi
.
MachineInfo
{},
nil
)
...
...
pkg/kubelet/rkt/rkt.go
View file @
307d677e
...
@@ -31,7 +31,6 @@ import (
...
@@ -31,7 +31,6 @@ import (
"time"
"time"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
"github.com/GoogleCloudPlatform/kubernetes/pkg/client/record"
"github.com/GoogleCloudPlatform/kubernetes/pkg/credentialprovider"
"github.com/GoogleCloudPlatform/kubernetes/pkg/credentialprovider"
kubecontainer
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
kubecontainer
"github.com/GoogleCloudPlatform/kubernetes/pkg/kubelet/container"
...
@@ -213,13 +212,10 @@ func setIsolators(app *appctypes.App, c *api.Container) error {
...
@@ -213,13 +212,10 @@ func setIsolators(app *appctypes.App, c *api.Container) error {
// Retained capabilities/privileged.
// Retained capabilities/privileged.
privileged
:=
false
privileged
:=
false
if
!
capabilities
.
Get
()
.
AllowPrivileged
&&
securitycontext
.
HasPrivilegedRequest
(
c
)
{
if
c
.
SecurityContext
!=
nil
&&
c
.
SecurityContext
.
Privileged
!=
nil
{
return
fmt
.
Errorf
(
"container requested privileged mode, but it is disallowed globally."
)
privileged
=
*
c
.
SecurityContext
.
Privileged
}
else
{
if
c
.
SecurityContext
!=
nil
&&
c
.
SecurityContext
.
Privileged
!=
nil
{
privileged
=
*
c
.
SecurityContext
.
Privileged
}
}
}
var
addCaps
string
var
addCaps
string
if
privileged
{
if
privileged
{
addCaps
=
getAllCapabilities
()
addCaps
=
getAllCapabilities
()
...
...
pkg/kubelet/util.go
View file @
307d677e
...
@@ -22,6 +22,7 @@ import (
...
@@ -22,6 +22,7 @@ import (
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/api/resource"
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
"github.com/GoogleCloudPlatform/kubernetes/pkg/capabilities"
"github.com/GoogleCloudPlatform/kubernetes/pkg/securitycontext"
cadvisorApi
"github.com/google/cadvisor/info/v1"
cadvisorApi
"github.com/google/cadvisor/info/v1"
)
)
...
@@ -48,7 +49,14 @@ func canRunPod(pod *api.Pod) error {
...
@@ -48,7 +49,14 @@ func canRunPod(pod *api.Pod) error {
return
fmt
.
Errorf
(
"pod with UID %q specified host networking, but is disallowed"
,
pod
.
UID
)
return
fmt
.
Errorf
(
"pod with UID %q specified host networking, but is disallowed"
,
pod
.
UID
)
}
}
}
}
// TODO(vmarmol): Check Privileged too.
if
!
capabilities
.
Get
()
.
AllowPrivileged
{
for
_
,
container
:=
range
pod
.
Spec
.
Containers
{
if
securitycontext
.
HasPrivilegedRequest
(
&
container
)
{
return
fmt
.
Errorf
(
"pod with UID %q specified privileged container, but is disallowed"
,
pod
.
UID
)
}
}
}
return
nil
return
nil
}
}
...
...
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