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

nb.version Returns an Empty String Due to OIDC Proxy Configuration #640

Open
Kani999 opened this issue Aug 30, 2024 · 0 comments · May be fixed by #641
Open

nb.version Returns an Empty String Due to OIDC Proxy Configuration #640

Kani999 opened this issue Aug 30, 2024 · 0 comments · May be fixed by #641
Labels
type: bug A confirmed report of unexpected behavior in the application

Comments

@Kani999
Copy link
Contributor

Kani999 commented Aug 30, 2024

pynetbox version

v7.4.0

NetBox version

v4.0.9

Python version

3.11

Steps to Reproduce

Description:

When using NetBox with an OIDC (OpenID Connect) proxy for authentication, the nb.version property consistently returns an empty string (''). This issue arises because the get_version method in pynetbox does not receive the API-Version header, as the request is redirected to the OIDC login page due to missing authorization.

Steps to Reproduce:

  1. Set up NetBox behind an OIDC proxy with the following Apache configuration:

    <Location /api>
        <If "-z req('authorization')">
          Require valid-user
        </If>
        <Else>
           Require ip <IP_ADDRESS_RANGE>
        </Else>
    </Location>
  2. Use pynetbox to access the API.

  3. Call the nb.version property.

  4. Observe that nb.version returns an empty string.

Expected Behavior:

The nb.version property should return the correct NetBox version string.

Actual Behavior:

The nb.version property returns an empty string.

Cause:

The OIDC proxy redirects unauthorized requests to the login page, causing the get_version method to miss the API-Version header.

Proposed Solution:

Modify the version property in pynetbox/core/api.py to ensure the authorization token is passed to the get_version method. Here's the proposed change:

@property
def version(self):
    """Gets the API version of NetBox.

    Can be used to check the NetBox API version if there are
    version-dependent features or syntaxes in the API.

    :Returns: Version number as a string.
    :Example:

    >>> import pynetbox
    >>> nb = pynetbox.api(
    ...     'http://localhost:8000',
    ...     token='your_token_here'
    ... )
    >>> nb.version
    '3.1'
    >>>
    """
    version = Request(
        base=self.base_url,
        token=self.token,  # Ensure the token is passed here
        http_session=self.http_session,
    ).get_version()
    return version

Additional Context:

The issue is specific to environments where NetBox is protected by an OIDC proxy, requiring a valid token for API access.

Expected Behavior

nb.version
'4.0'

Observed Behavior

nb.version
''

@Kani999 Kani999 added the type: bug A confirmed report of unexpected behavior in the application label Aug 30, 2024
@Kani999 Kani999 linked a pull request Aug 30, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A confirmed report of unexpected behavior in the application
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant