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 apikey auth #46

Merged
merged 4 commits into from
May 30, 2021
Merged

Conversation

fgouteroux
Copy link
Contributor

Hi @jtopjian,

It's been a while, ;-)

Adding support of api key authentication (more secure than username/password), based on sensu/sensu-go#4256.

@fgouteroux
Copy link
Contributor Author

Tested on sensu backend 5.21 and 6.2.5

@jtopjian
Copy link
Owner

@fgouteroux Cool - thanks for working on this.

Overall this looks good to me. but now that username, password, and an API key are all optional, I think we should add some kind of additional logic to make sure that the user has supplied a valid combination of authentication. This should probably go in LoadAndValidate method. Something like:

if c.username == "" && c.password == "" && c.apiKey == "" {
    return nil, fmt.Errorf("Must provide a username and password or an API key")
}

if c.username != "" && c.password == "" {
  return nil, fmt.Errorf("Must provide a password when using a username")
}

etc

Thoughts?

@fgouteroux
Copy link
Contributor Author

@fgouteroux Cool - thanks for working on this.

Overall this looks good to me. but now that username, password, and an API key are all optional, I think we should add some kind of additional logic to make sure that the user has supplied a valid combination of authentication. This should probably go in LoadAndValidate method. Something like:

if c.username == "" && c.password == "" && c.apiKey == "" {
    return nil, fmt.Errorf("Must provide a username and password or an API key")
}

if c.username != "" && c.password == "" {
  return nil, fmt.Errorf("Must provide a password when using a username")
}

etc

Thoughts?

Yes, you are right, so I also added the schema conflicts keys, which provide this output when api_key and username/password are provided together.

Error: "api_key": conflicts with username

Error: "username": conflicts with api_key

Error: "password": conflicts with api_key

@jtopjian
Copy link
Owner

Nice work 🙂

Let me know if you're ready for this to be merged.

@fgouteroux
Copy link
Contributor Author

Yes, this is ready to be merged.

Copy link
Owner

@jtopjian jtopjian left a comment

Choose a reason for hiding this comment

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

LGTM - thank you!

@jtopjian jtopjian merged commit 96f5425 into jtopjian:master May 30, 2021
@fgouteroux fgouteroux deleted the support_apikey_auth branch May 31, 2021 07:06
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.

2 participants