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

Refactor token authentication #103

Merged
merged 3 commits into from Jun 26, 2020
Merged

Conversation

mdellweg
Copy link
Member

No description provided.

@mdellweg
Copy link
Member Author

mdellweg commented Jun 15, 2020

WIP: the redirect to content app preauthenticate part is not yet contained.

@pulpbot
Copy link
Member

pulpbot commented Jun 15, 2020

WARNING!!! This PR is not attached to an issue. In most cases this is not advisable. Please see our PR docs for more information about how to attach this PR to an issue.

@mdellweg mdellweg changed the title Refactor push api Refactor token authentication Jun 16, 2020
@mdellweg mdellweg force-pushed the refactor_push_api branch 2 times, most recently from c8c0f64 to 768af4a Compare June 17, 2020 10:07
@mdellweg mdellweg marked this pull request as ready for review June 17, 2020 10:07
@mdellweg mdellweg force-pushed the refactor_push_api branch 6 times, most recently from 22f245d to 4249e45 Compare June 18, 2020 12:12
Copy link
Member

@lubosmj lubosmj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good. However, I think that due to your current changes, it is not possible to disable the token authentication. Am I right? Did we decide to drop such a feature for real? If so, please update docs as well.

pulp_container/app/serializers.py Outdated Show resolved Hide resolved
if not digest == self._get_digest(salt, url):
raise PermissionError("Access not authenticated")

def sign_url(self, url, salt=None):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the name of this method is a bit misleading, isn't it? The hash and salt is appended to the existing URL.

requirements.txt Outdated
@@ -2,3 +2,4 @@ pulpcore>=3.4
ecdsa~=0.13.2
pyjwkest~=1.4.0
pyjwt[crypto]~=1.7.1
url-normalize
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we should pin this dependency too.

pulp_container/app/serializers.py Outdated Show resolved Hide resolved
"""
if self.content_guard:
url = self.content_guard.cast().sign_url(url)
return HttpResponseRedirect(url)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use redirect() instead of HttpResponseRedirect. It does the same thing and it looks a bit cleaner, see https://docs.djangoproject.com/en/3.0/topics/http/shortcuts/#redirect.

@mdellweg mdellweg force-pushed the refactor_push_api branch 4 times, most recently from 60a0653 to c2b76f0 Compare June 23, 2020 10:02
@mdellweg
Copy link
Member Author

I added the possibility to disable it again.
(It's an untested codepath though)

Copy link
Member

@ipanova ipanova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left mostly minor comments, nothing critical. Great work!

@@ -375,3 +386,54 @@ def append_chunk(self, chunk, chunk_size=None, save=True):
self.file.close() # Flush
for algorithm in Artifact.DIGEST_FIELDS:
setattr(self, algorithm, hashers[algorithm].hexdigest())


def _gen_shared_secret():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this be moved under content guard class? it does not appear to be used anywhere else

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It can. However the field using it as default generator must be defined afterwards.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out djangos migration mechanism really does not like it. Sorry, i'm moving it out again.

pulp_container/app/models.py Outdated Show resolved Hide resolved
}
return headers
try:
authorization_header = request.headers["Authorization"]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this code changes the behaviour where we return 401 even when hitting root endpoint (/v2 )

Some registries return 401 and others 200
https://registry-1.docker.io/v2/
https://quay.io/v2/

I am ok with both of approaches however I think that returning 401 and then asking for token auth, generating the token and then verifying it in the nuance is a surplus work because the only thing that the client cares is 1) presence of registry 2.0 header and 4) whatever code is fine except 404 because what he looks at is the header to identify whether this is a v2 api registry otherwise he needs to fall back to the v1 api.
Thoughts?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see both of the above examples returning 401.
Also, with the current implementation, i need to raise the AuthenticationFailed exception to spit out the Www-Authenticate header.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ha, you are right, quay does return 401. I did through the browser so the "true" response kinda implied to me that it was a 200.

CHANGES/6894.bugfix Outdated Show resolved Hide resolved
@ipanova
Copy link
Member

ipanova commented Jun 24, 2020

I added the possibility to disable it again.
(It's an untested codepath though)

I have tested and it does work. 🎈

@mdellweg mdellweg force-pushed the refactor_push_api branch 2 times, most recently from a0dccb6 to 7e446a0 Compare June 25, 2020 08:25
@mdellweg
Copy link
Member Author

@ipanova want to rereview?

@ipanova
Copy link
Member

ipanova commented Jun 25, 2020

@mdellweg looks good to me, thank you! Feel free to merge :)

@mdellweg mdellweg merged commit 11c9aae into pulp:2.0 Jun 26, 2020
@mdellweg mdellweg deleted the refactor_push_api branch June 26, 2020 08:32
lubosmj added a commit to lubosmj/pulp_container that referenced this pull request Jul 13, 2020
The token server runs on the port 24817 by default. In the docs, we provide the example of the settings file with the port number 24816. This may confuse users in the future.

```
(pulp) [vagrant@pulp3-source-fedora31 backup]$ http :24817/v2/
HTTP/1.1 401 Unauthorized
Allow: GET, HEAD, OPTIONS
Connection: close
Content-Length: 58
Content-Type: application/json
Date: Mon, 13 Jul 2020 08:39:20 GMT
Docker-Distribution-Api-Version: registry/2.0
Server: gunicorn/20.0.4
Vary: Accept
WWW-Authenticate: Bearer realm="http://localhost:24816/token",service="pulp3-source-fedora31.localhost.example.com"
X-Frame-Options: SAMEORIGIN

{
    "detail": "Authentication credentials were not provided."
}
```

In addition to that, the note stating that the push API is unauthenticated was removed because such a support wass added in pulp#105 and pulp#103.

[noissue]
lubosmj added a commit to lubosmj/pulp_container that referenced this pull request Jul 13, 2020
The token server runs on the port 24817 by default. In the docs, we provide the example of the settings file with the port number 24816. This may confuse users in the future.

```
(pulp) [vagrant@pulp3-source-fedora31 backup]$ http :24817/v2/
HTTP/1.1 401 Unauthorized
Allow: GET, HEAD, OPTIONS
Connection: close
Content-Length: 58
Content-Type: application/json
Date: Mon, 13 Jul 2020 08:39:20 GMT
Docker-Distribution-Api-Version: registry/2.0
Server: gunicorn/20.0.4
Vary: Accept
WWW-Authenticate: Bearer realm="http://localhost:24816/token",service="pulp3-source-fedora31.localhost.example.com"
X-Frame-Options: SAMEORIGIN

{
    "detail": "Authentication credentials were not provided."
}
```

In addition to that, the note stating that the push API is unauthenticated was removed because of pulp#105 and pulp#103.

[noissue]
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.

None yet

5 participants