canonical / cloud-init

Official upstream for the cloud-init: cloud instance initialization
https://cloud-init.io/
Other
3.01k stars 887 forks source link

fix(smartos): Add `addrconf` IPv6 support #5831

Closed blackhelicoptersdotnet closed 3 weeks ago

blackhelicoptersdotnet commented 1 month ago

Proposed Commit Message

fix(smartos): Add `addrconf` IPv6 support

SmartOS uses `addrconf` as a special value to indicate that an IPv6
address should be obtained via DHCPv6 or SLAAC. cloud-init does not
know how to handle this.

Added logic to DataSourceSmartOS.py to properly recognise and handle
this value.

Additional Context

The vendor's documentation describes how this is supposed to work.

https://docs.smartos.org/setting-up-ipv6-in-a-zone/

This works fine for native and lx-branded zones (where network configuration is handled by other means), but not for KVM or Bhyve zones in which cloud-init is expected to perform the appropriate configuration.

Before this change, addrconf would be passed through to cloud-init as a static address, causing errors.

# cloud-init status -l
status: error
extended_status: error
boot_status_code: enabled-by-generator
last_update: Mon, 21 Oct 2024 00:52:15 +0000
detail:
Cloud-init enabled by systemd cloud-init-generator
errors:
    - Address addrconf is not a valid ip address
    - Address addrconf is not a valid ip address
recoverable_errors:
ERROR:
    - Address addrconf is not a valid ip network
    - Address addrconf is not a valid ip network
WARNING:
    - failed stage init
    - failed stage init-local

Test Steps

  1. On a SmartOS host, follow the vendor's documentation to create a bhyve or kvm zone with the addrconf keyword in the NIC configuration.

  2. On the guest, check to see that an IPv6 address was autoconfigured.

# ip addr
[...]
2: net0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc fq_codel state UP group default qlen 1000
    link/ether e2:7f:c1:50:eb:99 brd ff:ff:ff:ff:ff:ff
    altname enp0s6
    inet 10.64.1.130/26 brd 10.64.1.191 scope global noprefixroute net0
       valid_lft forever preferred_lft forever
    inet6 2001:0db8::a8ac:2e5d:33d9:fdcd/128 scope global noprefixroute
       valid_lft forever preferred_lft forever
    inet6 2001:0db8::e07f:c1ff:fe50:eb99/64 scope global dynamic noprefixroute
       valid_lft 2591950sec preferred_lft 604750sec
    inet6 fe80::e07f:c1ff:fe50:eb99/64 scope link noprefixroute
       valid_lft forever preferred_lft forever

Merge type

TheRealFalcon commented 1 month ago

@blackhelicoptersdotnet , thanks for the PR! At first look, the changes look good, though there will need to be fixes for CI. To run the same checks as CI, you can run tox (with no arguments) locally.

Are you associated with the smartos project, or just providing a fix for your use case? Since I don't have the means to verify the fix myself, can add the tarball from cloud-init collect-logs from a run of this branch working as expected?

blackhelicoptersdotnet commented 1 month ago

@TheRealFalcon Thanks for the feedback! I've pushed a fix for the check that failed CI.

Not affiliated with SmartOS, just wanted to push a fix to resolve my issue and assist whoever comes after me :)

The log tarball contains some environment details that I'd prefer not to have in the public domain. Happy to provide one privately if you like, or alternatively, if there specific files that you need I can scrub those and upload them?

TheRealFalcon commented 1 month ago

@blackhelicoptersdotnet , sure. Could you provide the var/log/cloud-init.log and var/lib/cloud/instance/network-config.json?

bahamat commented 1 month ago

@TheRealFalcon Hi, I’m one of the maintainers for SmartOS (incidentally, I am also the person producing guest images that use cloud-init), so I can speak to that side of things. The keyword addrconf is how we indicate dynamic IPv6 addressing, whether DHCPv6 or SLAAC.

blackhelicoptersdotnet commented 1 month ago

@TheRealFalcon Here's the logs

cloud-init.log network-config.json