Add support for no_new_privs via AllowPrivilegeEscalation#47019
Add support for no_new_privs via AllowPrivilegeEscalation#47019k8s-github-robot merged 6 commits intokubernetes:masterfrom
no_new_privs via AllowPrivilegeEscalation#47019Conversation
dbcf72c to
7813f76
Compare
f948d60 to
d4cac92
Compare
|
@jessfraz : sorry for a dumb question. Is this feature meant to only be active/available when the kubelet |
|
@dims there is a chart in the proposal that might help, |
d4cac92 to
4e223b6
Compare
|
@jessfraz got it. thanks! |
12d5ddc to
8e1a8fa
Compare
8e1a8fa to
4b159e1
Compare
4b159e1 to
a8c7682
Compare
test/e2e_node/image_list.go
Outdated
| "gcr.io/google_containers/nginx-slim:0.7", | ||
| "gcr.io/google_containers/serve_hostname:v1.4", | ||
| "gcr.io/google_containers/netexec:1.7", | ||
| "r.j3ss.co/no_new_privs:latest", |
There was a problem hiding this comment.
I will switch this to google_containers before merge don't worry
There was a problem hiding this comment.
fixed the image to be on google container registry
|
/lint |
k8s-ci-robot
left a comment
There was a problem hiding this comment.
@spxtr: 7 warnings.
Details
In response to this:
/lint
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.
|
|
||
| return nil | ||
| } | ||
| func Convert_api_SecurityContext_To_v1_SecurityContext(in *api.SecurityContext, out *v1.SecurityContext, s conversion.Scope) error { |
There was a problem hiding this comment.
Golint naming: don't use underscores in Go names; func Convert_api_SecurityContext_To_v1_SecurityContext should be ConvertAPISecurityContextToV1SecurityContext. More info.
| return nil | ||
| } | ||
|
|
||
| func Convert_extensions_PodSecurityPolicySpec_To_v1beta1_PodSecurityPolicySpec(in *extensions.PodSecurityPolicySpec, out *extensionsv1beta1.PodSecurityPolicySpec, s conversion.Scope) error { |
There was a problem hiding this comment.
Golint naming: don't use underscores in Go names; func Convert_extensions_PodSecurityPolicySpec_To_v1beta1_PodSecurityPolicySpec should be ConvertExtensionsPodSecurityPolicySpecToV1beta1PodSecurityPolicySpec. More info.
| yyb14 = yyj14 > l | ||
| var yyj16 int | ||
| var yyb16 bool | ||
| var yyhl16 bool = l >= 0 |
There was a problem hiding this comment.
Golint type-inference: should omit type bool from declaration of var yyhl16; it will be inferred from the right-hand side.
| } | ||
| } | ||
|
|
||
| func NewNoNewPrivsAdmitHandler(runtime kubecontainer.Runtime) PodAdmitHandler { |
There was a problem hiding this comment.
Golint comments: exported function NewNoNewPrivsAdmitHandler should have comment or be unexported. More info.
|
|
||
| func TestAddNoNewPrivileges(t *testing.T) { | ||
| var nonRoot int64 = 1000 | ||
| var root int64 = 0 |
There was a problem hiding this comment.
Golint zero-value: should drop = 0 from declaration of var root; it is the zero value.
| return "" | ||
| } | ||
|
|
||
| func (m *LinuxContainerSecurityContext) GetNoNewPrivs() bool { |
There was a problem hiding this comment.
Golint comments: exported method LinuxContainerSecurityContext.GetNoNewPrivs should have comment or be unexported. More info.
| yyb28 = yyj28 > l | ||
| var yyj32 int | ||
| var yyb32 bool | ||
| var yyhl32 bool = l >= 0 |
There was a problem hiding this comment.
Golint type-inference: should omit type bool from declaration of var yyhl32; it will be inferred from the right-hand side.
|
Lint comments on generated code aren't too useful 😞 |
|
this is all updated and green :) |
|
/lgtm |
|
/retest
…On Jul 28, 2017 20:29, "k8s-ci-robot" ***@***.***> wrote:
@jessfraz <https://github.com/jessfraz>: The following test *failed*, say
/retest to rerun them all:
Test name Commit Details Rerun command
pull-kubernetes-e2e-kops-aws a5e4c6f
<a5e4c6f>
link
<https://k8s-gubernator.appspot.com/build/kubernetes-jenkins/pr-logs/pull/47019/pull-kubernetes-e2e-kops-aws/37905/> /test
pull-kubernetes-e2e-kops-aws
Full PR test history <https://k8s-gubernator.appspot.com/pr/47019>. Your
PR dashboard <https://k8s-gubernator.appspot.com/pr/jessfraz>. Please
help us cut down on flakes by linking to
<https://github.com/kubernetes/community/blob/master/contributors/devel/flaky-tests.md#filing-issues-for-flaky-tests>
an open issue
<https://github.com/kubernetes/kubernetes/issues?q=is:issue+is:open> when
you hit one in your PR.
Instructions for interacting with me using PR comments are available here
<https://github.com/kubernetes/community/blob/master/contributors/devel/pull-requests.md>.
If you have questions or suggestions related to my behavior, please file an
issue against the kubernetes/test-infra
<https://github.com/kubernetes/test-infra/issues/new?title=Prow%20issue:>
repository. I understand the commands that are listed here
<https://github.com/kubernetes/test-infra/blob/master/commands.md>.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#47019 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABYNbAH6PtUVf8iRfE-Y0MPavb0NcJfuks5sSnz8gaJpZM4Nw1Aj>
.
|
|
ping @smarterclayton for approval 😇 |
|
API approved as per the proposal and discussion on the thread. /approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: jessfraz, smarterclayton, tallclair Associated issue: 639 The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these OWNERS Files:
You can indicate your approval by writing |
|
/test pull-kubernetes-bazel |
|
Automatic merge from submit-queue (batch tested with PRs 49651, 49707, 49662, 47019, 49747) |
| @@ -0,0 +1,22 @@ | |||
| // Copyright 2017 The Kubernetes Authors. | |||
There was a problem hiding this comment.
Is there any specif reason why we are using C code? I see even os library in go has Geteuid() which can be used.
There was a problem hiding this comment.
Yes. For multi arch test images we are planning to have all images under kubernetes/tests/images directory for supported architectures like amd64, arm, arm64, ppc64le. So its always very easy to cross build the go code over a C code.
|
Which sig does this fall under? |
|
sig-auth
…On Aug 16, 2017 13:48, "grodrigues3" ***@***.***> wrote:
Which sig does this fall under?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#47019 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABYNbK92W_zltYwO7qZXMwUV2LuPWlcsks5sYyuFgaJpZM4Nw1Aj>
.
|
|
Sure thanks
…On Aug 29, 2017 08:56, "Vyacheslav Semushin" ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In pkg/apis/extensions/v1beta1/types.go
<#47019 (comment)>
:
> @@ -933,6 +933,15 @@ type PodSecurityPolicySpec struct {
// host paths may be used.
// +optional
AllowedHostPaths []string `json:"allowedHostPaths,omitempty" protobuf:"bytes,15,opt,name=allowedHostPaths"`
+ // DefaultAllowPrivilegeEscalation controls the default setting for whether a
+ // process can gain more privileges than it's parent process.
+ // // +optional
@jessfraz <https://github.com/jessfraz> I see that s/it's parent/its
parent/ wasn't fixed. Do you want me to prepare PR for that?
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#47019 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/ABYNbBeUnZqwIVlGeDLR3xA0vePnRL7_ks5sdAqSgaJpZM4Nw1Aj>
.
|
| func TestValidateAllowPrivilegeEscalation(t *testing.T) { | ||
| pod := defaultPod() | ||
| pe := true | ||
| pod.Spec.Containers[0].SecurityContext.AllowPrivilegeEscalation = &pe |
There was a problem hiding this comment.
I see that tests don't cover that case of using InitContainers? Does this validation work for them? I assume that it should but I don't see any mentions about them in the code.
| return PodAdmitResult{Admit: true} | ||
| } | ||
|
|
||
| func noNewPrivsRequired(pod *v1.Pod) bool { |
There was a problem hiding this comment.
@jessfraz Should we handle InitContainers here too? Looks like, yes, we should.
There was a problem hiding this comment.
Are init containers handled differently that should probably be documented somewhere so it's not overlooked unless I missed it
There was a problem hiding this comment.
As far I understand, the most of the code from this PR is handling initContainers correctly because it works only with securityContext. The existing infrastructure is aware about containers/initContainers and executes validation on their SecurityContexts.
But when we're manually inspecting PodSpec we obligated to take care about initContainers. In this particular case, I see that noNewPrivsRequired() will return false for a pod that has initContainers with allowPrivielegeEscalation=false. I'm not sure what will be the consequence of this, perhaps allowPrivielegeEscalation=false won't work for a pod?
| // the no_new_privs flag will be set on the container process. | ||
| // AllowPrivilegeEscalation is true always when the container is: | ||
| // 1) run as Privileged | ||
| // 2) has CAP_SYS_ADMIN |
There was a problem hiding this comment.
@jessfraz Are we missing the case "when a container is not run as root" here?
There was a problem hiding this comment.
We got rid of that functionality
There was a problem hiding this comment.
There was a problem hiding this comment.
Also some tests can be deleted then:
kubernetes/pkg/securitycontext/util_test.go
Lines 203 to 212 in 28f6b3f
What this PR does / why we need it:
Implements kubernetes/community#639
Fixes #38417
Adds
AllowPrivilegeEscalationandDefaultAllowPrivilegeEscalationtoPodSecurityPolicy.Adds
AllowPrivilegeEscalationto containerSecurityContext.Adds the proposed behavior to
kuberuntime,dockershim, andrkt. Adds a bunch of unit tests to ensure the desired default behavior and that whenDefaultAllowPrivilegeEscalationis explicitly set.Tests pass locally with docker and rkt runtimes. There are also a few integration tests with a
setuidbinary for sanity.Release note: