-
Notifications
You must be signed in to change notification settings - Fork 431
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2214 from mboersma/uai-test
Use MSI ClientID as userAssignedIdentityID in azure.json
- Loading branch information
Showing
15 changed files
with
170 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
Copyright 2022 The Kubernetes Authors. | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
package identities | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/Azure/azure-sdk-for-go/services/msi/mgmt/2018-11-30/msi" | ||
"github.com/Azure/go-autorest/autorest" | ||
azuresdk "github.com/Azure/go-autorest/autorest/azure" | ||
"sigs.k8s.io/cluster-api-provider-azure/azure" | ||
"sigs.k8s.io/cluster-api-provider-azure/util/tele" | ||
) | ||
|
||
// AzureClient contains the Azure go-sdk Client. | ||
type AzureClient struct { | ||
userAssignedIdentities msi.UserAssignedIdentitiesClient | ||
} | ||
|
||
// NewClient creates a new MSI client from auth info. | ||
func NewClient(auth azure.Authorizer) *AzureClient { | ||
c := newUserAssignedIdentitiesClient(auth.SubscriptionID(), auth.BaseURI(), auth.Authorizer()) | ||
return &AzureClient{c} | ||
} | ||
|
||
// newUserAssignedIdentitiesClient creates a new MSI client from subscription ID, base URI, and authorizer. | ||
func newUserAssignedIdentitiesClient(subscriptionID string, baseURI string, authorizer autorest.Authorizer) msi.UserAssignedIdentitiesClient { | ||
userAssignedIdentitiesClient := msi.NewUserAssignedIdentitiesClientWithBaseURI(baseURI, subscriptionID) | ||
azure.SetAutoRestClientDefaults(&userAssignedIdentitiesClient.Client, authorizer) | ||
return userAssignedIdentitiesClient | ||
} | ||
|
||
// Get returns a managed service identity. | ||
func (ac *AzureClient) Get(ctx context.Context, resourceGroupName, name string) (msi.Identity, error) { | ||
ctx, _, done := tele.StartSpanWithLogger(ctx, "identities.AzureClient.Get") | ||
defer done() | ||
|
||
return ac.userAssignedIdentities.Get(ctx, resourceGroupName, name) | ||
} | ||
|
||
// GetClientID returns the client ID of a managed service identity, given its full URL identifier. | ||
func (ac *AzureClient) GetClientID(ctx context.Context, providerID string) (string, error) { | ||
ctx, _, done := tele.StartSpanWithLogger(ctx, "identities.GetClientID") | ||
defer done() | ||
|
||
parsed, err := azuresdk.ParseResourceID(providerID) | ||
if err != nil { | ||
return "", err | ||
} | ||
ident, err := ac.Get(ctx, parsed.ResourceGroup, parsed.ResourceName) | ||
if err != nil { | ||
return "", err | ||
} | ||
return ident.ClientID.String(), nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
6 changes: 6 additions & 0 deletions
6
templates/test/ci/cluster-template-prow-external-cloud-provider.yaml
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
templates/test/ci/prow-dual-stack/patches/azure-machine-template-control-plane.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 | ||
kind: AzureMachineTemplate | ||
metadata: | ||
name: ${CLUSTER_NAME}-control-plane | ||
namespace: default | ||
spec: | ||
template: | ||
spec: | ||
identity: UserAssigned | ||
userAssignedIdentities: | ||
- providerID: /subscriptions/${AZURE_SUBSCRIPTION_ID}/resourceGroups/${CI_RG:=capz-ci}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/${USER_IDENTITY:=cloud-provider-user-identity} |
11 changes: 11 additions & 0 deletions
11
templates/test/ci/prow-dual-stack/patches/azure-machine-template.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 | ||
kind: AzureMachineTemplate | ||
metadata: | ||
name: ${CLUSTER_NAME}-md-0 | ||
namespace: default | ||
spec: | ||
template: | ||
spec: | ||
identity: UserAssigned | ||
userAssignedIdentities: | ||
- providerID: /subscriptions/${AZURE_SUBSCRIPTION_ID}/resourceGroups/${CI_RG:=capz-ci}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/${USER_IDENTITY:=cloud-provider-user-identity} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...es/test/ci/prow-external-cloud-provider/patches/azure-machine-template-control-plane.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 | ||
kind: AzureMachineTemplate | ||
metadata: | ||
name: ${CLUSTER_NAME}-control-plane | ||
namespace: default | ||
spec: | ||
template: | ||
spec: | ||
identity: UserAssigned | ||
userAssignedIdentities: | ||
- providerID: /subscriptions/${AZURE_SUBSCRIPTION_ID}/resourceGroups/${CI_RG:=capz-ci}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/${USER_IDENTITY:=cloud-provider-user-identity} |
11 changes: 11 additions & 0 deletions
11
templates/test/ci/prow-external-cloud-provider/patches/azure-machine-template.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1 | ||
kind: AzureMachineTemplate | ||
metadata: | ||
name: ${CLUSTER_NAME}-md-0 | ||
namespace: default | ||
spec: | ||
template: | ||
spec: | ||
identity: UserAssigned | ||
userAssignedIdentities: | ||
- providerID: /subscriptions/${AZURE_SUBSCRIPTION_ID}/resourceGroups/${CI_RG:=capz-ci}/providers/Microsoft.ManagedIdentity/userAssignedIdentities/${USER_IDENTITY:=cloud-provider-user-identity} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters