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

Make OAuth 2.0 client_id and client_secret mandatory #294

Merged

Conversation

LeviHarrison
Copy link
Contributor

These should be mandatory as per the spec.

cc @roidelapluie

Signed-off-by: Levi Harrison <git@leviharrison.dev>
@@ -210,6 +210,9 @@ func (c *HTTPClientConfig) Validate() error {
if c.BasicAuth != nil {
return fmt.Errorf("at most one of basic_auth, oauth2 & authorization must be configured")
}
if len(c.OAuth2.ClientID) < 1 || (len(c.OAuth2.ClientSecret) < 1 || len(c.OAuth2.ClientSecretFile) < 1) {
Copy link
Member

Choose a reason for hiding this comment

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

We generally use == 0 to check this.

Can we have 2 distincts errors? This would be more readable and more direct for the user.

Copy link
Member

Choose a reason for hiding this comment

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

We also need the token url mandatory.

Copy link
Member

@roidelapluie roidelapluie left a comment

Choose a reason for hiding this comment

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

Thanks,

token URL is also mandatory.

Signed-off-by: Levi Harrison <git@leviharrison.dev>
@LeviHarrison
Copy link
Contributor Author

Whoops, that too. Thanks!

@@ -210,6 +210,12 @@ func (c *HTTPClientConfig) Validate() error {
if c.BasicAuth != nil {
return fmt.Errorf("at most one of basic_auth, oauth2 & authorization must be configured")
}
if len(c.OAuth2.ClientID) < 1 || (len(c.OAuth2.ClientSecret) < 1 && len(c.OAuth2.ClientSecretFile) < 1) {
return fmt.Errorf("the oauth2 client_id and either the client_secret or client_secret_file must be configured")
Copy link
Member

Choose a reason for hiding this comment

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

I think that I would still prefer to use == 0 like elsewhere and have 2 different errors for better readability.

if len(c.OAuth2.ClientID) < 1 || (len(c.OAuth2.ClientSecret) < 1 && len(c.OAuth2.ClientSecretFile) < 1) {
return fmt.Errorf("the oauth2 client_id and either the client_secret or client_secret_file must be configured")
}
if len(c.OAuth2.TokenURL) < 1 {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if len(c.OAuth2.TokenURL) < 1 {
if len(c.OAuth2.TokenURL) == 0 {

Signed-off-by: Levi Harrison <git@leviharrison.dev>
Copy link
Member

@roidelapluie roidelapluie left a comment

Choose a reason for hiding this comment

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

Final nits to be consistent with the other error messages. After this is changed I will merge and release 0.23.0

return fmt.Errorf("the oauth2 client_id must be configured")
}
if len(c.OAuth2.ClientSecret) == 0 && len(c.OAuth2.ClientSecretFile) == 0 {
return fmt.Errorf("either the oauth2 client_secret or client_secret_file must be configured")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("either the oauth2 client_secret or client_secret_file must be configured")
return fmt.Errorf("either oauth2 client_secret or client_secret_file must be configured")

return fmt.Errorf("either the oauth2 client_secret or client_secret_file must be configured")
}
if len(c.OAuth2.TokenURL) == 0 {
return fmt.Errorf("the oauth2 token_url must be configured")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("the oauth2 token_url must be configured")
return fmt.Errorf("oauth2 token_url must be configured")

@@ -210,6 +210,15 @@ func (c *HTTPClientConfig) Validate() error {
if c.BasicAuth != nil {
return fmt.Errorf("at most one of basic_auth, oauth2 & authorization must be configured")
}
if len(c.OAuth2.ClientID) == 0 {
return fmt.Errorf("the oauth2 client_id must be configured")
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return fmt.Errorf("the oauth2 client_id must be configured")
return fmt.Errorf("oauth2 client_id must be configured")

Signed-off-by: Levi Harrison <git@leviharrison.dev>
Copy link
Member

@roidelapluie roidelapluie left a comment

Choose a reason for hiding this comment

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

Thanks!!!

@roidelapluie roidelapluie merged commit b4304c5 into prometheus:main Apr 27, 2021
@LeviHarrison LeviHarrison deleted the oauth-require-client-fields branch April 27, 2021 21:38
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