diff --git a/cluster/common.sh b/cluster/common.sh index 10a547fe40e..2a20e26e6c1 100755 --- a/cluster/common.sh +++ b/cluster/common.sh @@ -753,6 +753,7 @@ NUM_NODES: $(yaml-quote ${NUM_NODES}) STORAGE_BACKEND: $(yaml-quote ${STORAGE_BACKEND:-etcd3}) STORAGE_MEDIA_TYPE: $(yaml-quote ${STORAGE_MEDIA_TYPE:-}) ENABLE_GARBAGE_COLLECTOR: $(yaml-quote ${ENABLE_GARBAGE_COLLECTOR:-}) +ENABLE_LEGACY_ABAC: $(yaml-quote ${ENABLE_LEGACY_ABAC:-}) MASTER_ADVERTISE_ADDRESS: $(yaml-quote ${MASTER_ADVERTISE_ADDRESS:-}) ETCD_CA_KEY: $(yaml-quote ${ETCD_CA_KEY_BASE64:-}) ETCD_CA_CERT: $(yaml-quote ${ETCD_CA_CERT_BASE64:-}) diff --git a/cluster/gce/config-default.sh b/cluster/gce/config-default.sh index b7097139bc8..0386c80b227 100755 --- a/cluster/gce/config-default.sh +++ b/cluster/gce/config-default.sh @@ -204,6 +204,9 @@ SCHEDULING_ALGORITHM_PROVIDER="${SCHEDULING_ALGORITHM_PROVIDER:-}" # Optional: install a default StorageClass ENABLE_DEFAULT_STORAGE_CLASS="${ENABLE_DEFAULT_STORAGE_CLASS:-true}" +# Optional: Enable legacy ABAC policy that makes all service accounts superusers. +ENABLE_LEGACY_ABAC="${ENABLE_LEGACY_ABAC:-true}" # true, false + # TODO(dawn1107): Remove this once the flag is built into CVM image. # Kernel panic upon soft lockup issue SOFTLOCKUP_PANIC="${SOFTLOCKUP_PANIC:-false}" # true, false diff --git a/cluster/gce/config-test.sh b/cluster/gce/config-test.sh index b9c4c7780a5..57cd7835701 100755 --- a/cluster/gce/config-test.sh +++ b/cluster/gce/config-test.sh @@ -241,6 +241,17 @@ SCHEDULING_ALGORITHM_PROVIDER="${SCHEDULING_ALGORITHM_PROVIDER:-}" # Optional: install a default StorageClass ENABLE_DEFAULT_STORAGE_CLASS="${ENABLE_DEFAULT_STORAGE_CLASS:-true}" +# Optional: Enable legacy ABAC policy that makes all service accounts superusers. +if [[ "${E2E_UPGRADE_TEST:-}" == "true" ]]; then + # Enable (match the regular default) when running upgrade tests (E2E_UPGRADE_TEST=true is set by upgrade CI jobs). + # This ensures the combination of legacy ABAC and default RBAC policies work properly for upgrade scenarios. + ENABLE_LEGACY_ABAC="${ENABLE_LEGACY_ABAC:-true}" # true, false +else + # Disable by default when running regular e2e tests. + # This ensures default RBAC policies alone are sufficient for e2e tests from 1.6+ + ENABLE_LEGACY_ABAC="${ENABLE_LEGACY_ABAC:-false}" # true, false +fi + # TODO(dawn1107): Remove this once the flag is built into CVM image. # Kernel panic upon soft lockup issue SOFTLOCKUP_PANIC="${SOFTLOCKUP_PANIC:-true}" # true, false diff --git a/cluster/gce/container-linux/configure-helper.sh b/cluster/gce/container-linux/configure-helper.sh index 8cafc811a91..8d9015d20f7 100755 --- a/cluster/gce/container-linux/configure-helper.sh +++ b/cluster/gce/container-linux/configure-helper.sh @@ -888,10 +888,27 @@ function start-kube-apiserver { fi local authorization_mode="RBAC" - if [[ -n "${ABAC_AUTHZ_FILE:-}" && -e "${ABAC_AUTHZ_FILE}" ]]; then - params+=" --authorization-policy-file=${ABAC_AUTHZ_FILE}" + local -r src_dir="${KUBE_HOME}/kube-manifests/kubernetes/gci-trusty" + + # Enable ABAC mode unless the user explicitly opts out with ENABLE_LEGACY_ABAC=false + if [[ "${ENABLE_LEGACY_ABAC:-}" != "false" ]]; then + echo "Warning: Enabling legacy ABAC policy. All service accounts will have superuser API access. Set ENABLE_LEGACY_ABAC=false to disable this." + # Create the ABAC file if it doesn't exist yet, or if we have a KUBE_USER set (to ensure the right user is given permissions) + if [[ -n "${KUBE_USER:-}" || ! -e /etc/srv/kubernetes/abac-authz-policy.jsonl ]]; then + local -r abac_policy_json="${src_dir}/abac-authz-policy.jsonl" + remove-salt-config-comments "${abac_policy_json}" + if [[ -n "${KUBE_USER:-}" ]]; then + sed -i -e "s/{{kube_user}}/${KUBE_USER}/g" "${abac_policy_json}" + else + sed -i -e "/{{kube_user}}/d" "${abac_policy_json}" + fi + cp "${abac_policy_json}" /etc/srv/kubernetes/ + fi + + params+=" --authorization-policy-file=/etc/srv/kubernetes/abac-authz-policy.jsonl" authorization_mode+=",ABAC" fi + local webhook_config_mount="" local webhook_config_volume="" if [[ -n "${GCP_AUTHZ_URL:-}" ]]; then @@ -900,7 +917,6 @@ function start-kube-apiserver { webhook_config_mount="{\"name\": \"webhookconfigmount\",\"mountPath\": \"/etc/gcp_authz.config\", \"readOnly\": false}," webhook_config_volume="{\"name\": \"webhookconfigmount\",\"hostPath\": {\"path\": \"/etc/gcp_authz.config\"}}," fi - local -r src_dir="${KUBE_HOME}/kube-manifests/kubernetes/gci-trusty" params+=" --authorization-mode=${authorization_mode}" local container_env="" diff --git a/cluster/gce/gci/configure-helper.sh b/cluster/gce/gci/configure-helper.sh index b59f098ad26..bdd9fac92dc 100644 --- a/cluster/gce/gci/configure-helper.sh +++ b/cluster/gce/gci/configure-helper.sh @@ -1091,8 +1091,10 @@ function start-kube-apiserver { local authorization_mode="RBAC" local -r src_dir="${KUBE_HOME}/kube-manifests/kubernetes/gci-trusty" - # Create the ABAC file only if it's explicitly requested. - if [[ -n "${ENABLE_LEGACY_ABAC_16_ONLY:-}" ]]; then + # Enable ABAC mode unless the user explicitly opts out with ENABLE_LEGACY_ABAC=false + if [[ "${ENABLE_LEGACY_ABAC:-}" != "false" ]]; then + echo "Warning: Enabling legacy ABAC policy. All service accounts will have superuser API access. Set ENABLE_LEGACY_ABAC=false to disable this." + # Create the ABAC file if it doesn't exist yet, or if we have a KUBE_USER set (to ensure the right user is given permissions) if [[ -n "${KUBE_USER:-}" || ! -e /etc/srv/kubernetes/abac-authz-policy.jsonl ]]; then local -r abac_policy_json="${src_dir}/abac-authz-policy.jsonl" remove-salt-config-comments "${abac_policy_json}" @@ -1103,15 +1105,11 @@ function start-kube-apiserver { fi cp "${abac_policy_json}" /etc/srv/kubernetes/ fi - fi - # Load existing ABAC policy files written by versions < 1.6 of this script - # TODO: only default to this legacy path when in upgrade mode - local abac_authorization_file="${ABAC_AUTHZ_FILE:-/etc/srv/kubernetes/abac-authz-policy.jsonl}" - if [[ -n "${abac_authorization_file:-}" && -e "${abac_authorization_file}" ]]; then - params+=" --authorization-policy-file=${abac_authorization_file}" + params+=" --authorization-policy-file=/etc/srv/kubernetes/abac-authz-policy.jsonl" authorization_mode+=",ABAC" fi + local webhook_config_mount="" local webhook_config_volume="" if [[ -n "${GCP_AUTHZ_URL:-}" ]]; then