Skip to content

Commit 59a05af

Browse files
John ZakrzewskiJohn Zakrzewski
authored andcommitted
configuring diskpool operator to speak tls
1 parent 8b45433 commit 59a05af

File tree

2 files changed

+56
-12
lines changed
  • control-plane/csi-driver/src/bin/controller
  • k8s/operators/src/pool

2 files changed

+56
-12
lines changed

control-plane/csi-driver/src/bin/controller/client.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -124,16 +124,22 @@ impl RestApiClient {
124124
.map_err(|error| anyhow!("Invalid API endpoint URL {}: {:?}", endpoint, error))?;
125125
let concurrency_limit = cfg.create_volume_limit() * 2;
126126
let ca_certificate_path = cfg.ca_certificate_path();
127-
128-
let tower = match (url.scheme(), ca_certificate_path) {
129-
("https", Some(path)) => {
127+
let cert = match ca_certificate_path {
128+
Some(path) => {
129+
let cert = std::fs::read(path).expect("Failed to read certificate file");
130+
Some(cert)
131+
},
132+
None => None,
133+
};
134+
let tower = match (url.scheme(), cert) {
135+
("https", Some(cert)) => {
130136
debug!("Attempting TLS connection to {}", url);
131137

132138
// Use new_with_client method to create the configuration
133139
clients::tower::Configuration::builder()
134140
.with_timeout(Some(cfg.io_timeout()))
135141
.with_concurrency_limit(Some(concurrency_limit))
136-
.with_certificate(path.as_bytes())
142+
.with_certificate(cert.as_slice())
137143
.build_url(url)
138144
.map_err(|error| {
139145
anyhow::anyhow!(

k8s/operators/src/pool/main.rs

Lines changed: 46 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use kube::{
3131
use mayastorpool::client::{check_crd, delete, list};
3232
use openapi::clients::{self, tower::Url};
3333
use std::{collections::HashMap, sync::Arc, time::Duration};
34-
use tracing::{error, info, trace, warn};
34+
use tracing::{error, info, trace, warn, debug};
3535
use utils::tracing_telemetry::{FmtLayer, FmtStyle};
3636

3737
const PAGINATION_LIMIT: u32 = 100;
@@ -129,14 +129,47 @@ async fn pool_controller(args: ArgMatches) -> anyhow::Result<()> {
129129
.expect("timeout value is invalid")
130130
.into();
131131

132-
let cfg = clients::tower::Configuration::new(url, timeout, None, None, true, None).map_err(
133-
|error| {
134-
anyhow::anyhow!(
135-
"Failed to create openapi configuration, Error: '{:?}'",
136-
error
137-
)
132+
let ca_certificate_path:Option<&str> = args.get_one::<String>("tls-client-ca-path").map(|x| x.as_str());
133+
// take in cert path and make pem file
134+
let cert = match ca_certificate_path {
135+
Some(path) => {
136+
let cert = std::fs::read(path).expect("Failed to read certificate file");
137+
Some(cert)
138138
},
139-
)?;
139+
None => None,
140+
};
141+
let cfg = match (url.scheme(), cert) {
142+
("https", Some(cert)) => {
143+
debug!("Attempting TLS connection to {}", url);
144+
145+
clients::tower::Configuration::new(url, timeout, None, Some(cert.as_slice()), true, None)
146+
.map_err(
147+
|error| {
148+
anyhow::anyhow!(
149+
"Failed to create openapi configuration, Error: '{:?}'",
150+
error
151+
)
152+
},
153+
)?
154+
},
155+
("https", None) => {
156+
anyhow::bail!("HTTPS endpoint requires a CA certificate path");
157+
},
158+
(_, Some(_path)) => {
159+
anyhow::bail!("CA certificate path is only supported for HTTPS endpoints");
160+
},
161+
_ => {
162+
clients::tower::Configuration::new(url, timeout, None, None, true, None)
163+
.map_err(
164+
|error| {
165+
anyhow::anyhow!(
166+
"Failed to create openapi configuration, Error: '{:?}'",
167+
error
168+
)
169+
},
170+
)?
171+
}
172+
};
140173
let interval = args
141174
.get_one::<String>("interval")
142175
.unwrap()
@@ -243,6 +276,11 @@ async fn main() -> anyhow::Result<()> {
243276
.value_parser(clap::value_parser!(bool))
244277
.help("Enable ansi color for logs"),
245278
)
279+
.arg(
280+
Arg::new("tls-client-ca-path")
281+
.long("tls-client-ca-path")
282+
.help("path to the CA certificate file"),
283+
)
246284
.get_matches();
247285

248286
utils::print_package_info!();

0 commit comments

Comments
 (0)