apport tries to hit ec2 metadata service if cloud-init is installed

Bug #1855616 reported by Michael Hudson-Doyle
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
apport (Ubuntu)
New
Undecided
Unassigned

Bug Description

This probably made sense in 2012 but in focal all servers are going to have cloud-init installed. I *think* apport should consult "< /run/cloud-init/instance-data.json jq .v1.platform" but someone from server should probably check that.

Revision history for this message
Michael Hudson-Doyle (mwhudson) wrote :

Chad pointed out in IRC that cloud-init query platform is the supported way to get that information, but also that cloud-init query in general can probably be the source for all this information, on clouds other than EC2 as well.

Revision history for this message
Chad Smith (chad.smith) wrote :

I'll have to double check on UEC images and whether cloud-init is included in those image types, but we should be able to depend on the following function that that is the case:

def add_cloud_info(report):
    # EC2 and Ubuntu Enterprise Cloud instances
    try:
     instance_data = json.loads(
        subprocess.check_output(['cloud-init', 'query', '--all']).decode())
    except subprocess.CalledProcessError as e:
        return
    report = {}
    if instance_data.get('platform') == 'ec2':
        ami = instance_data.get('ds', {}).get('meta_data', {}).get('ami_id')
        if ami and ami.startswith('ami'):
            report['Ec2AMI'] = ami
            fields = {
                'Ec2AMIManifest': 'ds.meta_data.ami_manifest_path',
                'Ec2Kernel': 'ds.dynamic.instance_identity.document.kernelId',
                'Ec2Ramdisk':
                    'ds.dynamic.instance_identity.document.ramdiskId',
                'Ec2InstanceType': 'ds.meta_data.instance_type',
                'Ec2AvailabilityZone': 'availability_zone'}
            for key, path in fields.items():
                value = instance_data
                for path_part in path.split('.'):
                    value = value.get(path_part)
                    if not value:
                        break
                report[key] = value if value else 'unavailable'
        else:
            add_tag(report, 'uec-images')

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.