Expose EC2 platform type in machine readable format from ds-identify

Bug #1724626 reported by Robert C Jennings
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
cloud-init (Ubuntu)
Fix Released
Medium
Unassigned

Bug Description

I would like to see the EC2 platform information in /run/cloud-init/cloud.cfg (or someplace else sensible) so that we can capture AWS-specific data for bugs filed by apport (bug #1724623) without reproducing dscheck_Ec2() from ds-identify.

Also, if you have suggestions as to what cloud-init info should be appended to bug descriptions or attachments as part of bug #1724623, please comment there as the insight would be very helpful.

Robert C Jennings (rcj)
description: updated
Scott Moser (smoser)
Changed in cloud-init (Ubuntu):
status: New → Confirmed
importance: Undecided → Medium
Revision history for this message
Chad Smith (chad.smith) wrote :
Download full text (4.7 KiB)

Minimally this is resolved as of cloud-init version 21.4 which surfaced a /run/cloud-init/cloud-id file which represents the unique cloud datasource type cloud-init detects:

cat /run/cloud-init/cloud-id will have the following values:
aws
azure
gce
openstack
lxd
nocloud

Note as well that cloud-init creates a symlink pointing to this file of the format:
   /run/cloud-init/cloud-id-<cloud_name>

This allows scripts to easily check presence of a cloud-specific file /run/cloud-init/cloud-id-aws to indicate what platform cloud-init detected.

Note that this value will be incorrect if someone installs NoCloud datasource seed files on an Ec2 vm in /var/lib/cloud/seed/nocloud-net/(user-data|meta-data) because cloud-init will detect the NoCloud datasource before Ec2 datasource in that case.

Additional sources of flat files that can provide more context for identity of the system/platform

would be /run/cloud-init/instance-data.json which is structured configuration attributes that cloud-init reads from the datasource it detects.

instance-data.json provide versioning of generalized config variables under the v1 key of instance-data.json

Here are some examples on various clouds (again note that any cloud could have a NoCloud seed file placed in the environment that would prevent cloud-init from detecting the underlying cloud platform config on those systems):

https://hackmd.io/aAJFerDRRNaoL0Q_vDRYBg

Keep in mind as well there are additional pieces of data that are cloud-specific which give you more details about the offering, instance size etc under a top-level key in instance-data.json "ds".

On EC2 you get something like the following under 'ds'

{
 "_doc": "EXPERIMENTAL: The structure and format of content scoped under the 'ds' key may change in subsequent releases of cloud-init.",
 "_metadata_api_version": "2021-03-23",
 "dynamic": {
  "instance-identity": {
   "document": {
    "accountId": "329910648999",
    "architecture": "x86_64",
    "availabilityZone": "us-east-2b",
    "billingProducts": null,
    "devpayProductCodes": null,
    "imageId": "ami-0283a57753b18025b",
    "instanceId": "i-0ecd5e14298b43fbf",
    "instanceType": "t2.micro",
    "kernelId": null,
    "marketplaceProductCodes": null,
    "pendingTime": "2022-12-16T21:13:36Z",
    "privateIp": "172.31.24.213",
    "ramdiskId": null,
    "region": "us-east-2",
    "version": "2017-09-30"
   },
   "pkcs7": [
    "MIAGCSqGSIb3DQEHAqCAMI..."
   ],
   "rsa2048": [
    "MIAGCS..."
   ],
   "signature": [
    "Qk99HHJxS..."
   ]
  }
 },
 "meta-data": {
  "ami-id": "ami-0283a57753b18025b",
  "ami-launch-index": "0",
  "ami-manifest-path": "(unknown)",
  "block-device-mapping": {
   "ami": "/dev/sda1",
   "ephemeral0": "sdb",
   "ephemeral1": "sdc",
   "root": "/dev/sda1"
  },
  "events": {
   "maintenance": {
    "history": "[]",
    "scheduled": "[]"
   }
  },
  "hostname": "ip-172-31-24-213.us-east-2.compute.internal",
  "identity-credentials": {
   "ec2": {
    "info": {
     "AccountId": "32991064...",
     "Code": "Success",
     "LastUpdated": "2022-12-16T21:13:57Z"
    }
   }
  },
  "instance-action": "none",
  "instance-id": "i-0ecd5e14298b43fbf",
  "instance-li...

Read more...

Changed in cloud-init (Ubuntu):
status: Confirmed → Fix Released
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.