T09 · Insecure Skill Coding Practices
- Location
scripts/script.sh:188- Finding
Kubernetes Credentials Persisted Without Restrictive File Permissions or Cleanup
- Content
View full analysis
~/.kube/config ``` ### Technical Analysis The generated GitHub Actions workflow decodes a Kubernetes configuration secret and writes it to the runner's persistent home directory. It does not establish a restrictive `umask`, explicitly set the file mode to `0600`, use a job-scoped temporary directory, or remove the credential after deployment. On an ephemeral GitHub-hosted runner, destruction of the runner limits the exposure window. However, the generated template does not require an ephemeral runner and may be used on a persistent or self-hosted runner. In that environment, `~/.kube/config` can remain available after the job finishes. Its effective permissions depend on the runner account's current `umask`. Any later process running as the same operating-system user may be able to read the kubeconfig. The credential's actual capabilities depend on the Kubernetes identity and RBAC permissions encoded in the supplied configuration. ### Attack Path 1. A project uses the generated Kubernetes workflow on a persistent or self-hosted runner. 2. The deployment job decodes `secrets.KUBE_CONFIG` into `~/.kube/config`. 3. The job finishes without deleting the credential file. 4. An attacker obtains code execution in a subsequent workflow, build step, compromised dependency, or another process running under the same runner account. 5. The attacker reads `~/.kube/config`. 6. The attacker uses the recovered server address and authentication material to connect to the Kubernetes API. 7. The attacker performs operations allowed by the associated Kubernetes RBAC identity. ### Impact Assessment Successful exploitation can disclose Kubernete ...[truncated 505 chars]- Remediation
View remediation
"$KUBECONFIG_FILE" chmod 600 "$KUBECONFIG_FILE" echo "KUBECONFIG=$KUBECONFIG_FILE" >> "$GITHUB_ENV" - name: Remove kubeconfig if: always() shell: bash run: | if [[ -n "${KUBECONFIG:-}" ]]; then rm -f -- "$KUBECONFIG" fi ``` Additional hardening measures: - Prefer ephemeral, isolated runners for deployment jobs. - Give the Kubernetes identity only the RBAC permissions required for deployment. - Use short-lived workload identity or OIDC-based authentication instead of long-lived kubeconfig credentials where supported. - Restrict deployment environments with approvals and protected branches. - Avoid sharing runner operating-system accounts between unrelated repositories or trust domains. ]]>
