330 Commits

Author SHA1 Message Date
Robert Dower 537f727dfb archive repository 2025-08-07 14:07:58 -07:00
Brett T. Warden c4b7f9161a v48 v48 2023-01-26 16:14:48 -08:00
Brett T. Warden 914ef1935a Merge pull request #60 from bwarden/fix-hostname-no-newline
Ensure newlines are added after each section
2023-01-26 16:13:02 -08:00
Brett T. Warden 4969696428 Make write_lines add a newline when necessary 2023-01-26 15:58:45 -08:00
Brett T. Warden 73cf8658da Add a newline after hostname entry
Always add a newline after printing the hostname: entry, just in case
userdata API call returns *just* the hostname.
Update the test data to just such a bare hostname.

Fixes #59
2023-01-26 14:33:38 -08:00
Brett T. Warden 5cb6a23902 v47 v47 2022-11-04 11:32:17 -07:00
Brett T. Warden befb158f36 Merge pull request #58 from bwarden/add-hostname-support
Add hostname support
Fixes #57
2022-11-04 11:30:32 -07:00
Brett T. Warden f9541b63ad Compare fetch test output with diff instead of cmp
...so we can see more clearly in the test logs what's different.
2022-11-04 10:40:55 -07:00
Brett T. Warden bd96e691a4 Fetch hostname and write to *-user-data file
Fixes https://github.com/clearlinux/micro-config-drive/issues/57
2022-11-04 10:26:16 -07:00
Brett T. Warden 1ec2e49399 Add hostname path field to templates 2022-11-04 10:24:55 -07:00
Brett T. Warden 7ab85beeb0 Add tests for hostname fetch
Also tell git to ignore intermediate test data
2022-11-04 10:24:22 -07:00
Brett T. Warden 2de5b52898 Merge pull request #53 from TBK/duplicate-lines
Remove duplicate lines
2022-11-04 09:49:24 -07:00
Brett T. Warden 8ce5728b08 v46 v46 2022-10-21 11:12:36 -07:00
Brett T. Warden 69103d62ec Wait up to 100 seconds for hostname lookup
In case networking takes as long as a minute to come up, give hostname
lookup up to 100 seconds to complete. Give initial HTTP request up to 120
seconds _from when we started_ to succeed, so even if we spent all our
time waiting on DNS, we still give 20 more seconds for the HTTP server.
2022-10-21 11:02:18 -07:00
Brett T. Warden 1ac420e18b Add a fetch test
To improve package test capabilities, introduce a test target that will
attempt to fetch SSH keys and user data from a locally-spawned test
server. Add other bits in ucd-data-fetch.c to support testing.

Add fetch_test, which spawns an HTTP server to serve some sample
user-data and cloud-config files, and verify that ucd-data-fetch can
retrieve them.
2022-10-21 11:02:18 -07:00
Brett T. Warden 636094a34f Support setting a TCP port for HTTP fetch 2022-10-21 11:02:18 -07:00
Brett T. Warden 5fd46807fb Fetch the user-configured user data for equinix
Additional URI https://metadata.platformequinix.com/userdata

Also add missing users key in generated equinix conf
Our output for the equinix cloud config file omitted the "users:" key
prior to defining the user.
2022-10-21 11:02:18 -07:00
Brett T. Warden 430dd74d73 Make sure fds are closed in error paths
Don't close the socket until we're done reading.
Make sure the socket fd/stream gets closed in all the error paths
preceding our close/fclose.
Also ensure the output file is closed properly in error cases.
2022-10-21 11:02:18 -07:00
Auke Kok b7b657a824 Add equinix provisioning template
To provision on equinix we can grab the `keys` file from their
service. The address I entered in the template is tentative - it
needs to be checked that metadata.platformequinix.com resolves to that
address in their internal network as well that it's on a static IP
address and not some RR load balancer service - ideally.
2022-10-21 11:02:18 -07:00
Brett T. Warden b0596eab96 Allow use of hostname instead of IP address
Some servers require the host name to be sent in the user-data API request.
We can allow a host name instead of IP address in the config struct by
doing a lookup if it's not an IP address already.
2022-10-21 11:02:18 -07:00
Brett T. Warden d0f1601944 Adopt an instance service for providers
Instead of creating a unique service file for each provider, just use a
single instance service. We'll change the symlinks in packaging.
2022-10-21 11:02:18 -07:00
Auke Kok abc97b9f85 Fix data fetcher not being able to provision multiple SSH keys
The data fetcher tool operated assuming the key file presented on the
server contains only 1 key. However, several cloud providers use this
file to present multiple keys to the client systems at provisioning time
and this should be functional.

Without this change, only the first key will be properly inserted into
yaml, and all secondary keys will result in a yaml failure or be ignored
entirely. It would look something like this:

```
ssh_authorized_keys:
   - ssh-rsa <correct key 1>
ssh-rsa <this key 2 will be ignored>
ssh-rsa <this key 3 will be ignored>
```

The template is modified to allow line-by-line reading of the key file
from the server, and each line written will be prefixed with the yaml
"  - " entry prefix in the output file.

When writing the SSH keys to our generated cloud-config file, make sure
to follow with an extra line feed before we concatenate the user-data
contents. Otherwise, we could end up including the first line of the
user-data response in the authorized_keys file, e.g.
ssh-rsa <...key...> user@host#cloud-config
                             ^^^^^^^^^^^^^

Instead, worst case, /var/lib/cloud/<provider>-user-data might just have
an extra (ignored) blank line.
2022-10-21 11:02:18 -07:00
Auke Kok 4cb1db2fe9 CURL isn't used in this project - cleanup. 2022-10-21 11:02:18 -07:00
TBK 6744d6be59 Remove duplicate lines 2021-01-03 21:52:01 +01:00
Auke Kok 58e5a63551 v45 v45 2019-12-20 12:43:12 -08:00
Auke Kok 533c9a0065 Attempt harder to obtain config-drive.
There are some cases where a config-drive is on the system, but
not initially detected early at boot. One such case is when the
cdrom subsystem isn't builtin to the kernel but enabled as a module.

We can try and catch this issue. It will slow down boot a bit, so
this only waits 1 second total for now. But modprobing `sr_mod` which
depends on `cdrom` is a good start here, and covers obtaining the
`meda_data.json` file in case a VM is booted with the -native or
other non-kvm kernels.
2019-12-18 12:20:06 -08:00
Auke Kok ca976ef947 v44 v44 2019-12-03 11:30:07 -08:00
Auke Kok 919dcdd6b7 Remove forced dependency ordering on systemd-networkd.
These lines forced systemd-networkd to wait until `ucd` had
completed.

In turn, `ucd` requires the network to be active in order
to install packages. It waits for the network to become
active, even.

Surely, this is untenable. Ucd will have to accept any
network state and may not prevent it from starting as
early as possible, which would be counter to any fast
boot initiative.
2019-11-13 12:18:32 -08:00
Auke Kok 463cb9f1a2 check dependency for CI. 2019-11-06 11:26:31 -08:00
Auke Kok fe6b56d58c Dix dependency names. 2019-11-06 11:14:59 -08:00
Auke Kok 44a2dc1885 Fix suffix. 2019-11-06 11:12:22 -08:00
Auke Kok 714a13e43b Use sudo in actions. 2019-11-06 11:11:11 -08:00
Auke Kok feff4b8798 Install deps (guess). 2019-11-06 11:08:10 -08:00
Auke Kok a229e6c247 Clean up yml file. 2019-11-06 10:57:25 -08:00
ahkok 79f4836877 Add github actions integration. 2019-11-06 10:56:18 -08:00
Auke Kok 13e2a7b290 v43 v43 2019-11-06 09:03:49 -08:00
Auke Kok 65b6eddb4a Fix wait_for_network, tested now too. 2019-11-06 09:03:24 -08:00
Auke Kok 0407325314 v42 v42 2019-10-31 14:39:37 -07:00
Auke Kok 5aa46b9b7d Allow packages etc. to also enter a valid wait for network. 2019-10-31 14:39:13 -07:00
Auke Kok e95430c21a Consolidate 2 vars, ensure we sleep a few times here. 2019-10-31 14:35:09 -07:00
Auke Kok 68e27c67ef Header - multiple inclusion guard. 2019-10-31 14:21:44 -07:00
Auke Kok 85747cb4c2 v41 v41 2019-10-29 11:33:34 -07:00
Auke Kok 9644cbdc5d Add wait_for_network: <boolean>.
This option allows users to suspend execution of the cloud-init provisioning
until a valid network is detected.

This detection is currently done through requesting a DNS lookup for one
of the Clear Linux NTP service IP addresses (this is a RR record, we
don't actually look at the result).

This lookup is not infinite. After 5 minutes, the wait exits no matter
what even if there is no network detected.

The option can be provided manually. `packages` and `package_upgrade`
options *imply* this option, but one can explicitly disable the wait
by providing it early in the cloud-config file with a value of `false`.

The wait routing is active - it will retry relatively quickly to detect
an active connection. Any failure will result in another retry. In
a fully private network without public DNS, this will not work.

The DNS hostname used for testing can be manipulated through the
`-with-dnstestaddr=<hostname>` configure flag. You shouldn't put an
IP address in here, since that fully disables any network testing.
2019-10-29 11:33:17 -07:00
Auke Kok 4364c943e1 v40 v40 2019-10-15 11:31:18 -07:00
jwang 4706d35c2c Add aliyun cloud support
Enable ucd to work in aliyun cloud by add a config templete
for aliyun

Signed-off-by: jwang <jing.j.wang@intel.com>
2019-10-15 11:27:02 -07:00
Auke Kok 2c8d9c0d62 Add security concern section to the README.md. 2019-10-14 14:30:18 -07:00
Auke Kok 112e0a4e39 v39 2019-09-30 10:58:24 -07:00
Auke Kok 542b611ae1 user-data: allow missing user data.
When I deduplicated this code I mistakenly used parse_headers() in
the same way twice. This was incorrect.

We definitely need to error out if a 404 or something else happens
for the SSH keys, since then we've lost entirely.

But a missing `user-data` is mostly harmless and optional, so, in
case a 404 happens for the second `GET` request, we shouldn't error
out, because this makes the instance unusable. Instead, we can
carry on as normal.
2019-09-30 10:58:24 -07:00
Auke Kok a240a29d21 Fix typo in yaml tag for ssh_authorized_keys. 2019-09-30 10:58:24 -07:00
jwang 7ed37b2b41 fix typo in tencent cloud-config template 2019-09-24 20:55:25 -07:00