lacework-global-235
Ensure That Service Account Has No Admin Privileges (Automated)
Profile Applicability
• Level 1
Description
A service account is a special Google Account that belongs to an application or a VM, instead of to an individual end-user. The application uses the service account to call the service's Google API so that users are not directly involved. Best practices recommend not using administrator access for service accounts. This includes the Editor role, the Owner role and any role which grants administrator access to a particular service (such as Security Admin). This policy considers user created and default (user-managed but not user-created) service accounts. Though default service accounts are not created by the user, you can associate them with administrative privileges like any other service account.
Rationale
Service accounts represent service-level security of the Resources (application or a VM) which can be determined by the roles assigned to it. Enrolling ServiceAccount with Admin rights gives full access to an assigned application or a VM. A ServiceAccount Access holder can perform critical actions like delete, update change settings, etc. without user intervention. For this reason, it's recommended that service accounts not have Admin rights.
Impact
Removing *Admin
or *admin
or Editor
or Owner
role assignments from service accounts may break functionality that uses impacted service accounts. Required role(s) should be assigned to impacted service accounts in order to restore broken functionalities.
Audit
From Console:
- Navigate to the IAM section of the IAM & Admin console:
https://console.cloud.google.com/iam-admin/iam
. - Ensure the VIEW BY PRINCIPALS tab is active.
- Check the box to "Include Google-provided role grants".
- Add the following four filters to the table of principals:
- Type: Service account
- Role:admin
- Role:Editor
- Role:Owner
- Ensure that there are no service accounts with roles assigned the
Editor
role,Owner
role, or roles containing the wordAdmin
oradmin
.
From Command Line:
- Run the following command - replacing
<PROJECT_ID>
with the target project - to return all IAM policy bindings in the specified project:
gcloud projects get-iam-policy <PROJECT_ID> --format json
Ensure that the output of the command does not include any policies which bind the
Editor
role,Owner
role, or roles containing the wordAdmin
oradmin
to a service account, noting that service accounts are identifiable bound members with the prefixserviceAccount:
. The following example shows a service account that is bound to an admin role:{
"bindings": [
{
"members": [
"serviceAccount:project-foo@appspot.gserviceaccount.com",
],
"role": "roles/appengine.appAdmin"
}
]
}
Remediation
From Console:
- Navigate to the Identity and Access Management (IAM) section of the IAM & Admin console: https://console.cloud.google.com/iam-admin/iam.
- Ensure the View By Principals tab is active.
- Check the box to "Include Google-provided role grants".
- Add the following four filters to the table of principals:
- Type: Service account
- Role: *Admin
- Role: Editor
- Role: Owner
- In the resulting list of principals, click the pencil icon next to a service account to open the edit drawer.
- Edit the role to remove excess administrator privileges:
- If the offending administrator role is not required, remove it by clicking the Delete bin/trash icon.
- Alternatively, assign a lesser privileged role to the service account.
- The lesser privileged role should contain only the exact permissions required by the service account. If an appropriate role does not exist, create a custom role at https://console.cloud.google.com/iam-admin/roles.
- Validate the changes in the summary to the right.
- Click the save icon to confirm the role removal.
- Repeat steps 5-8 for each service account in the filtered list created in step 4.
From Command Line:
- Running the following command to retrieve all IAM policies and write them to a file on disk in JSON format:
gcloud projects get-iam-policy <PROJECT_ID> --format json > iam.json
Using a text editor, open iam.json and remove or update service account bindings to the editor role (roles/editor), owner role (roles/owner) or roles which contain the word admin. You can remove bindings by deleting the offending service account member from the bindings. Alternatively, you can update bindings to associate the offending service account with a role which contains only the permissions it requires (this may be a custom role if required). The following example binds a service account to a custom role:
{
bindings": [
{
"members": [
"serviceAccount:project-foo@appspot.gserviceaccount.com"
],
"role": "projects/project-foo/roles/CustomFooRole"
},
]
}Save iam.json.
Write the IAM policy updates back to the GCP project with the following command:
gcloud projects set-iam-policy PROJECT_ID iam.json
References
https://cloud.google.com/sdk/gcloud/reference/iam/service-accounts/
https://cloud.google.com/iam/docs/understanding-roles
https://cloud.google.com/iam/docs/understanding-service-accounts