From cdb7305dac6f9089236539133f6c8eab1ec9dd55 Mon Sep 17 00:00:00 2001 From: Waldemar Hummer Date: Wed, 15 Nov 2017 14:37:39 -0500 Subject: [PATCH] use S3 path style addressing when running in kubernetes (#1315) --- moto/s3/responses.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/moto/s3/responses.py b/moto/s3/responses.py index fb1735a5c..6abb4f2d1 100755 --- a/moto/s3/responses.py +++ b/moto/s3/responses.py @@ -55,8 +55,10 @@ class ResponseObject(_TemplateEnvironmentMixin): if not host: host = urlparse(request.url).netloc - if not host or host.startswith("localhost") or re.match(r"^[^.]+$", host): - # For localhost or local domain names, default to path-based buckets + if (not host or host.startswith('localhost') or + re.match(r'^[^.]+$', host) or re.match(r'^.*\.svc\.cluster\.local$', host)): + # Default to path-based buckets for (1) localhost, (2) local host names that do not + # contain a "." (e.g., Docker container host names), or (3) kubernetes host names return False match = re.match(r'^([^\[\]:]+)(:\d+)?$', host)