Skip to content

Implement mTLS resources for CloudWatch Agent client #163

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

Merged
merged 4 commits into from
Jun 13, 2025
Merged
Show file tree
Hide file tree
Changes from 2 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: 29 additions & 4 deletions charts/amazon-cloudwatch-observability/templates/certmanager.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ spec:
{{- end }}
{{- end }}

{{- if ( .Values.agent.certManager.enabled) }}
{{- if ( .Values.agent.certManager.enabled) }}
---
apiVersion: cert-manager.io/v1
kind: Certificate
Expand Down Expand Up @@ -100,7 +100,25 @@ spec:
issuerRef:
kind: Issuer
name: "agent-ca"
secretName: "amazon-cloudwatch-observability-agent-client-cert"
secretName: "amazon-cloudwatch-observability-agent-client-cert"
usages:
- digital signature
- key encipherment
- cert sign
---
apiVersion: cert-manager.io/v1
kind: Certificate
metadata:
labels:
{{- include "amazon-cloudwatch-observability.labels" . | nindent 4 }}
name: "amazon-cloudwatch-observability-agent-outbound-cert"
Copy link
Contributor

Choose a reason for hiding this comment

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

is there a reason why we can't use "amazon-cloudwatch-observability-agent-cert" ?

I see that we specify the target allocator service as a dns name we can make calls to?

Are we using this outbound cert specifically for target allocator?

Copy link
Collaborator Author

@musa-asad musa-asad Jan 24, 2025

Choose a reason for hiding this comment

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

We do use "amazon-cloudwatch-observability-agent-cert" for the server cert and key for the TA server: https://github.com/aws/amazon-cloudwatch-agent-operator/blob/d6c5c6d9aa983222ac3557fe1c3bb2c367fff615/internal/manifests/targetallocator/volume.go#L47.

The "amazon-cloudwatch-observability-agent-outbound-cert" is for the client cert and key for the agent client. We could technically use "amazon-cloudwatch-observability-agent-server-cert", but I avoided doing so due to separation of concerns.

Copy link
Contributor

Choose a reason for hiding this comment

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

Could you elaborate on what you meant by

I avoided doing so due to separation of concerns.

Copy link
Collaborator Author

@musa-asad musa-asad Feb 12, 2025

Choose a reason for hiding this comment

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

The server-cert is used to generate server cert and keys when the CloudWatch Agent operates as a server for FluentBit.

The outbound-cert is used to generate client cert and keys when the CloudWatch Agent operates as a client for the Target Allocator.

We are able to use the server-cert to generate client cert and keys as well when the CloudWatch Agent operates as a client, but it's preferable to separate that functionality to the outbound-cert.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Updated the naming from outbound-cert to ta-client-cert.

namespace: {{ .Release.Namespace }}
spec:
commonName: "agent-outbound"
issuerRef:
kind: Issuer
name: "agent-ca"
secretName: "amazon-cloudwatch-observability-agent-outbound-cert"
usages:
- digital signature
- key encipherment
Expand Down Expand Up @@ -143,7 +161,14 @@ kind: Secret
metadata:
labels:
{{- include "amazon-cloudwatch-observability.labels" . | nindent 4 }}
name: "amazon-cloudwatch-observability-agent-client-cert"
name: "amazon-cloudwatch-observability-agent-client-cert"
namespace: {{ .Release.Namespace }}
---
apiVersion: v1
kind: Secret
metadata:
labels:
{{- include "amazon-cloudwatch-observability.labels" . | nindent 4 }}
name: "amazon-cloudwatch-observability-agent-outbound-cert"
namespace: {{ .Release.Namespace }}
{{- end }}

Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{{- $cert := genSignedCert ("agent") nil $altNames ( .Values.admissionWebhooks.autoGenerateCert.expiryDays | int ) $ca -}}
{{- $serverCert := genSignedCert ("agent-server") nil $agentAltNames ( .Values.admissionWebhooks.autoGenerateCert.expiryDays | int ) $ca -}}
{{- $clientCert := genSignedCert ("agent-client") nil nil ( .Values.admissionWebhooks.autoGenerateCert.expiryDays | int ) $ca -}}
{{- $outboundCert := genSignedCert ("agent-outbound") nil nil ( .Values.admissionWebhooks.autoGenerateCert.expiryDays | int ) $ca -}}
apiVersion: v1
kind: Secret
metadata:
Expand Down Expand Up @@ -45,6 +46,18 @@ data:
tls.crt: {{ $clientCert.Cert | b64enc }}
tls.key: {{ $clientCert.Key | b64enc }}
---
apiVersion: v1
kind: Secret
metadata:
labels:
{{- include "amazon-cloudwatch-observability.labels" . | nindent 4}}
name: "amazon-cloudwatch-observability-agent-outbound-cert"
namespace: {{ .Release.Namespace }}
data:
ca.crt: {{ $ca.Cert | b64enc }}
tls.crt: {{ $outboundCert.Cert | b64enc }}
tls.key: {{ $outboundCert.Key | b64enc }}
---
{{- end -}}

{{- $clusterName := .Values.clusterName | required ".Values.clusterName is required." -}}
Expand Down Expand Up @@ -129,6 +142,9 @@ spec:
- mountPath: /etc/amazon-cloudwatch-observability-agent-server-cert
name: agentservertls
readOnly: true
- mountPath: /etc/amazon-cloudwatch-observability-agent-outbound-cert
name: agentoutboundtls
readOnly: true
- mountPath: /var/lib/kubelet/pod-resources
name: kubelet-podresources
volumes:
Expand Down Expand Up @@ -174,6 +190,14 @@ spec:
path: server.crt
- key: tls.key
path: server.key
- name: agentoutboundtls
secret:
secretName: amazon-cloudwatch-observability-agent-outbound-cert
items:
- key: tls.crt
path: client.crt
- key: tls.key
path: client.key
env:
- name: K8S_NODE_NAME
valueFrom:
Expand Down
Loading