Skip to content

Commit 06bf7e8

Browse files
LK4D4marefr
authored andcommitted
OAuth: Removes send_client_credentials_via_post setting (grafana#20044)
Removes send_client_credentials_via_post oauth setting and use auto-detect mechanism instead. By these changes also fixes statichcheck errors Ref grafana#8968
1 parent b12dc89 commit 06bf7e8

File tree

7 files changed

+47
-69
lines changed

7 files changed

+47
-69
lines changed

conf/defaults.ini

-1
Original file line numberDiff line numberDiff line change
@@ -387,7 +387,6 @@ tls_skip_verify_insecure = false
387387
tls_client_cert =
388388
tls_client_key =
389389
tls_client_ca =
390-
send_client_credentials_via_post = false
391390

392391
#################################### SAML Auth ###########################
393392
[auth.saml] # Enterprise only

conf/sample.ini

-4
Original file line numberDiff line numberDiff line change
@@ -378,10 +378,6 @@
378378
;tls_client_key =
379379
;tls_client_ca =
380380

381-
; Set to true to enable sending client_id and client_secret via POST body instead of Basic authentication HTTP header
382-
; This might be required if the OAuth provider is not RFC6749 compliant, only supporting credentials passed via POST payload
383-
;send_client_credentials_via_post = false
384-
385381
#################################### SAML Auth ###########################
386382
[auth.saml] # Enterprise only
387383
# Defaults to false. If true, the feature is enabled.

docs/sources/auth/generic-oauth.md

-14
Original file line numberDiff line numberDiff line change
@@ -219,20 +219,6 @@ allowed_organizations =
219219
auth_url = https://<your domain>.my.centrify.com/OAuth2/Authorize/<Application ID>
220220
token_url = https://<your domain>.my.centrify.com/OAuth2/Token/<Application ID>
221221
api_url = https://<your domain>.my.centrify.com/OAuth2/UserInfo/<Application ID>
222-
```
223-
224-
## Set up OAuth2 with non-compliant providers
225-
226-
> Only available in Grafana v6.0 and above.
227-
228-
Some OAuth2 providers might not support `client_id` and `client_secret` passed via Basic Authentication HTTP header, which
229-
results in `invalid_client` error. To allow Grafana to authenticate via these type of providers, the client identifiers must be
230-
send via POST body, which can be enabled via the following settings:
231-
232-
```bash
233-
[auth.generic_oauth]
234-
send_client_credentials_via_post = true
235-
```
236222
237223
## JMESPath examples
238224

docs/sources/installation/upgrading.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ sudo apt-get update
8585

8686
#### Upgrade from binary .tar file
8787

88-
If you downloaded the binary `.tar.gz` package, then you can just download and extract the new package and overwrite all your existing files. However, this might overwrite your config changes.
88+
If you downloaded the binary `.tar.gz` package, then you can just download and extract the new package and overwrite all your existing files. However, this might overwrite your config changes.
8989

9090
We recommend that you save your custom config changes in a file named `<grafana_install_dir>/conf/custom.ini`.
9191
This allows you to upgrade Grafana without risking losing your configuration changes.
@@ -222,3 +222,7 @@ Pre Grafana 6.5.0, the CloudWatch datasource used the GetMetricStatistics API fo
222222
Each request to the GetMetricData API can include 100 queries. This means that each panel in Grafana will only issue one GetMetricData request, regardless of the number of query rows that are present in the panel. Consequently as it is no longer possible to set `HighRes` on a per query level anymore, this switch is now removed from the query editor. High resolution can still be achieved by choosing a smaller minimum period in the query editor.
223223

224224
The handling of multi-valued template variables in dimension values has been changed in Grafana 6.5. When a multi template variable is being used, Grafana will generate a search expression. In the GetMetricData API, expressions are limited to 1024 characters, so it might be the case that this limit is reached when a multi-valued template variable that has a lot of values is being used. If this is the case, we suggest you start using `*` wildcard as dimension value instead of a multi-valued template variable.
225+
226+
## Upgrading to v6.6
227+
228+
The Generic OAuth setting `send_client_credentials_via_post`, used for supporting non-compliant providers, has been removed. From now on, Grafana will automatically detect if credentials should be sent as part of the URL or request body for a specific provider. The result will be remembered and used for additional OAuth requests for that provider.

pkg/login/social/social.go

+24-29
Original file line numberDiff line numberDiff line change
@@ -65,37 +65,30 @@ func NewOAuthService() {
6565
for _, name := range allOauthes {
6666
sec := setting.Raw.Section("auth." + name)
6767
info := &setting.OAuthInfo{
68-
ClientId: sec.Key("client_id").String(),
69-
ClientSecret: sec.Key("client_secret").String(),
70-
Scopes: util.SplitString(sec.Key("scopes").String()),
71-
AuthUrl: sec.Key("auth_url").String(),
72-
TokenUrl: sec.Key("token_url").String(),
73-
ApiUrl: sec.Key("api_url").String(),
74-
Enabled: sec.Key("enabled").MustBool(),
75-
EmailAttributeName: sec.Key("email_attribute_name").String(),
76-
EmailAttributePath: sec.Key("email_attribute_path").String(),
77-
RoleAttributePath: sec.Key("role_attribute_path").String(),
78-
AllowedDomains: util.SplitString(sec.Key("allowed_domains").String()),
79-
HostedDomain: sec.Key("hosted_domain").String(),
80-
AllowSignup: sec.Key("allow_sign_up").MustBool(),
81-
Name: sec.Key("name").MustString(name),
82-
TlsClientCert: sec.Key("tls_client_cert").String(),
83-
TlsClientKey: sec.Key("tls_client_key").String(),
84-
TlsClientCa: sec.Key("tls_client_ca").String(),
85-
TlsSkipVerify: sec.Key("tls_skip_verify_insecure").MustBool(),
86-
SendClientCredentialsViaPost: sec.Key("send_client_credentials_via_post").MustBool(),
68+
ClientId: sec.Key("client_id").String(),
69+
ClientSecret: sec.Key("client_secret").String(),
70+
Scopes: util.SplitString(sec.Key("scopes").String()),
71+
AuthUrl: sec.Key("auth_url").String(),
72+
TokenUrl: sec.Key("token_url").String(),
73+
ApiUrl: sec.Key("api_url").String(),
74+
Enabled: sec.Key("enabled").MustBool(),
75+
EmailAttributeName: sec.Key("email_attribute_name").String(),
76+
EmailAttributePath: sec.Key("email_attribute_path").String(),
77+
RoleAttributePath: sec.Key("role_attribute_path").String(),
78+
AllowedDomains: util.SplitString(sec.Key("allowed_domains").String()),
79+
HostedDomain: sec.Key("hosted_domain").String(),
80+
AllowSignup: sec.Key("allow_sign_up").MustBool(),
81+
Name: sec.Key("name").MustString(name),
82+
TlsClientCert: sec.Key("tls_client_cert").String(),
83+
TlsClientKey: sec.Key("tls_client_key").String(),
84+
TlsClientCa: sec.Key("tls_client_ca").String(),
85+
TlsSkipVerify: sec.Key("tls_skip_verify_insecure").MustBool(),
8786
}
8887

8988
if !info.Enabled {
9089
continue
9190
}
9291

93-
// handle the clients that do not properly support Basic auth headers and require passing client_id/client_secret via POST payload
94-
if info.SendClientCredentialsViaPost {
95-
// TODO: Fix the staticcheck error
96-
oauth2.RegisterBrokenAuthHeaderProvider(info.TokenUrl) //nolint:staticcheck
97-
}
98-
9992
if name == "grafananet" {
10093
name = grafanaCom
10194
}
@@ -106,8 +99,9 @@ func NewOAuthService() {
10699
ClientID: info.ClientId,
107100
ClientSecret: info.ClientSecret,
108101
Endpoint: oauth2.Endpoint{
109-
AuthURL: info.AuthUrl,
110-
TokenURL: info.TokenUrl,
102+
AuthURL: info.AuthUrl,
103+
TokenURL: info.TokenUrl,
104+
AuthStyle: oauth2.AuthStyleAutoDetect,
111105
},
112106
RedirectURL: strings.TrimSuffix(setting.AppUrl, "/") + SocialBaseUrl + name,
113107
Scopes: info.Scopes,
@@ -181,8 +175,9 @@ func NewOAuthService() {
181175
ClientID: info.ClientId,
182176
ClientSecret: info.ClientSecret,
183177
Endpoint: oauth2.Endpoint{
184-
AuthURL: setting.GrafanaComUrl + "/oauth2/authorize",
185-
TokenURL: setting.GrafanaComUrl + "/api/oauth2/token",
178+
AuthURL: setting.GrafanaComUrl + "/oauth2/authorize",
179+
TokenURL: setting.GrafanaComUrl + "/api/oauth2/token",
180+
AuthStyle: oauth2.AuthStyleInHeader,
186181
},
187182
RedirectURL: strings.TrimSuffix(setting.AppUrl, "/") + SocialBaseUrl + name,
188183
Scopes: info.Scopes,

pkg/services/provisioning/dashboards/file_reader.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -54,11 +54,10 @@ func NewDashboardFileReader(cfg *DashboardsAsConfig, log log.Logger) (*fileReade
5454
// pollChanges periodically runs startWalkingDisk based on interval specified in the config.
5555
func (fr *fileReader) pollChanges(ctx context.Context) {
5656

57-
// TODO: Fix the staticcheck error
58-
ticker := time.Tick(time.Duration(int64(time.Second) * fr.Cfg.UpdateIntervalSeconds)) //nolint:staticcheck
57+
ticker := time.NewTicker(time.Duration(int64(time.Second) * fr.Cfg.UpdateIntervalSeconds))
5958
for {
6059
select {
61-
case <-ticker:
60+
case <-ticker.C:
6261
if err := fr.startWalkingDisk(); err != nil {
6362
fr.log.Error("failed to search for dashboards", "error", err)
6463
}

pkg/setting/setting_oauth.go

+16-17
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,22 @@
11
package setting
22

33
type OAuthInfo struct {
4-
ClientId, ClientSecret string
5-
Scopes []string
6-
AuthUrl, TokenUrl string
7-
Enabled bool
8-
EmailAttributeName string
9-
EmailAttributePath string
10-
RoleAttributePath string
11-
AllowedDomains []string
12-
HostedDomain string
13-
ApiUrl string
14-
AllowSignup bool
15-
Name string
16-
TlsClientCert string
17-
TlsClientKey string
18-
TlsClientCa string
19-
TlsSkipVerify bool
20-
SendClientCredentialsViaPost bool
4+
ClientId, ClientSecret string
5+
Scopes []string
6+
AuthUrl, TokenUrl string
7+
Enabled bool
8+
EmailAttributeName string
9+
EmailAttributePath string
10+
RoleAttributePath string
11+
AllowedDomains []string
12+
HostedDomain string
13+
ApiUrl string
14+
AllowSignup bool
15+
Name string
16+
TlsClientCert string
17+
TlsClientKey string
18+
TlsClientCa string
19+
TlsSkipVerify bool
2120
}
2221

2322
type OAuther struct {

0 commit comments

Comments
 (0)