gke-workload-security
Workflows for auditing and hardening the security of GKE workloads.
- License 许可
- Apache-2.0
- 最近更新
- 2026-11-14
- Stars
- ★ 126
- Forks
- 44
01 前言 Front Matter
- name
- gke-workload-security
- description
- Workflows for auditing and hardening the security of GKE workloads.
02 资源文件 2
- 资产文件assets/default-deny-netpol.yaml235 B
- 资产文件assets/workload-identity-pod.yaml1.2 KB
03 SKILL.md 正文
GKE Workload Security
This skill provides workflows and best practices for securing GKE workloads. It covers security auditing, Identity and Access Management (Workload Identity), Network Security (Network Policies), and Node Security.
You are read-only: each change below is a proposal you report with your findings, never a command you run.
Workflows
1. Security Audit
Assess the current security posture of your cluster using the provided audit script.
Capabilities:
- Checks for Workload Identity.
- Verifies Network Policy is enabled.
- Checks if Shielded Nodes are enabled.
- Checks if Binary Authorization is enabled.
- Checks for Private Cluster configuration.
Command:
/opt/data/scripts/audit_cluster.sh <cluster-name> <region> <project-id>
2. Configure Workload Identity
Workload Identity allows Kubernetes Service Accounts (KSAs) to impersonate Google Service Accounts (GSAs). This is the recommended method for workloads to access Google Cloud APIs.
Steps:
Each step is a change you propose.
-
Namespace and KSA: propose the Namespace and the KSA:
apiVersion: v1 kind: Namespace metadata: name: workload-identity-test-ns --- apiVersion: v1 kind: ServiceAccount metadata: name: <ksa-name> namespace: workload-identity-test-ns annotations: iam.gke.io/gcp-service-account: <gsa-name>@<project-id>.iam.gserviceaccount.com -
Bind KSA to GSA: propose granting
roles/iam.workloadIdentityUseron the GSA<gsa-name>@<project-id>.iam.gserviceaccount.comto the memberserviceAccount:<project-id>.svc.id.goog[workload-identity-test-ns/<ksa-name>]. -
Annotate KSA: the
iam.gke.io/gcp-service-accountannotation in the manifest above links the KSA to the GSA. -
Example Pod: propose a test Pod in
workload-identity-test-nswithserviceAccountName: <ksa-name>and the node selectoriam.gke.io/gke-metadata-server-enabled: "true". A complete example is inassets/workload-identity-pod.yaml.
3. Implement Network Policies
Control traffic flow between Pods using Network Policies. By default, all traffic is allowed.
Check Network Policy Enforcement & Dataplane:
Before modifying cluster networking, inspect whether NetworkPolicy enforcement is already active or provided natively by Dataplane V2:
gcloud container clusters describe <cluster-name> \
--location <location> \
--format='value(networkConfig.datapathProvider,networkPolicy.enabled)'
- If
datapathProviderisADVANCED_DATAPATH(Dataplane V2), NetworkPolicy enforcement is built-in natively via eBPF/Cilium from cluster creation. Calico addons cannot be enabled and are not needed. - If
networkPolicy.enabledisTrue, Calico enforcement is already enabled on nodes. - If neither is active, propose enabling Calico network policy enforcement in the two steps below.
Network Policy Enforcement (non-DPv2 clusters):
On clusters without Dataplane V2 this is two sequential changes, in this order:
first enable the NetworkPolicy addon on the control plane (Config Connector
ContainerCluster field spec.addonsConfig.networkPolicyConfig.disabled: false,
with spec.networkPolicy.enabled: false alongside it, since the addon setting
does nothing without a networkPolicy block), then enable network policy
enforcement on the nodes (spec.networkPolicy.enabled: true, provider: CALICO).
GKE rejects node enforcement with HTTP 400 until the addon is enabled, and
node pools may be recreated, which can take several minutes. Propose both, with
that order stated.
Default Deny Policy: Isolate namespaces by denying all ingress and egress traffic by default.
Propose this manifest, with <target-namespace> set to the namespace to
isolate. assets/default-deny-netpol.yaml
holds the same policy without the metadata.namespace line.
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
name: default-deny-all
namespace: <target-namespace>
spec:
podSelector: {}
policyTypes:
- Ingress
- Egress
4. Enable Shielded Nodes
Ensure nodes are running with verifiable integrity.
Propose enabling Shielded Nodes (Config Connector ContainerCluster field
spec.enableShieldedNodes: true).
5. GKE Sandbox (gVisor)
Run untrusted workloads in a sandbox for extra isolation.
GKE Sandbox:
Propose a node pool with GKE Sandbox enabled (Config Connector
ContainerNodePool field spec.nodeConfig.sandboxConfig.sandboxType: gvisor).
Run a Sandboxed Pod:
Add runtimeClassName: gvisor to your Pod spec.
6. Pod Security Standards
Enforce security policies on namespaces using labels.
Enforce Restricted Profile: Propose these labels on the namespace:
apiVersion: v1
kind: Namespace
metadata:
name: <namespace>
labels:
pod-security.kubernetes.io/enforce: restricted
pod-security.kubernetes.io/enforce-version: latest
[!NOTE] Using
latestensures you use the policies corresponding to the cluster's current version. You can pin it to a specific version (e.g.,v1.30) to lock down the namespace to policies of a specific release.
7. Secret Manager Integration (CSI Driver)
Mount secrets from Google Cloud Secret Manager directly as volumes in your pods.
Prerequisites: Secret Manager CSI driver must be enabled on the cluster.
Example SecretProviderClass:
apiVersion: secrets-store.csi.x-k8s.io/v1
kind: SecretProviderClass
metadata:
name: my-secret-provider
spec:
provider: gcp
parameters:
secrets: |
- resourceName: "projects/<project-id>/secrets/my-secret/versions/latest"
fileName: "my-secret-file"
Example Pod Spec excerpt:
spec:
containers:
- name: my-app
volumeMounts:
- name: secrets-store-inline
mountPath: "/mnt/secrets"
readOnly: true
volumes:
- name: secrets-store-inline
csi:
driver: secrets-store.csi.k8s.io
readOnly: true
volumeAttributes:
secretProviderClass: "my-secret-provider"
8. Enable Network Policy Logging
If using GKE Dataplane V2, you can log allowed and denied connections.
Steps:
- Propose the
NetworkLoggingcustom resource.
Example NetworkLogging Manifest:
apiVersion: networking.gke.io/v1alpha1
kind: NetworkLogging
metadata:
name: default
spec:
cluster:
allow:
log: true
delegate: true
deny:
log: true
delegate: true
This will log connection details to Cloud Logging.
Best Practices
- Least Privilege: Always use Workload Identity with minimal IAM roles. Avoid using Node default service accounts.
- Network Isolation: Use Network Policies to restrict Pod-to-Pod communication. Enable Network Policy Logging for visibility.
- Image Security: Use Binary Authorization to ensure only trusted images are deployed.
- Secret Management: Use Secret Manager CSI driver instead of default Kubernetes secrets for sensitive data.
- Pod Security: Enforce
baselineorrestrictedPod Security Standards on all non-system namespaces. - Policy Enforcement: Consider using Policy Controller (Gatekeeper) to enforce custom security and compliance policies across the cluster.
04 同仓库更多 Skills
gke-workload-troubleshooting
Diagnoses GKE workload failures (CrashLoopBackOff, OOMKilled, ImagePullBackOff, Pending, etc.) via logs and events. Use when pods fail to start or crash repeatedly. Don't use for GKE cluster infrastructure provisioning, node pool creation, or non-Kubernetes Google Cloud services.
gke-workload-security
Audits, configures, and hardens workload-level security controls for Google Kubernetes Engine (GKE) applications and namespaces. Covers running security audits (`audit_cluster.sh`), enforcing Network Policies (default-deny and Dataplane V2 logging), isolating high-risk pods inside GKE Sandbox (`gVisor`), enforcing Pod Security Standards (`restricted` labeling) and pod securityContext, and mounting Secret Manager secrets via CSI (`SecretProviderClass`). Use when auditing workload security posture, isolating namespaces, applying pod security standards, or configuring network policies and secret volume mounts. Don't use for Workload Identity (use gke-workload-identity), cluster-wide control plane security, RBAC hardening, Binary Authorization, Shielded Nodes, or enabling platform-level GKE add-ons (use gke-platform-security instead).
gke-workload-scaling
Manages scaling for GKE workloads using HPA and VPA. Use when configuring Horizontal Pod Autoscaler (HPA), configuring Vertical Pod Autoscaler (VPA), or applying best practices for GKE workload autoscaling. Do not use for cluster-level autoscaling (Cluster Autoscaler), static cluster sizing, or configuring node-level machine styles directly.
gke-workload-identity
Configures and diagnoses Workload Identity Federation for GKE authentication failures for Pods (403 "iam.serviceAccounts.getAccessToken" / permission denied, "could not find default credentials", or GKE metadata server unreachable) by verifying cluster and node-pool Workload Identity configuration, the Kubernetes ServiceAccount (KSA) to IAM binding (direct principal binding and legacy Google ServiceAccount impersonation), target-resource IAM roles, and gke-metadata-server health. Use when setting up KSA/GSA bindings (`roles/iam.workloadIdentityUser`, `iam.gke.io/gcp-service-account`) or when a Pod cannot authenticate to Google Cloud APIs. Don't use for in-cluster Kubernetes RBAC errors (API-server authorization), general workload crashes (use gke-workload-troubleshooting), or Pod Security Standards and NetworkPolicies (use gke-workload-security).
gke-upgrades
Plans, executes, and validates Google Kubernetes Engine (GKE) cluster upgrades and maintenance operations for both Standard and Autopilot clusters. Produces upgrade plans, pre/post-upgrade checklists, maintenance runbooks with gcloud commands, release channel strategy, and troubleshooting guides. Handles node pool upgrade strategies (surge, blue-green), version compatibility, PDB management, and workload-specific concerns (stateful, GPU, operators). Use this skill whenever the user mentions GKE upgrades, Kubernetes version bumps, node pool maintenance, GKE patching, cluster version management, release channel selection, maintenance windows, surge upgrades, stuck upgrades, or any GKE lifecycle management task — even casual mentions like "we need to upgrade our clusters" or "plan our next GKE maintenance" or "our upgrade is stuck." Don't use for GKE cluster creation, application onboarding, general networking/routing setup, or security policy configurations (use gke-basics or relevant GKE skills instead).
gke-tpu-metrics-monitoring
Monitors and troubleshoots GKE TPU workloads, nodes, and node pools using GKE system metrics and PromQL. Use when monitoring TensorCore duty cycle, TPU memory, node readiness, multi-host TPU node pool availability, host maintenance or preemption interruptions, and calculating MTTR or MTBI metrics for GKE TPUs. Don't use for general non-TPU GKE workload monitoring or non-metric TPU debugging.