wvandeun/nornir_netbox

Options for querying netbox behind a reverse proxy / load-balancer

WillIrvine opened this issue · 2 comments

Hi,

Firstly, thanks for this inventory plugin.

I have an issue where I use Netbox through a reverse proxy that has a different FQDN to the local netbox instance.
When paginating through the devices the url returned for the netbox next page is the local one, rather than the one originally queried, which means it cannot resolve the next page.

I have a couple of patch ideas i'm planning on putting together, and want to open a discussion if you would like them as a pull request.

To fix the issue I see two options:

  1. Have the option "nb_usecount" to itterate through the list using count rather than next_page. i.e itterate using offset until the total number of devices reaches count - a common alternative to the next page iteration

  2. when receiving the next page extract the FQDN from the result and replace with the one in the config file. I can't see this causing issues, but there might be consequences i'm not thinking about

I believe i wont be the only one with this issue so would like to contribute either of these options to your plugin
Let me know your thoughts, thanks.

Not sure if I understand the issue and if the plugin code would be the correct place to resolve this.
Could you clarify further what your setup and configuration looks like?

I personally have no issue with such a setup at all and the correct Netbox address is returned.

Based on what I here. I think you may have to set the host header to the fqdn that points to the "proxy" when proxying to the backend. You will also have to configure that fqdn as the ALLOWED_HOSTS in the netbox configuration.

For example with nginx:

location / {
    proxy_pass http://local-netbox.domain.com;
    proxy_set_header Host front-netbox.domain.com;
}

Where front-netbox.domain.com is the fqdn that points towards the reverse proxy.
The Netbox config should then have both fqdns in the allowed_hosts configuration.

ALLOWED_HOSTS=[ 'front-netbox.domain.com', 'local-netbox.domain.com' ]

Well I'm a dummy, that works as expected. Thanks for your help. will remove the PR