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

fix: do not set empty token so anon works for public ecr #176

Merged
merged 1 commit into from
Dec 6, 2024

Conversation

natefaerber
Copy link
Contributor

Fixes #167

The TokenAuth object has a None value for token until a login is executed. AWS ECR returns a 400 Bad Request when presented with Authorization: Bearer None while Docker Hub returns a 401 Unauthorized with proper www-authenticate header.

This patch simply skips adding Authorization: Bearer None which AWS ECR seems to expect. Docker Hub seems to handle the lack of Authorization header the same as if it got Bearer None.

My testing of this patch follows.

>>> from oras.logger import setup_logger, logger
>>> setup_logger(quiet=False, debug=True)
>>> from oras.client import OrasClient
>>> client = OrasClient('public.ecr.aws')
>>> client.get_tags('/aws-controllers-k8s/acm-chart')
Requesting anon token with params: {'service': 'public.ecr.aws', 'scope': 'aws'}
Successfully obtained anonymous token!

client = OrasClient('registry.hub.docker.com')
client.get_tags('openresty/openresty', N=10)
['0.0.13', '0.0.19', '0.0.20', 'v0.0.6', '0.0.4', '0.0.5', '0.0.11', '0.0.7', 'v0.0.4', '0.0.17', '0.0.16', 'v0.0.3', '0.0.6', 'v0.0.5', 'v0.0.1', '0.0.10', 'v0.0.2', '0.0.2', '0.0.8', '0.0.18', '0.0.3', '0.0.1', '0.0.15', '1.0.0', '0.0.12', '0.0.9', '0.0.14']
>>>
>>> client = OrasClient('registry.hub.docker.com')
>>> client.get_tags('openresty/openresty', N=10)
Requesting anon token with params: {'service': 'registry.docker.io', 'scope': 'repository:openresty/openresty:pull'}
Successfully obtained anonymous token!
['1.11.2.1-alpine', '1.11.2.1-centos', '1.11.2.1-centos-rpm', '1.11.2.1-trusty', '1.11.2.1-xenial', '1.11.2.2-alpine', '1.11.2.2-alpine-fat', '1.11.2.2-centos', '1.11.2.2-centos-rpm', '1.11.2.2-jessie']
>>>

@vsoch vsoch merged commit c5289c1 into oras-project:main Dec 6, 2024
5 checks passed
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.

Issue with public ECR since 0.2.21
2 participants