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

Give descriptive error if auth method not found #10163

Merged
merged 2 commits into from
May 3, 2021

Conversation

lkysow
Copy link
Member

@lkysow lkysow commented May 1, 2021

Previously during a consul login -method=blah, if the auth method was not found, the
error returned would be "ACL not found". This is potentially confusing
because there may be many different ACLs involved in a login: the ACL of
the Consul client, perhaps the binding rule or the auth method.

Now the error will be "auth method blah not found", which is much easier
to debug.

@lkysow lkysow force-pushed the lkysow/auth-method-not-found branch from 4f1f60f to 984e50d Compare May 1, 2021 04:55
@vercel vercel bot temporarily deployed to Preview – consul May 1, 2021 04:56 Inactive
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging May 1, 2021 04:56 Inactive
@lkysow lkysow force-pushed the lkysow/auth-method-not-found branch from 984e50d to 2a75560 Compare May 1, 2021 04:56
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging May 1, 2021 04:56 Inactive
@vercel vercel bot temporarily deployed to Preview – consul May 1, 2021 04:56 Inactive
Previously during a `consul login -method=blah`, if the auth method was not found, the
error returned would be "ACL not found". This is potentially confusing
because there may be many different ACLs involved in a login: the ACL of
the Consul client, perhaps the binding rule or the auth method.

Now the error will be "auth method blah not found", which is much easier
to debug.
@lkysow lkysow force-pushed the lkysow/auth-method-not-found branch from 2a75560 to 9dd9013 Compare May 1, 2021 05:13
@vercel vercel bot temporarily deployed to Preview – consul-ui-staging May 1, 2021 05:14 Inactive
@vercel vercel bot temporarily deployed to Preview – consul May 1, 2021 05:14 Inactive
Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

Thanks @lkysow for working on improving the error message! Left some comments about how we can keep the 4xx status code.

@@ -143,7 +143,7 @@ func TestLoginCommand(t *testing.T) {

code := cmd.Run(args)
require.Equal(t, code, 1, "err: %s", ui.ErrorWriter.String())
require.Contains(t, ui.ErrorWriter.String(), "403 (ACL not found)")
require.Contains(t, ui.ErrorWriter.String(), "500 (auth method \"test\" not found)")
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't think we want a 500 response code for this. Either a 404 or 403 seems appropriate.

There's some related context in #8520 (comment) (and the associated issue).

Copy link
Member Author

Choose a reason for hiding this comment

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

Totally agreed, didn't know how to do that but your suggestion works like a charm!

@@ -2380,7 +2380,7 @@ func (a *ACL) Login(args *structs.ACLLoginRequest, reply *structs.ACLToken) erro
if err != nil {
return err
} else if method == nil {
return acl.ErrNotFound
return fmt.Errorf("auth method %q not found", auth.AuthMethod)
Copy link
Contributor

Choose a reason for hiding this comment

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

Oops, forgot to submit this comment:

I think we'll need something like this:

Suggested change
return fmt.Errorf("auth method %q not found", auth.AuthMethod)
return fmt.Errorf("auth method %q: %w", auth.AuthMethod, acl.ErrNotFound)

Copy link
Member Author

Choose a reason for hiding this comment

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

I swapped it around so it reads ACL not found: auth method <blah> not found

@vercel vercel bot temporarily deployed to Preview – consul-ui-staging May 3, 2021 18:25 Inactive
@vercel vercel bot temporarily deployed to Preview – consul May 3, 2021 18:25 Inactive
@lkysow lkysow requested a review from dnephin May 3, 2021 18:26
Copy link
Contributor

@dnephin dnephin left a comment

Choose a reason for hiding this comment

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

LGTM!

@dnephin dnephin added backport/1.10 theme/acls ACL and token generation type/enhancement Proposed improvement or new feature labels May 3, 2021
@lkysow lkysow merged commit 8d6cbe7 into master May 3, 2021
@lkysow lkysow deleted the lkysow/auth-method-not-found branch May 3, 2021 20:39
@hc-github-team-consul-core
Copy link
Contributor

🍒 If backport labels were added before merging, cherry-picking will start automatically.

To retroactively trigger a backport after merging, add backport labels and re-run https://circleci.com/gh/hashicorp/consul/361410.

@hc-github-team-consul-core
Copy link
Contributor

🍒✅ Cherry pick of commit 8d6cbe7 onto release/1.10.x succeeded!

hc-github-team-consul-core pushed a commit that referenced this pull request May 3, 2021
* Give descriptive error if auth method not found

Previously during a `consul login -method=blah`, if the auth method was not found, the
error returned would be "ACL not found". This is potentially confusing
because there may be many different ACLs involved in a login: the ACL of
the Consul client, perhaps the binding rule or the auth method.

Now the error will be "auth method blah not found", which is much easier
to debug.
@hc-github-team-consul-core
Copy link
Contributor

🍒✅ Cherry pick of commit 8d6cbe7 onto release/1.9.x succeeded!

hc-github-team-consul-core pushed a commit that referenced this pull request May 3, 2021
* Give descriptive error if auth method not found

Previously during a `consul login -method=blah`, if the auth method was not found, the
error returned would be "ACL not found". This is potentially confusing
because there may be many different ACLs involved in a login: the ACL of
the Consul client, perhaps the binding rule or the auth method.

Now the error will be "auth method blah not found", which is much easier
to debug.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
theme/acls ACL and token generation type/enhancement Proposed improvement or new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants