JonasProgrammer / docker-machine-driver-hetzner

Docker machine driver for the new hetzner cloud API
https://jonasprogrammer.github.io/docker-machine-driver-hetzner/
MIT License
432 stars 53 forks source link

Adding a flag for RDNS domain #123

Open Powerhamster opened 4 months ago

Powerhamster commented 4 months ago

I want to create whitelisting in our firewall for specific RDNS entries because I don't know the PrimaryIPv4 address of the machine that will be created.

Is it possible to add a flag for providing a domain that is used for the RDNS pointer?

I am a go newbie. Would something like this work?

func (d *Driver) setupRDNS() error {
    if d.RDNSDomain == "" {
        return nil
    }
    log.Infof("configuring RDNS ...")
    opts := hcloud.PrimaryIPChangeDNSPtrOpts{
        DNSPtr: d.MachineName + "." + d.RDNSDomain,
    }
    act, _, err := d.getClient().PrimaryIP.ChangeDNSPtr(context.Background(), opts)

    if err != nil {
        return fmt.Errorf("could not change DNS pointer: %w", err)
    }

    return d.waitForAction(act)
}
JonasProgrammer commented 3 months ago

Hi,

sorry for being gone for so long. Juding from just glaring a the code, I don't see why this should not work. I'll have a look.

JonasProgrammer commented 3 months ago

After a little bit of trying, I think, we need a bit more discussion here.

First of all, I dislike the idea of just giving a domain suffix and having the machine name hardcoded as the actual hostname. While this surely makes sense a lot of times, I feel like the user specifying it once more is much less of a hassle than providing a somewhat usable flag interface for the non-default case. The much bigger problem I see is the fact you have to specify the IP you actually want to assign the PTR for. It is easy for the IPv4 case, but for IPv6 you can actually assign multiple RDNS ptrs to the same prefix. So the question is, should the user specify suffix-name pairs for the IPv6 case or actual IPs. If you do know the IP beforehand though, you already have an existing one configured and could just add the RDNS there.

In 2024, providing an IPv4-only solution is a step backward. But right now I cannot think of a nice interface that is actually intuitive and does not feel like two separate things.