-
Notifications
You must be signed in to change notification settings - Fork 49
T keithyao/batch purge Adds ABAC support for purge command with batched token requests #577
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
base: main
Are you sure you want to change the base?
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
when you setup basic auth and you try to use purge on abac, does it work?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is tagDeletionSince? It's not a declared variable
lizMSFT
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
tagsToKeep is undefined
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Implemented
Purpose of the PR
Fixes #