Skip to content

12Compute and containersService 12 of 13

GKEsecurity hardening

Harden GKE clusters: private nodes, DNS-based control plane, Workload Identity Federation, node service accounts, RBAC, Pod Security and secrets encryption.

Baseline
12 controls
Category
Compute and containers
Updated
Reading
9 min read

A GKE cluster has two attack surfaces: the Google Cloud resources around it (control plane endpoint, nodes, node service account, network) and the Kubernetes API inside it (RBAC, pods, secrets). Weak settings on either side compound. The recurring incident pattern is short: a public control plane endpoint, a pod that can reach the node metadata server, and a node pool running as the Compute Engine default service account with Editor. One container escape or SSRF then becomes a project compromise. Other well-known paths are RBAC bindings to system:authenticated (which means any Google account, not just your users), legacy client certificates nobody rotates, and service account keys mounted as Kubernetes Secrets. This page covers the cluster-level settings that close those paths, aligned with Google's GKE hardening guide and the CIS GKE Benchmark. It assumes the network and identity baselines from VPC and firewall rules and IAM.

Baseline controls

The CIS GCP Foundations Benchmark does not cover GKE (that is the separate CIS GKE Benchmark), so the last column lists Security Health Analytics findings.

ControlWhyHow to checkCIS / SCC
Use private nodesNodes get no public IPsprivateClusterConfig in describePRIVATE_CLUSTER_DISABLED
Restrict control plane accessAPI server is the top targetcontrolPlaneEndpointsConfig in describeMASTER_AUTHORIZED_NETWORKS_DISABLED
Enable Workload Identity Federation for GKEPods stop using node credentialsworkloadIdentityConfig in describeWORKLOAD_IDENTITY_DISABLED
Run nodes as a dedicated service accountDefault SA often holds EditornodeConfig.serviceAccountOVER_PRIVILEGED_ACCOUNT
Use Shielded nodes with Secure BootBlocks rootkits and node impersonationshieldedNodes and node pool configCLUSTER_SHIELDED_NODES_DISABLED, NODEPOOL_SECURE_BOOT_DISABLED
Use Container-Optimized OSMinimal, read-only, Google-patchednodeConfig.imageTypeCOS_NOT_USED
Enroll in a release channel with auto-upgradeSecurity patches land without ticketsreleaseChannel in describeRELEASE_CHANNEL_DISABLED, AUTO_UPGRADE_DISABLED
Enforce network policyPods are flat by defaultnetworkConfig.datapathProviderNETWORK_POLICY_DISABLED
Encrypt Secrets with Cloud KMSYou control the key for Secret objectsdatabaseEncryption in describeCLUSTER_SECRETS_ENCRYPTION_DISABLED
Keep legacy ABAC disabledABAC bypasses RBAClegacyAbac in describeLEGACY_AUTHORIZATION_ENABLED
Require Binary AuthorizationOnly trusted images runbinaryAuthorization in describeBINARY_AUTHORIZATION_DISABLED
Apply Pod Security AdmissionBlocks privileged and root podsNamespace labelsn/a

Autopilot first, then a hardened Standard cluster

GKE Autopilot applies many of these controls by default and does not let you turn them off: Workload Identity Federation for GKE, Shielded GKE nodes with Secure Boot, Container-Optimized OS with containerd, mandatory release channels with Google-managed upgrades, no SSH to nodes, and no privileged pods outside allowlisted partner workloads. Unless you need node-level customization (specific kernels, privileged DaemonSets, custom GPU drivers), Autopilot removes a large part of this checklist. The rest of this page is written for Standard clusters, with notes where Autopilot differs.

A Standard cluster with the main controls set at creation:

gcloud container clusters create prod-ew1 \
  --project=prj-website-prod \
  --region=europe-west1 \
  --release-channel=regular \
  --network=vpc-prod --subnetwork=snet-gke-ew1 \
  --enable-ip-alias \
  --enable-private-nodes \
  --enable-dns-access \
  --no-enable-ip-access \
  --workload-pool=prj-website-prod.svc.id.goog \
  --service-account=sa-gke-nodes@prj-website-prod.iam.gserviceaccount.com \
  --shielded-secure-boot --shielded-integrity-monitoring \
  --image-type=COS_CONTAINERD \
  --enable-dataplane-v2 \
  --database-encryption-key=projects/prj-kms-prod/locations/europe-west1/keyRings/kr-gke/cryptoKeys/k-gke-secrets \
  --security-group=gke-security-groups@example.com \
  --security-posture=standard \
  --binauthz-evaluation-mode=PROJECT_SINGLETON_POLICY_ENFORCE \
  --no-enable-insecure-kubelet-readonly-port \
  --logging=SYSTEM,WORKLOAD,API_SERVER \
  --monitoring=SYSTEM

Flag names evolve between gcloud releases; check gcloud container clusters create --help for your version. Inspect an existing cluster in one call:

gcloud container clusters describe prod-ew1 --region=europe-west1 \
  --format="yaml(privateClusterConfig,controlPlaneEndpointsConfig,masterAuthorizedNetworksConfig,workloadIdentityConfig,shieldedNodes,releaseChannel,databaseEncryption,legacyAbac,masterAuth,binaryAuthorization,authenticatorGroupsConfig)"

Control plane access and private nodes

The Kubernetes API server is the most valuable target in the cluster. Limit who can reach it at the network layer and at the identity layer:

  • Private nodes (--enable-private-nodes): nodes have only internal IPs. Egress goes through Cloud NAT.
  • DNS-based endpoint (--enable-dns-access): clients reach the control plane through a DNS name, and every request is authorized with IAM (container.clusters.connect), so you do not need to expose an IP endpoint or run a bastion. You can also put the endpoint inside a VPC Service Controls perimeter.
  • IP-based endpoints: disable them with --no-enable-ip-access once all clients use DNS. If you keep them, turn on authorized networks (--enable-master-authorized-networks --master-authorized-networks=10.10.0.0/16) and never include 0.0.0.0/0.

Switch an existing cluster to DNS-only access:

gcloud container clusters update prod-ew1 --region=europe-west1 \
  --enable-dns-access
gcloud container clusters update prod-ew1 --region=europe-west1 \
  --no-enable-ip-access

Console: Kubernetes Engine > Clusters > (cluster) > Networking > Control plane access.

Enforce org-wide with the managed constraints container.managed.enablePrivateNodes and container.managed.enableControlPlaneDNSOnlyAccess:

name: organizations/ORG_ID/policies/container.managed.enablePrivateNodes
spec:
  rules:
  - enforce: true
gcloud org-policies set-policy gke-private-nodes.yaml

Node service account and node hardening

Nodes need a service account to write logs and metrics and to pull images. Never use the Compute Engine default. Create a dedicated one with only the minimal role:

gcloud iam service-accounts create sa-gke-nodes --project=prj-website-prod

gcloud projects add-iam-policy-binding prj-website-prod \
  --member="serviceAccount:sa-gke-nodes@prj-website-prod.iam.gserviceaccount.com" \
  --role="roles/container.defaultNodeServiceAccount"

gcloud artifacts repositories add-iam-policy-binding app-images \
  --location=europe --project=prj-artifacts \
  --member="serviceAccount:sa-gke-nodes@prj-website-prod.iam.gserviceaccount.com" \
  --role="roles/artifactregistry.reader"

roles/container.defaultNodeServiceAccount bundles the logging and monitoring permissions nodes need; image pull access is granted on the specific repository. Enforce with container.managed.disallowDefaultComputeServiceAccount.

Node settings to keep:

  • Shielded GKE nodes are on by default and protect against rootkits and node impersonation. Add --shielded-secure-boot on every node pool (container.managed.enableShieldedNodes enforces the cluster setting).
  • Container-Optimized OS with containerd (COS_CONTAINERD) is a minimal image with a read-only root filesystem, maintained by Google.
  • Release channels and auto-upgrade. Use regular or stable for production, keep auto-upgrade and auto-repair on, and use maintenance windows and exclusions to control timing instead of disabling upgrades. Subscribe to security bulletins (container.managed.enableSecurityBulletinNotifications).
  • Insecure kubelet read-only port. Port 10255 exposes pod and node information without authentication. Disable it with --no-enable-insecure-kubelet-readonly-port and enforce container.managed.disableInsecureKubeletReadOnlyPort.
  • No SSH to nodes in normal operation. For debugging, use OS Login with IAP, as on any Compute Engine VM.

Workload Identity Federation and metadata protection

Pods should never use the node's service account and never use exported service account keys mounted as Secrets. Workload Identity Federation for GKE lets a Kubernetes service account act as an IAM principal. With the workload pool set on the cluster, run the GKE metadata server on every node pool:

gcloud container node-pools update default-pool \
  --cluster=prod-ew1 --region=europe-west1 \
  --workload-metadata=GKE_METADATA

The GKE metadata server intercepts pod requests to the metadata endpoint, so pods cannot read the node's credentials or sensitive instance attributes such as kubelet bootstrap credentials. This replaces the old metadata concealment feature. The legacy metadata endpoints (v0.1 and v1beta1) are disabled on current versions; Security Health Analytics reports LEGACY_METADATA_ENABLED if an old node pool still exposes them.

Grant roles directly to a Kubernetes service account principal, without creating a Google service account:

gcloud storage buckets add-iam-policy-binding gs://app-uploads \
  --role="roles/storage.objectViewer" \
  --member="principal://iam.googleapis.com/projects/PROJECT_NUMBER/locations/global/workloadIdentityPools/prj-website-prod.svc.id.goog/subject/ns/app/sa/uploader"

Pods running as the uploader service account in the app namespace now get short-lived tokens for that access, and nothing else. Enforce with container.managed.enableWorkloadIdentityFederation. Autopilot clusters always have it on.

Secrets encryption

GKE encrypts etcd at rest by default. Application-layer secrets encryption (--database-encryption-key) adds envelope encryption of Secret objects with a Cloud KMS key you control. The GKE service agent (service-PROJECT_NUMBER@container-engine-robot.iam.gserviceaccount.com) needs roles/cloudkms.cryptoKeyEncrypterDecrypter on the key, and the key must be in the same location as the cluster.

gcloud container clusters update prod-ew1 --region=europe-west1 \
  --database-encryption-key=projects/prj-kms-prod/locations/europe-west1/keyRings/kr-gke/cryptoKeys/k-gke-secrets

Enforce with container.managed.enableSecretsEncryption. For sensitive credentials, the Secret Manager add-on (--enable-secret-manager) mounts secrets from Secret Manager as volumes, so they never become Kubernetes Secret objects at all.

RBAC, Google Groups and legacy authentication

Use Kubernetes RBAC for in-cluster authorization and Google Groups for subjects. Google Groups for RBAC needs a group named gke-security-groups@YOUR_DOMAIN whose members are the groups you reference in RoleBindings; set it with --security-group and enforce with container.managed.enableGoogleGroupsRBAC. Keep IAM coarse (roles/container.clusterViewer for kubectl access) and grant real permissions in RBAC per namespace:

apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
  name: app-developers
  namespace: app
subjects:
- kind: Group
  name: app-dev@example.com
  apiGroup: rbac.authorization.k8s.io
roleRef:
  kind: ClusterRole
  name: edit
  apiGroup: rbac.authorization.k8s.io

Avoid cluster-admin bindings to humans. Check what exists:

kubectl get clusterrolebindings -o json \
  | jq -r '.items[] | select(.roleRef.name=="cluster-admin") | .metadata.name + " -> " + ([.subjects[]?.name] | join(", "))'

Review bindings to system:anonymous, system:unauthenticated and system:authenticated. The managed constraint container.managed.disableRBACSystemBindings blocks new non-default bindings to those identities.

Legacy authentication should be off everywhere:

  • Legacy ABAC (--no-enable-legacy-authorization): grants broad permissions outside RBAC. Enforce container.managed.disableABAC.
  • Basic authentication: removed from GKE 1.19 onward; very old clusters that still show a masterAuth.username must be upgraded.
  • Client certificates: not issued by default on new clusters. A legacy client certificate cannot be revoked short of rotating the cluster CA. Enforce container.managed.disableLegacyClientCertificateIssuance.

Pod Security Admission and network policy

Pod Security Admission enforces the Kubernetes Pod Security Standards per namespace. Label application namespaces with the restricted profile:

kubectl label namespace app \
  pod-security.kubernetes.io/enforce=restricted \
  pod-security.kubernetes.io/warn=restricted \
  pod-security.kubernetes.io/audit=restricted

restricted blocks privileged containers, host namespaces, hostPath volumes, running as root and privilege escalation. Use baseline only for namespaces that genuinely need more. The old PodSecurityPolicy was removed in Kubernetes 1.25. For richer rules, Policy Controller (based on OPA Gatekeeper) adds constraint templates, including a CIS GKE bundle.

By default, every pod can reach every other pod. With GKE Dataplane V2 (--enable-dataplane-v2), Kubernetes NetworkPolicy is enforced natively (container.managed.enableNetworkPolicy requires it). Start with a default deny per namespace and add explicit allows, including egress to kube-dns:

apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: default-deny
  namespace: app
spec:
  podSelector: {}
  policyTypes: ["Ingress", "Egress"]

Binary Authorization and security posture

Binary Authorization ensures only images that meet a policy (attested by your CI, from your Artifact Registry repositories) are deployed. Start in dry-run mode, then enforce, and require it org-wide with container.managed.enableBinaryAuthorization.

GKE security posture (--security-posture=standard) audits workload configuration against Pod Security Standards and surfaces security bulletins at no extra charge. The workload vulnerability scanning tiers of the posture dashboard are deprecated (OS scanning shut down in July 2025, advanced vulnerability insights in June 2026), so scan images in Artifact Registry with Artifact Analysis instead and gate deployments with Binary Authorization.

Measure the result with the CIS GKE Benchmark through Security Command Center or Prowler, as described in Security Command Center.

Logging and detection

Keep SYSTEM, WORKLOAD and API_SERVER logging enabled (container.managed.enableCloudLogging enforces at least the default). Kubernetes audit logs land in Cloud Logging under resource.type="k8s_cluster"; GKE API changes under resource.type="gke_cluster".

Alert on interactive access and privilege changes inside the cluster:

resource.type="k8s_cluster"
logName:"cloudaudit.googleapis.com%2Factivity"
(protoPayload.methodName=~"io.k8s.core.v1.pods.exec.*"
 OR protoPayload.methodName:"io.k8s.authorization.rbac.v1")

And on cluster configuration changes that weaken controls:

resource.type="gke_cluster"
protoPayload.methodName:("ClusterManager.UpdateCluster" OR "ClusterManager.SetLegacyAbac" OR "ClusterManager.SetMasterAuth")

Reads of Secret objects (io.k8s.core.v1.secrets.get and list) are Data Access entries; enable Data Access logs for container.googleapis.com if you need them (see Cloud Audit Logs and Cloud Logging). In Security Command Center, the Security Health Analytics findings in the baseline table cover configuration, and Event Threat Detection and Container Threat Detection report runtime activity such as unexpected binaries and RBAC escalation.

Common mistakes

  • Enabling Workload Identity on the cluster but leaving older node pools on GCE_METADATA, so pods in those pools still read the node token.
  • Adding 0.0.0.0/0 to authorized networks "temporarily" for a CI runner and never removing it.
  • Binding a role to system:authenticated to unblock a tool, which grants it to every Google account in the world.
  • Turning off auto-upgrade to avoid disruptions, then running unpatched nodes for months. Use maintenance windows and exclusions instead.
  • Mounting a service account key JSON as a Kubernetes Secret instead of using Workload Identity Federation.
  • Labeling namespaces with Pod Security warn only and never switching to enforce.
  • Writing a default-deny NetworkPolicy without an egress rule to kube-dns, then disabling policies after DNS breaks.

References

About the author

Security engineer writing practical, benchmark-aligned guides to hardening Google Cloud organizations, projects and workloads.

Related services

All services