Amazon MSK Mutual TLS authentication
Amazon MSK Mutual TLS authentication
Estimated time to complete 20-30 minutes.
Overview
The Zilla Plus for Amazon MSK Secure Public Access proxy lets authorized Kafka clients connect, publish messages and subscribe to topics in your Amazon MSK cluster via the internet.
In this guide we will deploy the Zilla Plus for Amazon MSK Secure Public Access proxy and showcase globally trusted public internet connectivity to an MSK cluster from a Kafka client, using the custom wildcard domain *.example.aklivity.io
. Kafka clients will use TLS client certificates to verify trusted client identity.
AWS services used
Service | Required | Usage | Quota |
---|---|---|---|
Resource Groups and Tagging | Yes | Startup only | None |
Secrets Manager | Yes | Startup only | Not reached |
Certificate Manager | No Private key and certificate can be inline in Secrets Manager instead | Startup only | Not reached |
Private Certificate Manager | No Private key and certificate can be inline in Secrets Manager instead | Startup only | Not reached |
Default AWS Service Quotas are recommended.
Prerequisites
Before setting up internet access to your MSK Cluster, you will need the following:
- an MSK Cluster configured for TLS encrypted client access and TLS client authentication
- an VPC security group for Zilla proxies
- an IAM security role for Zilla proxies
- subscription to Zilla Plus for Amazon MSK via AWS Marketplace
- permission to modify global DNS records for a custom domain
- permission to generate client certificates signed by a private certificate authority
Tips
Check out the Troubleshooting guide if you run into any issues.
Create Certificate Authority for mTLS
This creates a new private certificate authority in ACM.
Follow the Create Certificate Authority to create a private certificate authority to verify TLS client authentication.
- Distinguished NameCommon Name (CN)
Mutual Authentication CA
Create the MSK Cluster
This creates your MSK cluster in preparation for secure access via the internet.
An MSK cluster is needed for secure remote access via the internet. You can skip this step if you have already created an MSK cluster with equivalent configuration.
Follow the Create MSK Cluster guide to setup the a new MSK cluster. We will use the below resource names to reference the AWS resources needed in this guide.
- Cluster Name:
my-msk-cluster
- Access control methods:
TLS client certificates
- AWS Private CAs:
Mutual Authentication CA
- VPC:
my-msk-cluster-vpc
- Subnet:
my-msk-cluster-subnet-*
- Route tables:
my-msk-cluster-rtb-*
- Internet gateway:
my-msk-cluster-igw
Create Client Certificate for mTLS
This allows an authorized Kafka client to connect directly to your MSK cluster with Mutual TLS (mTLS). Follow the Create Client Certificate to create a private certificate authority.
You can create additional client certificates for each different authorized client identity that will connect via the internet to your Zilla proxy deployment.
Update the security settings of your MSK cluster. Update your Access control methods to include
Common Name: client-1
Private Certificate Authority: Mutual Authentication CA
Create the Zilla proxy security group
This creates your Zilla proxy security group to allow Kafka clients and SSH access.
A VPC security group is needed for the Zilla proxies when they are launched.
Follow the Create Security Group wizard with the following parameters and defaults. This creates your Zilla proxy security group to allow Kafka clients and SSH access.
- VPC:
my-msk-cluster-vpc
- Name:
my-zilla-proxy-sg
- Description:
Kafka clients and SSH access
- Add Inbound Rule
- Type:
CUSTOM TCP
- Port Range:
9094
- Source type:
Anywhere-IPv4
- Type:
- Add Inbound Rule
- Type:
SSH
- Source type:
My IP
- Type:
- Add Outbound Rule (if not exists)
- Type:
All traffic
- Destination:
Anywhere-IPv4
- Type:
- Create the Security Group
Check your network settings
Your IP may be different when you SSH into the EC2 instance. VPNs and other networking infrastructure may cause the My IP
inbound rule to fail. Instead, you can use one of the other ways AWS provides to execute commands in an EC2 instance.
Update the default security group rules
This allows the Zilla proxies to communicate with your MSK cluster.
Navigate to the VPC Management Console Security Groups table.
Check your selected region
Make sure you have selected the desired region, ex: US East (N. Virginia) us-east-1
.
Filter the security groups by selecting a VPC
and select the default
security group.
- VPC:
my-msk-cluster-vpc
- Security Group:
default
Add a Custom TCP Rule
Add this Inbound Rule to allow the Zilla proxies to communicate with the MSK cluster.
- Type:
Custom TCP
- Port Range:
9094
- Source type:
Custom
- Source:
my-zilla-proxy-sg
Create the Zilla proxy IAM security role
This creates an IAM security role to enable the required AWS services for the Zilla proxies.
Follow the Create IAM Role guide to create an IAM security role with the following parameters:
aklivity-zilla-proxy
AWSCertificateManagerReadOnly
AWSCertificateManagerPrivateCAReadOnly
ResourceGroupsandTagEditorReadOnlyAccess
AmazonSSMManagedInstanceCore
IAM role Inline Policies
This creates an IAM security role to enable the required AWS services for the Zilla proxies.
MSKProxySecretsManagerRead
{
"Version": "2012-10-17",
"Statement": [
{
"Sid": "VisualEditor0",
"Effect": "Allow",
"Action": [
"acm-pca:GetCertificate",
"acm-pca:GetCertificateAuthorityCertificate",
"acm-pca:DescribeCertificateAuthority",
"tag:GetResources",
"secretsmanager:GetSecretValue",
"secretsmanager:DescribeSecret"
],
"Resource": [
"arn:aws:secretsmanager:*:*:secret:wildcard.example.aklivity.io*",
"arn:aws:secretsmanager:*:*:secret:client-*",
"arn:aws:acm-pca:*:*:certificate-authority*"
]
}
]
}
If you used a different names for your certificate resources.
This example pattern uses resources with names including wildcard.example.aklivity.io
, client-
, certificate-authority
etc. Replace them with the names you used or use wildcard resource selectors.
Subscribe via AWS Marketplace
The Zilla Plus for Amazon MSK is available through the AWS Marketplace. You can skip this step if you have already subscribed to Zilla Plus for Amazon MSK via AWS Marketplace.
To get started, visit the Proxy's Marketplace Product Page and Subscribe
to the offering. You should now see Zilla Plus for Amazon MSK
listed in your AWS Marketplace subscriptions.
Create the Public TLS Server Certificate
We need a Public TLS Server Certificate for your custom DNS wildcard domain that can be trusted by a Kafka Client from anywhere.
Follow the Create Server Certificate (LetsEncrypt) guide to create a new TLS Server Certificate. Use your own custom wildcard DNS domain in place of the example wildcard domain *.example.aklivity.io
.
Info
Note the server certificate secret ARN as we will need to reference it from the Secure Public Access CloudFormation template.
Deploy the Zilla Plus Secure Public Access Proxy
This initiates deployment of the Zilla Plus for Amazon MSK stack via CloudFormation.
Navigate to your AWS Marketplace subscriptions and select Zilla Plus for Amazon MSK
to show the manage subscription page.
- From the
Agreement
section >Actions
menu > selectLaunch CloudFormation stack
- Select the
Secure Public Access (mTLS)
fulfillment option - Make sure you have selected the desired region selected, such as
us-east-1
- Click
Continue to Launch
- Choose the action
Launch CloudFormation
- Choose the action
Click Launch
to complete the Create stack
wizard with the following details:
Step 1. Create Stack
- Prepare template:
Template is ready
- Specify template:
Amazon S3 URL
- Amazon S3 URL:
(auto-filled)
- Amazon S3 URL:
Step 2. Specify stack details
my-zilla-proxy
Parameters:
- Network Configuration
- VPC:
my-msk-cluster-vpc
- Subnets:
my-msk-cluster-1a
my-msk-cluster-1b
my-msk-cluster-1c
- VPC:
- MSK Configuration
- Wildcard DNS pattern:
*.aklivity.[...].amazonaws.com
*1 - Port number:
9094
- Private Certificate Authority:
<private certificate authority ARN>
*2
- Wildcard DNS pattern:
- Secure Public Access Configuration
- Instance count:
2
- Instance type:
t3.small
*3 - Role:
aklivity-zilla-proxy
- Security Groups:
my-zilla-proxy
- Secrets Manager Secret ARN:
<TLS certificate private key secret ARN>
*3 - Public Wildcard DNS:
*.example.aklivity.io
*4 - Public Port:
9094
- Public Certificate Authority:
<private certificate authority ARN>
*2 - Key pair for SSH access:
my-key-pair
*5
- Instance count:
- *Configuration Reference
- Follow the Lookup MSK Server Names guide to discover the wildcard DNS pattern for your MSK cluster.
- These can be the same Private Certificate Authority that authorizes existing clients connecting directly to MSK, allowing existing trusted client certificates to connect via Zilla proxy.
- Consider the network throughput characteristics of the AWS instance type as that will impact the upper bound on network performance.
- Replace with your own custom wildcard DNS pattern.
- Follow the Create Key Pair guide to create a new key pair used when launching EC2 instances with SSH access.
Step 3. Configure stack options: (use defaults)
Step 4. Review
Confirm the stack details are correct and Submit
to start the CloudFormation deploy.
Info
When your Zilla proxy is ready, the CloudFormation console will show CREATE_COMPLETE
for the newly created stack.
Verify Zilla proxy Service
This checks that the services and networking were properly configured.
Navigate to the EC2 running instances dashboard.
Check your selected region
Make sure you have selected the desired region, ex: US East (N. Virginia) us-east-1
.
Select either of the Zilla proxies launched by the CloudFormation template to show the details.
Info
They each have an IAM Role name starting with aklivity-zilla-proxy
.
Find the Public IPv4 Address
and then SSH into the instance.
ssh -i ~/.ssh/<key-pair.cer> ec2-user@<instance-public-ip-address>
After logging in via SSH, check the status of the zilla-plus
system service.
Verify that the zilla-plus
service is active and logging output similar to that shown below.
systemctl status zilla-plus.service
zilla-plus.service - Zilla Plus
Loaded: loaded (/etc/systemd/system/zilla-plus.service; enabled; vendor preset: disabled)
Active: active (running) since...
Check for the active ports with netstat
.
netstat -ntlp
tcp6 0 0 :::9092 :::* LISTEN 1726/.zpm/image/bin
You can get an stdout dump of the zilla-plus.service
using journalctl
.
journalctl -e -u zilla-plus.service | tee -a /tmp/zilla.log
systemd[1]: Started zilla-plus.service - Zilla Plus.
...
All output from cloud-init is captured by default to /var/log/cloud-init-output.log
. There shouldn't be any errors in this log.
cat /var/log/cloud-init-output.log
Cloud-init v. 22.2.2 running 'init'...
Check the networking of the Zilla proxy instances to MSK.
Verify that the instance can resolve the private Route53 DNS address.
nslookup *.aklivity.[...].amazonaws.com
Server: ***
Address: ***
Non-authoritative answer:
Name: *.aklivity.[...].amazonaws.com
Address: ***
Check the communication over necessary ports with netcat
.
nc -vz *.aklivity.[...].amazonaws.com 9094
Connection to *.aklivity.[...].amazonaws.com port 9094 [tcp/italk] succeeded!
Repeat these steps for each of the other Zilla proxies launched by the CloudFormation template if necessary.
Configure Global DNS
This ensures that any new Kafka brokers added to the cluster can still be reached via the Zilla proxy.
When using a wildcard DNS name for your own domain, such as *.example.aklivity.io
then the DNS entries are setup in your DNS provider.
Navigate to the CloudFormation console. Then select the my-zilla-proxy
stack to show the details.
In the stack Outputs
tab, find the public DNS name of the NetworkLoadBalancer
. You need to create a CNAME
record mapping your public DNS wildcard pattern to the public DNS name of the Network Load Balancer.
Info
You might prefer to use an Elastic IP address for each NLB public subnet, providing DNS targets for your CNAME
record that can remain stable even after restarting the stack.
For testing purposes you can edit your local /etc/hosts
file instead of updating your DNS provider.
Verify Kafka Client Connectivity
To verify that we have successfully enabled public internet connectivity to our Kafka cluster from the local development environment, we will use a generic Kafka client to create a topic, publish messages and then subscribe to receive these messages from our Kafka cluster via the public internet.
Install the Kafka Client
First, we must install a Java runtime that can be used by the Kafka client.
sudo yum install java-1.8.0
Now we are ready to install the Kafka client:
wget https://archive.apache.org/dist/kafka/2.8.0/kafka_2.13-2.8.0.tgz
tar -xzf kafka_2.13-2.8.0.tgz
cd kafka_2.13-2.8.0
Tips
We use a generic Kafka client here, however the setup for any Kafka client, including KaDeck, Conduktor, and akhq.io will be largely similar. With the Zilla proxy you can use these GUI Kafka clients to configure and monitor your Kafka applications, clusters and streams.
Configure the Kafka Client
With the Kaka client now installed we are ready to configure it and point it at the Zilla proxy.
We need to import the trusted client certificate and corresponding private key into the local key store used by the Kafka client when connecting to the Zilla proxy.
openssl pkcs12 -export -in client-1.cert -inkey client-1.pkcs8.key.pem -out client-1.p12 -name client-1
keytool -importkeystore -destkeystore /tmp/kafka.client.keystore.jks -deststorepass generated -srckeystore client-1.p12 -srcstoretype PKCS12 -srcstorepass generated -alias client-1
In this example, we are importing a private key and certificate with Common Name
client-1
signed by a private certificate authority. First the private key and signed certificate are converted into a p12
formatted key store.
Then the key store is converted to /tmp/kafka.client.keystore.jks
in JKS
format. When prompted, use a consistent password for each command. We use the password generated
to illustrate these steps.
The Zilla proxy relies on TLS so we need to create a file called client.properties
that tells the Kafka client to use SSL as the security protocol and to specify the key store containing authorized client certificates.
security.protocol=SSL
ssl.keystore.location=/tmp/kafka.client.keystore.jks
ssl.keystore.password=generated
The password configured in client.properties
should match the password used in the commands above used to create the key store.
Tips
As the TLS certificate is signed by a globally trusted certificate authority, there is no need to configure your Kafka client to override the trusted certificate authorities.
Test the Kafka Client
This verifies internet connectivity to your MSK cluster via Zilla Plus for Amazon MSK.
We can now verify that the Kafka client can successfully communicate with your MSK cluster via the internet from your local development environment to create a topic, then publish and subscribe to the same topic.
If using the wildcard DNS pattern *.example.aklivity.io
, then we use the following as TLS bootstrap server names for the Kafka client:
b-1.example.aklivity.io:9094,b-2.example.aklivity.io:9094,b-3.example.aklivity.io:9094
Warning
Replace these TLS bootstrap server names accordingly for your own custom wildcard DNS pattern.
Create a Topic
Use the Kafka client to create a topic called zilla-proxy-test
, replacing <tls-bootstrap-server-names>
in the command below with the TLS proxy names of your Zilla proxy:
bin/kafka-topics.sh --create --topic zilla-proxy-test --partitions 3 --replication-factor 3 --command-config client.properties --bootstrap-server <tls-bootstrap-server-names>
A quick summary of what just happened
- The Kafka client with access to the public internet issued a request to create a new topic
- This request was directed to the internet-facing Network Load Balancer
- The Network Load Balancer forwarded the request to the Zilla proxy
- The Zilla proxy verified the client identity of the Kafka client
- The Zilla proxy selected a matching client certificate to propagate client identity
- The Zilla proxy routed the request to the appropriate MSK broker
- The topic was created in the MSK broker
- Public access was verified, authorized by trusted client certificate
Publish messages
Publish two messages to the newly created topic via the following producer command:
bin/kafka-console-producer.sh --topic zilla-proxy-test --producer.config client.properties --broker-list <tls-bootstrap-server-names>
A prompt will appear for you to type in the messages:
>This is my first event
>This is my second event
Receive messages
Read these messages back via the following consumer command:
bin/kafka-console-consumer.sh --topic zilla-proxy-test --from-beginning --consumer.config client.properties --bootstrap-server <tls-bootstrap-server-names>
You should see the This is my first event
and This is my second event
messages.
This is my first event
This is my second event
Conclusion
You have successfully deployed the Zilla Plus for Amazon MSK Secure Public Access. Instructions on how to Monitor and Upgrade your Zilla proxy can be found in the managing a cloudformation stack section.