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

[v2.9] Azuread support #346

Merged
merged 15 commits into from
Apr 23, 2024
Merged

[v2.9] Azuread support #346

merged 15 commits into from
Apr 23, 2024

Conversation

enrichman
Copy link
Contributor

@enrichman enrichman commented Feb 1, 2024

Ref:

SURE-4275


This PR adds the support for the AzureAD provider. When configured the rancher token command will prompt the user to select it, or use the local login.

The CLI will use the Device Authorization Grant, so it will ask the user to enter a code in the URL, as discussed in the RFC.

The PR adds also some refinements and refactor:

The getAuthProviders func now returns a []TypedProvider. With rancher/rancher#44285 the GetType method was added, so that every provider automatically implements any interface with the same method.

type TypedProvider interface {
	GetType() string
}

func getAuthProviders(server string) ([]TypedProvider, error) {
	// fetch providers
}

With this we can actually do a type assertion on the returned interface and get the concrete underlying type.

Note: before merging the import for the struct will need to be updated.

Copy link
Contributor

@crobby crobby left a comment

Choose a reason for hiding this comment

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

One thought I had about the --prompt option that I figured I'd capture here before I forget. While it certainly works well, it feels like a bit of a non-standard approach to this sort of operation (copy/paste a URL from a blank page). We should definitely make sure that this UX is reasonable, and if it is, we should definitely add some extra text in the cli output to make it very clear to the user what the expected flow is in this scenario.

@enrichman
Copy link
Contributor Author

One thought I had about the --prompt option that I figured I'd capture here before I forget. While it certainly works well, it feels like a bit of a non-standard approach to this sort of operation (copy/paste a URL from a blank page). We should definitely make sure that this UX is reasonable, and if it is, we should definitely add some extra text in the cli output to make it very clear to the user what the expected flow is in this scenario.

@crobby that's a legit concern. What about having a Rancher UI page that is not doing anything in the backend, but just showing you the URL, or maybe the query params? That will be pretty cool, and actually useful also to show the errors. The user will be prompted to input the code, and/or the other parameters.

It need a bit of work on the UI side, but not much.

@enrichman
Copy link
Contributor Author

Just to have something visual this is what I was trying to come up:

Screenshot from 2024-02-12 17-38-44

Please don't pay too much attention to the graphic, I'm not a frontend guy. It will be nice to have also a "copy" button, so the user can easily copy-paste the code, or whatever he needs.

@enrichman enrichman force-pushed the azuread-support branch 2 times, most recently from 0965aa1 to 4a26aff Compare February 15, 2024 14:01
@enrichman enrichman mentioned this pull request Mar 26, 2024
@enrichman enrichman force-pushed the azuread-support branch 2 times, most recently from 3bbfa67 to 0a27e78 Compare March 29, 2024 09:57
@enrichman enrichman changed the title [POC][WIP] Azuread support Azuread support Mar 29, 2024
@enrichman
Copy link
Contributor Author

In the final implementation, implementing the RFC there is no update on the UI.

@crobby crobby self-requested a review April 12, 2024 15:49
@samjustus samjustus removed the request for review from bigkevmcd April 15, 2024 20:22
Copy link
Contributor

@crobby crobby left a comment

Choose a reason for hiding this comment

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

I think this looks pretty good.
Any chance of adding some unit tests? Might be reasonable to add a few at least for the new functionality.

- added getClient func to create once the HTTP client with the same TLS configuration.
- added tests for the getAuthProviders func
@enrichman
Copy link
Contributor Author

enrichman commented Apr 17, 2024

Thanks @crobby. I've added just a couple of tests to the getAuthProviders func. Others are probably possible, but not without a bit of a refactors.

With the latest commit I've added a getClient func, used to create the HTTP client once, with the same TLS config.

/cc FYI @samjustus @anupama2501

cmd/kubectl_token_test.go Outdated Show resolved Hide resolved
cmd/kubectl_token_test.go Outdated Show resolved Hide resolved
Copy link

@andreas-kupries andreas-kupries left a comment

Choose a reason for hiding this comment

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

The main issue with the local references is done.
Regarding the cert pool I defer to @pjbgf 's final assessment

Copy link
Contributor

@crobby crobby left a comment

Choose a reason for hiding this comment

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

I think this lgtm pending the feedback/resolution on the cert pool.

@enrichman
Copy link
Contributor Author

As discussed internally we can keep the changes as-is (reverting a func name) to keep the existing behaviour. We will address the issues in a next version of the cli.

/cc @crobby @andreas-kupries

@enrichman enrichman merged commit 36d1121 into rancher:v2.9 Apr 23, 2024
2 checks passed
@enrichman enrichman changed the title Azuread support [v2.9] Azuread support May 27, 2024
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.

[RFE] Rancher CLI doesn't have a driver for AzureAD for authenticating with kubectl
4 participants