|
|
|
@ -76,7 +76,6 @@ const policyRefreshInterval = 10 * time.Millisecond
|
|
|
|
|
func Test_ValidateNamespace_NoParams_Success(t *testing.T) {
|
|
|
|
|
resetPolicyRefreshInterval := generic.SetPolicyRefreshIntervalForTests(policyRefreshInterval)
|
|
|
|
|
defer resetPolicyRefreshInterval()
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -191,7 +190,6 @@ func Test_ValidateNamespace_NoParams_Success(t *testing.T) {
|
|
|
|
|
func Test_ValidateNamespace_NoParams_Failures(t *testing.T) {
|
|
|
|
|
resetPolicyRefreshInterval := generic.SetPolicyRefreshIntervalForTests(policyRefreshInterval)
|
|
|
|
|
defer resetPolicyRefreshInterval()
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -437,8 +435,6 @@ func Test_ValidateAnnotationsAndWarnings(t *testing.T) {
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
|
|
|
|
|
// prepare audit policy file
|
|
|
|
|
policyFile, err := os.CreateTemp("", "audit-policy.yaml")
|
|
|
|
|
if err != nil {
|
|
|
|
@ -524,7 +520,6 @@ func Test_ValidateAnnotationsAndWarnings(t *testing.T) {
|
|
|
|
|
func Test_ValidateNamespace_WithConfigMapParams(t *testing.T) {
|
|
|
|
|
resetPolicyRefreshInterval := generic.SetPolicyRefreshIntervalForTests(policyRefreshInterval)
|
|
|
|
|
defer resetPolicyRefreshInterval()
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -597,7 +592,6 @@ func Test_ValidateNamespace_WithConfigMapParams(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestMultiplePolicyBindings(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, nil, framework.SharedEtcd())
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
@ -724,7 +718,6 @@ func TestMultiplePolicyBindings(t *testing.T) {
|
|
|
|
|
// Test_PolicyExemption tests that ValidatingAdmissionPolicy and ValidatingAdmissionPolicyBinding resources
|
|
|
|
|
// are exempt from policy rules.
|
|
|
|
|
func Test_PolicyExemption(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -811,7 +804,6 @@ func Test_PolicyExemption(t *testing.T) {
|
|
|
|
|
// the new ParamKind to be allowed. For example, when Paramkind is v1/ConfigMap, only namespaces prefixed with "configmap"
|
|
|
|
|
// is allowed and when ParamKind is updated to v1/Secret, only namespaces prefixed with "secret" is allowed, etc.
|
|
|
|
|
func Test_ValidatingAdmissionPolicy_UpdateParamKind(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -952,7 +944,6 @@ func Test_ValidatingAdmissionPolicy_UpdateParamKind(t *testing.T) {
|
|
|
|
|
// only the ParamRef in the binding is updated. This test creates a policy where namespaces must have a prefix that matches
|
|
|
|
|
// the ParamRef set in the policy binding. The paramRef in the binding is then updated to a different object.
|
|
|
|
|
func Test_ValidatingAdmissionPolicy_UpdateParamRef(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -1100,7 +1091,6 @@ func Test_ValidatingAdmissionPolicy_UpdateParamRef(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Test_ValidatingAdmissionPolicy_UpdateParamResource validates behavior of a policy after updates to the param resource.
|
|
|
|
|
func Test_ValidatingAdmissionPolicy_UpdateParamResource(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -1233,7 +1223,6 @@ func Test_ValidatingAdmissionPolicy_UpdateParamResource(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_ValidatingAdmissionPolicy_MatchByObjectSelector(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -1301,7 +1290,6 @@ func Test_ValidatingAdmissionPolicy_MatchByObjectSelector(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_ValidatingAdmissionPolicy_MatchByNamespaceSelector(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -1393,7 +1381,6 @@ func Test_ValidatingAdmissionPolicy_MatchByNamespaceSelector(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_ValidatingAdmissionPolicy_MatchByResourceNames(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -1452,7 +1439,6 @@ func Test_ValidatingAdmissionPolicy_MatchByResourceNames(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_ValidatingAdmissionPolicy_MatchWithExcludeResources(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -1524,7 +1510,6 @@ func Test_ValidatingAdmissionPolicy_MatchWithExcludeResources(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_ValidatingAdmissionPolicy_MatchWithMatchPolicyEquivalent(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -1616,7 +1601,6 @@ func Test_ValidatingAdmissionPolicy_MatchWithMatchPolicyEquivalent(t *testing.T)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_ValidatingAdmissionPolicy_MatchWithMatchPolicyExact(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -1711,7 +1695,6 @@ func Test_ValidatingAdmissionPolicy_MatchWithMatchPolicyExact(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func Test_ValidatingAdmissionPolicy_MatchExcludedResource(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -1778,7 +1761,6 @@ func Test_ValidatingAdmissionPolicy_MatchExcludedResource(t *testing.T) {
|
|
|
|
|
// Test_ValidatingAdmissionPolicy_PolicyDeletedThenRecreated validates that deleting a ValidatingAdmissionPolicy
|
|
|
|
|
// removes the policy from the apiserver admission chain and recreating it re-enables it.
|
|
|
|
|
func Test_ValidatingAdmissionPolicy_PolicyDeletedThenRecreated(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -1896,7 +1878,6 @@ func Test_ValidatingAdmissionPolicy_PolicyDeletedThenRecreated(t *testing.T) {
|
|
|
|
|
// Test_ValidatingAdmissionPolicy_BindingDeletedThenRecreated validates that deleting a ValidatingAdmissionPolicyBinding
|
|
|
|
|
// removes the policy from the apiserver admission chain and recreating it re-enables it.
|
|
|
|
|
func Test_ValidatingAdmissionPolicy_BindingDeletedThenRecreated(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -2015,7 +1996,6 @@ func Test_ValidatingAdmissionPolicy_BindingDeletedThenRecreated(t *testing.T) {
|
|
|
|
|
// Test_ValidatingAdmissionPolicy_ParamResourceDeletedThenRecreated validates that deleting a param resource referenced
|
|
|
|
|
// by a binding renders the policy as invalid. Recreating the param resource re-enables the policy.
|
|
|
|
|
func Test_ValidatingAdmissionPolicy_ParamResourceDeletedThenRecreated(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -2352,7 +2332,6 @@ func generateValidationsWithAuthzCheck(num int, exp string) []admissionregistrat
|
|
|
|
|
func TestCRDParams(t *testing.T) {
|
|
|
|
|
resetPolicyRefreshInterval := generic.SetPolicyRefreshIntervalForTests(policyRefreshInterval)
|
|
|
|
|
defer resetPolicyRefreshInterval()
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -2459,7 +2438,6 @@ func TestCRDParams(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestBindingRemoval(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
}, framework.SharedEtcd())
|
|
|
|
@ -2555,7 +2533,6 @@ func TestBindingRemoval(t *testing.T) {
|
|
|
|
|
func Test_ValidateSecondaryAuthorization(t *testing.T) {
|
|
|
|
|
resetPolicyRefreshInterval := generic.SetPolicyRefreshIntervalForTests(policyRefreshInterval)
|
|
|
|
|
defer resetPolicyRefreshInterval()
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
server, err := apiservertesting.StartTestServer(t, nil, []string{
|
|
|
|
|
"--enable-admission-plugins", "ValidatingAdmissionPolicy",
|
|
|
|
|
"--authorization-mode=RBAC",
|
|
|
|
@ -2687,7 +2664,6 @@ func Test_ValidateSecondaryAuthorization(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestCRDsOnStartup(t *testing.T) {
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
|
|
|
|
|
testContext, testCancel := context.WithCancel(context.Background())
|
|
|
|
|
defer testCancel()
|
|
|
|
@ -2837,7 +2813,6 @@ func TestAuthorizationDecisionCaching(t *testing.T) {
|
|
|
|
|
defer resetPolicyRefreshInterval()
|
|
|
|
|
ctx, cancel := context.WithCancel(context.TODO())
|
|
|
|
|
defer cancel()
|
|
|
|
|
featuregatetesting.SetFeatureGateDuringTest(t, utilfeature.DefaultFeatureGate, genericfeatures.ValidatingAdmissionPolicy, true)
|
|
|
|
|
var nChecks int
|
|
|
|
|
webhook := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
|
|
|
|
var review authorizationv1.SubjectAccessReview
|
|
|
|
|