mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-05 10:19:50 +00:00
Merge pull request #68805 from davidz627/fix/storagePSP
Add privileged test pod security policy to local volume provisioner test service account
This commit is contained in:
commit
4278b75668
@ -1464,6 +1464,7 @@ func setupLocalVolumeProvisioner(config *localTestConfig) {
|
|||||||
By("Bootstrapping local volume provisioner")
|
By("Bootstrapping local volume provisioner")
|
||||||
createServiceAccount(config)
|
createServiceAccount(config)
|
||||||
createProvisionerClusterRoleBinding(config)
|
createProvisionerClusterRoleBinding(config)
|
||||||
|
utils.PrivilegedTestPSPClusterRoleBinding(config.client, config.ns, false /* teardown */, []string{testServiceAccount})
|
||||||
createVolumeConfigMap(config)
|
createVolumeConfigMap(config)
|
||||||
|
|
||||||
for _, node := range config.nodes {
|
for _, node := range config.nodes {
|
||||||
@ -1477,6 +1478,7 @@ func setupLocalVolumeProvisioner(config *localTestConfig) {
|
|||||||
func cleanupLocalVolumeProvisioner(config *localTestConfig) {
|
func cleanupLocalVolumeProvisioner(config *localTestConfig) {
|
||||||
By("Cleaning up cluster role binding")
|
By("Cleaning up cluster role binding")
|
||||||
deleteClusterRoleBinding(config)
|
deleteClusterRoleBinding(config)
|
||||||
|
utils.PrivilegedTestPSPClusterRoleBinding(config.client, config.ns, true /* teardown */, []string{testServiceAccount})
|
||||||
|
|
||||||
for _, node := range config.nodes {
|
for _, node := range config.nodes {
|
||||||
By(fmt.Sprintf("Removing the test discovery directory on node %v", node.Name))
|
By(fmt.Sprintf("Removing the test discovery directory on node %v", node.Name))
|
||||||
|
@ -14,7 +14,10 @@ go_library(
|
|||||||
importpath = "k8s.io/kubernetes/test/e2e/storage/utils",
|
importpath = "k8s.io/kubernetes/test/e2e/storage/utils",
|
||||||
deps = [
|
deps = [
|
||||||
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
"//staging/src/k8s.io/api/core/v1:go_default_library",
|
||||||
|
"//staging/src/k8s.io/api/rbac/v1:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/api/errors:go_default_library",
|
||||||
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
"//staging/src/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||||
|
"//staging/src/k8s.io/apimachinery/pkg/util/wait:go_default_library",
|
||||||
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
"//staging/src/k8s.io/client-go/kubernetes:go_default_library",
|
||||||
"//test/e2e/framework:go_default_library",
|
"//test/e2e/framework:go_default_library",
|
||||||
"//test/utils/image:go_default_library",
|
"//test/utils/image:go_default_library",
|
||||||
|
@ -24,7 +24,10 @@ import (
|
|||||||
. "github.com/onsi/ginkgo"
|
. "github.com/onsi/ginkgo"
|
||||||
. "github.com/onsi/gomega"
|
. "github.com/onsi/gomega"
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
|
rbacv1 "k8s.io/api/rbac/v1"
|
||||||
|
apierrs "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
|
"k8s.io/apimachinery/pkg/util/wait"
|
||||||
clientset "k8s.io/client-go/kubernetes"
|
clientset "k8s.io/client-go/kubernetes"
|
||||||
"k8s.io/kubernetes/test/e2e/framework"
|
"k8s.io/kubernetes/test/e2e/framework"
|
||||||
imageutils "k8s.io/kubernetes/test/utils/image"
|
imageutils "k8s.io/kubernetes/test/utils/image"
|
||||||
@ -40,6 +43,11 @@ const (
|
|||||||
KRestart KubeletOpt = "restart"
|
KRestart KubeletOpt = "restart"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// ClusterRole name for e2e test Priveledged Pod Security Policy User
|
||||||
|
podSecurityPolicyPrivilegedClusterRoleName = "e2e-test-privileged-psp"
|
||||||
|
)
|
||||||
|
|
||||||
// PodExec wraps RunKubectl to execute a bash cmd in target pod
|
// PodExec wraps RunKubectl to execute a bash cmd in target pod
|
||||||
func PodExec(pod *v1.Pod, bashExec string) (string, error) {
|
func PodExec(pod *v1.Pod, bashExec string) (string, error) {
|
||||||
return framework.RunKubectl("exec", fmt.Sprintf("--namespace=%s", pod.Namespace), pod.Name, "--", "/bin/sh", "-c", bashExec)
|
return framework.RunKubectl("exec", fmt.Sprintf("--namespace=%s", pod.Namespace), pod.Name, "--", "/bin/sh", "-c", bashExec)
|
||||||
@ -386,3 +394,50 @@ func StartExternalProvisioner(c clientset.Interface, ns string, externalPluginNa
|
|||||||
|
|
||||||
return pod
|
return pod
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func PrivilegedTestPSPClusterRoleBinding(client clientset.Interface,
|
||||||
|
namespace string,
|
||||||
|
teardown bool,
|
||||||
|
saNames []string) {
|
||||||
|
bindingString := "Binding"
|
||||||
|
if teardown {
|
||||||
|
bindingString = "Unbinding"
|
||||||
|
}
|
||||||
|
roleBindingClient := client.RbacV1().RoleBindings(namespace)
|
||||||
|
for _, saName := range saNames {
|
||||||
|
By(fmt.Sprintf("%v priviledged Pod Security Policy to the service account %s", bindingString, saName))
|
||||||
|
binding := &rbacv1.RoleBinding{
|
||||||
|
ObjectMeta: metav1.ObjectMeta{
|
||||||
|
Name: "psp-" + saName,
|
||||||
|
Namespace: namespace,
|
||||||
|
},
|
||||||
|
Subjects: []rbacv1.Subject{
|
||||||
|
{
|
||||||
|
Kind: rbacv1.ServiceAccountKind,
|
||||||
|
Name: saName,
|
||||||
|
Namespace: namespace,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
RoleRef: rbacv1.RoleRef{
|
||||||
|
Kind: "ClusterRole",
|
||||||
|
Name: podSecurityPolicyPrivilegedClusterRoleName,
|
||||||
|
APIGroup: "rbac.authorization.k8s.io",
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
roleBindingClient.Delete(binding.GetName(), &metav1.DeleteOptions{})
|
||||||
|
err := wait.Poll(2*time.Second, 2*time.Minute, func() (bool, error) {
|
||||||
|
_, err := roleBindingClient.Get(binding.GetName(), metav1.GetOptions{})
|
||||||
|
return apierrs.IsNotFound(err), nil
|
||||||
|
})
|
||||||
|
framework.ExpectNoError(err, "Timed out waiting for deletion: %v", err)
|
||||||
|
|
||||||
|
if teardown {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
_, err = roleBindingClient.Create(binding)
|
||||||
|
framework.ExpectNoError(err, "Failed to create %s role binding: %v", binding.GetName(), err)
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user