Is it possible to use a JSON Web Token/JWT in a pip.conf file?

2024/11/17 3:29:00

I'm trying to make it possible for my application to fetch a package from a private feed in Azure DevOps using pip and a pip.conf file. I don't want to use a PAT for obvious reasons, so I've created a service principal for the app. The app can retrieve a JWT with the service principal, which I would like to put into the pip.conf file instead of my PAT. Now my question is pretty simple, but I really couldn't find an answer even after hours of searching the internet:

Is it possible to use a JWT in a pip.conf file?

The file looks like this, and I would like to put the JWT where the PAT normally goes:

[global]
extra-index-url=https://<JWT>@pkgs.dev.azure.com/<myfeed>/pypi/simple/

Is this syntax possible, and if not, is there another way to use a JWT to authenticate with pip?

Thanks in advance!

Answer

Is this syntax possible, and if not, is there another way to use a JWT to authenticate with pip?

No, JWT is not supported in the syntax. You can check below alternatives:

If you are using devops pipeline to install the package, you can use system.accesstoken instead of PAT to authenticate with the feed. Just make sure you have set the job acccess token properly, add Project Collection Build Service ({OrgName}) or {Project Name} Build Service ({Org Name}) to the feed as contributor accordingly.

For feeds in same devops organization.

- task: Bash@3inputs:targetType: 'inline'script: |pip install twine keyring artifacts-keyringpython -m pip install --upgrade pipexport PIP_INDEX_URL='https://build:$(system.accesstoken)@pkgs.dev.azure.com/{orgname}/_packaging/{feedname}/pypi/simple'pip install simple-package

enter image description here

If the feed is in another organization which is different with pipeline, but the organizations are linked to same Azure Active Directory, you can set the outside feed as upstream source. If the organization are linked to different azure active directory, you can use task below which needs a python service connection(username&password, or personal access token to create).

  - task: TwineAuthenticate@0displayName: Configure twine authenticationinputs:artifactFeeds: '$(artifactFeed)'externalFeeds: 'ExternalPythonFeed'

Another way is use rest api Python - Download Package to download the file, and install python package. steps:

  1. Add the service principal as DevOps user, and add to the target project.

  2. Add the service principal as contributor/reader role on the feed role setting.

  3. az login with service principal, and get the token(az account get-access-token)

enter image description here 4. Use the token as bear token for the rest api to download the python feed package file.

enter image description here

  1. Install the package.

enter image description here

https://en.xdnf.cn/q/118852.html

Related Q&A

sqlite3.Cursor object has no attribute __getitem__ Error in Python Flask

This is my code. I get this error everytime I press login:sqlite3.Cursor object has no attribute __getitem__This is my login tab:@app.route(/, methods=[GET, POST]) def login():error= Noneif request.met…

Merge Sort Implementation Check

I am doubtful of my implementation of the merge sort for two cases specifically:1. If the size of the list is 2, then I have swapped the values if they are not in the ascending order else I have return…

How to create a def in python that pick a specific value and then make a new dict like this

myDict ={"key1" : "val1","key2" : "val2","key3" : "val3","key4" : "x","key5" : "x"}I need a def in py…

Inputs required in python on csv files

I have a problem and need to solve it using Pandas/Python. Not sure how to achieve it and would be great if someone help here to build the logic. I have to generate the output file as below: df = pd.Da…

ServiceBusError : Handler failed: tuple object has no attribute get_token

Im getting the below error when i run my code. This code is to requeue the Deadletter messages. Error: Exception has occurred: ServiceBusError Handler failed: tuple object has no attribute get_token. A…

sqlite3.OperationalError: near WHERE: syntax error

I want to update a series of columns Country1, Country2... Country 9 based on a comma delimited string of country names in column Country. Ive programmed a single statement to accomplish this task. cur…

If statement not working correctly in Python 3

This is the start of an RPG I am going to make, and It runs smoothly until I try to change the gender by saying yes or any other of the answers that activate the if statement. Is there something I am f…

pymc3 error. AttributeError: module arviz has no attribute geweke [closed]

Closed. This question needs debugging details. It is not currently accepting answers.Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to repro…

how to prevent duplicate text in the output file while using for loop

I have this code which compares a number to a number(what i called item in my code) in the domain range to see if it is already there. If it its then print to the output file if it is not then only pri…

How to replace \\ with \ without raising an EOL error?

I am reading from a file that contains byte data but when I open the file and store the readline data into a variable it stores it in a string with backslash escapes, So when trying to decode that data…