Skip to content

Commit 9976519

Browse files
committed
replace field with existing TlsClientDetails struct
1 parent 8892204 commit 9976519

3 files changed

Lines changed: 90 additions & 25 deletions

File tree

crates/stackable-operator/crds/DummyCluster.yaml

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -84,12 +84,6 @@ spec:
8484
8585
Since git-sync v4.x.x this field is mapped to the flag `--ref`.
8686
type: string
87-
caCertSecretName:
88-
description: |-
89-
An optional secret used for holding CA certificates that will be used to verify the git server's TLS certificate by passing it to the git config option `http.sslCAInfo` passed with the gitsync command. The secret must have a key named `ca.crt` whose value is the PEM-encoded certificate bundle.
90-
If `http.sslCAInfo` is also set via `gitSyncConf` (the `--git-config` option) then a warning will be logged.
91-
nullable: true
92-
type: string
9387
credentials:
9488
description: An optional secret used for git access.
9589
nullable: true
@@ -148,6 +142,51 @@ spec:
148142
description: 'The git repository URL that will be cloned, for example: `https://github.com/stackabletech/airflow-operator` or `ssh://git@github.com:stackable-airflow/dags.git`.'
149143
format: uri
150144
type: string
145+
tls:
146+
description: Use a TLS connection. If not specified no TLS will be used.
147+
nullable: true
148+
properties:
149+
verification:
150+
description: The verification method used to verify the certificates of the server and/or the client.
151+
oneOf:
152+
- required:
153+
- none
154+
- required:
155+
- server
156+
properties:
157+
none:
158+
description: Use TLS but don't verify certificates.
159+
type: object
160+
server:
161+
description: Use TLS and a CA certificate to verify the server.
162+
properties:
163+
caCert:
164+
description: CA cert to verify the server.
165+
oneOf:
166+
- required:
167+
- webPki
168+
- required:
169+
- secretClass
170+
properties:
171+
secretClass:
172+
description: |-
173+
Name of the [SecretClass](https://docs.stackable.tech/home/nightly/secret-operator/secretclass) which will provide the CA certificate.
174+
Note that a SecretClass does not need to have a key but can also work with just a CA certificate,
175+
so if you got provided with a CA cert but don't have access to the key you can still use this method.
176+
type: string
177+
webPki:
178+
description: |-
179+
Use TLS and the CA certificates trusted by the common web browsers to verify the server.
180+
This can be useful when you e.g. use public AWS S3 or other public available services.
181+
type: object
182+
type: object
183+
required:
184+
- caCert
185+
type: object
186+
type: object
187+
required:
188+
- verification
189+
type: object
151190
wait:
152191
default: 20s
153192
description: |-

crates/stackable-operator/src/crd/git_sync/mod.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,17 @@ use serde::{Deserialize, Serialize};
77
use stackable_shared::time::Duration;
88
use url::Url;
99

10-
use crate::{crd::git_sync::v1alpha2::Credentials, versioned::versioned};
10+
use crate::{
11+
commons::tls_verification::TlsClientDetails, crd::git_sync::v1alpha2::Credentials,
12+
versioned::versioned,
13+
};
1114

1215
mod v1alpha1_impl;
1316
mod v1alpha2_impl;
1417

1518
#[versioned(version(name = "v1alpha1"), version(name = "v1alpha2"))]
1619
pub mod versioned {
20+
1721
pub mod v1alpha1 {
1822
pub use v1alpha1_impl::{Error, GitSyncResources};
1923
}
@@ -69,10 +73,11 @@ pub mod versioned {
6973
))]
7074
pub credentials: Option<Credentials>,
7175

72-
/// An optional secret used for holding CA certificates that will be used to verify the git server's TLS certificate by passing it to the git config option `http.sslCAInfo` passed with the gitsync command. The secret must have a key named `ca.crt` whose value is the PEM-encoded certificate bundle.
76+
/// An optional field used for referencing CA certificates that will be used to verify the git server's TLS certificate by passing it to the git config option `http.sslCAInfo` passed with the gitsync command. The secret must have a key named `ca.crt` whose value is the PEM-encoded certificate bundle.
7377
/// If `http.sslCAInfo` is also set via `gitSyncConf` (the `--git-config` option) then a warning will be logged.
74-
#[versioned(added(since = "v1alpha2"))]
75-
pub ca_cert_secret_name: Option<String>,
78+
/// If not specified no TLS will be used, defaulting to github/lab using commonly-recognised certificates.
79+
#[serde(flatten)]
80+
pub tls: TlsClientDetails,
7681
}
7782

7883
#[derive(strum::Display, Clone, Debug, Deserialize, Eq, JsonSchema, PartialEq, Serialize)]

crates/stackable-operator/src/crd/git_sync/v1alpha2_impl.rs

Lines changed: 36 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ use crate::{
1212
resources::ResourceRequirementsBuilder,
1313
volume::{VolumeBuilder, VolumeMountBuilder},
1414
},
15-
commons::product_image_selection::ResolvedProductImage,
15+
commons::{
16+
self, product_image_selection::ResolvedProductImage, secret_class::SecretClassVolume,
17+
},
1618
crd::git_sync::v1alpha2::{Credentials, GitSync},
1719
product_config_utils::insert_or_update_env_vars,
1820
product_logging::{
@@ -46,6 +48,11 @@ pub enum Error {
4648
AddVolumeMount {
4749
source: crate::builder::pod::container::Error,
4850
},
51+
52+
#[snafu(display("failed to convert secret class volume into named Kubernetes volume"))]
53+
SecretClassVolume {
54+
source: commons::secret_class::SecretClassVolumeError,
55+
},
4956
}
5057

5158
/// Kubernetes resources generated from `GitSync` specifications which should be added to the Pod.
@@ -161,7 +168,7 @@ impl GitSyncResources {
161168
git_sync_container_volume_mounts.push(ssh_volume_mount);
162169
}
163170

164-
if git_sync.ca_cert_secret_name.is_some() {
171+
if git_sync.tls.tls_ca_cert_secret_class().is_some() {
165172
let ca_cert_secret_mount_path = format!("{CA_CERT_MOUNT_PATH_PREFIX}-{i}");
166173
let ca_cert_secret_volume_name = format!("{CA_CERT_VOLUME_NAME_PREFIX}-{i}");
167174

@@ -171,9 +178,9 @@ impl GitSyncResources {
171178
git_sync_container_volume_mounts.push(ca_cert_volume_mount);
172179
}
173180

174-
let ca_cert_path: Option<String> = git_sync
175-
.ca_cert_secret_name
176-
.as_ref()
181+
let ca_cert_path = git_sync
182+
.tls
183+
.tls_ca_cert_secret_class()
177184
.map(|_| format!("{CA_CERT_MOUNT_PATH_PREFIX}-{i}/ca.crt"));
178185

179186
let container = Self::create_git_sync_container(
@@ -235,11 +242,12 @@ impl GitSyncResources {
235242
resources.git_ssh_volumes.push(ssh_secret_volume);
236243
}
237244

238-
if let Some(ca_cert_secret_name) = &git_sync.ca_cert_secret_name {
239-
let ca_cert_secret_volume_name = format!("{CA_CERT_VOLUME_NAME_PREFIX}-{i}");
240-
let ca_cert_secret_volume = VolumeBuilder::new(&ca_cert_secret_volume_name)
241-
.with_secret(ca_cert_secret_name, false)
242-
.build();
245+
if let Some(secret_class) = git_sync.tls.tls_ca_cert_secret_class() {
246+
let secret_class_volume = SecretClassVolume::new(secret_class.clone(), None);
247+
let volume_name = format!("{CA_CERT_VOLUME_NAME_PREFIX}-{i}");
248+
let ca_cert_secret_volume = secret_class_volume
249+
.to_volume(&volume_name)
250+
.context(SecretClassVolumeSnafu)?;
243251
resources.git_ca_cert_volumes.push(ca_cert_secret_volume);
244252
}
245253
}
@@ -1157,7 +1165,11 @@ secret:
11571165
gitFolder: ""
11581166
depth: 3
11591167
wait: 1m
1160-
caCertSecretName: git-ca-cert
1168+
tls:
1169+
verification:
1170+
server:
1171+
caCert:
1172+
secretClass: git-tls-ca
11611173
gitSyncConf:
11621174
--rev: HEAD
11631175
"#;
@@ -1335,10 +1347,19 @@ name: content-from-git-0
13351347
assert_eq!(1, git_sync_resources.git_ca_cert_volumes.len());
13361348

13371349
assert_eq!(
1338-
"name: ca-cert-0
1339-
secret:
1340-
optional: false
1341-
secretName: git-ca-cert
1350+
"ephemeral:
1351+
volumeClaimTemplate:
1352+
metadata:
1353+
annotations:
1354+
secrets.stackable.tech/class: git-tls-ca
1355+
spec:
1356+
accessModes:
1357+
- ReadWriteOnce
1358+
resources:
1359+
requests:
1360+
storage: '1'
1361+
storageClassName: secrets.stackable.tech
1362+
name: ca-cert-0
13421363
",
13431364
serde_yaml::to_string(&git_sync_resources.git_ca_cert_volumes.first()).unwrap()
13441365
);

0 commit comments

Comments
 (0)