Getting a VM instance identity document
When you create a VM, an identity document that stores information about the VM is generated. It contains the IDs of the VM instance, Marketplace product, disk image, etc.
To request an identity document:
-
Connect to the VM:
ssh <VM_IP_address>
-
Run this command to get the identity document in Google Compute Engine format:
curl \ --header Metadata-Flavor:Google 169.254.169.254/computeMetadata/v1/instance/vendor/identity/document
Response example:
{"instanceId":"fhmm5252k8vl********","productCodes":null,"imageId":"fd8evlqsgg4e********","productIds":["f2e3ia802lab********"],"createdAt":"2023-05-29T09:46:59Z","version":"2023-03-01"}
Note
If you created your VM before June 9, 2023, and you cannot get its identity document, stop and restart the VM.
Checking identity document signature
Apart from the identity document itself, the VM instance metadata service provides its cryptographic signatures.
You can use these signatures to verify the document's origin, validity, and integrity. To do this:
-
Connect to the VM:
ssh <VM_IP_address>
-
Get an RSA signature from the VM metadata and save it to a file named
rsa2048
:curl \ --header Metadata-Flavor:Google 169.254.169.254/computeMetadata/v1/instance/vendor/identity/rsa > rsa2048
-
Create a file named
certificate
and add a public certificate to it:-----BEGIN CERTIFICATE----- MIIC4TCCAcmgAwIBAgIUP0zcGO1MeRwze8VdSMEt/OdBXoIwDQYJKoZIhvcNAQEL BQAwADAeFw0yMzA2MDcwNjU4MTBaFw0zMzA2MDQwNjU4MTBaMAAwggEiMA0GCSqG SIb3DQEBAQUAA4IBDwAwggEKAoIBAQDw6TvAvrbJvY4tzIIuDnLEVfRUW4BZJD3y K8fyyxXrYDvC69RKCKk9+TQhnUOLhZNlDST4HFfSPlakOjXUduyJE5M1EmoLAstN 81aP3TejseDavxmaNijXRsa9E731T5H+zo44PgAHfQJmiD7rtcr+QOIosKUB2dwp F2acp9hLKd389BfNctziG0Oxq7hlISTDBnhzBg7eKuqWtShjVW5RqQvp3bARfUPa RWdYjmZvR+AnmozV1SGnpAnatzhnF6tNAb5XSEw49tumsX1D4A11J6mtrafO6bsP wdIPwy9W15iCszUNlFcdBaZhESc34VbyCyLMvA5T0Uj1FJHz1RFlAgMBAAGjUzBR MB0GA1UdDgQWBBQq0z6Vcmjcn8wnRTwKGSm5YGas9TAfBgNVHSMEGDAWgBQq0z6V cmjcn8wnRTwKGSm5YGas9TAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUA A4IBAQBplippQ/Pxn7AkuwOTSwSTeJ7S+rMSb6iSL9chNHetanft0Ikr5BDsSrd6 TeHV0sEMilDIjX0EjSNHwYtYrDPk6cGjkzDTYb6/U10c5Xhwi0g7/lMH/RPihPz5 co80VEqXWlgfgHuE7/cAiTJ61PiFD9oI494bQcIISQNDfbUUiYfn32+8nK20rn8C w7PbGoIv6zz6A0c6DJT7yXJF5sAHgX4M03Oi9edzQ077ZOboXSuUKe4VfHIpjTjZ 0sM/NbG5BFstyetVc3FZOGWGukTRb0C0GSASOm6hCyh5ctmpwlS4menc/OAx9BYO r9ZBjEa0oLFVV0pP5Tj4Gf1DDpuJ -----END CERTIFICATE-----
-
Verify the signature and save the contents of the document to a file named
document
:openssl smime -verify -in rsa2048 -inform PEM -certfile certificate -noverify | tee document
If the signature is valid, you will see a message saying
Verification successful
.
-
Connect to the VM:
ssh <VM_IP_address>
-
Get a signature from the VM metadata and save it to a file named
dsa2048
:curl \ --header Metadata-Flavor:Google 169.254.169.254/computeMetadata/v1/instance/vendor/identity/dsa > dsa2048
-
Create a
certificate
file and save a public certificate to it:-----BEGIN CERTIFICATE----- MIIERjCCA+ugAwIBAgIULIUmuptqf9Pz7nMGMHeW+BPNneYwCwYJYIZIAWUDBAMC MAAwHhcNMjMwNjA3MDY1NjI0WhcNMzMwNjA0MDY1NjI0WjAAMIIDRjCCAjkGByqG SM44BAEwggIsAoIBAQDFyteKPnUOauqiHzsLCw2Z//c1IjSqVVPpIbETQ1NUCsUI o6+at1VkxJ76K/HqvFlhC87nSGWuQMgflQXcVIEQ8c0wnQGRj4lwkkjm8WClo4xv t/FsNyv4uEcPgcz45A2YxE4+5odjicKMCz4pPW+kc9t4BiKw4I9uGySBhA1p21e+ fmR4AzDSHdHGRlvlYOfYAN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bg LFFIJGlNWgIhAO0b749SY5+6UMEOLsxgvNzKKcv58BKADfBdJAXE6fRk -----END CERTIFICATE-----
-
Verify the signature and save the contents of the document to a file named
document
:openssl smime -verify -in dsa2048 -inform PEM -certfile certificate -noverify | tee document
If the signature is valid, you will see a message saying
Verification successful
.
-
Connect to the VM:
ssh <VM_IP_address>
-
Get a base64 signature from the VM metadata and save it to a file named
signature
:curl \ --header Metadata-Flavor:Google 169.254.169.254/computeMetadata/v1/instance/vendor/identity/base64 | \ base64 -d >> signature
-
Get an identity document and save it to a file named
document
:curl \ --header Metadata-Flavor:Google 169.254.169.254/computeMetadata/v1/instance/vendor/identity/document > document
-
Create a
certificate
file and save a public certificate to it:-----BEGIN CERTIFICATE----- MIIC4TCCAcmgAwIBAgIUP0zcGO1MeRwze8VdSMEt/OdBXoIwDQYJKoZIhvcNAQEL BQAwADAeFw0yMzA2MDcwNjU4MTBaFw0zMzA2MDQwNjU4MTBaMAAwggEiMA0GCSqG SIb3DQEBAQUAA4IBDwAwggEKAoIBAQDw6TvAvrbJvY4tzIIuDnLEVfRUW4BZJD3y K8fyyxXrYDvC69RKCKk9+TQhnUOLhZNlDST4HFfSPlakOjXUduyJE5M1EmoLAstN 81aP3TejseDavxmaNijXRsa9E731T5H+zo44PgAHfQJmiD7rtcr+QOIosKUB2dwp F2acp9hLKd389BfNctziG0Oxq7hlISTDBnhzBg7eKuqWtShjVW5RqQvp3bARfUPa RWdYjmZvR+AnmozV1SGnpAnatzhnF6tNAb5XSEw49tumsX1D4A11J6mtrafO6bsP wdIPwy9W15iCszUNlFcdBaZhESc34VbyCyLMvA5T0Uj1FJHz1RFlAgMBAAGjUzBR MB0GA1UdDgQWBBQq0z6Vcmjcn8wnRTwKGSm5YGas9TAfBgNVHSMEGDAWgBQq0z6V cmjcn8wnRTwKGSm5YGas9TAPBgNVHRMBAf8EBTADAQH/MA0GCSqGSIb3DQEBCwUA A4IBAQBplippQ/Pxn7AkuwOTSwSTeJ7S+rMSb6iSL9chNHetanft0Ikr5BDsSrd6 TeHV0sEMilDIjX0EjSNHwYtYrDPk6cGjkzDTYb6/U10c5Xhwi0g7/lMH/RPihPz5 co80VEqXWlgfgHuE7/cAiTJ61PiFD9oI494bQcIISQNDfbUUiYfn32+8nK20rn8C w7PbGoIv6zz6A0c6DJT7yXJF5sAHgX4M03Oi9edzQ077ZOboXSuUKe4VfHIpjTjZ 0sM/NbG5BFstyetVc3FZOGWGukTRb0C0GSASOm6hCyh5ctmpwlS4menc/OAx9BYO r9ZBjEa0oLFVV0pP5Tj4Gf1DDpuJ -----END CERTIFICATE-----
-
Extract a public key from the certificate and save it to a file named
key
:openssl x509 -pubkey -noout -in certificate >> key
-
Verify the signature and save the contents of the document to a file named
document
:openssl dgst -sha256 -verify key -signature signature document
If the signature is valid, you will see a message saying
Verified OK
.
Map the identity document from the VM metadata to the document saved to the file:
curl http://169.254.169.254/latest/vendor/instance-identity/document | \
openssl dgst -sha256
openssl dgst -sha256 < document
If they have the same hash, the identity document saved to the file matches the document from the VM metadata.