Skip to content

Commit 58c87a7

Browse files
feat: Support configuring the name of the ca.crt in the TrustStore (#679)
* feat: Support configuring the name of the ca.crt in the TrustStore Secret * changelog * changelog * Apply suggestions from code review Co-authored-by: maltesander <malte.sander.it@gmail.com> * Fix callout number and pick docs suggestion --------- Co-authored-by: maltesander <malte.sander.it@gmail.com>
1 parent 4703ada commit 58c87a7

7 files changed

Lines changed: 82 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ All notable changes to this project will be documented in this file.
44

55
## [Unreleased]
66

7+
### Added
8+
9+
- Support configuring the name of the key in the ConfigMap/Secret, in which the PEM encoded CA certificate of the Truststore should be placed.
10+
This is e.g. needed to be able to use the generated Secret within an OpenShift Ingress ([#679]).
11+
712
### Changed
813

914
- Document Helm deployed RBAC permissions and remove unnecessary permissions ([#693]).
@@ -53,6 +58,7 @@ All notable changes to this project will be documented in this file.
5358
[#670]: https://github.com/stackabletech/secret-operator/pull/670
5459
[#671]: https://github.com/stackabletech/secret-operator/pull/671
5560
[#674]: https://github.com/stackabletech/secret-operator/pull/674
61+
[#679]: https://github.com/stackabletech/secret-operator/pull/679
5662
[#685]: https://github.com/stackabletech/secret-operator/pull/685
5763
[#687]: https://github.com/stackabletech/secret-operator/pull/687
5864
[#688]: https://github.com/stackabletech/secret-operator/pull/688

docs/modules/secret-operator/examples/truststore-tls.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ spec:
77
secretClassName: tls # <2>
88
format: tls-pem # <3>
99
targetKind: ConfigMap # <4>
10+
tlsPemCaName: ca.crt # <5>

docs/modules/secret-operator/pages/truststore.adoc

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ include::example$truststore-tls.yaml[]
1616
<3> Optional requested xref:secretclass.adoc#format[format]
1717
<4> Optional Kubernetes resource kind, which should be used to output the requested information to.
1818
Either `ConfigMap` or `Secret`, defaults to `ConfigMap`.
19+
<5> Optional name of the key in the ConfigMap/Secret, in which the PEM encoded CA certificate should be placed.
20+
Only takes effect in case the `format` is `tls-pem`.
21+
Defaults to `ca.crt`.
1922

2023
This will create a ConfigMap (or `Secret` based on `targetKind`) named `truststore-pem` containing a `ca.crt` with the trust root certificates.
2124
It can then either be mounted into a Pod or retrieved and used from outside of Kubernetes.
@@ -24,3 +27,47 @@ Expired or retired (see xref:secretclass.adoc#ca-rotation[Certificate Authority
2427

2528
NOTE: Make sure to have a procedure for updating the retrieved certificates.
2629
The Secret Operator will automatically rotate the xref:secretclass.adoc#backend-autotls[autoTls] certificate authority as needed, but all trust roots will require some form of update occasionally.
30+
31+
== Integration with OpenShift Ingress
32+
33+
Sometimes you want to create an OpenShift Ingress to expose a stacklet that is secured using `https`.
34+
For the TLS re-encryption to work, you need to specify a Secret that contains a `tls.crt` key with the PEM ca certificate.
35+
36+
A concrete example is shown below:
37+
38+
[source,yaml]
39+
----
40+
apiVersion: secrets.stackable.tech/v1alpha1
41+
kind: TrustStore
42+
metadata:
43+
name: cluster-internal-ca
44+
namespace: my-trino-namespace
45+
spec:
46+
secretClassName: tls # Or any other SecretClass you are using
47+
format: tls-pem # As expected by OpenShift
48+
targetKind: Secret # As expected by OpenShift
49+
tlsPemCaName: tls.crt # As expected by OpenShift
50+
---
51+
apiVersion: networking.k8s.io/v1
52+
kind: Ingress
53+
metadata:
54+
name: trino
55+
namespace: my-trino-namespace
56+
annotations:
57+
route.openshift.io/termination: "reencrypt"
58+
route.openshift.io/destination-ca-certificate-secret: cluster-internal-ca
59+
spec:
60+
rules:
61+
- host: trino.example.com
62+
http:
63+
paths:
64+
- backend:
65+
service:
66+
name: trino-coordinator
67+
port:
68+
name: https
69+
path: /
70+
pathType: Prefix
71+
tls:
72+
- {}
73+
----

extra/crds.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -921,6 +921,14 @@ spec:
921921
- Secret
922922
- ConfigMap
923923
type: string
924+
tlsPemCaName:
925+
default: ca.crt
926+
description: |-
927+
The name of the key in the ConfigMap/Secret, in which the PEM encoded CA certificate should be placed.
928+
929+
Only takes effect in case the `format` is `tls-pem`.
930+
Defaults to `ca.crt`.
931+
type: string
924932
required:
925933
- secretClassName
926934
type: object

rust/operator-binary/src/crd/trust_store/mod.rs

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use stackable_operator::{
55
versioned::versioned,
66
};
77

8-
use crate::format::SecretFormat;
8+
use crate::format::{SecretFormat, well_known::FILE_PEM_CERT_CA};
99

1010
#[versioned(
1111
version(name = "v1alpha1"),
@@ -41,6 +41,13 @@ pub mod versioned {
4141

4242
/// The [format](DOCS_BASE_URL_PLACEHOLDER/secret-operator/secretclass#format) that the data should be converted into.
4343
pub format: Option<SecretFormat>,
44+
45+
/// The name of the key in the ConfigMap/Secret, in which the PEM encoded CA certificate should be placed.
46+
///
47+
/// Only takes effect in case the `format` is `tls-pem`.
48+
/// Defaults to `ca.crt`.
49+
#[serde(default = "TrustStoreSpec::default_tls_pem_ca_name")]
50+
pub tls_pem_ca_name: String,
4451
}
4552

4653
#[derive(Clone, Debug, Default, PartialEq, JsonSchema, Serialize, Deserialize)]
@@ -52,3 +59,9 @@ pub mod versioned {
5259
ConfigMap,
5360
}
5461
}
62+
63+
impl v1alpha1::TrustStoreSpec {
64+
fn default_tls_pem_ca_name() -> String {
65+
FILE_PEM_CERT_CA.to_owned()
66+
}
67+
}

rust/operator-binary/src/format/well_known.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::{backend::ProvisionParts, utils::ResultExt};
88

99
const FILE_PEM_CERT_CERT: &str = "tls.crt";
1010
const FILE_PEM_CERT_KEY: &str = "tls.key";
11-
const FILE_PEM_CERT_CA: &str = "ca.crt";
11+
pub const FILE_PEM_CERT_CA: &str = "ca.crt";
1212

1313
const FILE_PKCS12_CERT_KEYSTORE: &str = "keystore.p12";
1414
const FILE_PKCS12_CERT_TRUSTSTORE: &str = "truststore.p12";

rust/operator-binary/src/truststore_controller.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,11 +281,15 @@ async fn reconcile(
281281
.get_trust_data(&selector)
282282
.await
283283
.context(BackendGetTrustDataSnafu)?;
284+
let naming_options = NamingOptions {
285+
tls_pem_ca_name: truststore.spec.tls_pem_ca_name.clone(),
286+
..Default::default()
287+
};
284288
let trust_file_contents = trust_data
285289
.data
286290
.into_files(
287291
truststore.spec.format,
288-
NamingOptions::default(),
292+
naming_options,
289293
CompatibilityOptions::default(),
290294
ProvisionParts::PublicPrivate,
291295
)

0 commit comments

Comments
 (0)