Skip to content

Commit efc8d92

Browse files
ap-kulkarniefiop
authored andcommitted
Fixes #6141. Adds support for SSE-C in s3fs.
1 parent aab0da7 commit efc8d92

File tree

1 file changed

+22
-2
lines changed
  • src/dvc_objects/fs/implementations

1 file changed

+22
-2
lines changed

src/dvc_objects/fs/implementations/s3.py

+22-2
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,10 @@ def _load_aws_config_file(self, profile):
7474
return self._split_s3_config(s3_config)
7575

7676
def _prepare_credentials(self, **config):
77+
import base64
78+
79+
from s3fs.utils import SSEParams
80+
7781
login_info = defaultdict(dict)
7882

7983
# credentials
@@ -98,8 +102,24 @@ def _prepare_credentials(self, **config):
98102

99103
# encryptions
100104
additional = login_info["s3_additional_kwargs"]
101-
additional["ServerSideEncryption"] = config.get("sse")
102-
additional["SSEKMSKeyId"] = config.get("sse_kms_key_id")
105+
sse_customer_key = None
106+
if config.get("sse_customer_key"):
107+
if config.get("sse_kms_key_id"):
108+
raise ConfigError(
109+
"`sse_kms_key_id` and `sse_customer_key` AWS S3 config "
110+
"options are mutually exclusive"
111+
)
112+
sse_customer_key = base64.b64decode(config.get("sse_customer_key"))
113+
sse_customer_algorithm = config.get("sse_customer_algorithm")
114+
if not sse_customer_algorithm and sse_customer_key:
115+
sse_customer_algorithm = "AES256"
116+
sse_params = SSEParams(
117+
server_side_encryption=config.get("sse"),
118+
sse_customer_algorithm=sse_customer_algorithm,
119+
sse_customer_key=sse_customer_key,
120+
sse_kms_key_id=config.get("sse_kms_key_id"),
121+
)
122+
additional.update(sse_params.to_kwargs())
103123
additional["ACL"] = config.get("acl")
104124
for grant_option, grant_key in self._GRANTS.items():
105125
if config.get(grant_option):

0 commit comments

Comments
 (0)