2

I have a question regarding accessing custom data from a Azure Linux VM after boot up. I am currently using the Azure GO SDK to programmatically create VMs which are based on CentOS Linux 7.5. For each VM, I am attaching a unique set of environment variables so that the boot up service scripts can access the environment. The custom data is only a set of environment variables, no actual scripts.

In the OS profile, I fill in the base64 encoded string as follows:

OsProfile: compute.OSProfile{
 ComputerName:  to.StringPtr(p.InstanceName),
 AdminUsername: to.StringPtr(p.UserName),
 LinuxConfiguration: compute.LinuxConfiguration{
  SSH: compute.SSHConfiguration{
   PublicKeys: []compute.SSHPublicKey{
    {
     Path: to.StringPtr(
      fmt.Sprintf("/home/%s/.ssh/authorized_keys",
       p.UserName)),
     KeyData: to.StringPtr(p.SshPublicKey),
    },
   },
  },
 },
 CustomData: to.StringPtr(base64.StdEncoding.EncodeToString([]byte(p.UserData))),
},

Its not clear to me, how to access the custom data from inside the VM.

In AWS case, we use the instance user data and access the data from the EC2 instance as follows:

https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.html

http://169.254.169.254/latest/user-data

Md Farid Uddin Kiron
  • 16,817
  • 3
  • 17
  • 43

3 Answers3

3

Azure Instance Metadata Service now provides the ability for the VM to have access to its custom data. The binary data must be less than 64KB and is provided to the VM in base64 encoded form. For details on how to create a VM with custom data, see Deploy a Virtual Machine with CustomData.

Retrieving custom data in Virtual Machine Instance Metadata Service provides custom data to the VM in base64 encoded form. The following example decodes the base64 encoded string.

curl -H "Metadata:true" "http://169.254.169.254/metadata/instance/compute/customData?api-version=2019-02-01&&format=text" | base64 --decode

Reference Doc: https://learn.microsoft.com/en-us/azure/virtual-machines/windows/instance-metadata-service#custom-data

  • It shows as disabled for now: "customData This feature is currently disabled. We will update this documentation when it becomes available 2019-02-01" – Dmitry Shmakov Jul 09 '20 at 01:07
  • 1
    Until the customData metadata API is enabled, this workaround worked for me on Ubunto 18.04: `sudo cat /var/lib/waagent/ovf-env.xml | grep 'CustomData>' | sed -r 's/.*CustomData>([^<]+).*/\1/' | base64 --decode` – Alex Pop Oct 22 '20 at 09:34
0

Ok found the answer. Not very well documented.

https://azure.microsoft.com/en-us/blog/custom-data-and-cloud-init-on-windows-azure/

/var/lib/waagent/CustomData

  • 1
    `/var/lib/waagent/ovf-env.xml` contains the custom data encoded in base64; I couldn't find any files on an Ubuntu 18.04 VM with `find /var/log/ -iname "*custom*"` – jlucktay Aug 01 '19 at 07:52
-1

The Azure Instance Metadata Service provides information about running virtual machine instances that can be used to manage and configure your virtual machines. This includes information such as SKU, network configuration, and upcoming maintenance events. For more information on what type of information is available, see metadata categories.

Azure's Instance Metadata Service is a REST Endpoint accessible to IaaS VMs created via the Azure Resource Manager. The endpoint is available at a well-known non-routable IP address (169.254.169.254) that can be accessed only from within the VM.

Ken W - Zero Networks
  • 3,533
  • 1
  • 13
  • 18
  • Hi Ken, my question was specifically about accessing the Custom Data, and from the documentation I dont see the "Azure Instance Metadata" returning the "custom data" set during VM creation. – Praveen Valtix Oct 23 '18 at 02:28