diff --git a/Chart.yaml b/Chart.yaml index 1842a2573632ccf58a8ae6c6455709c030fc31e5..bbf76f4e7b02874e9256ee603a8fc9ea0b3d800f 100644 --- a/Chart.yaml +++ b/Chart.yaml @@ -1,4 +1,4 @@ apiVersion: v2 name: constraint-templates -version: 1.5.5 +version: 1.5.6 appVersion: 1.0.0 diff --git a/rego/allow_rollout_restart_deployment/policy.rego b/rego/allow_rollout_restart_deployment/policy.rego index 83f4ccd079449c215824df7244b52d63bf48f870..ddfa5e5863e0130ebfd21bae50cc6efa2b49c3f5 100644 --- a/rego/allow_rollout_restart_deployment/policy.rego +++ b/rego/allow_rollout_restart_deployment/policy.rego @@ -1,7 +1,8 @@ package allow_rollout_restart -# Violation caused when user is not flux and not in the admin group, trying to use UPDATE to change a DEPLOYMENT. The old annotations get patched with a value to build the datastructure, but it gets removed in the next step, so the value is innocuous. +# Violation caused when user is not the local flux, nor stakater-reloader, and not in the admin group, trying to use UPDATE to change a DEPLOYMENT. The old annotations get patched with a value to build the datastructure, but it gets removed in the next step, so the value is innocuous. violation[{"msg": msg}] { + not input.review.userInfo.username == "system:serviceaccount:platform-stakater-reloader:stakater-reloader" flux_username := concat("",["system:serviceaccount:",input.review.namespace,":flux"]) not input.review.userInfo.username == flux_username not contains(input.review.userInfo.groups, "oidc:it.platform.roles.admin") diff --git a/rego/allow_rollout_restart_deployment/policy_test.rego b/rego/allow_rollout_restart_deployment/policy_test.rego index 74ef125e94cf3418af2e28cada5df7aaaa78b198..9416bbf3b4c9e27960201312456a7a55fafc6801 100644 --- a/rego/allow_rollout_restart_deployment/policy_test.rego +++ b/rego/allow_rollout_restart_deployment/policy_test.rego @@ -27,6 +27,15 @@ test_with_deployment_and_incorrect_annotation_with_flux { count(results) == 0 } +test_with_deployment_and_incorrect_annotation_with_stakater { + input := review_deployment_patch_existing("wrongAnnotation","wrong","system:serviceaccount:platform-stakater-reloader:stakater-reloader","randomgroup","13oclock") + + results := violation + with input as input + + count(results) == 0 +} + test_with_deployment_and_incorrect_annotation_with_platform_admin_group { input := review_deployment_patch_existing("wrongAnnotation","wrong","randomuser","oidc:it.platform.roles.admin","13oclock") diff --git a/rego/allow_rollout_restart_statefulset/policy.rego b/rego/allow_rollout_restart_statefulset/policy.rego index b5bec76de2c06930626d9415987fe136a3e7ad40..c9888c070af73e54ac7898be546fe3405b3f0e75 100644 --- a/rego/allow_rollout_restart_statefulset/policy.rego +++ b/rego/allow_rollout_restart_statefulset/policy.rego @@ -1,7 +1,8 @@ package allow_rollout_restart -# Violation caused when user is not flux and not in the admin group, trying to use UPDATE to change a StatefulSet. The old annotations get patched with a value to build the datastructure, but it gets removed in the next step, so the value is innocuous. +# Violation caused when user is not local flux, not the stakater-reloader, and not in the admin group, trying to use UPDATE to change a StatefulSet. The old annotations get patched with a value to build the datastructure, but it gets removed in the next step, so the value is innocuous. violation[{"msg": msg}] { + not input.review.userInfo.username == "system:serviceaccount:platform-stakater-reloader:stakater-reloader" flux_username := concat("",["system:serviceaccount:",input.review.namespace,":flux"]) not input.review.userInfo.username == flux_username not contains(input.review.userInfo.groups, "oidc:it.platform.roles.admin") diff --git a/rego/allow_rollout_restart_statefulset/policy_test.rego b/rego/allow_rollout_restart_statefulset/policy_test.rego index 3f52e3ce3e03e0571b517ec06908f8898f1962e8..2f7e1a2493e8819d7d024201171136bea80b6623 100644 --- a/rego/allow_rollout_restart_statefulset/policy_test.rego +++ b/rego/allow_rollout_restart_statefulset/policy_test.rego @@ -27,6 +27,15 @@ test_with_statefulset_and_incorrect_annotation_with_flux { count(results) == 0 } +test_with_statefulset_and_incorrect_annotation_with_stakater { + input := review_statefulset_patch_existing("wrongAnnotation","wrong",""system:serviceaccount:platform-stakater-reloader:stakater-reloader","randomgroup","13oclock") + + results := violation + with input as input + + count(results) == 0 +} + test_with_statefulset_and_incorrect_annotation_with_platform_admin_group { input := review_statefulset_patch_existing("wrongAnnotation","wrong","randomuser","oidc:it.platform.roles.admin","13oclock")