{"data":{"slug":"github-google-skills-skills-cloud-gke-workload-security-8efeb1b697f0","title":"GKE Workload Security Hardening","summary":"Audits, configures, and hardens workload-level security controls for Google Kubernetes Engine (GKE) applications and namespaces. Covers running security audits, enforcing Network Policies, isolating high-risk pods with gVisor, enforcing Pod Security Standards, and mounting Secret Manager secrets via CSI.","url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-gke-workload-security-8efeb1b697f0","json_url":"https:\/\/skillshunter.net\/api\/public\/v1\/skills\/github-google-skills-skills-cloud-gke-workload-security-8efeb1b697f0","markdown_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-gke-workload-security-8efeb1b697f0.md","download_url":"https:\/\/skillshunter.net\/skills\/github-google-skills-skills-cloud-gke-workload-security-8efeb1b697f0\/download","category":{"slug":"software-development","name":"Software & Development"},"editor_note":"Before executing any `gcloud`, REST API, or MCP command, you MUST read [Usage Attribution](references\/attribution.md). For commands executed directly in the terminal, prefix `gcloud` with `CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:gke-workload-security)\"` and append `agent-skills\/1.0 (skill:gke-workload-security)` to `User-Agent` headers. The Secret Manager CSI driver must be enabled on the cluster.","instructions":"---\nname: gke-workload-security\ndescription: >-\n  Audits, configures, and hardens workload-level security controls for Google\n  Kubernetes Engine (GKE) applications and namespaces. Covers running security\n  audits (`audit_cluster.sh`), enforcing Network Policies (default-deny and Dataplane\n  V2 logging), isolating high-risk pods inside GKE Sandbox (`gVisor`), enforcing Pod\n  Security Standards (`restricted` labeling) and pod securityContext, and mounting Secret Manager secrets via\n  CSI (`SecretProviderClass`). Use when auditing workload security posture, isolating\n  namespaces, applying pod security standards, or\n  configuring network policies and secret volume mounts. Don't use for Workload Identity (use gke-workload-identity), cluster-wide\n  control plane security, RBAC hardening, Binary Authorization, Shielded Nodes,\n  or enabling platform-level GKE add-ons (use gke-platform-security instead).\nmetadata:\n  version: \"1.0.3\"\n  category: Security\n---\n\n# GKE Workload Security\n\n> **Routing Note:** For Workload Identity IAM and KSA\/GSA bindings, use the `gke-workload-identity` skill. For cluster-level security flags (`--database-encryption-key`, `--security-posture`, RBAC, Shielded Nodes, Binary Authorization), use the `gke-platform-security` skill.\n\nThis skill provides workflows and best practices for securing GKE workloads. It\ncovers security auditing, Identity and Access Management (Workload Identity),\nNetwork Security (Network Policies), and Node Security.\n\n## Attribution\n\n**MUST READ**: Before executing any `gcloud`, REST API, or MCP command, you\nMUST read [Usage Attribution](references\/attribution.md). For commands executed\ndirectly in the terminal (never in generated scripts, Terraform, or user code),\nprefix `gcloud` with\n`CLOUDSDK_METRICS_REQUEST_ATTRIBUTION=\"agent-skills\/1.0 (skill:gke-workload-security)\"`\nand append `agent-skills\/1.0 (skill:gke-workload-security)` to `User-Agent` headers.\n\n## Workflows\n\n### 1. Security Audit\n\nAssess the current security posture of your cluster using the provided audit\nscript.\n\n**Prerequisites:**\n\n-   `gcloud` CLI authenticated.\n-   `jq` command-line JSON processor installed.\n\n**Capabilities:**\n\n-   Checks for Workload Identity.\n-   Verifies Network Policy is enabled.\n-   Checks if Shielded Nodes are enabled.\n-   Checks if Binary Authorization is enabled.\n-   Checks for Private Cluster configuration.\n\n**Command:**\n\n```bash\nscripts\/audit_cluster.sh <cluster-name> <region> <project-id>\n```\n\n### 2. Configure Workload Identity\n\nWorkload Identity allows Kubernetes Service Accounts (KSAs) to impersonate\nGoogle Service Accounts (GSAs). Use this method when workloads require a\ndedicated GSA to access Google Cloud APIs; for most workloads, direct IAM\nprincipal binding (covered in the `gke-workload-identity` skill) is the\nrecommended method.\n\n**Steps:**\n\n1.  **Create Namespace and KSA:**\n\n    ```bash\n    kubectl create namespace workload-identity-test-ns\n    kubectl create serviceaccount <ksa-name> \\\n        --namespace workload-identity-test-ns\n    ```\n\n2.  **Bind KSA to GSA:**\n\n    ```bash\n    gcloud iam service-accounts add-iam-policy-binding <gsa-name>@<project-id>.iam.gserviceaccount.com \\\n        --role roles\/iam.workloadIdentityUser \\\n        --member \"serviceAccount:<project-id>.svc.id.goog[workload-identity-test-ns\/<ksa-name>]\"\n    ```\n\n3.  **Annotate KSA:**\n\n    ```bash\n    kubectl annotate serviceaccount <ksa-name> \\\n        --namespace workload-identity-test-ns \\\n        iam.gke.io\/gcp-service-account=<gsa-name>@<project-id>.iam.gserviceaccount.com\n    ```\n\n4.  **Verify Example Pod:** Use existing asset\n    `assets\/workload-identity-pod.yaml` to test the configuration. Update the\n    `<ksa-name>` in the file first.\n\n    ```bash\n    kubectl apply -f assets\/workload-identity-pod.yaml -n workload-identity-test-ns\n    ```\n\n### 3. Implement Network Policies\n\nControl traffic flow between Pods using Network Policies. By default, all\ntraffic is allowed.\n\n**Enable Network Policy Enforcement:**\n\n```bash\ngcloud container clusters update <cluster-name> \\\n    --update-addons=NetworkPolicy=ENABLED \\\n    --region <region>\n```\n\n> [!NOTE] If your cluster uses Dataplane V2 (`--enable-dataplane-v2`), Network\n> Policy enforcement is built-in and this step is not required (and may fail).\n\n**Apply Default Deny Policy:** Isolate namespaces by denying all ingress and\negress traffic by default.\n\n**Replace `<target-namespace>` with the namespace you want to isolate.**\n\n```bash\nkubectl apply -f assets\/default-deny-netpol.yaml -n <target-namespace>\n```\n\n### 4. GKE Sandbox (gVisor) Pod Isolation\n\nRun untrusted workloads in a sandbox for extra kernel isolation. *(Note:\nEnabling Shielded Nodes (`--enable-shielded-nodes`) and GKE Sandbox\n(`--enable-gke-sandbox`) at the cluster control plane level are platform-level\nactions covered in the `gke-platform-security` skill.)*\n\n**Run a Sandboxed Pod:** Add `runtimeClassName: gvisor` to your Pod spec:\n\n```yaml\napiVersion: v1\nkind: Pod\nmetadata:\n  name: sandboxed-pod\nspec:\n  runtimeClassName: gvisor\n  containers:\n  - name: app\n    image: nginx\n```\n\n### 5. Pod Security Standards\n\nEnforce security policies on namespaces using labels.\n\n**Enforce Restricted Profile:**\n\n```bash\nkubectl label --overwrite ns <namespace> \\\n    pod-security.kubernetes.io\/enforce=restricted \\\n    pod-security.kubernetes.io\/enforce-version=latest\n```\n\n> [!NOTE] Using `latest` ensures you use the policies corresponding to the\n> cluster's current version. You can pin it to a specific version (e.g.,\n> `v1.30`) to lock down the namespace to policies of a specific release.\n\n### 6. Secret Manager Integration (CSI Driver)\n\nMount secrets from Google Cloud Secret Manager directly as volumes in your pods.\n\n**Prerequisites**: Secret Manager CSI driver must be enabled on the cluster.\n\n**Example SecretProviderClass:**\n\n```yaml\napiVersion: secrets-store.csi.x-k8s.io\/v1\nkind: SecretProviderClass\nmetadata:\n  name: my-secret-provider\nspec:\n  provider: gcp\n  parameters:\n    secrets: |\n      - resourceName: \"projects\/<project-id>\/secrets\/my-secret\/versions\/latest\"\n        fileName: \"my-secret-file\"\n```\n\n**Example Pod Spec excerpt:**\n\n```yaml\nspec:\n  containers:\n    - name: my-app\n      volumeMounts:\n        - name: secrets-store-inline\n          mountPath: \"\/mnt\/secrets\"\n          readOnly: true\n  volumes:\n    - name: secrets-store-inline\n      csi:\n        driver: secrets-store.csi.k8s.io\n        readOnly: true\n        volumeAttributes:\n          secretProviderClass: \"my-secret-provider\"\n```\n\n### 7. Enable Network Policy Logging\n\nIf using GKE Dataplane V2, you can log allowed and denied connections.\n\n**Steps:**\n\n1.  Configure the `NetworkLogging` custom resource.\n\n**Example NetworkLogging Manifest:**\n\n```yaml\napiVersion: networking.gke.io\/v1alpha1\nkind: NetworkLogging\nmetadata:\n  name: default\nspec:\n  cluster:\n    allow:\n      log: true\n      delegate: true\n    deny:\n      log: true\n      delegate: true\n```\n\nThis will log connection details to Cloud Logging.\n\n## Best Practices\n\n1.  **Least Privilege:** Always use Workload Identity with minimal IAM roles.\n    Avoid using Node default service accounts.\n2.  **Network Isolation:** Use Network Policies to restrict Pod-to-Pod\n    communication. Enable Network Policy Logging for visibility.\n3.  **Image Security:** Use Binary Authorization to ensure only trusted images\n    are deployed.\n4.  **Secret Management**: Use Secret Manager CSI driver instead of default\n    Kubernetes secrets for sensitive data.\n5.  **Pod Security**: Enforce `baseline` or `restricted` Pod Security Standards\n    on all non-system namespaces.\n6.  **Policy Enforcement**: Consider using **Policy Controller** (Gatekeeper) to\n    enforce custom security and compliance policies across the cluster.\n\n## Resources\n\n-   [Workload Identity Federation for GKE](https:\/\/cloud.google.com\/kubernetes-engine\/docs\/how-to\/workload-identity)\n-   [GKE Network Policies](https:\/\/cloud.google.com\/kubernetes-engine\/docs\/how-to\/network-policy)\n-   [Pod Security Standards in GKE](https:\/\/cloud.google.com\/kubernetes-engine\/docs\/how-to\/podsecurityadmission)\n-   [Google Secret Manager CSI Driver](https:\/\/cloud.google.com\/secret-manager\/docs\/secret-manager-managed-csi-component)\n-   [GKE Dataplane V2 Network Logging](https:\/\/cloud.google.com\/kubernetes-engine\/docs\/how-to\/network-policy-logging)\n","use_cases":["Auditing workload security posture","Isolating high-risk pods with gVisor","Enforcing Pod Security Standards","Mounting Secret Manager secrets via CSI"],"limitations":[],"compatibility":[],"setup_tip":null,"sample_input":null,"sample_output":null,"source_url":"https:\/\/github.com\/google\/skills\/blob\/e3c591afe426ea585e4c21799e5199d6d47cd1be\/skills\/cloud\/gke-workload-security\/SKILL.md","source_commit":"e3c591afe426ea585e4c21799e5199d6d47cd1be","license":null,"version":null,"listing_approved_at":"2026-11-17","created_at":"2026-11-16T16:58:00.000000Z","updated_at":"2026-11-17T10:20:00.000000Z","seo_title":"GKE Workload Security Hardening Guide","seo_description":"Secure GKE workloads with audit scripts, network policies, pod isolation, and secret integration. Learn how to harden your Kubernetes clusters.","seo_keywords":["GKE workload security","Kubernetes security hardening","Pod Security Standards","Secret Manager integration","Network Policy enforcement","gVisor isolation"]}}