Skip to content

Commit fbbbe2e

Browse files
John ZakrzewskiJohn Zakrzewski
authored andcommitted
configuring csi-controller to speak tls
Signed-off-by: John Zakrzewski <[email protected]>
1 parent 1524559 commit fbbbe2e

File tree

3 files changed

+54
-11
lines changed

3 files changed

+54
-11
lines changed

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

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -123,16 +123,44 @@ impl RestApiClient {
123123
let url = clients::tower::Url::parse(endpoint)
124124
.map_err(|error| anyhow!("Invalid API endpoint URL {}: {:?}", endpoint, error))?;
125125
let concurrency_limit = cfg.create_volume_limit() * 2;
126-
let tower = clients::tower::Configuration::builder()
127-
.with_timeout(cfg.io_timeout())
128-
.with_concurrency_limit(Some(concurrency_limit))
129-
.build_url(url)
130-
.map_err(|error| {
131-
anyhow::anyhow!(
132-
"Failed to create openapi configuration, Error: '{:?}'",
133-
error
134-
)
135-
})?;
126+
let ca_certificate_path = cfg.ca_certificate_path();
127+
128+
let tower = match (url.scheme(), ca_certificate_path) {
129+
("https", Some(path)) => {
130+
debug!("Attempting TLS connection to {}", url);
131+
132+
// Use new_with_client method to create the configuration
133+
clients::tower::Configuration::builder()
134+
.with_timeout(Some(cfg.io_timeout()))
135+
.with_concurrency_limit(Some(concurrency_limit))
136+
.with_certificate(path.as_bytes())
137+
.build_url(url)
138+
.map_err(|error| {
139+
anyhow::anyhow!(
140+
"Failed to create openapi configuration, Error: '{:?}'",
141+
error
142+
)
143+
})?
144+
},
145+
("https", None) => {
146+
anyhow::bail!("HTTPS endpoint requires a CA certificate path");
147+
},
148+
(_, Some(_path)) => {
149+
anyhow::bail!("CA certificate path is only supported for HTTPS endpoints");
150+
},
151+
_ => {
152+
clients::tower::Configuration::builder()
153+
.with_timeout(Some(cfg.io_timeout()))
154+
.with_concurrency_limit(Some(concurrency_limit))
155+
.build_url(url)
156+
.map_err(|error| {
157+
anyhow::anyhow!(
158+
"Failed to create openapi configuration, Error: '{:?}'",
159+
error
160+
)
161+
})?
162+
}
163+
};
136164

137165
REST_CLIENT.get_or_init(|| Self {
138166
rest_client: clients::tower::ApiClient::new(tower.clone()),

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

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ pub(crate) struct CsiControllerConfig {
1717
create_volume_limit: usize,
1818
/// Force unstage volume.
1919
force_unstage_volume: bool,
20+
/// Path to the CA certificate file.
21+
ca_certificate_path: Option<String>,
2022
}
2123

2224
impl CsiControllerConfig {
@@ -50,14 +52,17 @@ impl CsiControllerConfig {
5052
tracing::warn!(
5153
"Force unstage volume is disabled, can trigger potential data corruption!"
5254
);
53-
}
55+
};
56+
57+
let ca_certificate_path = args.get_one::<String>("tls-client-ca-path");
5458

5559
CONFIG.get_or_init(|| Self {
5660
rest_endpoint: rest_endpoint.into(),
5761
io_timeout: io_timeout.into(),
5862
node_selector,
5963
create_volume_limit,
6064
force_unstage_volume,
65+
ca_certificate_path: ca_certificate_path.cloned(),
6166
});
6267
Ok(())
6368
}
@@ -92,4 +97,9 @@ impl CsiControllerConfig {
9297
pub(crate) fn force_unstage_volume(&self) -> bool {
9398
self.force_unstage_volume
9499
}
100+
101+
/// Path to the CA certificate file.
102+
pub(crate) fn ca_certificate_path(&self) -> Option<&str> {
103+
self.ca_certificate_path.as_deref()
104+
}
95105
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,11 @@ async fn main() -> anyhow::Result<()> {
131131
.value_parser(clap::value_parser!(bool))
132132
.help("Enable force unstage volume feature")
133133
)
134+
.arg(
135+
Arg::new("tls-client-ca-path")
136+
.long("tls-client-ca-path")
137+
.help("path to the CA certificate file"),
138+
)
134139
.get_matches();
135140

136141
utils::print_package_info!();

0 commit comments

Comments
 (0)