-
Notifications
You must be signed in to change notification settings - Fork 820
Adds support to S3 server side encryption using AWS KMS #3651
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
Conversation
2749d74
to
eaf5f8a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for working on this! I haven't review it properly. Just leaving a comment about a little thing I've noticed and then will do a proper review.
1df3429
to
7e6f625
Compare
Manual tests performed
|
0411e31
to
46fcdc0
Compare
b9c7f82
to
683c61d
Compare
Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com>
683c61d
to
0925ad6
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job @lucasvmiguel and sorry for the extremely delay in the review! Overall LGTM, just left few comments to polish it a bit before merging. Thanks!
pkg/chunk/aws/s3_storage_client.go
Outdated
@@ -100,7 +108,10 @@ func (cfg *S3Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { | |||
f.StringVar(&cfg.AccessKeyID, prefix+"s3.access-key-id", "", "AWS Access Key ID") | |||
f.StringVar(&cfg.SecretAccessKey, prefix+"s3.secret-access-key", "", "AWS Secret Access Key") | |||
f.BoolVar(&cfg.Insecure, prefix+"s3.insecure", false, "Disable https on s3 connection.") | |||
f.BoolVar(&cfg.SSEEncryption, prefix+"s3.sse-encryption", false, "Enable AES256 AWS Server Side Encryption") | |||
f.BoolVar(&cfg.SSEEncryption, prefix+"s3.sse-encryption", false, "Enable AWS Server Side Encryption [Deprecated: Use sse-config instead. if s3.sse-encryption is enabled, it assumes sse-config SSE-S3 type]") | |||
f.StringVar(&cfg.SSEConfig.Type, prefix+"s3.sse-config.type", "", "Enable AWS Server Side Encryption. Only SSE-S3 and SSE-KMS are supported") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're used to define RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet)
on the receiver config. I would suggest you to do the same on SSEConfig
, passing prefix+"s3.sse."
as prefix to SSEConfig.RegisterFlagsWithPrefix()
.
pkg/chunk/aws/s3_storage_client.go
Outdated
@@ -100,7 +108,10 @@ func (cfg *S3Config) RegisterFlagsWithPrefix(prefix string, f *flag.FlagSet) { | |||
f.StringVar(&cfg.AccessKeyID, prefix+"s3.access-key-id", "", "AWS Access Key ID") | |||
f.StringVar(&cfg.SecretAccessKey, prefix+"s3.secret-access-key", "", "AWS Secret Access Key") | |||
f.BoolVar(&cfg.Insecure, prefix+"s3.insecure", false, "Disable https on s3 connection.") | |||
f.BoolVar(&cfg.SSEEncryption, prefix+"s3.sse-encryption", false, "Enable AES256 AWS Server Side Encryption") | |||
f.BoolVar(&cfg.SSEEncryption, prefix+"s3.sse-encryption", false, "Enable AWS Server Side Encryption [Deprecated: Use sse-config instead. if s3.sse-encryption is enabled, it assumes sse-config SSE-S3 type]") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please add also a // TODO Remove in Cortex 1.9.0
(because we guarantee deprecated config to be removed at least after 2 minor releases).
pkg/chunk/aws/sse_config.go
Outdated
) | ||
|
||
// SSEEncryptionConfig configures server side encryption (SSE) | ||
type SSEEncryptionConfig struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why do we need this when we already have SSEConfig
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
SSEConfig
is the struct responsible to receive the config from the CLI or a config file. After SSEConfig
is filled with the values provided by the user, a SSEEncryptionConfig
struct will be created to be worked inside the application. In the end, SSEEncryptionConfig
will have different values than SSEConfig
.
KMSKeyID *string | ||
KMSEncryptionContext *string |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a big fan of pointers in config structs. You can achieve the same assuming empty string means not configured (which should be fine in this context).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AWS lib uses string pointers several times in there. Removing string pointers from sse_config.go (SSEEncryptionConfig)
means that I will have to treat that on the file s3_storage_client.go
, which has more logic that should have.
pkg/chunk/aws/s3_storage_client.go
Outdated
@@ -72,6 +72,7 @@ type S3Config struct { | |||
SSEEncryption bool `yaml:"sse_encryption"` | |||
HTTPConfig HTTPConfig `yaml:"http_config"` | |||
SignatureVersion string `yaml:"signature_version"` | |||
SSEConfig SSEConfig `yaml:"sse_config"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In recent times we stopped appending _config
to sub-config structs cause it's a bit redundant. I would remove it from here too.
SSEConfig SSEConfig `yaml:"sse_config"` | |
SSEConfig SSEConfig `yaml:"sse"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we decide to not use _config
, we won't be compatible with Thanos config.
I don't mind to remove _config
, I just thought that we wanted the config interface exactly the same as Thanos. (to not "break" any future migration)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not 1:1 compatible with Thanos even in the blocks storage. It's perfectly fine. We just wanna let configure the same things, so that when we'll add KMS support to blocks storage too we can keep the same config struct.
CHANGELOG.md
Outdated
@@ -2,6 +2,11 @@ | |||
|
|||
## master / unreleased | |||
|
|||
|
|||
* [FEATURE] Adds support to S3 server side encryption using KMS. The following config fields have been added. #3651 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're used to group CHANGELOG entries together by type. Please move this entry below, under the group of [FEATURE]
.
Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com>
Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com>
CHANGELOG.md
Outdated
@@ -24,13 +24,17 @@ | |||
* `-cluster.peer-timeout` in favor of `-alertmanager.cluster.peer-timeout` | |||
* [CHANGE] Blocks storage: the default value of `-blocks-storage.bucket-store.sync-interval` has been changed from `5m` to `15m`. #3724 | |||
* [FEATURE] Querier: Queries can be federated across multiple tenants. The tenants IDs involved need to be specified separated by a `|` character in the `X-Scope-OrgID` request header. This is an experimental feature, which can be enabled by setting `-tenant-federation.enabled=true` on all Cortex services. #3250 | |||
* [ENHANCEMENT] Allow specifying JAEGER_ENDPOINT instead of sampling server or local agent port. #3682 | |||
* [FEATURE] Adds support to S3 server side encryption using KMS. Deprecated `<prefix>.s3.sse-encryption`, you should use the following config fields that have been added. #3651 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've just released 1.7.0-rc.0
. Could you rebase master
and move the CHANGELOG entry under the master / unreleased
section, please?
CHANGELOG.md
Outdated
* [FEATURE] Alertmanager: introduced the experimental option `-alertmanager.sharding-enabled` to shard tenants across multiple Alertmanager instances. This feature is still under heavy development and its usage is discouraged. The following new metrics are exported by the Alertmanager: #3664 | ||
* `cortex_alertmanager_ring_check_errors_total` | ||
* `cortex_alertmanager_sync_configs_total` | ||
* `cortex_alertmanager_sync_configs_failed_total` | ||
* `cortex_alertmanager_tenants_discovered` | ||
* `cortex_alertmanager_tenants_owned` | ||
* [ENHANCEMENT] Allow specifying JAEGER_ENDPOINT instead of sampling server or local agent port. #3682 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We've just released 1.7.0-rc.0
. Could you rebase master
and move the CHANGELOG entry under the master / unreleased
section, please?
Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com>
Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com>
Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the follow up! We're very close! I left last comments.
Please mention that S3 server-side encryption is experimental in docs/configuration/v1-guarantees.md
(there's a list of experimental features). This will allow us to introduce config breaking changes in the near future if we find out any issue (or improvement).
CHANGELOG.md
Outdated
@@ -2,6 +2,10 @@ | |||
|
|||
## master / unreleased | |||
|
|||
* [FEATURE] Adds support to S3 server side encryption using KMS. Deprecated `<prefix>.s3.sse-encryption`, you should use the following config fields that have been added. #3651 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
* [FEATURE] Adds support to S3 server side encryption using KMS. Deprecated `<prefix>.s3.sse-encryption`, you should use the following config fields that have been added. #3651 | |
* [FEATURE] Adds support to S3 server side encryption using KMS. Deprecated `-<prefix>.s3.sse-encryption`, you should use the following CLI flags that have been added. #3651 |
CHANGELOG.md
Outdated
@@ -2,6 +2,10 @@ | |||
|
|||
## master / unreleased | |||
|
|||
* [FEATURE] Adds support to S3 server side encryption using KMS. Deprecated `<prefix>.s3.sse-encryption`, you should use the following config fields that have been added. #3651 | |||
- `<prefix>.s3.sse.type` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `<prefix>.s3.sse.type` | |
- `-<prefix>.s3.sse.type` |
CHANGELOG.md
Outdated
@@ -2,6 +2,10 @@ | |||
|
|||
## master / unreleased | |||
|
|||
* [FEATURE] Adds support to S3 server side encryption using KMS. Deprecated `<prefix>.s3.sse-encryption`, you should use the following config fields that have been added. #3651 | |||
- `<prefix>.s3.sse.type` | |||
- `<prefix>.s3.sse.kms-key-id` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `<prefix>.s3.sse.kms-key-id` | |
- `-<prefix>.s3.sse.kms-key-id` |
CHANGELOG.md
Outdated
* [FEATURE] Adds support to S3 server side encryption using KMS. Deprecated `<prefix>.s3.sse-encryption`, you should use the following config fields that have been added. #3651 | ||
- `<prefix>.s3.sse.type` | ||
- `<prefix>.s3.sse.kms-key-id` | ||
- `<prefix>.s3.sse.kms-encryption-context` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- `<prefix>.s3.sse.kms-encryption-context` | |
- `-<prefix>.s3.sse.kms-encryption-context` |
pkg/chunk/aws/sse_config.go
Outdated
type SSEConfig struct { | ||
Type string `yaml:"type"` | ||
KMSKeyID string `yaml:"kms_key_id"` | ||
KMSEncryptionContext chunk.Tags `yaml:"kms_encryption_context"` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should use chunk.Tags
here. I would simplify it just taking in input the context json as a string
. Moreover, I would clarify in the CLI flag description that it expects a JSON as a string.
pkg/chunk/aws/sse_config_test.go
Outdated
}, | ||
}, | ||
{ | ||
name: "Test invalid SEE type", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name: "Test invalid SEE type", | |
name: "Test invalid SSE type", |
}, | ||
}, | ||
{ | ||
name: "Test SSE encryption with SSEKMS type with context", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This test is duplicated from above.
Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the follow up! I have a last question about context parsing.
Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you! Please take a look at final comments before merging.
pkg/chunk/aws/sse_config.go
Outdated
} | ||
|
||
// NewSSEParsedConfig creates a struct to configure server side encryption (SSE) | ||
func NewSSEParsedConfig(sseType string, kmsKeyID string, kmsEncryptionContext string) (*SSEParsedConfig, error) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit: Perhaps this should have been a method on SSEConfig
or take it as a parameter?
func TestNewSSEParsedConfig(t *testing.T) { | ||
kmsKeyID := "test" | ||
kmsEncryptionContext := `{"a": "bc", "b": "cd"}` | ||
parsedKMSEncryptionContext := "eyJhIjoiYmMiLCJiIjoiY2QifQ==" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
parsedKMSEncryptionContext := "eyJhIjoiYmMiLCJiIjoiY2QifQ==" | |
parsedKMSEncryptionContext = base64.StdEncoding.EncodeToString([]byte(`{"a":"bc","b":"cd"}`)) // compact form of kmsEncryptionContext |
Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com>
Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com>
…t/cortex#3651) * Adds support to S3 server side encryption using AWS KMS Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com> * refatored based on PR review Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com> * small refactor Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com> * rebased master Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com> * rebased master correctly Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com> * added new line Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com> * refactored Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com> * reordered changelog Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com> * refactored NewSSEParsedConfig Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com> * removed unused struct Signed-off-by: Lucas Miguel <lucasvieira.dev@gmail.com> Co-authored-by: Lucas Vieira <lucas.vieira@ASSUMESEEQUITE.workdayinternal.com>
What this PR does: Adds support to S3 server side encryption using KMS.
Which issue(s) this PR fixes:
Fixes #3437
Checklist
CHANGELOG.md
updated - the order of entries should be[CHANGE]
,[FEATURE]
,[ENHANCEMENT]
,[BUGFIX]
s3.sse-encryption=true
)sse-config.type=SSE-S3
)sse-config.type=SSE-KMS
)TIP: Just to help future folks that want to use this feature (because I lost sometime to understand how I'd fetch the data back from the S3 bucket). You basically have to create the following IAM policy and attach to an IAM role.