-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(mTLS): adds mTLS support to dataplane api-server
- Loading branch information
1 parent
c8151d5
commit dab1f86
Showing
5 changed files
with
169 additions
and
57 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/* | ||
Copyright 2023 The Kubernetes Authors. | ||
SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) | ||
*/ | ||
use clap::Parser; | ||
use std::path::PathBuf; | ||
|
||
#[derive(Debug, Parser, Clone)] | ||
pub struct GrpcConfig { | ||
#[clap(long, default_value = "false")] | ||
pub enable_tls: bool, | ||
#[clap(long, default_value = "false")] | ||
pub enable_mtls: bool, | ||
pub certificate_authority_root_path: Option<PathBuf>, | ||
pub server_certificate_path: Option<PathBuf>, | ||
pub server_private_key_path: Option<PathBuf>, | ||
pub client_certificate_authority_root_path: Option<PathBuf>, | ||
pub client_certificate_path: Option<PathBuf>, | ||
pub client_private_key_path: Option<PathBuf>, | ||
} | ||
|
||
impl GrpcConfig { | ||
pub fn validate(&self) -> Result<(), String> { | ||
fn validate_paths(paths: &[(&Option<PathBuf>, &str)]) -> Result<(), String> { | ||
for (path, name) in paths { | ||
if path.is_none() { | ||
return Err(format!("Missing required path: {}", name)); | ||
} | ||
} | ||
Ok(()) | ||
} | ||
|
||
let tls_paths = &[ | ||
( | ||
&self.certificate_authority_root_path, | ||
"certificate_authority_root_path", | ||
), | ||
(&self.server_certificate_path, "server_certificate_path"), | ||
(&self.server_private_key_path, "server_private_key_path"), | ||
]; | ||
|
||
let mtls_paths = &[ | ||
( | ||
&self.client_certificate_authority_root_path, | ||
"client_certificate_authority_root_path", | ||
), | ||
(&self.client_certificate_path, "client_certificate_path"), | ||
(&self.client_private_key_path, "client_private_key_path"), | ||
]; | ||
|
||
if self.enable_mtls { | ||
validate_paths(tls_paths)?; | ||
validate_paths(mtls_paths)?; | ||
} else if self.enable_tls { | ||
validate_paths(tls_paths)?; | ||
} | ||
|
||
Ok(()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters