Skip to content

Conversation

bdonlan
Copy link
Contributor

@bdonlan bdonlan commented Nov 8, 2017

The current KMS MKP constructors use legacy (@deprecated) KMS client
constructors, and are likely to break at some point in the future. In addition,
they also mutate the client that is passed in, and have an unfortunate
combinatorial explosion of argument types.

This change introduces a new builder API for constructing KMS MKPs, and
deprecates the old one. In addition, it adds support for decrypting KMS keys
from multiple regions with the same MKP, bringing us to feature parity with the
Python SDK.

For now, the semantics of code using the old constructors is unchanged, but
it's likely that we'll want to remove these constructors the next time we make
a breaking change to our APIs.

The current KMS MKP constructors use legacy (@deprecated) KMS client
constructors, and are likely to break at some point in the future. In addition,
they also mutate the client that is passed in, and have an unfortunate
combinatorial explosion of argument types.

This change introduces a new builder API for constructing KMS MKPs, and
deprecates the old one. In addition, it adds support for decrypting KMS keys
from multiple regions with the same MKP, bringing us to feature parity with the
Python SDK.

For now, the semantics of code using the old constructors is unchanged, but
it's likely that we'll want to remove these constructors the next time we make
a breaking change to our APIs.
@bdonlan
Copy link
Contributor Author

bdonlan commented Nov 8, 2017

Note that this change preserves the behavior that new KmsMasterKeyProvider() binds to the us-west-2 region, ignoring environment variable/system property/etc default region selection. This is why the default constructor is marked deprecated in this change.

This failed in cases where the default region isn't configured anywhere (e.g.
in our travis builds...)
This was referenced Nov 8, 2017
}

if (defaultRegion_ == null) {
throw new AwsCryptoException("Can't use non-ARN key identifiers or aliases when no default region is set");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should probably complain on build() actually - since the list of key IDs for encrypt can't change after construction using the builder, and this isn't relevant on decrypt.

Copy link
Member

Choose a reason for hiding this comment

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

++

AWSKMS getClient(String regionName);
}

public static class Builder implements Cloneable {
Copy link
Contributor

Choose a reason for hiding this comment

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

I generally like making internal Builders final.

* @param tokens
* @return
*/
public Builder withGrantTokens(List<String> tokens) {
Copy link
Contributor

Choose a reason for hiding this comment

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

GrantTokens are fundamentally regional and should be treated that way. There is no value (and some negative) to passing them into the wrong region.

*/
@Deprecated
@Override
public void setGrantTokens(final List<String> grantTokens) {
Copy link
Contributor

Choose a reason for hiding this comment

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

As noted elsewhere, GrantTokens are regional things.

private String defaultRegion_ = null;
private RegionalClientSupplier regionalClientSupplier_ = null;
private AWSKMSClientBuilder templateBuilder_ = null;
private List<String> keyIds_ = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be copied when .clone() is invoked. A shallow copy here will likely cause problems.

public static class Builder implements Cloneable {
private String defaultRegion_ = null;
private RegionalClientSupplier regionalClientSupplier_ = null;
private AWSKMSClientBuilder templateBuilder_ = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be copied when .clone() is invoked. A shallow copy here will likely cause problems.

private RegionalClientSupplier regionalClientSupplier_ = null;
private AWSKMSClientBuilder templateBuilder_ = null;
private List<String> keyIds_ = new ArrayList<>();
private List<String> grantTokens_ = new ArrayList<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be copied when .clone() is invoked. A shallow copy here will likely cause problems.


package com.amazonaws.encryptionsdk.kms;

import javax.crypto.SecretKey;
Copy link
Member

Choose a reason for hiding this comment

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

Are these new imports used anywhere?

}

/**
* Provides a custom factory function that will vend KMS clients. This is provided for advanced use cases which
Copy link
Member

Choose a reason for hiding this comment

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

Hmm, I like this. This would be good to add to the Python client too; currently we just always create a standard client.

}

if (defaultRegion_ == null) {
throw new AwsCryptoException("Can't use non-ARN key identifiers or aliases when no default region is set");
Copy link
Member

Choose a reason for hiding this comment

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

++


public Builder clone() {
try {
Builder cloned = (Builder)super.clone();
Copy link
Contributor

Choose a reason for hiding this comment

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

NitPick: space after the cast

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants