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

Use workload identity for azure cli when Federated token file is present #4939

Merged
merged 2 commits into from
Jul 10, 2024

Conversation

nawazkh
Copy link
Member

@nawazkh nawazkh commented Jun 24, 2024

What type of PR is this?
/kind feature

What this PR does / why we need it:

  • ensure-azcli.sh will log in using AZURE_WORKLOAD_ID and --federated-token when AZURE_FEDERATED_TOKEN_FILE is available in the env.

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
POC as part of https://github.com/kubernetes/test-infra/blob/master/docs/job-migration-todo.md and #4976

Special notes for your reviewer:

  • Once this PR merges

    • We should be updating CAPZ test jobs with preset-azure-cred-wi: "true" preset and dropping any unrelated credential presets.
    • Migrate other test jobs to use WI.
  • cherry-pick candidate

TODOs:

  • squashed commits
  • includes documentation
  • adds unit tests

Release note:

`ensure-azcli.sh` will log in using `AZURE_WORKLOAD_ID` if `AZURE_FEDERATED_TOKEN_FILE` is available in the env.

@k8s-ci-robot
Copy link
Contributor

Skipping CI for Draft Pull Request.
If you want CI signal for your change, please convert it to an actual PR.
You can still manually trigger a test run with /test all

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 24, 2024
@nawazkh nawazkh changed the title fetch AZURE_WORKLOAD_ID var from prow use AZURE_WORKLOAD_ID var for prow Jun 24, 2024
Copy link

codecov bot commented Jun 24, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 62.24%. Comparing base (5a3f86f) to head (c3f6e88).
Report is 4 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main    #4939      +/-   ##
==========================================
- Coverage   62.25%   62.24%   -0.02%     
==========================================
  Files         201      201              
  Lines       16912    16912              
==========================================
- Hits        10529    10527       -2     
- Misses       5590     5592       +2     
  Partials      793      793              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

hack/parse-prow-creds.sh Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Jun 25, 2024
@nawazkh nawazkh marked this pull request as ready for review June 25, 2024 18:30
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Jun 25, 2024
hack/ensure-azcli.sh Outdated Show resolved Hide resolved
Copy link
Contributor

@mboersma mboersma left a comment

Choose a reason for hiding this comment

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

/lgtm

Seems like the right first step, so as not to break anything. I like your plan of action in the PR description. 👍🏻

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

LGTM label has been added.

Git tree hash: 1ad89fce498c9d1e5d73f4822f4df9d3cc83499e

@jackfrancis
Copy link
Contributor

/test ls

@k8s-ci-robot
Copy link
Contributor

@jackfrancis: The specified target(s) for /test were not found.
The following commands are available to trigger required jobs:

  • /test pull-cluster-api-provider-azure-apiversion-upgrade
  • /test pull-cluster-api-provider-azure-build
  • /test pull-cluster-api-provider-azure-ci-entrypoint
  • /test pull-cluster-api-provider-azure-e2e
  • /test pull-cluster-api-provider-azure-e2e-aks
  • /test pull-cluster-api-provider-azure-test
  • /test pull-cluster-api-provider-azure-verify

The following commands are available to trigger optional jobs:

  • /test pull-cluster-api-provider-azure-apidiff
  • /test pull-cluster-api-provider-azure-capi-e2e
  • /test pull-cluster-api-provider-azure-conformance
  • /test pull-cluster-api-provider-azure-conformance-custom-builds
  • /test pull-cluster-api-provider-azure-conformance-dual-stack-with-ci-artifacts
  • /test pull-cluster-api-provider-azure-conformance-ipv6-with-ci-artifacts
  • /test pull-cluster-api-provider-azure-conformance-with-ci-artifacts
  • /test pull-cluster-api-provider-azure-e2e-optional
  • /test pull-cluster-api-provider-azure-e2e-workload-upgrade
  • /test pull-cluster-api-provider-azure-windows-containerd-upstream-with-ci-artifacts-serial-slow
  • /test pull-cluster-api-provider-azure-windows-custom-builds
  • /test pull-cluster-api-provider-azure-windows-with-ci-artifacts

Use /test all to run the following jobs that were automatically triggered:

  • pull-cluster-api-provider-azure-apidiff
  • pull-cluster-api-provider-azure-build
  • pull-cluster-api-provider-azure-ci-entrypoint
  • pull-cluster-api-provider-azure-e2e
  • pull-cluster-api-provider-azure-e2e-aks
  • pull-cluster-api-provider-azure-test
  • pull-cluster-api-provider-azure-verify

In response to this:

/test ls

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-sigs/prow repository.

@jackfrancis
Copy link
Contributor

/test pull-cluster-api-provider-azure-capi-e2e
/test pull-cluster-api-provider-azure-conformance
/test pull-cluster-api-provider-azure-conformance-custom-builds
/test pull-cluster-api-provider-azure-conformance-dual-stack-with-ci-artifacts
/test pull-cluster-api-provider-azure-conformance-ipv6-with-ci-artifacts
/test pull-cluster-api-provider-azure-conformance-with-ci-artifacts
/test pull-cluster-api-provider-azure-e2e-optional
/test pull-cluster-api-provider-azure-e2e-workload-upgrade
/test pull-cluster-api-provider-azure-windows-custom-builds
/test pull-cluster-api-provider-azure-windows-with-ci-artifacts

@mboersma
Copy link
Contributor

This isn't a bugfix per se, but still I think we may want to cherry-pick this change in order to test it through test-infra.

@nawazkh
Copy link
Member Author

nawazkh commented Jun 27, 2024

/test pull-cluster-api-provider-azure-e2e-optional

@nawazkh
Copy link
Member Author

nawazkh commented Jul 9, 2024

/test pull-cluster-api-provider-azure-e2e-with-wi-optional

@nawazkh
Copy link
Member Author

nawazkh commented Jul 9, 2024

/test pull-cluster-api-provider-azure-e2e-with-wi-optional

nawazkh and others added 2 commits July 9, 2024 17:11
- use AZURE_FEDERATED_TOKEN_FILE while logging in via wi
- overload Azure client ID with Azure workload ID for WI based auth
- use auth mode for azure storage commands when using federated identity
- SC2086 use unquoted expansion with alt value
- use auth mode for azure storage commands when using federated identity
- SC2086 use unquoted expansion with alt value

Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
@nawazkh
Copy link
Member Author

nawazkh commented Jul 10, 2024

/test pull-cluster-api-provider-azure-e2e-with-wi-optional

@@ -69,16 +68,16 @@ main() {
echo "Building and pushing Linux and Windows amd64 Azure ACR credential provider"
make -C "${AZURE_CLOUD_PROVIDER_ROOT}" bin/azure-acr-credential-provider bin/azure-acr-credential-provider.exe

if [[ "$(az storage container exists --name "${AZURE_BLOB_CONTAINER_NAME}" --query exists --output tsv)" == "false" ]]; then
if [[ "$(az storage container exists ${ENABLE_AUTH_MODE_LOGIN:+"--auth-mode login"} --name "${AZURE_BLOB_CONTAINER_NAME}" --query exists --output tsv)" == "false" ]]; then
Copy link
Member Author

Choose a reason for hiding this comment

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

${ENABLE_AUTH_MODE_LOGIN:+"--auth-mode login"} is the penultimate workaround in the list of exceptions.
SC2086#exceptions

Note that the value of ENABLE_AUTH_MODE_LOGIN immaterial as long as it is set for ${ENABLE_AUTH_MODE_LOGIN:+"--auth-mode login"} evaluate to "--auth-mode login"

Copy link
Contributor

Choose a reason for hiding this comment

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

TIL

@nawazkh
Copy link
Member Author

nawazkh commented Jul 10, 2024

/test pull-cluster-api-provider-azure-windows-custom-builds

@nawazkh
Copy link
Member Author

nawazkh commented Jul 10, 2024

Created and closed the PR kubernetes/test-infra#32938. Adding here for my reference.

@jsturtevant
Copy link
Contributor

/lgtm

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

LGTM label has been added.

Git tree hash: 3866d1706d03a0465758caa8c982783d9830e1a8

@jsturtevant
Copy link
Contributor

/retitle Use workload identity for azure cli when Federated token file is present

@k8s-ci-robot k8s-ci-robot changed the title use AZURE_WORKLOAD_ID var for prow Use workload identity for azure cli when Federated token file is present Jul 10, 2024
@nawazkh
Copy link
Member Author

nawazkh commented Jul 10, 2024

/unhold

@k8s-ci-robot k8s-ci-robot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Jul 10, 2024
Copy link
Contributor

@nojnhuh nojnhuh left a comment

Choose a reason for hiding this comment

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

/lgtm

Thanks @nawazkh!

Copy link
Contributor

@mboersma mboersma left a comment

Choose a reason for hiding this comment

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

/lgtm


# Use --auth-mode "login" in az storage commands.
ENABLE_AUTH_MODE_LOGIN="true"
export ENABLE_AUTH_MODE_LOGIN
Copy link
Contributor

Choose a reason for hiding this comment

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

You can assign and export in one line, just fyi:

export ENABLE_AUTH_MODE_LOGIN="true"

Copy link
Member Author

Choose a reason for hiding this comment

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

I got a diff to use in the upcoming CAPZ test migration PR :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Sometimes linter complains about assign + export in one line though!

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Jul 10, 2024

@nawazkh: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-cluster-api-provider-azure-e2e-optional ebe5917 link false /test pull-cluster-api-provider-azure-e2e-optional

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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-sigs/prow repository. I understand the commands that are listed here.

@nawazkh
Copy link
Member Author

nawazkh commented Jul 10, 2024

Timed out.. :(

 [FAILED] Timed out after 1800.001s.
  Timed out waiting for 3 control plane machines to exist
  Expected
      <int>: 1
  to equal
      <int>: 3
  In [It] at: /home/prow/go/pkg/mod/sigs.k8s.io/cluster-api/test@v1.7.3/framework/controlplane_helpers.go:116 @ 07/10/24 20:48:37.121

/test pull-cluster-api-provider-azure-e2e

@k8s-ci-robot k8s-ci-robot merged commit 21479a9 into kubernetes-sigs:main Jul 10, 2024
28 checks passed
@nawazkh nawazkh deleted the capz_prow_2_wi branch July 10, 2024 22:35
jsturtevant added a commit to ritikaguptams/windows-testing that referenced this pull request Jul 10, 2024
Signed-off-by: James Sturtevant <jsturtevant@gmail.com>
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. 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
Archived in project
Development

Successfully merging this pull request may close these issues.

6 participants