Skip to content

Commit 3a2cb41

Browse files
Merge pull request #807 from r4f4/azure-azid-adal
IR-311: storage: azure: use azidentity with an adapter
2 parents bda548e + 0927eac commit 3a2cb41

File tree

157 files changed

+17149
-1839
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

157 files changed

+17149
-1839
lines changed

go.mod

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ require (
66
cloud.google.com/go/storage v1.10.0
77
github.com/Azure/azure-pipeline-go v0.2.3
88
github.com/Azure/azure-sdk-for-go v55.6.0+incompatible
9+
github.com/Azure/azure-sdk-for-go/sdk/azcore v1.1.4
10+
github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.1.0
911
github.com/Azure/azure-storage-blob-go v0.7.0
1012
github.com/Azure/go-autorest/autorest v0.11.27
11-
github.com/Azure/go-autorest/autorest/azure/auth v0.5.7
1213
github.com/Azure/go-autorest/autorest/mocks v0.4.2
1314
github.com/Azure/go-autorest/autorest/to v0.4.0
1415
github.com/IBM/go-sdk-core/v5 v5.5.0
@@ -25,6 +26,7 @@ require (
2526
github.com/gophercloud/gophercloud v1.1.0
2627
github.com/gophercloud/utils v0.0.0-20221124081324-7bac6f5cdf99
2728
github.com/goware/urlx v0.3.2
29+
github.com/jongio/azidext/go/azidext v0.4.0
2830
github.com/openshift/api v0.0.0-20221123130830-0dea1780a599
2931
github.com/openshift/build-machinery-go v0.0.0-20220913142420-e25cf57ea46d
3032
github.com/openshift/client-go v0.0.0-20221107163225-3335a34a1d24
@@ -47,13 +49,14 @@ require (
4749

4850
require (
4951
cloud.google.com/go v0.97.0 // indirect
52+
github.com/Azure/azure-sdk-for-go/sdk/internal v1.0.0 // indirect
5053
github.com/Azure/go-autorest v14.2.0+incompatible // indirect
5154
github.com/Azure/go-autorest/autorest/adal v0.9.20 // indirect
52-
github.com/Azure/go-autorest/autorest/azure/cli v0.4.2 // indirect
5355
github.com/Azure/go-autorest/autorest/date v0.3.0 // indirect
54-
github.com/Azure/go-autorest/autorest/validation v0.2.0 // indirect
56+
github.com/Azure/go-autorest/autorest/validation v0.3.1 // indirect
5557
github.com/Azure/go-autorest/logger v0.2.1 // indirect
5658
github.com/Azure/go-autorest/tracing v0.6.0 // indirect
59+
github.com/AzureAD/microsoft-authentication-library-for-go v0.5.1 // indirect
5760
github.com/NYTimes/gziphandler v1.1.1 // indirect
5861
github.com/PuerkitoBio/purell v1.1.1 // indirect
5962
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
@@ -64,7 +67,6 @@ require (
6467
github.com/cespare/xxhash/v2 v2.1.2 // indirect
6568
github.com/coreos/go-semver v0.3.0 // indirect
6669
github.com/coreos/go-systemd/v22 v22.3.2 // indirect
67-
github.com/dimchansky/utfbom v1.1.1 // indirect
6870
github.com/emicklei/go-restful/v3 v3.8.0 // indirect
6971
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
7072
github.com/felixge/httpsnoop v1.0.1 // indirect
@@ -80,7 +82,7 @@ require (
8082
github.com/go-playground/universal-translator v0.17.0 // indirect
8183
github.com/go-stack/stack v1.8.0 // indirect
8284
github.com/gogo/protobuf v1.3.2 // indirect
83-
github.com/golang-jwt/jwt/v4 v4.2.0 // indirect
85+
github.com/golang-jwt/jwt/v4 v4.4.1 // indirect
8486
github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
8587
github.com/golang/protobuf v1.5.2 // indirect
8688
github.com/google/gnostic v0.5.7-v3refs // indirect
@@ -95,6 +97,7 @@ require (
9597
github.com/jmespath/go-jmespath v0.4.0 // indirect
9698
github.com/josharian/intern v1.0.0 // indirect
9799
github.com/json-iterator/go v1.1.12 // indirect
100+
github.com/kylelemons/godebug v1.1.0 // indirect
98101
github.com/leodido/go-urn v1.2.0 // indirect
99102
github.com/mailru/easyjson v0.7.6 // indirect
100103
github.com/mattn/go-ieproxy v0.0.1 // indirect
@@ -106,6 +109,7 @@ require (
106109
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
107110
github.com/oklog/ulid v1.3.1 // indirect
108111
github.com/onsi/ginkgo v1.16.4 // indirect
112+
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4 // indirect
109113
github.com/pkg/errors v0.9.1 // indirect
110114
github.com/pkg/profile v1.3.0 // indirect
111115
github.com/pmezard/go-difflib v1.0.0 // indirect

go.sum

Lines changed: 31 additions & 17 deletions
Large diffs are not rendered by default.

pkg/storage/azure/azure.go

Lines changed: 24 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ import (
1111
"time"
1212

1313
"github.com/Azure/azure-pipeline-go/pipeline"
14+
"github.com/Azure/azure-sdk-for-go/sdk/azcore"
15+
"github.com/Azure/azure-sdk-for-go/sdk/azcore/cloud"
16+
"github.com/Azure/azure-sdk-for-go/sdk/azidentity"
1417
"github.com/Azure/azure-sdk-for-go/services/storage/mgmt/2019-06-01/storage"
1518
"github.com/Azure/azure-storage-blob-go/azblob"
1619
"github.com/Azure/go-autorest/autorest"
1720
autorestazure "github.com/Azure/go-autorest/autorest/azure"
18-
"github.com/Azure/go-autorest/autorest/azure/auth"
1921
"github.com/Azure/go-autorest/autorest/to"
22+
"github.com/jongio/azidext/go/azidext"
2023

2124
corev1 "k8s.io/api/core/v1"
2225
"k8s.io/apimachinery/pkg/api/errors"
@@ -299,16 +302,30 @@ func (d *driver) storageAccountsClient(cfg *Azure, environment autorestazure.Env
299302
if d.authorizer != nil {
300303
storageAccountsClient.Authorizer = d.authorizer
301304
} else {
302-
clientCredentialsConfig := auth.NewClientCredentialsConfig(cfg.ClientID, cfg.ClientSecret, cfg.TenantID)
303-
clientCredentialsConfig.Resource = environment.TokenAudience
304-
clientCredentialsConfig.AADEndpoint = environment.ActiveDirectoryEndpoint
305-
306-
auth, err := clientCredentialsConfig.Authorizer()
305+
cloudConfig := cloud.Configuration{
306+
ActiveDirectoryAuthorityHost: environment.ActiveDirectoryEndpoint,
307+
Services: map[cloud.ServiceName]cloud.ServiceConfiguration{
308+
cloud.ResourceManager: {
309+
Audience: environment.TokenAudience,
310+
Endpoint: environment.ResourceManagerEndpoint,
311+
},
312+
},
313+
}
314+
options := azidentity.ClientSecretCredentialOptions{
315+
ClientOptions: azcore.ClientOptions{
316+
Cloud: cloudConfig,
317+
},
318+
}
319+
cred, err := azidentity.NewClientSecretCredential(cfg.TenantID, cfg.ClientID, cfg.ClientSecret, &options)
307320
if err != nil {
308321
return storage.AccountsClient{}, err
309322
}
323+
scope := environment.TokenAudience
324+
if !strings.HasSuffix(scope, "/.default") {
325+
scope += "/.default"
326+
}
310327

311-
storageAccountsClient.Authorizer = auth
328+
storageAccountsClient.Authorizer = azidext.NewTokenCredentialAdapter(cred, []string{scope})
312329
}
313330

314331
if d.sender != nil {

0 commit comments

Comments
 (0)