Skip to content

Commit

Permalink
change auth behavior to match upstream on unknown/empty user - use nu…
Browse files Browse the repository at this point in the history
…ll auth (#1595)

Signed-off-by: Aviram Hassan <[email protected]>
  • Loading branch information
aviramha authored Oct 8, 2024
1 parent 7920fc3 commit 3c3939f
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 5 deletions.
11 changes: 10 additions & 1 deletion kube-client/src/config/file_loader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,21 @@ impl ConfigLoader {
.ok_or_else(|| KubeconfigError::LoadClusterOfContext(cluster_name.clone()))?;

let user_name = user.unwrap_or(&current_context.user);

// client-go doesn't fail on empty/missing user, so we don't either
// see https://github.com/kube-rs/kube/issues/1594
let mut user = config
.auth_infos
.iter()
.find(|named_user| &named_user.name == user_name)
.and_then(|named_user| named_user.auth_info.clone())
.ok_or_else(|| KubeconfigError::FindUser(user_name.clone()))?;
.unwrap_or_else(|| {
// assuming that empty user is ok but if it's not empty user we should warn
if !user_name.is_empty() {
tracing::warn!("User {user_name} wasn't found in kubeconfig, using null auth");
}
AuthInfo::default()
});

if let Some(exec_config) = &mut user.exec {
if exec_config.provide_cluster_info {
Expand Down
4 changes: 0 additions & 4 deletions kube-client/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,6 @@ pub enum KubeconfigError {
#[error("failed to load the cluster of context: {0}")]
LoadClusterOfContext(String),

/// Failed to find named user
#[error("failed to find named user: {0}")]
FindUser(String),

/// Failed to find the path of kubeconfig
#[error("failed to find the path of kubeconfig")]
FindPath,
Expand Down

0 comments on commit 3c3939f

Please sign in to comment.