Skip to content

Commit 5ccebcd

Browse files
committed
remote/azuread: use Secret type for OAuth client_secret
The ClientSecret field in OAuthConfig was typed as plain string, causing it to be exposed in plaintext via the /-/config HTTP endpoint. Change it to config_util.Secret so Prometheus redacts it as <secret>. Signed-off-by: Julien Pivotto <[email protected]>
1 parent f0f0fdd commit 5ccebcd

2 files changed

Lines changed: 9 additions & 7 deletions

File tree

storage/remote/azuread/azuread.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ import (
2727
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
2828
"github.com/google/uuid"
2929
"github.com/grafana/regexp"
30+
config_util "github.com/prometheus/common/config"
3031
)
3132

3233
// Clouds.
@@ -75,7 +76,7 @@ type OAuthConfig struct {
7576
ClientID string `yaml:"client_id,omitempty"`
7677

7778
// ClientSecret is the clientSecret of the azure active directory application that is being used to authenticate.
78-
ClientSecret string `yaml:"client_secret,omitempty"`
79+
ClientSecret config_util.Secret `yaml:"client_secret,omitempty"`
7980

8081
// TenantID is the tenantId of the azure active directory application that is being used to authenticate.
8182
TenantID string `yaml:"tenant_id,omitempty"`
@@ -357,7 +358,7 @@ func newWorkloadIdentityTokenCredential(clientOpts *azcore.ClientOptions, worklo
357358
// newOAuthTokenCredential returns new OAuth token credential.
358359
func newOAuthTokenCredential(clientOpts *azcore.ClientOptions, oAuthConfig *OAuthConfig) (azcore.TokenCredential, error) {
359360
opts := &azidentity.ClientSecretCredentialOptions{ClientOptions: *clientOpts}
360-
return azidentity.NewClientSecretCredential(oAuthConfig.TenantID, oAuthConfig.ClientID, oAuthConfig.ClientSecret, opts)
361+
return azidentity.NewClientSecretCredential(oAuthConfig.TenantID, oAuthConfig.ClientID, string(oAuthConfig.ClientSecret), opts)
361362
}
362363

363364
// newSDKTokenCredential returns new SDK token credential.

storage/remote/azuread/azuread_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,19 @@ import (
2525
"github.com/Azure/azure-sdk-for-go/sdk/azcore/policy"
2626
"github.com/google/uuid"
2727
"github.com/prometheus/client_golang/prometheus/promhttp"
28+
config_util "github.com/prometheus/common/config"
2829
"github.com/stretchr/testify/mock"
2930
"github.com/stretchr/testify/require"
3031
"github.com/stretchr/testify/suite"
3132
"go.yaml.in/yaml/v2"
3233
)
3334

3435
const (
35-
dummyAudience = "dummyAudience"
36-
dummyClientID = "00000000-0000-0000-0000-000000000000"
37-
dummyClientSecret = "Cl1ent$ecret!"
38-
dummyTenantID = "00000000-a12b-3cd4-e56f-000000000000"
39-
testTokenString = "testTokenString"
36+
dummyAudience = "dummyAudience"
37+
dummyClientID = "00000000-0000-0000-0000-000000000000"
38+
dummyClientSecret config_util.Secret = "Cl1ent$ecret!"
39+
dummyTenantID = "00000000-a12b-3cd4-e56f-000000000000"
40+
testTokenString = "testTokenString"
4041
)
4142

4243
func testTokenExpiry() time.Time { return time.Now().Add(5 * time.Second) }

0 commit comments

Comments
 (0)