Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Azure resource ID as userAssignedIdentityID #1290

Merged

Conversation

ArchangelSDY
Copy link
Contributor

@ArchangelSDY ArchangelSDY commented Mar 20, 2022

What type of PR is this?

/kind feature

What this PR does / why we need it:

Support Azure resource ID as userAssignedIdentityID. This makes it a bit more convenient as resource ID is more user-friendly.

Which issue(s) this PR fixes:

Fixes #

Special notes for your reviewer:

Does this PR introduce a user-facing change?

Support ARM resource ID as `userAssignedIdentityID`

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:


@k8s-ci-robot k8s-ci-robot added kind/feature Categorizes issue or PR as related to a new feature. do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Mar 20, 2022
@k8s-ci-robot
Copy link
Contributor

Welcome @ArchangelSDY!

It looks like this is your first PR to kubernetes-sigs/cloud-provider-azure 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes-sigs/cloud-provider-azure has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @ArchangelSDY. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 20, 2022
@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed do-not-merge/release-note-label-needed Indicates that a PR should not merge because it's missing one of the release note labels. labels Mar 20, 2022
@ArchangelSDY ArchangelSDY changed the title Support ARM resource ID as userAssignedIdentityID Support Azure resource ID as userAssignedIdentityID Mar 20, 2022
return adal.NewServicePrincipalTokenFromMSIWithUserAssignedID(msiEndpoint,
resource,
config.UserAssignedIdentityID)
if config.UserAssignedIdentityID[0] == '/' {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what about changing the validation to something like below:

var isResourceID = regexp.MustCompile(
	`(?i)/subscriptions/(.+?)/resourcegroups/(.+?)/providers/Microsoft..*`).MatchString

if if isResourceID(config.UserAssignedIdentityID) {...}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea. Updated to use a standard function azure.ParseResourceID()

resource,
config.UserAssignedIdentityID)
} else {
klog.V(4).Info("azure: User Assigned MSI ID is client ID")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should be error here instead of info

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Resource ID paring error doesn't necessarily mean a config error because it could be a client id (GUID). I will include the error message in the info log for better diagnostics.

@nilo19
Copy link
Contributor

nilo19 commented Mar 25, 2022

Is it possible to enrich unit test for this change?

@nilo19
Copy link
Contributor

nilo19 commented Mar 25, 2022

/ok-to-test

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Mar 25, 2022
@ArchangelSDY
Copy link
Contributor Author

Is it possible to enrich unit test for this change?

Added some unit tests.

@nilo19
Copy link
Contributor

nilo19 commented Mar 25, 2022

Don't forget to squash the commits.

This makes it a bit more convenient.
@ArchangelSDY
Copy link
Contributor Author

Don't forget to squash the commits.

Squashed.

@ArchangelSDY
Copy link
Contributor Author

/retest

1 similar comment
@nilo19
Copy link
Contributor

nilo19 commented Mar 27, 2022

/retest

@nilo19
Copy link
Contributor

nilo19 commented Mar 29, 2022

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 29, 2022
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: ArchangelSDY, nilo19

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 29, 2022
@k8s-ci-robot k8s-ci-robot merged commit b61509f into kubernetes-sigs:master Mar 29, 2022
@jackfrancis
Copy link
Contributor

are we planning on cherry-picking this PR?

@feiskyer
Copy link
Member

@lzhecheng could you help to cherry-pick this PR?

@lzhecheng
Copy link
Contributor

/cherrypick release-1.23

@lzhecheng
Copy link
Contributor

/cherrypick release-1.1

@lzhecheng
Copy link
Contributor

/cherrypick release-1.0

@k8s-infra-cherrypick-robot

@lzhecheng: new pull request created: #1616

In response to this:

/cherrypick release-1.23

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-infra-cherrypick-robot

@lzhecheng: new pull request created: #1617

In response to this:

/cherrypick release-1.1

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-infra-cherrypick-robot

@lzhecheng: new pull request created: #1618

In response to this:

/cherrypick release-1.0

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

config.UserAssignedIdentityID)
}

klog.V(4).Info("azure: User Assigned MSI ID is client ID. Resource ID parsing error: %+v", err)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ArchangelSDY , I got this error now, from current code logic, looks like it's just an info log, I think we need to refine the logging, otherwise there will be following error as long as User Assigned MSI ID is client ID

[pod/csi-blob-node-8trh8/blob] I0812 03:15:51.934107       1 azure_auth.go:245] Using AzurePublicCloud environment
[pod/csi-blob-node-8trh8/blob] I0812 03:15:51.934127       1 azure_auth.go:96] azure: using managed identity extension to retrieve access token
[pod/csi-blob-node-8trh8/blob] I0812 03:15:51.934131       1 azure_auth.go:102] azure: using User Assigned MSI ID to retrieve access token
[pod/csi-blob-node-8trh8/blob] I0812 03:15:51.934162       1 azure_auth.go:113] azure: User Assigned MSI ID is client ID. Resource ID parsing error: %+vparsing failed for 82e9bd91-c283-4b2d-8708-6d11b07d630d. Invalid resource Id format

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

anyway, let me refine the logging to fix this error msg

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants