gravity icon indicating copy to clipboard operation
gravity copied to clipboard

DHCP scope option 6 (`name_server`) breaks when using `value64` attribute

Open tigattack opened this issue 2 years ago • 5 comments

When applying the name_server option as shown in the example below, it appears to break the data served to DHCP clients.

- tagName: name_server
  value64:
    - "MTAuNTEuMTAuMjA="
    - "MTAuNTIuMTAuMjA="

For example, dhclient successfully retrieves a lease, but warns: domain-name-servers 2 extra bytes at end of array

The result is that dhclient appears to parse this as 49.48.46.53,49.46.49.48,46.50.48.49,48.46.53.50,46.49.48.46 rather than the configured base64 representation of [10.51.10.20,10.52.10.20].

The following configuration works fine, but means I can only pass a single DNS server to the client (unless I'm unaware of some syntax which makes this possible?).

- tagName: name_server
  value: 10.51.10.20

Note: the issue appears to be present regardless of the number of servers specified (tested with 1-3). The only difference is the warning from dhclient notes a differing number of extra bytes at the end of the array.

tigattack avatar Nov 13 '23 11:11 tigattack

when using value64 you're responsible for encoding the values correctly yourself

BeryJu avatar Nov 13 '23 13:11 BeryJu

Maybe I'm missing something then, but MTAuNTEuMTAuMjA= and MTAuNTIuMTAuMjA= (from the example config at the top) decode to 10.51.10.20 and 10.52.10.20 as expected.

tigattack avatar Nov 13 '23 14:11 tigattack

@tigattack The issue is you're converting UTF-8 (Text) to Base64. you need to convert decimal (Number) to Base64. this took me a while to figure out. image

Red Markings are there for aid

july12123 avatar Dec 22 '23 14:12 july12123

Thank you @july12123, good spot!

tigattack avatar Jan 02 '24 13:01 tigattack

Probably a good shout to document this, @BeryJu. I'd happily do it myself, but I'm not sure which options this may be necessary for, so I'll leave it to you to ensure accuracy.

I believe the DHCP options page and docs for the Terraform provider's gravity_dhcp_scope resource will need updating.

tigattack avatar Jan 02 '24 13:01 tigattack