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

Use idtoken for auth with basic as fallback #49

Merged
merged 4 commits into from
Dec 8, 2021

Conversation

rxbchen
Copy link
Collaborator

@rxbchen rxbchen commented Dec 3, 2021

With #48, adding idtoken auth for voucher_client. It auth fails, we fallback to basic

newClient.SetBasicAuth(defaultConfig.Username, defaultConfig.Password)
var newClient *client.Client
newClient, err := client.NewAuthClient(defaultConfig.Server)
if err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

FYI, this will not fail in GKE, so this will be executed only if voucher runs in a non-GCP environment. You need to use NewClient and SetBasicAuth directly, without AuthClient for it to work in GKE.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I wonder if we should have some flag to indicate that auth is required, so if I want to use the voucher_client cli I can specify that this requires auth via id tokens. Then, we can call either NewClient or AuthClient depending on auth being enabled or not...

Copy link
Collaborator

@lynnsh lynnsh Dec 3, 2021

Choose a reason for hiding this comment

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

That could be another option for sure. I was considering that, but I thought it'd be cleaner to choose between 2 functions instead of providing a flag or a boolean.
But good point, maybe it'd be more convenient here specifically. This way it'd be easier to switch between GKE and CloudRun.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I can definitely add support for that here! Since this is basically standalone from rest of voucher

Copy link
Collaborator

@dani-santos-code dani-santos-code Dec 8, 2021

Choose a reason for hiding this comment

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

Yeah. My thought here was that we wouldn't be getting an error back and it would try to create a client with Auth and it would fail the vouch checks as we've seen in auto-voucher. With the flag approach, we're making sure it's backwards compatible, so we know for sure which client to instantiate based on the flag

@rxbchen rxbchen requested a review from lynnsh December 7, 2021 22:08
@rxbchen
Copy link
Collaborator Author

rxbchen commented Dec 7, 2021

Updated the code to add support of configuring auth type

v2/cmd/voucher_client/README.md Outdated Show resolved Hide resolved
v2/cmd/voucher_client/root.go Show resolved Hide resolved
@dani-santos-code
Copy link
Collaborator

how are we testing this?

newClient, err := client.NewAuthClient(defaultConfig.Server)
return newClient, err
default:
newClient, err := client.NewClient(defaultConfig.Server)
Copy link
Collaborator

Choose a reason for hiding this comment

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

neat! 👏

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I ran the check manually (check if basic auth works) + will be testing it with cloudbuild later!

Copy link
Collaborator

Choose a reason for hiding this comment

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

Idea: be more explicit about how the basic option flows here (it's the same as the "default" case).

case "basic":
     fallthrough

Idea: maybe strings.ToLower(defaultConfig.Auth) ? The user can probably be trusted, but --auth IDTOKEN using basic auth is certainly unexpected.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

good point! I definitely like the idea of having default return an error! Will implement the changes you suggested

@rxbchen rxbchen requested a review from thepwagner December 8, 2021 18:05
Copy link
Collaborator

@thepwagner thepwagner left a comment

Choose a reason for hiding this comment

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

LGTM, and backwards compat.

I pondered if because "basic" is included as the default value, maybe the case "basic": clause should be made explicit, and the default: clause made to return an error (e.g. fmt.Errorf("invalid auth value: %q", defaultConfig.Auth)).
My thinking is that since the user has to be actively breaking something (by passing the --auth flag), it might be productive to fail fast.

newClient, err := client.NewAuthClient(defaultConfig.Server)
return newClient, err
default:
newClient, err := client.NewClient(defaultConfig.Server)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Idea: be more explicit about how the basic option flows here (it's the same as the "default" case).

case "basic":
     fallthrough

Idea: maybe strings.ToLower(defaultConfig.Auth) ? The user can probably be trusted, but --auth IDTOKEN using basic auth is certainly unexpected.

@rxbchen rxbchen merged commit 44492dd into main Dec 8, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants