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

Dont replace jira url #1913

Open
4 tasks done
dimanoga opened this issue Oct 30, 2024 · 7 comments · May be fixed by #1925
Open
4 tasks done

Dont replace jira url #1913

dimanoga opened this issue Oct 30, 2024 · 7 comments · May be fixed by #1925

Comments

@dimanoga
Copy link

Bug summary

Hi there,

In our company, API access is provided through a white list system.
To "fix" IP addresses, we use Nginx as a proxy server for accessing Jira.
However, we have noticed that when we use the connection.issuel), in the dictresource method, the URL is replaced with one that Jira returns, rather than the one from which the request originated. Additionally, when updating issues using the issue.update method, the URL used is not the one that the authorization was initiated from, but rather the one provided by the Jira server.

Due to this, when attempting to update a task, we receive a 401 unauthorized error. We are hoping to resolve this issue and ensure that the correct URL is used for all API requests.

Could you please assist us in resolving this issue? We would greatly appreciate any assistance you can provide. Thank you in advance for your attention.

Is there an existing issue for this?

  • I have searched the existing issues

Jira Instance type

Jira Server or Data Center (Self-hosted)

Jira instance version

8.20.0

jira-python version

3.5.2

Python Interpreter version

3.11

Which operating systems have you used?

  • Linux
  • macOS
  • Windows

Reproduction steps

#1 connect to jira via nginx url
connection = JIRA(options={'server':"https://my-nginx.url/', 'verify': False}, auth=(login, pass))
#2 get issue
issue = connection.issue(key='JIRA-1')
#3 try to update issue
issue.update(fields={'description':'test'}) # the url is already used here = jira.company.com

Stack trace

File "/PycharmProjects/portal_back/venv/lib/python3.11/site-packages/jira/resources•py", Line 852, in update
super (). update(async_=async_, jira-jira, notify=notify, fields=data)
File "/PycharmProjects/portal_back/venv/lib/python3.11/site-packages/jira/resources-py", Line 328, in update
r = self._session.put (self.self + querystring, data-json.dumps (data))
Fetur se. euest Por, urt, vtadta, uergs) se-packages/requests/sesstons.py". Line 649, in put.
File "/PycharmProjects/portal_back/venv/lib/python3.11/site-packages/jira/resilientsession-py", line 247, in request elif raise_on_error (response, **processed_kwargs):
File "/PycharmProjects/portal_back/venv/lib/python3.11/site-packages/jira/resilientsession-py", Line 72, in raise_on_error
raise JIRAError(
jira.exceptions.JIRAError: JiraError HTTP 401 url: https://jira.company.com/rest/api/2/issue/15832118
text: You do not have the permission to see the specified issue., Login Required
response headers = {''}
response text = ("errorMessages": ["You do not have the permission to see the specified issue.", "Login Required"], "errors":}}
Process finished with exit code 1

Expected behaviour

The Jira URL has not been replaced, but the one that was used for authorization is still being used,

Additional Context

No response

@dimanoga dimanoga changed the title Dont replace jira ul Dont replace jira url Oct 30, 2024
@ichimukuren
Copy link

We’re experiencing a very similar issue in our setup! We also use Nginx as a proxy for Jira with IP whitelisting, and have noticed the URL handling seems inconsistent, which causes authentication errors like the 401 Unauthorized you mentioned.

It would be great if the Jira team could help clarify or address this behavior. Thanks for sharing your experience—it’s helpful to know we’re not alone with this issue!

@skiedude
Copy link

skiedude commented Nov 21, 2024

We also hit this, in our case. To reach jira from a server, you have to use a proxy address, but in some of the helper methods, they use the address returned on the issue object.

My specific use case was in the Issue().add_field_value which forwards to => Resource().update which uses the self.self value returned on the ticket from jira. (which appears to be the same place that @dimanoga referenced in their opening comment)

To get around it in our local testing we used the urllib.parse library to compare things.

import jira
user = 'username'
password = 'password'
j = jira.JIRA('https://jira.internal.net', basic_auth=(user, password))
issue = j.issue('ID-363772')
issue.add_field_value(field='labels', value='testpython')

The above code would fail due to the wrong jira address being used. To fix it, we added the following to https://github.com/pycontribs/jira/blob/main/jira/resources.py#L329

from urllib.parse import urlparse, urlunparse, ParseResult 
...
self_parsed = urlparse(self.self) #Get the ticket url from the ticket returned from jira, and run it through urlparse
server_parsed = urlparse(self._options['server']) #run the server address we configured in the JIRA object through urlparse
if self_parsed.netloc != server_parsed.netloc: #compare the two values
    self.self = urlunparse(
        ParseResult(
            scheme=self_parsed.scheme,
            netloc=server_parsed.netloc,  #use the server address we set in our config, everything else the same
            path=self_parsed.path, 
            params=self_parsed.params, 
            query=self_parsed.query, 
            fragment= self_parsed.fragment
        )
)
r = self._session.put(self.self + querystring, data=json.dumps(data))

This obviously very specific to the resource.py, but it may be adapted to other parts of the code.

@skiedude
Copy link

This can actually be achieved with the already included methods of the class Resource a bit more precise

        path = self._resource.format(self.key)
        self.self = self._get_url(path)

I'll put in a PR for discussion/review

@YanvarevDmitry
Copy link

We are now bypassing this by substituting the correct link through self.self, but this does not seem to be the right solution.

@skiedude skiedude linked a pull request Nov 22, 2024 that will close this issue
@studioj
Copy link
Collaborator

studioj commented Nov 22, 2024

This can actually be achieved with the already included methods of the class Resource a bit more precise

        path = self._resource.format(self.key)
        self.self = self._get_url(path)

I'll put in a PR for discussion/review

if opening a pr , do know we'd like to have it tested.

This repo is not under active development and maintained by volunteers. As you can see prs get merged slowly. We cheer to contributors wanting to do the effort of creating a PR but ask for patience ... and a short bump once in a while :-) this is by far our main project

@studioj
Copy link
Collaborator

studioj commented Nov 22, 2024

aha a PR was created, => we need to get deployment working first though.

https://github.com/pycontribs/jira/pull/1925/files

@skiedude
Copy link

skiedude commented Nov 22, 2024

aha a PR was created, => we need to get deployment working first though.

https://github.com/pycontribs/jira/pull/1925/files

Linting hopefully fixed 😃

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants