Skip to content

Commit 18e6d92

Browse files
Fix handling of self-signed certs in s3_conn (#1141)
* Fix handling of self-signed certs in s3_conn Take insecure/verify/cacert parameter from clouds.yaml and pass it to boto3.resource. If insecure is True or verify is False use verify=False also for boto3. Else, if you provide cacert(via cacert or verify parameter) it is also used for boto3. If nothing from above is met, use verify=None to keep default boto3 behaviour. Signed-off-by: Roman Hros <roman.hros@dnation.cloud> * Simplify logic a bit and add documentation to code Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud> * Take cacert from cacert parameter only, not from verify Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud> * Rectify comment regarding boto3 default behavior Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud> * Improve comment further thanks @chess-knight! Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud> --------- Signed-off-by: Roman Hros <roman.hros@dnation.cloud> Signed-off-by: Matthias Büchse <matthias.buechse@alasca.cloud> Co-authored-by: Matthias Büchse <matthias.buechse@alasca.cloud>
1 parent 14237f6 commit 18e6d92

1 file changed

Lines changed: 12 additions & 5 deletions

File tree

Tests/iaas/scs_0123_mandatory_services/mandatory_services.py

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,19 @@ def compute_scs_0123_service_presence(services_lookup, *names):
2828

2929
def s3_conn(creds, conn):
3030
"""Return an s3 client conn"""
31-
cacert = conn.config.config.get("cacert")
32-
# TODO: Handle self-signed certs (from ca_cert in openstack config)
33-
if cacert:
34-
logger.warning(f"Trust all Certificates in S3, OpenStack uses {cacert}")
31+
cfg = conn.config.config
32+
# Take insecure/verify/cacert parameter from clouds.yaml and pass it to boto3.resource.
33+
# If insecure is False/None and verify is True/None in clouds.yaml, fall back to cacert or None.
34+
# In the latter case (None), the default boto3 behavior is applied (where config file or env
35+
# variables can still be used, and otherwise, boto3 defaults to verify=True).
36+
# Note: cacert must be used to pass the certificate; don't use verify for that; cf.
37+
# https://docs.openstack.org/openstacksdk/latest/user/config/configuration.html#ssl-settings
38+
if cfg.get("insecure") or not cfg.get("verify", True):
39+
verify = False
40+
else:
41+
verify = cfg.get("cacert")
3542
return boto3.resource(
36-
's3', endpoint_url=creds["HOST"], verify=not cacert,
43+
's3', endpoint_url=creds["HOST"], verify=verify,
3744
aws_access_key_id=creds["AK"], aws_secret_access_key=creds["SK"],
3845
)
3946

0 commit comments

Comments
 (0)