For AI agents: A markdown version of this page is available at https://docs.datadoghq.com/security/code_security/iac_security/iac_rules/ansible-gcp-gke-using-default-service-account.md.
A documentation index is available at /llms.txt.
Kubernetes Engine clusters should not use the default node service account. The default account typically has broad permissions, increasing the blast radius if a node is compromised.
For Ansible resources using google.cloud.gcp_container_cluster or gcp_container_cluster, the node_config.service_account property must be defined and set to a dedicated, least-privilege IAM service account (full email address). Resources missing node_config.service_account or with a value containing "default" are flagged. Use a distinct service account with narrowly scoped IAM roles, for example, my-sa@PROJECT_ID.iam.gserviceaccount.com.
Secure configuration example:
- name:Create GKE cluster with custom node service accountgoogle.cloud.gcp_container_cluster:name:my-clusterlocation:us-central1node_config:service_account:my-sa@my-project.iam.gserviceaccount.com
Compliant Code Examples
- name:create a clustergoogle.cloud.gcp_container_cluster:name:my-clusterinitial_node_count:2master_auth:username:cluster_adminpassword:my-secret-passwordnode_config:machine_type:n1-standard-4disk_size_gb:500service_account:"{{ myaccount }}"location:us-central1-aproject:test_projectauth_kind:serviceaccountservice_account_file:"/tmp/auth.pem"state:present- name:create a service accountgoogle.cloud.gcp_iam_service_account:name:sa-{{ resource_name.split("-")[-1] }}@graphite-playground.google.com.iam.gserviceaccount.comdisplay_name:My Ansible test keyproject:test_projectauth_kind:serviceaccountservice_account_file:"/tmp/auth.pem"state:presentregister:myaccount
Non-Compliant Code Examples
- name:create a clustergoogle.cloud.gcp_container_cluster:name:my-clusterinitial_node_count:2master_auth:username:cluster_adminpassword:my-secret-passwordnode_config:machine_type:n1-standard-4disk_size_gb:500location:us-central1-aproject:test_projectauth_kind:serviceaccountservice_account_file:"/tmp/auth.pem"state:present
- name:create a clustergoogle.cloud.gcp_container_cluster:name:my-clusterinitial_node_count:2master_auth:username:cluster_adminpassword:my-secret-passwordnode_config:machine_type:n1-standard-4disk_size_gb:500service_account:"{{ default }}"location:us-central1-aproject:test_projectauth_kind:serviceaccountservice_account_file:"/tmp/auth.pem"state:present- name:create a service accountgoogle.cloud.gcp_iam_service_account:name:sa-{{ resource_name.split("-")[-1] }}@graphite-playground.google.com.iam.gserviceaccount.comdisplay_name:My Ansible test keyproject:test_projectauth_kind:serviceaccountservice_account_file:"/tmp/auth.pem"state:presentregister:default
1
2
rulesets:- Ansible / GCP # Rules to enforce / GCP.
Request a personalized demo
Get Started with Datadog
Ask AI
AI-generated responses may be inaccurate. Verify important info.