-
Notifications
You must be signed in to change notification settings - Fork 25
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
Implement mTLS resources and configuration for Target Allocator server #284
Open
musa-asad
wants to merge
21
commits into
main
Choose a base branch
from
mtls
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
musa-asad
changed the title
Implement mTLS for Target Allocator server
Implement mTLS resources and configuration for Target Allocator server
Jan 20, 2025
musa-asad
commented
Jan 21, 2025
@@ -3,6 +3,7 @@ FROM golang:1.22 as builder | |||
|
|||
# set goproxy=direct | |||
ENV GOPROXY direct | |||
ENV GOINSECURE go.opencensus.io |
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.
Temporarily needs to be added since their certificate expired, which is breaking our workflow.
Suggested change
ENV GOINSECURE go.opencensus.io |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description of the issue
The Target Allocator server already used TLS to encrypt data, but it did not enforce mutual TLS (mTLS), meaning only the client validates the server’s certificate while the server itself wouldn't need to validate the client’s. Implementing mTLS would enhance security to only allow the CloudWatch Agent client to access the Target Allocator server.
Description of changes
Note
In mTLS, both parties hold a certificate containing their public key (signed by a Certificate Authority) and a secure, private key. During the TLS handshake, each side exchanges certificates to verify identities using the CA's public key. The client generates a random pre‐master secret, encrypts it with the server’s public key, and sends it to the server. The server then decrypts it with its private key. Both sides use this pre‐master secret—along with additional handshake information—to derive a master secret via a key derivation function. This master secret is then used to generate the actual symmetric encryption keys for the session.
ASCII Visualization
Important
Co-PRs: 1) aws-observability/helm-charts#163; 2) aws/amazon-cloudwatch-agent#1510
CertAndCAWatcher
to monitor and update file paths for the server certificate, server key, and client certificate authority (CA) and added unit test.NewTLSConfig
function and added unit test.License
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Tests
Resources
Volume Mounts
Volumes
mTLS
helm upgrade --install --debug amazon-cloudwatch-observability helm-charts/charts/amazon-cloudwatch-observability --set clusterName=<cluster_name> --set region=us-west-2 --namespace amazon-cloudwatch --create-namespace
with custom helm charts (Implement mTLS resources for CloudWatch Agent client aws-observability/helm-charts#163) and editedvalues.yaml
with a custom agent and prometheus configuration.target-allocator-service
.apt update && apt install -y curl openssl && cd /tmp
.openssl genrsa -out dummyCA.key 2048
.openssl req -x509 -new -nodes -key dummyCA.key -sha256 -days 365 -out dummyCA.crt -subj "/C=US/ST=Test/L=Test/O=Test/OU=Test/CN=DummyCA"
cd ..
curl -iv --cert /etc/amazon-cloudwatch-observability-agent-outbound-cert/tls.crt --key /etc/amazon-cloudwatch-observability-agent-outbound-cert/tls.key --cacert /etc/amazon-cloudwatch-observability-agent-cert/ca.crt https://cloudwatch-agent-w-prom-target-allocator-service:80/jobs
Successfully got
{"kubernetes-pod-jmx":{"_link":"/jobs/kubernetes-pod-jmx/targets"},"kubernetes-pod-fluentbit-plugin":{"_link":"/jobs/kubernetes-pod-fluentbit-plugin/targets"},"kube-metrics":{"_link":"/jobs/kube-metrics/targets"},"kubernetes-pod-appmesh-envoy":{"_link":"/jobs/kubernetes-pod-appmesh-envoy/targets"},"kubernetes-service-endpoints":{"_link":"/jobs/kubernetes-service-endpoints/targets"}}
curl -iv --cert /etc/amazon-cloudwatch-observability-agent-outbound-cert/tls.crt --key /etc/amazon-cloudwatch-observability-agent-outbound-cert/tls.key --cacert /tmp/dummyCA.crt https://cloudwatch-agent-w-prom-target-allocator-service:80/jobs
Successfully got
curl: (60) SSL certificate problem: unable to get local issuer certificate
kubectl debug -n kube-system aws-node-xxxxx -it --image=ubuntu:latest
apt update && apt install -y curl jq
curl -k https://<NODE_IP>:8443/jobs
Successfully got
SSL routines::tlsv13 alert certificate required, errno 0
. Also gotTLS handshake error from XXXX: remote error: tls: bad certificate
in Target Allocator pod logs. Runningcurl -k https://<NODE_IP>:8443/jobs
from another node worked on previous image, which shows mTLS is now enforced.CertWatcher
cat
on each certificate/key to confirm value changed.curl -iv --cert /etc/amazon-cloudwatch-observability-agent-outbound-cert/tls.crt --key /etc/amazon-cloudwatch-observability-agent-outbound-cert/tls.key --cacert /etc/amazon-cloudwatch-observability-agent-cert/ca.crt https://cloudwatch-agent-w-prom-target-allocator-service:80/jobs
Successfully got
{"kubernetes-pod-jmx":{"_link":"/jobs/kubernetes-pod-jmx/targets"},"kubernetes-pod-fluentbit-plugin":{"_link":"/jobs/kubernetes-pod-fluentbit-plugin/targets"},"kube-metrics":{"_link":"/jobs/kube-metrics/targets"},"kubernetes-pod-appmesh-envoy":{"_link":"/jobs/kubernetes-pod-appmesh-envoy/targets"},"kubernetes-service-endpoints":{"_link":"/jobs/kubernetes-service-endpoints/targets"}}
. Also debug logs show metrics emit successfully after cert refresh.