forked from kubernetes/kubernetes
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request kubernetes#9384 from pmorie/emptydir-nonroot
Support emptydir volumes for containers running as non-root
- Loading branch information
Showing
14 changed files
with
734 additions
and
160 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
# Copyright 2015 Google Inc. All rights reserved. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
FROM gcr.io/google-containers/mounttest:0.3 | ||
USER 1001 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
all: push | ||
|
||
TAG = 0.1 | ||
|
||
image: | ||
sudo docker build -t gcr.io/google_containers/mounttest-user:$(TAG) . | ||
|
||
push: image | ||
gcloud docker push gcr.io/google_containers/mounttest-user:$(TAG) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/* | ||
Copyright 2014 The Kubernetes Authors All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package securitycontext | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/GoogleCloudPlatform/kubernetes/pkg/api" | ||
) | ||
|
||
func TestParseSELinuxOptions(t *testing.T) { | ||
cases := []struct { | ||
name string | ||
input string | ||
expected *api.SELinuxOptions | ||
}{ | ||
{ | ||
name: "simple", | ||
input: "user_t:role_t:type_t:s0", | ||
expected: &api.SELinuxOptions{ | ||
User: "user_t", | ||
Role: "role_t", | ||
Type: "type_t", | ||
Level: "s0", | ||
}, | ||
}, | ||
{ | ||
name: "simple + categories", | ||
input: "user_t:role_t:type_t:s0:c0", | ||
expected: &api.SELinuxOptions{ | ||
User: "user_t", | ||
Role: "role_t", | ||
Type: "type_t", | ||
Level: "s0:c0", | ||
}, | ||
}, | ||
{ | ||
name: "not enough fields", | ||
input: "type_t:s0:c0", | ||
}, | ||
} | ||
|
||
for _, tc := range cases { | ||
result, err := ParseSELinuxOptions(tc.input) | ||
|
||
if err != nil { | ||
if tc.expected == nil { | ||
continue | ||
} else { | ||
t.Errorf("%v: unexpected error: %v", tc.name, err) | ||
} | ||
} | ||
|
||
compareContexts(tc.name, tc.expected, result, t) | ||
} | ||
} | ||
|
||
func compareContexts(name string, ex, ac *api.SELinuxOptions, t *testing.T) { | ||
if e, a := ex.User, ac.User; e != a { | ||
t.Errorf("%v: expected user: %v, got: %v", name, e, a) | ||
} | ||
if e, a := ex.Role, ac.Role; e != a { | ||
t.Errorf("%v: expected role: %v, got: %v", name, e, a) | ||
} | ||
if e, a := ex.Type, ac.Type; e != a { | ||
t.Errorf("%v: expected type: %v, got: %v", name, e, a) | ||
} | ||
if e, a := ex.Level, ac.Level; e != a { | ||
t.Errorf("%v: expected level: %v, got: %v", name, e, a) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
Copyright 2014 The Kubernetes Authors All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package empty_dir | ||
|
||
// chconRunner knows how to chcon a directory. | ||
type chconRunner interface { | ||
SetContext(dir, context string) error | ||
} | ||
|
||
// newChconRunner returns a new chconRunner. | ||
func newChconRunner() chconRunner { | ||
return &realChconRunner{} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// +build linux | ||
|
||
/* | ||
Copyright 2014 The Kubernetes Authors All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package empty_dir | ||
|
||
import ( | ||
"github.com/docker/libcontainer/selinux" | ||
) | ||
|
||
type realChconRunner struct{} | ||
|
||
func (_ *realChconRunner) SetContext(dir, context string) error { | ||
// If SELinux is not enabled, return an empty string | ||
if !selinux.SelinuxEnabled() { | ||
return nil | ||
} | ||
|
||
return selinux.Setfilecon(dir, context) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
// +build !linux | ||
|
||
/* | ||
Copyright 2014 The Kubernetes Authors All rights reserved. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package empty_dir | ||
|
||
type realChconRunner struct{} | ||
|
||
func (_ *realChconRunner) SetContext(dir, context string) error { | ||
// NOP | ||
return nil | ||
} |
Oops, something went wrong.