Skip to content
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

Add support for user impersonation #797

Merged
merged 3 commits into from Jan 28, 2022

Conversation

nightkr
Copy link
Member

@nightkr nightkr commented Jan 27, 2022

Fixes #796

Also ended up adding support for user impersonation at all, because until now those config fields were simply ignored.

@nightkr nightkr added changelog-add changelog added category for prs client http issues with the client config Kube config related ergonomics ergonomics of the public interface labels Jan 27, 2022
@codecov-commenter
Copy link

codecov-commenter commented Jan 27, 2022

Codecov Report

Merging #797 (57b789f) into master (18b5316) will decrease coverage by 0.16%.
The diff coverage is 38.09%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #797      +/-   ##
==========================================
- Coverage   72.01%   71.84%   -0.17%     
==========================================
  Files          55       55              
  Lines        3730     3747      +17     
==========================================
+ Hits         2686     2692       +6     
- Misses       1044     1055      +11     
Impacted Files Coverage Δ
kube-client/src/config/mod.rs 56.41% <38.09%> (-7.53%) ⬇️
kube-runtime/src/wait.rs 70.00% <0.00%> (+2.00%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 18b5316...57b789f. Read the comment docs.

Fixes kube-rs#796

Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>
Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>
@nightkr nightkr changed the title Add support for overriding impersonation settings and cluster URL Add support for user impersonation Jan 27, 2022
Signed-off-by: Teo Klestrup Röijezon <teo@nullable.se>
@nightkr nightkr requested a review from a team January 27, 2022 16:52

#[derive(Clone)]
/// Layer that adds a static set of extra headers to each request
pub struct ExtraHeadersLayer {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah.. SRHL also means that we need to encode the exact number of headers into the type signature (or do a bunch of newtyping to hide it).

HeaderName::from_static("impersonate-user"),
HeaderValue::from_str(impersonate_user)
.map_err(http::Error::from)
.map_err(Error::HttpError)?,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be better to add an explicit error for invalid header value with the name.

Error::HttpError is only used by these

https://github.com/kube-rs/kube-rs/blob/18b5316b3a644a22ce64806b6cd2ed75d5e80b03/kube-client/src/client/mod.rs#L340-L345

and I think it should be removed eventually.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, but that also feels like a part of the larger error refactoring.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, we can do it later.

Copy link
Member

@clux clux left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

naming nits, but functionality looks sensible

kube-client/src/config/mod.rs Show resolved Hide resolved
kube-client/src/config/mod.rs Show resolved Hide resolved
Comment on lines +298 to +312
if let Ok(url) = std::env::var("KUBE_RS_DEBUG_OVERRIDE_URL") {
tracing::warn!(?url, "overriding cluster URL");
match url.parse() {
Ok(uri) => {
self.cluster_url = uri;
}
Err(err) => {
tracing::warn!(
?url,
error = &err as &dyn std::error::Error,
"failed to parse override cluster URL, ignoring"
);
}
}
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can put the secondary proxyUrl in the ~/.kube/config under the Cluster to have it work everywhere, but i guess you want some safety here for something that is kube only?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nevermind i see you want this as a method to be used with kubectl proxy rather than kube doing the proxying (which we support already)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, the latter.

There have also been cases where I have wanted to access the cluster in weird ways involving TCP reverse proxies, so this would have been helpful there as well.

@nightkr nightkr merged commit 93fcff3 into kube-rs:master Jan 28, 2022
@nightkr nightkr deleted the feature/debug-override branch January 28, 2022 09:51
@clux clux added this to the 0.68.0 milestone Jan 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
changelog-add changelog added category for prs client http issues with the client config Kube config related ergonomics ergonomics of the public interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ergonomic service account impersonation
4 participants