Skip to content

Add S3 SSE KMS key and bucketkey encryption - #26899

Closed
tsdicloud wants to merge 6 commits into
nextcloud:masterfrom
nextmcloud:s3ssekms
Closed

Add S3 SSE KMS key and bucketkey encryption#26899
tsdicloud wants to merge 6 commits into
nextcloud:masterfrom
nextmcloud:s3ssekms

Conversation

@tsdicloud

Copy link
Copy Markdown
Contributor

This is a replacement pull request for #26001 due to diverse rebase problems on the original request.

It also contains fixes for

Let´s try again. Sorry for the unconventional retry...

Signed-off-by: Bernd.Rederlechner@t-systems.com <bernd.rederlechner@t-systems.com>
@tsdicloudtsdicloud changed the title Add S3 SSE KMS key and bucketked encryptionAdd S3 SSE KMS key and bucketkey encryptionMay 6, 2021
Comment threadlib/private/Files/ObjectStore/S3ObjectTrait.php Outdated
Comment threadlib/private/Files/ObjectStore/S3ObjectTrait.php Outdated

@juliusknorrjuliusknorr left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The current commit seems to revert the additional mimetype parameter of the writeObject method which was added in #26575 with that change adjusted, tests should also pass.

Looks fine otherwise from my side 👍

@tsdicloud

tsdicloud commented May 7, 2021

Copy link
Copy Markdown
ContributorAuthor

I am working on the incompatibility and run unit test for it.

Signed-off-by: Bernd.Rederlechner@t-systems.com <bernd.rederlechner@t-systems.com>
Signed-off-by: Bernd.Rederlechner@t-systems.com <bernd.rederlechner@t-systems.com>
Comment threadlib/private/Files/ObjectStore/S3ConnectionTrait.php
Signed-off-by: Bernd.Rederlechner@t-systems.com <bernd.rederlechner@t-systems.com>
Signed-off-by: Bernd.Rederlechner@t-systems.com <bernd.rederlechner@t-systems.com>
Signed-off-by: Bernd.Rederlechner@t-systems.com <bernd.rederlechner@t-systems.com>
@tsdicloud

Copy link
Copy Markdown
ContributorAuthor

I cannot identify the php-cs-check problem. My dev setup does not show any fix for the corresponding files. Please help!

@blizzz

Copy link
Copy Markdown
Member

I cannot identify the php-cs-check problem. My dev setup does not show any fix for the corresponding files. Please help!

That's unrelated to your code – a change sneaked in into master. If you rebase to the current, it won't appear anymore.

@juliusknorrjuliusknorr added 3. to review Waiting for reviews and removed 2. developing Work in progress labels May 17, 2021
$encrypt_state = $this->connection->getBucketEncryption([
'Bucket' => $this->bucket,
]);
return;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
return;

$logger = \OC::$server->getLogger();

try {
$encrypt_state = $this->connection->getBucketEncryption([

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$encrypt_state is unused.

<?php
/**
* @copyright Copyright (c) 2016 Robin Appelman <robin@icewind.nl>
*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This will most likely be re-added by the license script. So better not remove it in the first place to keep the changeset clean.

}

$this->id = 'amazon::' . $params['bucket'];
$this->id = 'amazon::'.$params['bucket'];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is most likely why the code style CI job fails. We keep spaces around operators in our code style.

$this->uploadPartSize = !isset($params['uploadPartSize']) ? 524288000 : $params['uploadPartSize'];
$params['region'] = empty($params['region']) ? 'eu-west-1' : $params['region'];
$params['hostname'] = empty($params['hostname']) ? 's3.' . $params['region'] . '.amazonaws.com' : $params['hostname'];
$params['hostname'] = empty($params['hostname']) ? 's3.'.$params['region'].'.amazonaws.com' : $params['hostname'];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same code style issue.

$params['autocreate'] = !isset($params['autocreate']) ? false : $params['autocreate'];

// this avoid at least the hash lookups for each read/weite operation
if (isset($params['ssekmsbucketkeyid'])) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be documented in "admin_manual/configuration_files/primary_storage.rst" of the documentation.

// this avoid at least the hash lookups for each read/weite operation
if (isset($params['ssekmsbucketkeyid'])) {
$this->sseKmsBucketKeyId = $params['ssekmsbucketkeyid'];
} elseif (isset($params['ssekmskeyid'])) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be documented in "admin_manual/configuration_files/primary_storage.rst" of the documentation.

* @throws \Exception if bucket creation fails
*/
protected function createNewBucket() {
$logger = \OC::$server->getLogger();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't fully like that approach but as this is a trait I have no other good idea how to properly inject this dependency. Maybe @ChristophWurst has an idea, otherwise this should be fine.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤷

protected function createNewBucket() {
$logger = \OC::$server->getLogger();
try {
$logger->info('Bucket "'.$this->bucket.'" does not exist - creating it.', ['app' => 'objectstore']);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$logger->info('Bucket "'.$this->bucket.'" does not exist - creating it.', ['app' => 'objectstore']);
$logger->info('Bucket "' . $this->bucket . '" does not exist - creating it.', ['app' => 'objectstore']);

try {
$logger->info('Bucket "'.$this->bucket.'" does not exist - creating it.', ['app' => 'objectstore']);
if (!$this->connection::isBucketDnsCompatible($this->bucket)) {
throw new \Exception('The bucket will not be created because the name is not dns compatible, please correct it: '.$this->bucket);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
thrownew \Exception('The bucket will not be created because the name is not dns compatible, please correct it: '.$this->bucket);
thrownew \Exception('The bucket will not be created because the name is not dns compatible, please correct it: ' . $this->bucket);

'level' => ILogger::DEBUG,
'app' => 'objectstore',
]);
throw new \Exception('Creation of bucket "'.$this->bucket.'" failed. '.$e->getMessage());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
thrownew \Exception('Creation of bucket "'.$this->bucket.'" failed. '.$e->getMessage());
thrownew \Exception('Creation of bucket "' . $this->bucket . '" failed. ' . $e->getMessage());

return;
} catch (S3Exception $e) {
try {
$logger->info('Bucket key for "'.$this->bucket.'" is not set - adding it.', ['app' => 'objectstore']);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
$logger->info('Bucket key for "'.$this->bucket.'" is not set - adding it.', ['app' => 'objectstore']);
$logger->info('Bucket key for "' . $this->bucket . '" is not set - adding it.', ['app' => 'objectstore']);

'level' => ILogger::DEBUG,
'app' => 'objectstore',
]);
throw new \Exception('Putting configured bucket key to "'.$this->bucket.'" failed. '.$e->getMessage());

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
thrownew \Exception('Putting configured bucket key to "'.$this->bucket.'" failed. '.$e->getMessage());
thrownew \Exception('Putting configured bucket key to "' . $this->bucket . '" failed. ' . $e->getMessage());


$scheme = (isset($this->params['use_ssl']) && $this->params['use_ssl'] === false) ? 'http' : 'https';
$base_url = $scheme . '://' . $this->params['hostname'] . ':' . $this->params['port'] . '/';
$base_url = $scheme.'://'.$this->params['hostname'].':'.$this->params['port'].'/';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same code style issue.

$logger = \OC::$server->getLogger();
$logger->debug('Bucket "' . $this->bucket . '" This bucket name is not dns compatible, it may contain invalid characters.',
['app' => 'objectstore']);
$logger->debug('Bucket "'.$this->bucket.'" This bucket name is not dns compatible, it may contain invalid characters.',

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same code style issue.

<?php
/**
* @copyright Copyright (c) 2017 Robin Appelman <robin@icewind.nl>
*

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

@MorrisJobkeMorrisJobke left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mostly code style nitpicks. Beside that it looks good 👍

@tsdicloud

Copy link
Copy Markdown
ContributorAuthor

Thanks for all the code hints. We will change this soon. But we found today a conceptual issue with bucket keys and default keys that may are used as a replacement. Also, we don´t need to send kms:id on read. Thus, we also need a little re-work of functionality and handling. Update will follow,.

This was referenced May 20, 2021
@blizzzblizzz mentioned this pull request Jun 2, 2021
57 tasks
@MorrisJobkeMorrisJobke mentioned this pull request Jun 10, 2021
59 tasks
@blizzzblizzz mentioned this pull request Jun 16, 2021
45 tasks
@blizzz

Copy link
Copy Markdown
Member

Moving to 23 as we're in freeze and the last beta is just ahead

@juliusknorr

Copy link
Copy Markdown
Member

@tsdicloud I took over your changes from the nextmcloud repo and rebase them since the multipart upload optimization was already merged in #27877. Let's continue over there.

@juliusknorr

Copy link
Copy Markdown
Member

New pull request is in #28601

@tsdicloud
tsdicloud deleted the s3ssekms branch July 6, 2023 08:34
Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants

@tsdicloud@blizzz@juliusknorr@MorrisJobke@ChristophWurst@kesselb