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

Allow multiple clientAuthentication methods in MSK (IAM + TLS) #22041

Merged
merged 15 commits into from
Sep 15, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 31 additions & 2 deletions packages/@aws-cdk/aws-msk/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,6 @@ const cluster = msk.Cluster.fromClusterArn(this, 'Cluster',

[MSK supports](https://docs.aws.amazon.com/msk/latest/developerguide/kafka_apis_iam.html) the following authentication mechanisms.

> Only one authentication method can be enabled.

gmuslia marked this conversation as resolved.
Show resolved Hide resolved
### TLS

To enable client authentication with TLS set the `certificateAuthorityArns` property to reference your ACM Private CA. [More info on Private CAs.](https://docs.aws.amazon.com/msk/latest/developerguide/msk-authentication.html)
Expand Down Expand Up @@ -151,6 +149,37 @@ const cluster = new msk.Cluster(this, 'cluster', {
});
```


### SASL/IAM + TLS

Enable client authentication with [IAM](https://docs.aws.amazon.com/msk/latest/developerguide/iam-access-control.html)
as well as enable client authentication with TLS by setting the `certificateAuthorityArns` property to reference your ACM Private CA. [More info on Private CAs.](https://docs.aws.amazon.com/msk/latest/developerguide/msk-authentication.html)

```ts
import * as acmpca from '@aws-cdk/aws-acmpca';

declare const vpc: ec2.Vpc;
const cluster = new msk.Cluster(this, 'Cluster', {
clusterName: 'myCluster',
kafkaVersion: msk.KafkaVersion.V2_8_1,
vpc,
encryptionInTransit: {
clientBroker: msk.ClientBrokerEncryption.TLS,
},
clientAuthentication: msk.ClientAuthentication.saslTls({
iam: true,
certificateAuthorities: [
acmpca.CertificateAuthority.fromCertificateAuthorityArn(
this,
'CertificateAuthority',
'arn:aws:acm-pca:us-west-2:1234567890:certificate-authority/11111111-1111-1111-1111-111111111111',
gmuslia marked this conversation as resolved.
Show resolved Hide resolved
),
],
}),
});
```


## Logging

You can deliver Apache Kafka broker logs to one or more of the following destination types:
Expand Down
22 changes: 22 additions & 0 deletions packages/@aws-cdk/aws-msk/lib/cluster.ts
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,11 @@ export interface TlsAuthProps {
readonly certificateAuthorities?: acmpca.ICertificateAuthority[];
}

/**
* SASL + TLS authentication properties
*/
export interface SaslTlsAuthProps extends SaslAuthProps, TlsAuthProps { }

/**
* Configuration properties for client authentication.
*/
Expand All @@ -361,6 +366,13 @@ export class ClientAuthentication {
return new ClientAuthentication(undefined, props);
}

/**
* SASL + TLS authentication
*/
public static saslTls(saslTlsProps: SaslTlsAuthProps): ClientAuthentication {
return new ClientAuthentication(saslTlsProps, saslTlsProps);
}

/**
* @param saslProps - properties for SASL authentication
* @param tlsProps - properties for TLS authentication
Expand Down Expand Up @@ -616,6 +628,16 @@ export class Cluster extends ClusterBase {
clientAuthentication = {
sasl: { iam: { enabled: props.clientAuthentication.saslProps.iam } },
};
if (props.clientAuthentication?.tlsProps) {
clientAuthentication = {
sasl: { iam: { enabled: props.clientAuthentication.saslProps.iam } },
tls: {
certificateAuthorityArnList: props.clientAuthentication?.tlsProps?.certificateAuthorities?.map(
(ca) => ca.certificateAuthorityArn,
),
},
};
gmuslia marked this conversation as resolved.
Show resolved Hide resolved
}
} else if (props.clientAuthentication?.saslProps?.scram) {
clientAuthentication = {
sasl: {
Expand Down
Loading