Skip to content

Commit

Permalink
Document how to use Kubernetes secret and the cert-manager
Browse files Browse the repository at this point in the history
  • Loading branch information
cescoffier committed Jun 27, 2024
1 parent aeaeb4b commit ae5e11c
Showing 1 changed file with 114 additions and 1 deletion.
115 changes: 114 additions & 1 deletion docs/src/main/asciidoc/tls-registry-reference.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -579,4 +579,117 @@ quarkus.tls.http.key-store.pem.0.key=tls.key
----

Remember that the impacted server and client may need to listen to the `CertificateReloadedEvent` to apply the new certificates.

Check warning on line 581 in docs/src/main/asciidoc/tls-registry-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsWarnings] Consider using 'might (for possiblity)' or 'can (for ability)' rather than 'may' unless updating existing content that uses the term. Raw Output: {"message": "[Quarkus.TermsWarnings] Consider using 'might (for possiblity)' or 'can (for ability)' rather than 'may' unless updating existing content that uses the term.", "location": {"path": "docs/src/main/asciidoc/tls-registry-reference.adoc", "range": {"start": {"line": 581, "column": 46}}}, "severity": "WARNING"}

Check warning on line 581 in docs/src/main/asciidoc/tls-registry-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Fluff] Depending on the context, consider using 'Rewrite the sentence, or use 'must', instead of' rather than 'need to'. Raw Output: {"message": "[Quarkus.Fluff] Depending on the context, consider using 'Rewrite the sentence, or use 'must', instead of' rather than 'need to'.", "location": {"path": "docs/src/main/asciidoc/tls-registry-reference.adoc", "range": {"start": {"line": 581, "column": 50}}}, "severity": "INFO"}
This is automatically done for the Quarkus HTTP server (including the management interface if enabled).
This is automatically done for the Quarkus HTTP server (including the management interface if enabled).

== Using Kubernetes secrets or cert-manager

When running in Kubernetes, you can use Kubernetes secrets to store the key stores and trust stores.

=== Using Kubernetes secrets

To use Kubernetes secrets, you need to create a secret with the key stores and trust stores.

Check warning on line 590 in docs/src/main/asciidoc/tls-registry-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.Fluff] Depending on the context, consider using 'Rewrite the sentence, or use 'must', instead of' rather than 'need to'. Raw Output: {"message": "[Quarkus.Fluff] Depending on the context, consider using 'Rewrite the sentence, or use 'must', instead of' rather than 'need to'.", "location": {"path": "docs/src/main/asciidoc/tls-registry-reference.adoc", "range": {"start": {"line": 590, "column": 32}}}, "severity": "INFO"}
Let's take the following secret as an example:

Check warning on line 591 in docs/src/main/asciidoc/tls-registry-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'.", "location": {"path": "docs/src/main/asciidoc/tls-registry-reference.adoc", "range": {"start": {"line": 591, "column": 33}}}, "severity": "INFO"}

[source, yaml]
----
apiVersion: v1
data:
tls.crt: ...
tls.key: ...
kind: Secret
metadata:
name: my-certs
type: kubernetes.io/tls
----

The easiest way to uses these certificates is to mount the secret as a volume in the pod:

Check warning on line 605 in docs/src/main/asciidoc/tls-registry-reference.adoc

View workflow job for this annotation

GitHub Actions / Linting with Vale

[vale] reported by reviewdog 🐶 [Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'. Raw Output: {"message": "[Quarkus.TermsSuggestions] Depending on the context, consider using 'because' or 'while' rather than 'as'.", "location": {"path": "docs/src/main/asciidoc/tls-registry-reference.adoc", "range": {"start": {"line": 605, "column": 67}}}, "severity": "INFO"}

[source, yaml]
----
apiVersion: apps/v1
kind: Deployment
metadata:
labels:
app.kubernetes.io/name: demo
app.kubernetes.io/version: 1.0.0-SNAPSHOT
app.kubernetes.io/managed-by: quarkus
name: demo
spec:
replicas: 1
selector:
matchLabels:
app.kubernetes.io/name: demo
app.kubernetes.io/version: 1.0.0-SNAPSHOT
template:
metadata:
labels:
app.kubernetes.io/managed-by: quarkus
app.kubernetes.io/name: demo
app.kubernetes.io/version: 1.0.0-SNAPSHOT
spec:
containers:
- env:
- name: KUBERNETES_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
image: ...
imagePullPolicy: IfNotPresent
name: demo
ports:
- containerPort: 8443 # Configure the port to be HTTPS
name: http
protocol: TCP
volumeMounts:
- mountPath: /certs
name: my-volume
volumes:
- name: my-volume
secret:
defaultMode: 0666 # Set the permissions, otherwise the pod may not be able to read the files
optional: false
secretName: my-certs # Reference the secret
----

Then, you can configure the TLS registry to use the certificates:

[source, properties]
----
# ...
# TLS Registry configuration
%prod.quarkus.tls.http.key-store.pem.0.cert=/certs/tls.crt
%prod.quarkus.tls.http.key-store.pem.0.key=/certs/tls.key
# HTTP server configuration:
%prod.quarkus.http.tls-configuration-name=http
%prod.quarkus.http.insecure-requests=disabled
----

You can combine this with the periodic reloading to automatically reload the certificates when they change.

=== Using cert-manager

When running in Kubernetes, you can use cert-manager to automatically generate and renew certificates.
Cert-manager will produce a secret with the key stores and trust stores.
So, configuring the TLS registry is the same as when using Kubernetes secrets.
The generated secret uses the following files:

- `tls.crt` for the certificate
- `tls.key` for the private key
- `ca.crt` for the CA certificate (if needed)

To handle the renewal, you can use the periodic reloading mechanism:

[source, properties]
----
# ...
# TLS Registry configuration
%prod.quarkus.tls.http.key-store.pem.0.cert=/certs/tls.crt
%prod.quarkus.tls.http.key-store.pem.0.key=/certs/tls.key
%prod.quarkus.tls.http.reload-period=24h
# HTTP server configuration:
%prod.quarkus.http.tls-configuration-name=http
%prod.quarkus.http.insecure-requests=disabled
----

0 comments on commit ae5e11c

Please sign in to comment.