4.3 Ensure "Block Project-Wide SSH Keys" Is Enabled for VM Instances (Automated)
Profile Applicability
- Level 1
Description
It is recommended to use Instance specific SSH key(s) instead of using common/shared project-wide SSH key(s) to access Instances.
Rationale
Project-wide SSH keys are stored in Compute/Project-meta-data. Project wide SSH keys can be used to login into all the instances within project. Using project-wide SSH keys eases the SSH key management but if compromised, poses the security risk which can impact all the instances within project. It is recommended to use Instance specific SSH keys which can limit the attack surface if the SSH keys are compromised.
Impact
Users already having Project-wide ssh key pairs and using third party SSH clients will lose access to the impacted Instances. For Project users using gcloud or GCP Console based SSH option, no manual key creation and distribution is required and will be handled by GCE (Google Compute Engine) itself. To access Instance using third party SSH clients Instance specific SSH key pairs need to be created and distributed to the required users.
Audit
From Google Cloud Console
- Go to the
VM instancespage by visiting https://console.cloud.google.com/compute/instances. It will list all the instances in your project. - For every instance, click on the name of the instance.
- Under
SSH Keys, ensureBlock project-wide SSH keysis selected.
From Google Cloud CLI
- List the instances in your project and get details on each instance:
gcloud compute instances list --format=json
- Ensure
key: block-project-ssh-keysis set tovalue: 'true'.
Remediation
From Google Cloud Console
- Go to the
VM instancespage by visiting: https://console.cloud.google.com/compute/instances. It will list all the instances in your project. - Click on the name of the Impacted instance.
- Click
Editin the toolbar. - Under SSH Keys, go to the
Block project-wide SSH keyscheckbox. - To block users with project-wide SSH keys from connecting to this instance, select
Block project-wide SSH keys. - Click
Saveat the bottom of the page. - Repeat steps for every impacted Instance.
From Google Cloud CLI
To block project-wide public SSH keys, set the metadata value to TRUE:
gcloud compute instances add-metadata <INSTANCE_NAME> --metadata block-project-ssh-keys=TRUE
Default Value
By Default Block Project-wide SSH keys is not enabled.
References
- https://cloud.google.com/compute/docs/instances/adding-removing-ssh-keys
- https://cloud.google.com/sdk/gcloud/reference/topic/formats
Additional Information
If OS Login is enabled, SSH keys in instance metadata are ignored, and therefore blocking project-wide SSH keys is not necessary.
CIS Controls
| Controls Version | Control | IG 1 | IG 2 | IG 3 |
|---|---|---|---|---|
| v8 | 3.10 Encrypt Sensitive Data in Transit | X | X | |
| v8 | 5.2 Use Unique Passwords | X | X | X |
| v7 | 4.4 Use Unique Passwords | X | X | |
| v7 | 16.5 Encrypt Transmittal of Username and Authentication Credentials | X | X |