Skip to content

Implement apm support for presenting client certificates to elasticsearch#9307

Merged
pkoutsovasilis merged 5 commits intoelastic:mainfrom
pkoutsovasilis:feat/mtls_apm
Apr 15, 2026
Merged

Implement apm support for presenting client certificates to elasticsearch#9307
pkoutsovasilis merged 5 commits intoelastic:mainfrom
pkoutsovasilis:feat/mtls_apm

Conversation

@pkoutsovasilis
Copy link
Copy Markdown
Contributor

@pkoutsovasilis pkoutsovasilis commented Apr 3, 2026

Summary

This PR implements client certificate support for APM Server when connecting to an Elasticsearch cluster that has client authentication enabled.

Relates to #9081

Changes

  • APM ElasticsearchSelector: Changes ElasticsearchRef from ObjectSelector to ElasticsearchSelector, adding clientCertificateSecretName support to APM Server's elasticsearchRef
  • APM Server config: Configures output.elasticsearch.ssl.certificate and output.elasticsearch.ssl.key when client authentication is required, pointing to the mounted client certificate files
  • APM Server pod spec: Mounts client certificate volumes alongside existing CA certificate volumes for associations that have client certificates configured. Refactored withAssociationCACertsVolumes into withAssociationCertsVolumes to handle both CA and client certificate volume mounts
  • Webhook validation: Updated to use CheckElasticsearchSelectorRefs for the APM Server's elasticsearchRef
  • APM e2e tests: Added TestClientAuthRequiredTransition (verifies APM Server remains healthy when ES transitions from client auth required to disabled, and that client certificate secrets are cleaned up) and TestClientAuthRequiredCustomCertificate (verifies APM Server works with a user-provided client certificate)

API

apiVersion: apm.k8s.elastic.co/v1
kind: ApmServer
spec:
  elasticsearchRef:
    name: elasticsearch
    # Optional: use a custom client certificate
    clientCertificateSecretName: my-custom-client-cert

@pkoutsovasilis pkoutsovasilis self-assigned this Apr 3, 2026
@pkoutsovasilis pkoutsovasilis added the >feature Adds or discusses adding a feature to the product label Apr 3, 2026
@prodsecmachine
Copy link
Copy Markdown
Collaborator

prodsecmachine commented Apr 3, 2026

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues
Licenses 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@pkoutsovasilis pkoutsovasilis force-pushed the feat/mtls_apm branch 3 times, most recently from f48fe2b to 58159ba Compare April 3, 2026 09:11
@pkoutsovasilis
Copy link
Copy Markdown
Contributor Author

buildkite test this -f p=gke,t=TestClientAuthRequired.*,E2E_TAGS=apm -m s=9.3.2,s=8.19.13,s=9.2.7

@pkoutsovasilis pkoutsovasilis marked this pull request as ready for review April 3, 2026 10:22
@pkoutsovasilis pkoutsovasilis requested a review from a team as a code owner April 3, 2026 10:22
@pkoutsovasilis
Copy link
Copy Markdown
Contributor Author

buildkite test this -f p=gke,t=TestClientAuthRequired.*,E2E_TAGS=apm -m s=9.3.3,s=8.19.14,s=9.2.8

Copy link
Copy Markdown

@simitt simitt left a comment

Choose a reason for hiding this comment

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

Overall, LGMT, just some nits - but feel free to ignore.

nit: I wonder whether a test scenario where the ES cluster uses a publicly trusted cert but mTLS is configured is worth testing in the unit tests.

Comment thread test/e2e/test/apmserver/builder.go
# Conflicts:
#	docs/reference/api-reference/main.md
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 15, 2026

🔍 Preview links for changed docs

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 15, 2026

Vale Linting Results

Summary: 1 warning found

⚠️ Warnings (1)
File Line Rule Message
docs/reference/api-reference/main.md 207 Elastic.BritishSpellings Use American English spelling 'customization' instead of British English 'customisation'.

The Vale linter checks documentation changes against the Elastic Docs style guide.

To use Vale locally or report issues, refer to Elastic style guide for Vale.

@pkoutsovasilis
Copy link
Copy Markdown
Contributor Author

nit: I wonder whether a test scenario where the ES cluster uses a publicly trusted cert but mTLS is configured is worth testing in the unit tests.

A couple of thoughts on this:

  1. I'm not sure how we'd fabricate a publicly trusted cert in our e2e CI environment.
  2. A publicly trusted cert affects the client-side validation of the server (ES in our case) certificate - it would be trusted without needing a defining a custom trusted CA. But the server-side validation of client certificates (the mTLS part) remains the same regardless of how the server's own cert is issued. The client still needs to present a valid certificate that the server trusts.
  3. I'd also expect mTLS with publicly trusted server certificates to be fairly uncommon in practice - In my head, although I can be off here, mTLS is typically used in internal/private zero-trust environments where self-signed or internal CAs are the norm.

Is there a particular edge case you have in mind @simitt where the combination would behave differently? Happy to discuss and fabricate a test if there's a concrete scenario worth covering.

@simitt
Copy link
Copy Markdown

simitt commented Apr 15, 2026

@pkoutsovasilis , looking at this pod_test, my concern actually is already covered - client cert only, no CA. So you can safely drop my previous comment.

Is there a particular edge case you have in mind

No particular use case, just something I thought missing in test coverage.

@pkoutsovasilis pkoutsovasilis merged commit 06363e8 into elastic:main Apr 15, 2026
9 checks passed
@pkoutsovasilis pkoutsovasilis deleted the feat/mtls_apm branch April 15, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>feature Adds or discusses adding a feature to the product v3.5.0 (next)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants