-
-
Notifications
You must be signed in to change notification settings - Fork 332
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use SecretString in AuthInfo to avoid credential leaking #766
Conversation
Signed-off-by: ChinYing-Li <chinying.li@mail.utoronto.ca>
0203af0
to
05a5304
Compare
Seems like the CI is having connection issues; would be great if someone can kick the CI again. |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for doing this!
I think token
field should be Option<SecretString>
as well.
There's also client_key_data
, but we might want to clean up around identity_pem
first in a separate PR.
Signed-off-by: ChinYing-Li <chinying.li@mail.utoronto.ca>
…tion function Signed-off-by: ChinYing-Li <chinying.li@mail.utoronto.ca>
@kazk Seems like no one else is working on refactoring |
@ChinYing-Li Thanks, but I've been looking into it already (originally started looking into it because I have an idea for #542 and working with concatenated As far as I can tell, the concatenated But we'll need to look into why we're doing the following: to set If there's no problem with doing accept_invalid_certs = loader.cluster.insecure_skip_tls_verify.unwrap_or(false); then, I think we can just get rid of |
Opened #771 that removes |
@ChinYing-Li #771 is merged, so you can do something like the following after rebasing: diff --git i/kube-client/src/config/file_config.rs w/kube-client/src/config/file_config.rs
index a824699..4e16f90 100644
--- i/kube-client/src/config/file_config.rs
+++ w/kube-client/src/config/file_config.rs
@@ -181,7 +181,11 @@ pub struct AuthInfo {
/// PEM-encoded data from a client key file for TLS. Overrides `client_key`
#[serde(rename = "client-key-data")]
#[serde(skip_serializing_if = "Option::is_none")]
- pub client_key_data: Option<String>,
+ #[serde(
+ serialize_with = "serialize_secretstring",
+ deserialize_with = "deserialize_secretstring"
+ )]
+ pub client_key_data: Option<SecretString>,
/// The username to act-as.
#[serde(rename = "as")]
@@ -430,8 +434,11 @@ impl Cluster {
return Ok(None);
}
- let ca = load_from_base64_or_file(&self.certificate_authority_data, &self.certificate_authority)
- .map_err(KubeconfigError::LoadCertificateAuthority)?;
+ let ca = load_from_base64_or_file(
+ &self.certificate_authority_data.as_deref(),
+ &self.certificate_authority,
+ )
+ .map_err(KubeconfigError::LoadCertificateAuthority)?;
Ok(Some(ca))
}
}
@@ -448,24 +455,26 @@ impl AuthInfo {
pub(crate) fn load_client_certificate(&self) -> Result<Vec<u8>, KubeconfigError> {
// TODO Shouldn't error when `self.client_certificate_data.is_none() && self.client_certificate.is_none()`
- load_from_base64_or_file(&self.client_certificate_data, &self.client_certificate)
+ load_from_base64_or_file(&self.client_certificate_data.as_deref(), &self.client_certificate)
.map_err(KubeconfigError::LoadClientCertificate)
}
pub(crate) fn load_client_key(&self) -> Result<Vec<u8>, KubeconfigError> {
// TODO Shouldn't error when `self.client_key_data.is_none() && self.client_key.is_none()`
- load_from_base64_or_file(&self.client_key_data, &self.client_key)
- .map_err(KubeconfigError::LoadClientKey)
+ load_from_base64_or_file(
+ &self.client_key_data.as_ref().map(|s| s.expose_secret().as_str()),
+ &self.client_key,
+ )
+ .map_err(KubeconfigError::LoadClientKey)
}
}
fn load_from_base64_or_file<P: AsRef<Path>>(
- value: &Option<String>,
+ value: &Option<&str>,
file: &Option<P>,
) -> Result<Vec<u8>, LoadDataError> {
let data = value
- .as_deref()
.map(load_from_base64)
.or_else(|| file.as_ref().map(load_from_file))
.unwrap_or(Err(LoadDataError::NoBase64DataOrFile))?; |
Signed-off-by: ChinYing-Li <chinying.li@mail.utoronto.ca>
Signed-off-by: ChinYing-Li <chinying.li@mail.utoronto.ca>
Signed-off-by: ChinYing-Li <chinying.li@mail.utoronto.ca>
082bbe3
to
bd95a76
Compare
I have updated the PR, so now |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Just a few minor nits.
Signed-off-by: ChinYing-Li <chinying.li@mail.utoronto.ca>
Going to merge this to unblock #768. Thanks again. |
Motivation
This PR aims to solve #751.
Solution
the
secrecy
crate is used, andAuthInfo.password
is now of typeOption<SecretString>
. Are there other structs/fields that would require secrets?Since
SecretString
has noPartialEq
implementation, there's a customimpl PartialEq for AuthInfo
, which is a hack that compares serialized structs. Please let me know if such a hack is not acceptable.Any suggestion is appreciated!