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

Add support for API keys #4599

Closed
wants to merge 169 commits into from
Closed

Add support for API keys #4599

wants to merge 169 commits into from

Conversation

steiza
Copy link

@steiza steiza commented Aug 21, 2018

#994

This lets users provision an API key, and then use that API key with
forklift.legacy.file_upload. It uses macaroons so advanced users can
further restrict usage of their API key.

This work was originally started at https://github.com/lukesneeringer/warehouse/tree/tokens at the 2018 US PyCon.

It adds a section on /manage/accounts where you can create a new token:

screen shot 2018-08-19 at 11 12 44 pm

Then a splash shows up with your new API key (note that this key is just on my local dev instance, not a real production key):

screen shot 2018-08-19 at 11 12 52 pm

And the key is listed on /manage/accounts:

screen shot 2018-08-19 at 11 13 04 pm

You can then use the key with something like:

curl -X POST "http://127.0.0.1/legacy/?:action=file_upload&version=0.1&name=<package name>&account_token=<key from splash>

Macaroons allow you to further reduce the scope of the API key. For example:

>>> from pymacaroons import Macaroon
>>> macaroon = Macaroon.deserialize('MDAxNmxvY2F0aW9uIHB5cGkub3JnCjAwMjdpZGVudGlmaWVyICJhIHB1YmxpYyB0b2tlbiBhcGkgaWQiCjAwMzFjaWQgaWQ6IGE2YmQ3N2NiLWIzY2QtNDcwNS05N2JkLWEwMzZlMWZjYTkyMQowMDJmc2lnbmF0dXJlIIqV_7ozeE7EXj_xdacB_zUkUJTOT3l9wgjNfSWMuDurCg')
>>> macaroon.add_first_party_caveat("package: exampleproject")
<pymacaroons.macaroon.Macaroon object at 0x103f24630>
>>> macaroon.serialize()
'MDAxNmxvY2F0aW9uIHB5cGkub3JnCjAwMjdpZGVudGlmaWVyICJhIHB1YmxpYyB0b2tlbiBhcGkgaWQiCjAwMzFjaWQgaWQ6IGE2YmQ3N2NiLWIzY2QtNDcwNS05N2JkLWEwMzZlMWZjYTkyMQowMDIwY2lkIHBhY2thZ2U6IGV4YW1wbGVwcm9qZWN0CjAwMmZzaWduYXR1cmUgksBAiGLCnUJxORDKDc-XV0ZkrKGG3yglj0WYR8OazVEK'

... and then the key is scoped to uploading just that package.

There's many places this pull could go from here. There should probably be additional testing, particularly off the happy path. We could add a first party caveat to support the key expiring after a certain date. Make instead of package it should be packages so you can support restricting it to a set of packages? You wouldn't want to support multiple package caveats on a Macaroon - otherwise someone who gets your Macaroon could just add another package, defeating your earlier restriction!

Feedback welcome!

pypi#994

This lets users provision an API key, and then use that API key with
forklift.legacy.file_upload. It uses macaroons so advanced users can
further restrict usage of their API key.
@steiza steiza mentioned this pull request Aug 21, 2018
steiza added 3 commits August 22, 2018 08:50
- fix comment
- flake8 compliance
- satisfy DEPCHECKER
- add alembic migration
@dstufft
Copy link
Member

dstufft commented Aug 22, 2018

I just want to let you know, I plan on looking at this later this week.

@steiza
Copy link
Author

steiza commented Aug 22, 2018

Thanks! I finally figured out how to run the linter locally. I'll look at the coverage issues in the meantime.

pyup-bot and others added 23 commits August 22, 2018 22:18
* Update certifi from 2018.8.13 to 2018.8.24

* Update certifi from 2018.8.13 to 2018.8.24

* Update certifi from 2018.8.13 to 2018.8.24
* Update sphinx from 1.7.7 to 1.7.8

* Update sphinx from 1.7.7 to 1.7.8
* Update attrs from 18.1.0 to 18.2.0

* Update attrs from 18.1.0 to 18.2.0

* Update attrs from 18.1.0 to 18.2.0

* Update tests.txt
pyup-bot and others added 27 commits October 24, 2018 14:17
* Update flake8 from 3.5.0 to 3.6.0

* Update pyflakes from 1.6.0 to 2.0.0

* Update pycodestyle from 2.3.1 to 2.4.0

* Add setuptools==40.4.3 to requirements/lint.txt

* Fix linting errors
* Update pytz from 2018.5 to 2018.6

* Update pytz from 2018.5 to 2018.6
* Update urllib3 from 1.23 to 1.24

* Update urllib3 from 1.23 to 1.24

* Update urllib3 from 1.23 to 1.24
* Update responses from 0.9.0 to 0.10.1

* Add biscuits==0.1.1
Bumps [gunicorn](https://github.com/benoitc/gunicorn) from 19.7.1 to 19.9.0.
- [Release notes](https://github.com/benoitc/gunicorn/releases)
- [Commits](benoitc/gunicorn@19.7.1...19.9.0)

Signed-off-by: dependabot[bot] <support@dependabot.com>
Bumps [black](https://github.com/ambv/black) from 18.6b2 to 18.9b0.
- [Release notes](https://github.com/ambv/black/releases)
- [Commits](psf/black@18.6b2...18.9b0)

Signed-off-by: dependabot[bot] <support@dependabot.com>
* Update responses from 0.10.1 to 0.10.2

* Remove biscuits...
* Update python-dateutil from 2.7.3 to 2.7.4

* Update python-dateutil from 2.7.3 to 2.7.4
Bumps [boto3](https://github.com/boto/boto3) from 1.9.31 to 1.9.32.
- [Release notes](https://github.com/boto/boto3/releases)
- [Changelog](https://github.com/boto/boto3/blob/develop/CHANGELOG.rst)
- [Commits](boto/boto3@1.9.31...1.9.32)

Signed-off-by: dependabot[bot] <support@dependabot.com>
pypi#994

This lets users provision an API key, and then use that API key with
forklift.legacy.file_upload. It uses macaroons so advanced users can
further restrict usage of their API key.
- fix comment
- flake8 compliance
- satisfy DEPCHECKER
- add alembic migration
@steiza
Copy link
Author

steiza commented Oct 27, 2018

I accidentally hosed this branch when trying to update it / resolve merge conflicts last night. See instead #4949.

@steiza steiza closed this Oct 27, 2018
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 this pull request may close these issues.