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

support impersonation via auth_options and in kubectl config #600

Merged
merged 7 commits into from
Feb 7, 2023
Merged

support impersonation via auth_options and in kubectl config #600

merged 7 commits into from
Feb 7, 2023

Conversation

DocX
Copy link
Contributor

@DocX DocX commented Jan 20, 2023

This PR is rebase and update of #524 to current master version

We tested it and it works as expected

Ruby http clients (including adapters for Faraday) are not able to handle multiple headers of same name, which is how the kube API expects to receive the list of multiple groups or extra fields. To avoid any confusion, added explicit error when trying to configure client with multivalue groups. This may brake some applications, if user is not aware of the impersonation setting and were ignoring it until now

@headers[:'Impersonate-Uid'] = auth_as_uid
end
@auth_options[:as_user_extra]&.each do |k, v|
raise ArgumentError, "Kubeclient does not support impesonate extra field with multiple values" if v.count > 1
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cben what do you think about this error? this may introduce regression on users side. Should we print just some warning instead and fallback to trimming arrays with > 1 value to just the first value?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just for context, as mentioned in the PR summary, this is because Faraday does not support multiple headers with same name, however the Kube API is expecting those to be requested as duplicate headers (with same name, and each different value). It does not recognize joining the value as comma separated lists.

Copy link
Collaborator

Choose a reason for hiding this comment

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

yikes. doesn't the RFC require "aside from the well-known exception noted below, a sender MUST NOT generate multiple field lines with the same name in a message (whether in the headers or trailers) or append a field line when a field line of the same name already exists in the message, unless that field's definition allows multiple field line values to be recombined as a comma-separated list" ? (with the grandfathered exception being Set-Cookie)

Is there any plan to fix that in kubernetes API? (not that this helps us much here)

Is this supported better in Faraday 2?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@cben I've opened issue in faraday and actually it is down at the http libraries. Neither ruby's net/http nor exconn supports that. Maybe other client library does (my tip would be typhoeues, but did not test). Anyway I guess as kubeclient we don't want to impose the faraday adapter used on the user? Since user may set global adapter for Faraday that would also be used by kubeclient.

So I think there is nothing to do, except implementing own client? Or maybe forcing specific faraday adapter in kubeclient requests.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is also some issue in kubernetes around this problem, from using http proxies, that often reconstruct headers by joining them with comma, which breaks the semantic. But no fix seems to be on the way.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I see, thanks for the pointers. It's been open for several years, and even if k8s add a new interface in future, it's useful for kubeclient to be able to function against existing k8s versions. 👍

Compatibility on existing kubeconfig files is a good question, but given that previous behavior was a bug (impersonation settings were ignored), I'm not worried much about it.

Also, we're in the weird state that master branch has breaking changes since 4.y releases, but no 5.y releases were made yet, sparing the question of how exactly to semver it 😉

  • I like that Config supports multiple values but only Client will complain ✔️

Copy link
Collaborator

Choose a reason for hiding this comment

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

Should we print just some warning instead and fallback to trimming arrays with > 1 value to just the first value?

Not now. It would be incorrect & result will depend on order listed in kubeconfig.
If we do this invisibly, people may keep depending on it, making it hard to revert such a workaround...

I prefer merging with it correctly raising an error, and waiting for people to complain. Then they are in position to change their kubeconfigs, OR add custom trimming in their code between Config and Client — OR convince us the hassle is sufficient to bake the trimming kludge into kubeclient...

@DocX DocX requested a review from cben January 27, 2023 10:10
@cben
Copy link
Collaborator

cben commented Jan 29, 2023

  • Please add an entry in CHANGELOG.md. We grew a huge "changelog debt" :-(, which I hope to make up one day, but since this might break somebody best document it right away.

What about watches?

Watches still use https://github.com/httprb/http gem (#488 having some unresolved issues).
Does this implementation affect the headers we send there too? I think so, http_options method takes @headers.

  • Please add a unit test for watch. As long as we have 2 easy-to-diverge implementations, I prefer not to make HTTP-level changes without test coverage for both.

Otherwise LGTM 🚀

@DocX
Copy link
Contributor Author

DocX commented Feb 6, 2023

@cben thanks for the review. I've added the changelog and unit test for watch. Please take a look.

@DocX DocX changed the title support impersonation via aut_options and in kubectl config support impersonation via auth_options and in kubectl config Feb 6, 2023
Copy link
Collaborator

@cben cben left a comment

Choose a reason for hiding this comment

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

Excellent 💯

@cben cben merged commit 12ee475 into ManageIQ:master Feb 7, 2023
@DocX
Copy link
Contributor Author

DocX commented Feb 8, 2023

Thanks @cben. Is there any plan to publish new release with the update?

@DocX DocX deleted the grosser/impersonate branch February 8, 2023 10:59
@cben
Copy link
Collaborator

cben commented Feb 10, 2023

I need to make progress on my 5.0 changelog backlog to get master branch releasable...
I'm sorry, I can't give time estimate. But nagging is welcome ;-|

Alternatively, do you want to work on backporting this to v4.y branch which uses rest-client?
It'd require some changes, not sure it's worth the effort.

@DocX
Copy link
Contributor Author

DocX commented Feb 14, 2023

Ok, no problem. Just asking. It is not super critical for us, so we can wait (and we can always install gem from git if we need to)

@DocX DocX mentioned this pull request Feb 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants