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

config, remote: Made S3 CA bundle customizable #6018

Merged
merged 2 commits into from
Jun 1, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion dvc/config_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class RelPath(str):
"session_token": str,
Optional("listobjects", default=False): Bool, # obsoleted
Optional("use_ssl", default=True): Bool,
Optional("ssl_verify", default=True): Bool,
"ssl_verify": Any(Bool, str),
"sse": str,
"sse_kms_key_id": str,
"acl": str,
Expand Down
2 changes: 1 addition & 1 deletion dvc/fs/s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ def _prepare_credentials(self, **config):
client = login_info["client_kwargs"]
client["region_name"] = config.get("region")
client["endpoint_url"] = config.get("endpointurl")
client["verify"] = config.get("ssl_verify", True)
client["verify"] = config.get("ssl_verify")

# encryptions
additional = login_info["s3_additional_kwargs"]
Expand Down
33 changes: 32 additions & 1 deletion tests/unit/fs/test_s3.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,15 @@ def test_verify_ssl_default_param(dvc):
}
fs = S3FileSystem(**config)

assert fs.fs_args["client_kwargs"]["verify"]
assert "client_kwargs" not in fs.fs_args

config = {
"url": url,
"endpointurl": "https://my.custom.s3:1234",
}
fs = S3FileSystem(**config)

assert "verify" not in fs.fs_args["client_kwargs"]


def test_s3_config_credentialpath(dvc, monkeypatch):
Expand Down Expand Up @@ -74,6 +82,29 @@ def test_ssl_verify_bool_param(dvc):
assert fs.fs_args["client_kwargs"]["verify"] == config["ssl_verify"]


def test_ssl_verify_path_param(dvc):
config = {"url": url, "ssl_verify": "/path/to/custom/cabundle.pem"}
fs = S3FileSystem(**config)

assert fs.fs_args["client_kwargs"]["verify"] == config["ssl_verify"]


def test_ssl_verify_none_param(dvc):
config = {"url": url, "ssl_verify": None}
fs = S3FileSystem(**config)

assert "client_kwargs" not in fs.fs_args

config = {
"url": url,
"endpointurl": "https://my.custom.s3:1234",
"ssl_verify": None,
}
fs = S3FileSystem(**config)

assert "verify" not in fs.fs_args["client_kwargs"]


def test_grants(dvc):
config = {
"url": url,
Expand Down
37 changes: 37 additions & 0 deletions tests/unit/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
import textwrap

import pytest

Expand Down Expand Up @@ -33,3 +34,39 @@ def test_get_fs(tmp_dir, scm):
assert config._get_fs("local") == config.wfs
assert config._get_fs("global") == config.wfs
assert config._get_fs("system") == config.wfs


def test_s3_ssl_verify(tmp_dir, dvc):
config = Config(validate=False)
with config.edit() as conf:
conf["remote"]["remote-name"] = {"url": "s3://bucket/dvc"}

assert "ssl_verify" not in config["remote"]["remote-name"]

with config.edit() as conf:
section = conf["remote"]["remote-name"]
section["ssl_verify"] = False

assert (tmp_dir / ".dvc" / "config").read_text() == textwrap.dedent(
"""\
[core]
no_scm = True
['remote "remote-name"']
url = s3://bucket/dvc
ssl_verify = False
"""
)

with config.edit() as conf:
section = conf["remote"]["remote-name"]
section["ssl_verify"] = "/path/to/custom/cabundle.pem"

assert (tmp_dir / ".dvc" / "config").read_text() == textwrap.dedent(
"""\
[core]
no_scm = True
['remote "remote-name"']
url = s3://bucket/dvc
ssl_verify = /path/to/custom/cabundle.pem
"""
)