Skip to content

Commit 5cfdf26

Browse files
committed
Fix authentication priority: AWS-native -> docker login -> credHelpers -> credsStore
Signed-off-by: Rasmus Faber-Espensen <rfaber@gmail.com>
1 parent d296ffd commit 5cfdf26

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

oras/auth/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,19 +102,19 @@ def _load_auth(self, hostname: str) -> bool:
102102
return False
103103
self._basic_auth = auth
104104
return True
105-
# Check for credsStore:
106-
if self._auth_config.get("credsStore"):
105+
# Check for credHelper
106+
if self._auth_config.get("credHelpers", {}).get(hostname):
107107
auth = self._get_auth_from_creds_store(
108-
self._auth_config["credsStore"], hostname
108+
self._auth_config["credHelpers"][hostname], hostname
109109
)
110110
if auth is not None:
111111
self._basic_auth = auth
112112
auths[hostname] = {"auth": auth}
113113
return True
114-
# Check for credHelper
115-
if self._auth_config.get("credHelpers", {}).get(hostname):
114+
# Check for credsStore:
115+
if self._auth_config.get("credsStore"):
116116
auth = self._get_auth_from_creds_store(
117-
self._auth_config["credHelpers"][hostname], hostname
117+
self._auth_config["credsStore"], hostname
118118
)
119119
if auth is not None:
120120
self._basic_auth = auth

oras/auth/ecr.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,31 @@
33
__license__ = "Apache-2.0"
44

55
import re
6+
from typing import Optional
67

78
import requests
89

910
import oras.auth.utils as auth_utils
1011
from oras.auth.token import TokenAuth
1112
from oras.logger import logger
13+
from oras.types import container_type
1214

1315

1416
class EcrAuth(TokenAuth):
1517
"""
1618
Auth backend for AWS ECR (Elastic Container Registry) using token-based authentication.
1719
"""
20+
AWS_ECR_PATTERN = re.compile(r"(?P<account_id>\d{12})\.dkr\.ecr\.(?P<region>[^.]+)\.amazonaws\.com")
21+
AWS_ECR_REALM_PATTERN = re.compile(r"https://(?P<account_id>\d{12})\.dkr\.ecr\.(?P<region>[^.]+)\.amazonaws\.com/")
1822

1923
def __init__(self):
2024
super().__init__()
2125
self._tokens = {}
2226

27+
def load_configs(self, container: container_type, configs: Optional[list] = None) -> None:
28+
if not self.AWS_ECR_PATTERN.fullmatch(container.registry):
29+
super().load_configs(container, configs)
30+
2331
def authenticate_request(
2432
self, original: requests.Response, headers: dict, refresh=False
2533
):
@@ -46,7 +54,7 @@ def authenticate_request(
4654
token = self._tokens.get(h.realm)
4755
if not token or refresh:
4856
m = re.fullmatch(
49-
r"https://(?P<account_id>\d{12})\.dkr\.ecr\.(?P<region>[^.]+)\.amazonaws\.com/",
57+
self.AWS_ECR_REALM_PATTERN,
5058
h.realm,
5159
)
5260
if not m:

0 commit comments

Comments
 (0)