Make OAuth 2.0 client_id and client_secret mandatory#294
Make OAuth 2.0 client_id and client_secret mandatory#294roidelapluie merged 4 commits intoprometheus:mainfrom
Conversation
Signed-off-by: Levi Harrison <git@leviharrison.dev>
dd23553 to
e5fed51
Compare
config/http_config.go
Outdated
| 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) { |
There was a problem hiding this comment.
We generally use == 0 to check this.
Can we have 2 distincts errors? This would be more readable and more direct for the user.
There was a problem hiding this comment.
We also need the token url mandatory.
roidelapluie
left a comment
There was a problem hiding this comment.
Thanks,
token URL is also mandatory.
Signed-off-by: Levi Harrison <git@leviharrison.dev>
|
Whoops, that too. Thanks! |
config/http_config.go
Outdated
| 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") |
There was a problem hiding this comment.
I think that I would still prefer to use == 0 like elsewhere and have 2 different errors for better readability.
config/http_config.go
Outdated
| 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 { |
There was a problem hiding this comment.
| if len(c.OAuth2.TokenURL) < 1 { | |
| if len(c.OAuth2.TokenURL) == 0 { |
Signed-off-by: Levi Harrison <git@leviharrison.dev>
roidelapluie
left a comment
There was a problem hiding this comment.
Final nits to be consistent with the other error messages. After this is changed I will merge and release 0.23.0
config/http_config.go
Outdated
| 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") |
There was a problem hiding this comment.
| 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") |
config/http_config.go
Outdated
| 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") |
There was a problem hiding this comment.
| return fmt.Errorf("the oauth2 token_url must be configured") | |
| return fmt.Errorf("oauth2 token_url must be configured") |
config/http_config.go
Outdated
| 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") |
There was a problem hiding this comment.
| 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>
These should be mandatory as per the spec.
cc @roidelapluie