T keithyao/batch purge Adds ABAC support for purge command with batched token requests#577
T keithyao/batch purge Adds ABAC support for purge command with batched token requests#577keithy1012 wants to merge 11 commits intoAzure:mainfrom
Conversation
|
@keithy1012 please read the following Contributor License Agreement(CLA). If you agree with the CLA, please reply with the following information.
Contributor License AgreementContribution License AgreementThis Contribution License Agreement (“Agreement”) is agreed to by the party signing below (“You”),
|
| } | ||
|
|
||
| // newAcrCLIClientWithBasicAuth creates a client that uses basic authentication. | ||
| func newAcrCLIClientWithBasicAuth(loginURL string, username string, password string) AcrCLIClient { |
There was a problem hiding this comment.
when you setup basic auth and you try to use purge on abac, does it work?
There was a problem hiding this comment.
Yes, just tested and confirmed.
cmd/acr/purge.go
Outdated
| includeLocked bool) (deletedTagsCount int, deletedManifestsCount int, err error) { | ||
|
|
||
| // Parse the duration once instead of for every repository | ||
| agoDuration, err := parseDuration(tagDeletionSince) |
There was a problem hiding this comment.
What is tagDeletionSince? It's not a declared variable
lizMSFT
left a comment
There was a problem hiding this comment.
You could follow https://github.com/Azure/acr-cli/tree/main?tab=readme-ov-file#installation to build the binary or check https://github.com/Azure/acr-cli/blob/main/scripts/experimental/README-purge-testing.md#1-test-purge-allsh-consolidated-test-suite and test the changes locally first.
cmd/acr/purge.go
Outdated
| // Process all repositories in this batch with the batched token | ||
| for _, repoName := range batch { | ||
| tagRegex := tagFilters[repoName] | ||
| singleDeletedTagsCount, manifestToTagsCountMap, err := purgeTags(ctx, acrClient, repoParallelism, loginURL, repoName, agoDuration, tagRegex, tagsToKeep, filterTimeout, dryRun, includeLocked) |
cmd/acr/purge.go
Outdated
| singleDeletedManifestsCount := 0 | ||
| // If the untagged flag is set then also manifests are deleted. | ||
| if removeUtaggedManifests { | ||
| singleDeletedManifestsCount, err = purgeDanglingManifests(ctx, acrClient, repoParallelism, loginURL, repoName, agoDuration, manifestToTagsCountMap, dryRun, includeLocked) |
There was a problem hiding this comment.
The function signature requires keep int as the 7th parameter, but it's missing.
internal/api/acrsdk.go
Outdated
| // Each repository needs pull, delete, and metadata permissions for purge operations. | ||
| // Format: "registry:catalog:* repository:repo1:pull repository:repo1:delete repository:repo1:metadata_read ..." | ||
| var scopeParts []string | ||
| scopeParts = append(scopeParts, "registry:catalog:*") |
There was a problem hiding this comment.
registry:catalog:* might not needed for checking the repository level permissions
internal/api/acrsdk.go
Outdated
|
|
||
| // Build the scope string for all requested repositories. | ||
| // Each repository needs pull, delete, and metadata permissions for purge operations. | ||
| // Format: "registry:catalog:* repository:repo1:pull repository:repo1:delete repository:repo1:metadata_read ..." |
There was a problem hiding this comment.
should be repository:repo1:pull,delete,metadata_read,metadata_write
internal/api/acrsdk.go
Outdated
| newAcrCLIClient := newAcrCLIClient(loginURL) | ||
|
|
||
| // Detect if this is an ABAC-enabled registry by checking for aad_identity claim | ||
| newAcrCLIClient.isAbac = hasAadIdentityClaim(refreshToken) |
There was a problem hiding this comment.
Can we first check abac from refreshToken and then constrcrt newAcrCLIClient?
| // Request a token that covers all repositories in this batch | ||
| // The token scope will include: repository:repo1:pull repository:repo1:delete ... for each repo | ||
| if err := acrClient.RefreshTokenForAbac(ctx, batch); err != nil { | ||
| return deletedTagsCount, deletedManifestsCount, fmt.Errorf("failed to authorize ABAC repositories batch: %w", err) |
There was a problem hiding this comment.
can we output the repository names in the batch?
cmd/acr/purge.go
Outdated
| headerLink = "Link" | ||
|
|
||
| // abacBatchSize is the number of repositories to batch together when requesting tokens for ABAC registries. | ||
| abacBatchSize = 10 |
There was a problem hiding this comment.
I suggest we introudue an env to override it so that we can tune it in production environment. Something like ACR_CLI_ABAC_BATCH_SIZE
Purpose of the PR
Fixes #