summaryrefslogtreecommitdiff
path: root/doc/rtd/topics/datasources/azure.rst
blob: f73c3694ce35777c7d353990b029f9c8965027fe (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
.. _datasource_azure:

Azure
=====

This datasource finds metadata and user-data from the Azure cloud platform.

Azure Platform
--------------
The azure cloud-platform provides initial data to an instance via an attached
CD formatted in UDF.  That CD contains a 'ovf-env.xml' file that provides some
information.  Additional information is obtained via interaction with the
"endpoint".

To find the endpoint, we now leverage the dhcp client's ability to log its
known values on exit.  The endpoint server is special DHCP option 245.
Depending on your networking stack, this can be done
by calling a script in /etc/dhcp/dhclient-exit-hooks or a file in
/etc/NetworkManager/dispatcher.d.  Both of these call a sub-command
'dhclient_hook' of cloud-init itself. This sub-command will write the client
information in json format to /run/cloud-init/dhclient.hook/<interface>.json.

In order for cloud-init to leverage this method to find the endpoint, the
cloud.cfg file must contain:

datasource:
  Azure:
    set_hostname: False
    agent_command: __builtin__

If those files are not available, the fallback is to check the leases file
for the endpoint server (again option 245).

You can define the path to the lease file with the 'dhclient_lease_file'
configuration.  The default value is /var/lib/dhcp/dhclient.eth0.leases.

    dhclient_lease_file: /var/lib/dhcp/dhclient.eth0.leases

walinuxagent
------------
In order to operate correctly, cloud-init needs walinuxagent to provide much
of the interaction with azure.  In addition to "provisioning" code, walinux
does the following on the agent is a long running daemon that handles the
following things:
- generate a x509 certificate and send that to the endpoint

waagent.conf config
^^^^^^^^^^^^^^^^^^^
in order to use waagent.conf with cloud-init, the following settings are recommended.  Other values can be changed or set to the defaults.

  ::

   # disabling provisioning turns off all 'Provisioning.*' function
   Provisioning.Enabled=n
   # this is currently not handled by cloud-init, so let walinuxagent do it.
   ResourceDisk.Format=y
   ResourceDisk.MountPoint=/mnt


Configuration
-------------
The following configuration can be set for the datasource in system
configuration (in `/etc/cloud/cloud.cfg` or `/etc/cloud/cloud.cfg.d/`).

The settings that may be configured are:

 * **agent_command**: Either __builtin__ (default) or a command to run to getcw
   metadata. If __builtin__, get metadata from walinuxagent. Otherwise run the
   provided command to obtain metadata.
 * **apply_network_config**: Boolean set to True to use network configuration
   described by Azure's IMDS endpoint instead of fallback network config of
   dhcp on eth0. Default is True. For Ubuntu 16.04 or earlier, default is False.
 * **data_dir**: Path used to read metadata files and write crawled data.
 * **dhclient_lease_file**: The fallback lease file to source when looking for
   custom DHCP option 245 from Azure fabric.
 * **disk_aliases**: A dictionary defining which device paths should be
   interpreted as ephemeral images. See cc_disk_setup module for more info.
 * **hostname_bounce**: A dictionary Azure hostname bounce behavior to react to
   metadata changes.
 * **hostname_bounce**: A dictionary Azure hostname bounce behavior to react to
   metadata changes. Azure will throttle ifup/down in some cases after metadata
   has been updated to inform dhcp server about updated hostnames.
 * **set_hostname**: Boolean set to True when we want Azure to set the hostname
   based on metadata.

An example configuration with the default values is provided below:

.. sourcecode:: yaml

  datasource:
   Azure:
    agent_command: __builtin__
    apply_network_config: true
    data_dir: /var/lib/waagent
    dhclient_lease_file: /var/lib/dhcp/dhclient.eth0.leases
    disk_aliases:
        ephemeral0: /dev/disk/cloud/azure_resource
    hostname_bounce:
        interface: eth0
        command: builtin
        policy: true
        hostname_command: hostname
    set_hostname: true


Userdata
--------
Userdata is provided to cloud-init inside the ovf-env.xml file. Cloud-init
expects that user-data will be provided as base64 encoded value inside the
text child of a element named ``UserData`` or ``CustomData`` which is a direct
child of the ``LinuxProvisioningConfigurationSet`` (a sibling to ``UserName``)
If both ``UserData`` and ``CustomData`` are provided behavior is undefined on
which will be selected.

In the example below, user-data provided is 'this is my userdata', and the
datasource config provided is ``{"agent_command": ["start", "walinuxagent"]}``.
That agent command will take affect as if it were specified in system config.

Example:

.. sourcecode:: xml

 <wa:ProvisioningSection>
  <wa:Version>1.0</wa:Version>
  <LinuxProvisioningConfigurationSet
     xmlns="http://schemas.microsoft.com/windowsazure"
     xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
   <ConfigurationSetType>LinuxProvisioningConfiguration</ConfigurationSetType>
   <HostName>myHost</HostName>
   <UserName>myuser</UserName>
   <UserPassword/>
   <CustomData>dGhpcyBpcyBteSB1c2VyZGF0YQ===</CustomData>
   <dscfg>eyJhZ2VudF9jb21tYW5kIjogWyJzdGFydCIsICJ3YWxpbnV4YWdlbnQiXX0=</dscfg>
   <DisableSshPasswordAuthentication>true</DisableSshPasswordAuthentication>
   <SSH>
    <PublicKeys>
     <PublicKey>
      <Fingerprint>6BE7A7C3C8A8F4B123CCA5D0C2F1BE4CA7B63ED7</Fingerprint>
      <Path>this-value-unused</Path>
     </PublicKey>
    </PublicKeys>
   </SSH>
   </LinuxProvisioningConfigurationSet>
 </wa:ProvisioningSection>

Configuration
-------------
Configuration for the datasource can be read from the system config's or set
via the `dscfg` entry in the `LinuxProvisioningConfigurationSet`.  Content in
dscfg node is expected to be base64 encoded yaml content, and it will be
merged into the 'datasource: Azure' entry.

The '``hostname_bounce: command``' entry can be either the literal string
'builtin' or a command to execute.  The command will be invoked after the
hostname is set, and will have the 'interface' in its environment.  If
``set_hostname`` is not true, then ``hostname_bounce`` will be ignored.

An example might be:
  command:  ["sh", "-c", "killall dhclient; dhclient $interface"]

.. code:: yaml

  datasource:
   agent_command
   Azure:
    agent_command: [service, walinuxagent, start]
    set_hostname: True
    hostname_bounce:
     # the name of the interface to bounce
     interface: eth0
     # policy can be 'on', 'off' or 'force'
     policy: on
     # the method 'bounce' command.
     command: "builtin"
     hostname_command: "hostname"

hostname
--------
When the user launches an instance, they provide a hostname for that instance.
The hostname is provided to the instance in the ovf-env.xml file as
``HostName``.

Whatever value the instance provides in its dhcp request will resolve in the
domain returned in the 'search' request.

The interesting issue is that a generic image will already have a hostname
configured.  The ubuntu cloud images have 'ubuntu' as the hostname of the
system, and the initial dhcp request on eth0 is not guaranteed to occur after
the datasource code has been run.  So, on first boot, that initial value will
be sent in the dhcp request and *that* value will resolve.

In order to make the ``HostName`` provided in the ovf-env.xml resolve, a
dhcp request must be made with the new value.  Walinuxagent (in its current
version) handles this by polling the state of hostname and bouncing ('``ifdown
eth0; ifup eth0``' the network interface if it sees that a change has been
made.

cloud-init handles this by setting the hostname in the DataSource's 'get_data'
method via '``hostname $HostName``', and then bouncing the interface.  This
behavior can be configured or disabled in the datasource config.  See
'Configuration' above.

.. vi: textwidth=78