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 Addresses Used in IamAwsProvider #1460

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions minio/credentials/providers.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
from datetime import timedelta
from pathlib import Path
from typing import Callable, cast
from urllib.parse import urlencode, urlsplit, urlunsplit
from urllib.parse import urlencode, urlsplit, urljoin
from xml.etree import ElementTree as ET

import certifi
Expand All @@ -44,7 +44,7 @@

from urllib3.util import Retry, parse_url

from minio.helpers import sha256_hash, url_replace
from minio.helpers import sha256_hash
from minio.signer import sign_v4_sts
from minio.time import from_iso8601utc, to_amz_date, utcnow
from minio.xml import find, findtext
Expand Down Expand Up @@ -503,23 +503,25 @@ def retrieve(self) -> Credentials:
)
token = res.data.decode("utf-8")
headers = {"X-aws-ec2-metadata-token": token} if token else None

iam_security_creds_url = urlsplit(url)._replace(
path="/latest/meta-data/iam/security-credentials/"
)
# Get role name
res = _urlopen(
self._http_client,
"GET",
urlunsplit(
url_replace(
urlsplit(url),
path="/latest/meta-data/iam/security-credentials/",
),
),
iam_security_creds_url.geturl(),
headers=headers,
)
role_names = res.data.decode("utf-8").split("\n")
if not role_names:
raise ValueError(f"no IAM roles attached to EC2 service {url}")
url += "/" + role_names[0].strip("\r")
url = iam_security_creds_url._replace(
path=urljoin(
iam_security_creds_url.path,
role_names[0].strip("\r"),
)
).geturl()
if not url:
raise ValueError("url is empty; this should not happen")
self._credentials = self.fetch(url, headers=headers)
Expand Down