Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

render_config tries wrong url when Netbox is behind reverse proxy #590

Open
dsecik opened this issue Oct 24, 2023 · 1 comment
Open

render_config tries wrong url when Netbox is behind reverse proxy #590

dsecik opened this issue Oct 24, 2023 · 1 comment
Labels
pynetbox type: bug A confirmed report of unexpected behavior in the application

Comments

@dsecik
Copy link

dsecik commented Oct 24, 2023

pynetbox version

v7.1.0

NetBox version

v3.6.3

Python version

3.9

Steps to Reproduce

#!/usr/bin/python3

import pynetbox

def main():
  nb = pynetbox.api(url="netbox_url", token="my_netbox_token")
  device = nb.dcim.devices.get(680)
  print(device.render_config.create()["content"])

if __name__ == "__main__":
    main()

Expected Behavior

It should return rendered context for device id 680.

Observed Behavior

Works fine when pointed directly to the netbox URL.
How ever when used with nginx reverse proxy it fails with:

Traceback (most recent call last):
  File "/home/daniel.secik/./test2.py", line 11, in <module>
    main()
  File "/home/daniel.secik/./test2.py", line 8, in main
    print(device.render_config.create()["content"])
  File "/usr/lib/python3.9/site-packages/pynetbox/core/endpoint.py", line 706, in create
    req = Request(**self.request_kwargs).post(data)
  File "/usr/lib/python3.9/site-packages/pynetbox/core/query.py", line 368, in post
    return self._make_call(verb="post", data=data)
  File "/usr/lib/python3.9/site-packages/pynetbox/core/query.py", line 258, in _make_call
    raise RequestError(req)
pynetbox.core.query.RequestError: The requested url: <proxy_url>:8080/netbox/api/680//680/render-config/ could not be found.

We only saw this with render_config, other api calls work fine with proxy.

Proxy config:
    location ~ "^/netbox/api/" {
        limit_except GET POST {
            deny all;
        }

        rewrite netbox/(.*)$ /$1 break;
        proxy_set_header Accept "application/json";
        proxy_set_header Content-Type "application/json";
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;
        proxy_pass <netbox_url>;
    }
@dsecik dsecik added the type: bug A confirmed report of unexpected behavior in the application label Oct 24, 2023
@markkuleinio
Copy link
Contributor

Works for me, but I have BASE_PATH set correctly in NetBox (= no rewrite on the first Nginx). If I set BASE_PATH = "" and use rewrite, then I get the same error.

Pynetbox uses internally the URLs that NetBox returns in the objects (the url attribute), so if NetBox doesn't know what is the client-accessible path, it cannot return correct URLs.

@jeremystretch jeremystretch added the pynetbox label Nov 1, 2024 — with Linear
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pynetbox type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

No branches or pull requests

3 participants