-
Notifications
You must be signed in to change notification settings - Fork 21
feat: add ACR authentication #1014
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
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
c63356a
feat: add ACR authentication
xgugeng bd4fc3e
Enable registry scraping for image-pull-n10 scenario (#1013)
jasminetMSFT ca1ea37
add two pipeline job
xgugeng 023c28b
pipeline test
xgugeng ccfd379
Merge branch 'main' into gugeng/acr-auth
xgugeng 60edf47
fix typo
xgugeng 1a614f2
fix parsing error
xgugeng bdf81dc
fix location rissue
xgugeng 12e0b6d
remove location from az acr
xgugeng 1b90e2f
fix missing role
xgugeng cccc265
fix missing role #2
xgugeng 743749f
Merge branch 'main' into gugeng/acr-auth
xgugeng 6d701e0
reorder cases
xgugeng bdca669
Merge branch 'main' into gugeng/acr-auth
xgugeng a997672
Revert new-pipeline-test
xgugeng File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,68 @@ | ||
| parameters: | ||
| - name: region | ||
| type: string | ||
| - name: role | ||
| type: string | ||
|
|
||
| steps: | ||
| - script: | | ||
| set -euo pipefail | ||
| set -x | ||
|
|
||
| anonymous_pull="${ANONYMOUS_PULL:-True}" | ||
xgugeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| anonymous_pull="${anonymous_pull,,}" | ||
|
|
||
| acr_name="" | ||
| if [[ -n "$REGISTRY_ENDPOINT" ]]; then | ||
| az config unset defaults.location | ||
|
|
||
| acr_name=$(az resource list --resource-type Microsoft.ContainerRegistry/registries \ | ||
| --name "${REGISTRY_ENDPOINT%%.*}" \ | ||
| --query "[0].name" --output tsv) | ||
|
|
||
| az config set defaults.location="$REGION" | ||
| fi | ||
|
|
||
| [[ -n "$acr_name" ]] || exit 0 | ||
|
|
||
| acr_info=$(az acr show --name "$acr_name" --output json) | ||
| anonymous_pull_enabled=$(echo "$acr_info" | jq -r '.anonymousPullEnabled') | ||
| role_assignment_mode=$(echo "$acr_info" | jq -r '.roleAssignmentMode') | ||
|
|
||
| if [[ "$anonymous_pull" == "true" ]]; then | ||
| if [[ "$anonymous_pull_enabled" == "false" ]]; then | ||
| echo "Enabling anonymous pull for ACR $acr_name" | ||
| az acr update --name $acr_name --anonymous-pull-enabled | ||
xgugeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fi | ||
| else | ||
| if [[ "$anonymous_pull_enabled" == "true" ]]; then | ||
| echo "Disabling anonymous pull for ACR $acr_name" | ||
| az acr update --name $acr_name --anonymous-pull-enabled false | ||
xgugeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fi | ||
|
|
||
| if [[ "$role_assignment_mode" == "AbacRepositoryPermissions" ]]; then | ||
| echo "Updating role assignment mode from rbac-abac to rbac for ACR $acr_name" | ||
| az acr update --name $acr_name --role-assignment-mode "rbac" | ||
xgugeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fi | ||
|
|
||
| aks_info=$(az resource list \ | ||
| --resource-type Microsoft.ContainerService/managedClusters \ | ||
| --location "$REGION" \ | ||
| --query "[?tags.run_id=='${RUN_ID}' && tags.role=='${ROLE}']" \ | ||
| --output json) | ||
|
|
||
| aks_name=$(echo "$aks_info" | jq -r '.[0].name') | ||
| aks_rg=$(echo "$aks_info" | jq -r '.[0].resourceGroup') | ||
|
|
||
| if [ -z "$aks_name" ]; then | ||
| echo "##vso[task.logissue type=error;] No AKS instance with role $ROLE and tag $RUN_ID found in region $REGION." | ||
xgugeng marked this conversation as resolved.
Show resolved
Hide resolved
xgugeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| exit 1 | ||
| fi | ||
|
|
||
| az aks update --name $aks_name --resource-group $aks_rg --attach-acr $acr_name | ||
xgugeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| fi | ||
| env: | ||
| RUN_ID: $(RUN_ID) | ||
| REGION: ${{ parameters.region }} | ||
| ROLE: ${{ parameters.role }} | ||
xgugeng marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| displayName: "Authenticate with ACR from AKS" | ||
This file contains hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.