-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add conformance test for setting user
This change adds a conformance test to validate that a user set in the securityContext is reflected in the container. This change also adds the group information to the runtime test image, but we do not validate this as 1. it is not currently part of the runtime contract and 2. Setting group is currently an alpha feature that does not work on many Kubernetes clusters. See kubernetes/enhancements#213 Related to: #3223
- Loading branch information
Dan Gerdesmeier
committed
Mar 13, 2019
1 parent
d454ec9
commit 6a58aa1
Showing
7 changed files
with
115 additions
and
6 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
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,65 @@ | ||
// +build e2e | ||
|
||
/* | ||
Copyright 2019 The Knative Authors | ||
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 conformance | ||
|
||
import ( | ||
"strconv" | ||
"testing" | ||
|
||
"github.com/knative/serving/test" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
) | ||
|
||
const userId = 2020 | ||
|
||
// TestMustRunAsUser verifies that a supplied runAsUser through securityContext takes | ||
// effect as delared by "MUST" in the runtime-contract. | ||
func TestMustRunAsUser(t *testing.T) { | ||
t.Parallel() | ||
clients := setup(t) | ||
|
||
securityContext := &corev1.SecurityContext{ | ||
runAsUser: userId, | ||
} | ||
|
||
ri, err := fetchRuntimeInfo(t, clients, &test.Options{SecurityContext: securityContext}) | ||
if err != nil { | ||
t.Fatalf("Error fetching runtime info: %v", err) | ||
} | ||
|
||
if ri.Host == nil { | ||
t.Fatal("Missing host information from runtime info.") | ||
} | ||
|
||
if ri.Host.User == nil { | ||
t.Fatal("Missing user information from runtime info.") | ||
} | ||
|
||
if got, want := ri.Host.User.Uid, userId; got != want { | ||
t.Errorf("uid = %d, want: %d", got, want) | ||
} | ||
|
||
// We expect the effective userId to match the userId as we | ||
// did not use setuid. | ||
if got, want := ri.Host.User.Euid, userId; got != want { | ||
t.Errorf("euid = %d, want: %d", got, want) | ||
} | ||
} |
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,31 @@ | ||
/* | ||
Copyright 2019 The Knative Authors | ||
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 handlers | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/knative/serving/test/types" | ||
) | ||
|
||
func userInfo() *types.UserInfo { | ||
return &types.UserInfo{ | ||
Uid: os.Getuid(), | ||
Euid: os.Geteuid(), | ||
Gid: os.Getgid(), | ||
Egid: os.Getegid()} | ||
} |
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