Skip to content

fix: enable chunked blob upload for Azure ACR replication - #23016

Merged
chlins merged 7 commits into
goharbor:mainfrom
xrkolovos:fix/azurecr-chunked-upload
Jun 15, 2026
Merged

chlins merged 7 commits into
goharbor:mainfrom
xrkolovos:fix/azurecr-chunked-upload

Conversation

@xrkolovos

@xrkolovos xrkolovos commented Mar 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Fixes #23015 β€” Azure ACR replication fails with HTTP 413 for blob layers larger than ~20MB.
Related: #21640

Root cause

Two issues were identified:

  1. Missing adapter capability declaration β€” The Azure ACR adapter's Info() method did not set SupportedCopyByChunk: true. Because the capability was not declared, the "Copy by chunk" option was not available in the replication rule UI for ACR endpoints, so replications always used monolithic (single PUT) blob uploads β€” which ACR rejects with HTTP 413 for blobs larger than ~20MB.

  2. req.ContentLength not set in PushBlobChunk() β€” The registry client set Content-Length via req.Header.Set(), but Go's HTTP client ignores manually set Content-Length headers. It uses the req.ContentLength struct field to decide between sending a Content-Length header or using Transfer-Encoding: chunked. Without setting req.ContentLength, Go sent blob chunks with HTTP chunked transfer encoding, which Azure ACR rejects with CONTENT_LENGTH_INVALID (400).

Changes

File Change
src/pkg/reg/adapter/azurecr/adapter.go Set SupportedCopyByChunk: true in Info()
src/pkg/registry/client.go Set req.ContentLength in PushBlobChunk() to ensure proper Content-Length header

Note (review follow-up): An earlier revision of this PR also auto-enabled chunked upload in the copy flow whenever the destination adapter declared SupportedCopyByChunk. Per review feedback, that change was reverted to keep the replication policy's Copy By Chunk setting authoritative β€” the user's choice decides. With the adapter now declaring the capability, the "Copy by chunk" checkbox appears when creating/editing a replication rule that targets an ACR endpoint; users replicating images with layers larger than ~20MB to ACR should enable it.

Testing

  • Unit tests β€” Updated the azurecr adapter test to cover the capability declaration.
  • Integration test β€” Added integration_test.go that performs a real 25MB chunked blob upload (5 Γ— 5MB chunks) against a live Azure Container Registry instance. The test is skipped unless ACR_URL, ACR_USER, and ACR_PASS environment variables are set.
=== RUN   TestChunkedUploadToACR/chunked_upload_succeeds
    Uploading chunk 0-5242879 (5242880 bytes, last=false)
    OK - new location length: 328
    Uploading chunk 5242880-10485759 (5242880 bytes, last=false)
    OK - new location length: 336
    Uploading chunk 10485760-15728639 (5242880 bytes, last=false)
    OK - new location length: 336
    Uploading chunk 15728640-20971519 (5242880 bytes, last=false)
    OK - new location length: 336
    Uploading chunk 20971520-26214399 (5242880 bytes, last=true)
    OK - new location length: 106
    === SUCCESS: Chunked upload to Azure ACR works! ===
--- PASS: TestChunkedUploadToACR (6.09s)

How to run integration test

ACR_URL=https://yourregistry.azurecr.io ACR_USER=admin ACR_PASS=secret \
  go test -v -run TestChunkedUploadToACR ./src/pkg/reg/adapter/azurecr/...

@xrkolovos
xrkolovos requested a review from a team as a code owner March 19, 2026 13:53

@themavik themavik left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

OR-ing policy CopyByChunk with adapter SupportedCopyByChunk fixes ACR without manual policy flags; test asserts task param. nit: adapters that set SupportedCopyByChunk but work fine monolithically may pay extra chunk round trips β€” confirm that is acceptable. nit: integration_test comment example uses a concrete azurecr hostname β€” scrub if you do not want a real-looking name in-tree.

@MinerYang

Copy link
Copy Markdown
Contributor

Hi @xrkolovos ,

Thanks for contributing to our community! Due to limited resource for use to test replication on ACR, Could you help to have a demo record or documentation reference for us that would increase confidence for us to adopt this adapter enhancement.

Best,
Miner

@themavik themavik left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

copyByChunk := policy CopyByChunk OR adapter SupportedCopyByChunk matches ACR-style destinations without flipping the policy bit alone. TestCopyByChunkAutoEnabled asserts Create runs with chunking when Info sets SupportedCopyByChunk true.

@xrkolovos

Copy link
Copy Markdown
Contributor Author

Hi @MinerYang, thanks for the review!

The PR includes an integration test (TestChunkedUploadToACR) that runs against a live Azure ACR instance. Here is the output from a successful run:

=== RUN   TestChunkedUploadToACR
    ACR URL: https://min01rg72arc.azurecr.io
    Repository: test/chunked-upload-test
    Blob size: 25MB, Chunk size: 5MB
=== RUN   TestChunkedUploadToACR/monolithic_upload_fails_413
    Monolithic upload failed as expected: 413
=== RUN   TestChunkedUploadToACR/chunked_upload_succeeds
    Uploading chunk 0-5242879 (5242880 bytes, last=false)
    Uploading chunk 5242880-10485759 (5242880 bytes, last=false)
    Uploading chunk 10485760-15728639 (5242880 bytes, last=false)
    Uploading chunk 15728640-20971519 (5242880 bytes, last=false)
    Uploading chunk 20971520-26214399 (5242880 bytes, last=true)
    === SUCCESS: Chunked upload to Azure ACR works! ===
--- PASS: TestChunkedUploadToACR

The test validates the exact replication flow: it first demonstrates that a monolithic 25MB push fails with HTTP 413 (confirming the original issue), then shows the same blob succeeding via 5MB chunked uploads. You can reproduce it by setting ACR_URL, ACR_USER, and ACR_PASS env vars and running:

go test -v -run TestChunkedUploadToACR ./src/pkg/reg/adapter/azurecr/...

Let me know if you'd like a screen recording as well or if the test output is sufficient.

@xrkolovos

Copy link
Copy Markdown
Contributor Author

hello,

@MinerYang can you provide some feedback? are you ok with my latest reply?

@xrkolovos

Copy link
Copy Markdown
Contributor Author

Hello @chlins and @MinerYang ,

Just following up on this pull request. We need it for our system, and I would really appreciate your feedback when you have a chance.

Thank you very much.

@xrkolovos

Copy link
Copy Markdown
Contributor Author

@wy65701436 @stonezdj can you help with the merge in this issue?

Comment thread src/controller/replication/flow/copy.go Resolved
xrkolovos added a commit to xrkolovos/harbor that referenced this pull request Jun 10, 2026
Per review feedback on goharbor#23016, drop the auto-enabling of chunked
upload when the destination adapter declares SupportedCopyByChunk.
Whether a replication uses chunked upload is the user's choice via
the replication policy setting; an adapter declaring support must
not force the behavior, as that would also silently change the
default for Harbor-to-Harbor replications.

The Azure ACR adapter still declares SupportedCopyByChunk: true,
which exposes the "Copy by chunk" option in the replication rule UI
for ACR endpoints, and PushBlobChunk() still sets req.ContentLength
so chunked uploads work against ACR when the user enables the
option.

Also remove TestCopyByChunkAutoEnabled, which validated the removed
behavior.

Signed-off-by: Chrysostomos Kolovos <xrkolovos@egritosgroup.gr>
@chlins
chlins force-pushed the fix/azurecr-chunked-upload branch from 4536d3e to 929877f Compare June 10, 2026 07:41
chlins pushed a commit to xrkolovos/harbor that referenced this pull request Jun 10, 2026
Per review feedback on goharbor#23016, drop the auto-enabling of chunked
upload when the destination adapter declares SupportedCopyByChunk.
Whether a replication uses chunked upload is the user's choice via
the replication policy setting; an adapter declaring support must
not force the behavior, as that would also silently change the
default for Harbor-to-Harbor replications.

The Azure ACR adapter still declares SupportedCopyByChunk: true,
which exposes the "Copy by chunk" option in the replication rule UI
for ACR endpoints, and PushBlobChunk() still sets req.ContentLength
so chunked uploads work against ACR when the user enables the
option.

Also remove TestCopyByChunkAutoEnabled, which validated the removed
behavior.

Signed-off-by: Chrysostomos Kolovos <xrkolovos@egritosgroup.gr>
@chlins chlins added area/replication replication/adapters related to replication adapters release-note/enhancement Label to mark PR to be added under release notes as enhancement labels Jun 10, 2026
@codecov

codecov Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 50.00000% with 1 line in your changes missing coverage. Please review.
βœ… Project coverage is 66.11%. Comparing base (a26dea0) to head (d16fc3f).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
src/pkg/registry/client.go 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main   #23016      +/-   ##
==========================================
- Coverage   66.12%   66.11%   -0.01%     
==========================================
  Files        1073     1073              
  Lines      116882   116883       +1     
  Branches     2959     2959              
==========================================
- Hits        77283    77280       -3     
- Misses      35320    35326       +6     
+ Partials     4279     4277       -2     
Flag Coverage Ξ”
unittests 66.11% <50.00%> (-0.01%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Ξ”
src/pkg/reg/adapter/azurecr/adapter.go 40.62% <100.00%> (+0.94%) ⬆️
src/pkg/registry/client.go 46.59% <0.00%> (ΓΈ)

... and 8 files with indirect coverage changes

πŸš€ New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • πŸ“¦ JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Enables chunked/resumable blob uploads for Azure ACR replication by (1) advertising the adapter capability so the UI can enable the option for ACR endpoints and (2) ensuring the registry client sends a proper Content-Length for each uploaded chunk (avoiding Azure ACR’s rejection of Transfer-Encoding: chunked).

Changes:

  • Declare SupportedCopyByChunk: true in the Azure ACR adapter Info().
  • Set req.ContentLength in PushBlobChunk() so Go emits a real Content-Length header for each chunk.
  • Add an opt-in (env-gated) integration test that uploads a 25MB blob in 5MB chunks to a live ACR.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.

File Description
src/pkg/registry/client.go Ensures chunk uploads use Content-Length via req.ContentLength (avoids Go sending chunked transfer encoding).
src/pkg/reg/adapter/azurecr/adapter.go Advertises ACR adapter support for β€œCopy by chunk”.
src/pkg/reg/adapter/azurecr/adapter_test.go Extends unit coverage to assert the new capability flag is set.
src/pkg/reg/adapter/azurecr/integration_test.go Adds an env-gated integration test validating chunked uploads against a real ACR instance.

πŸ’‘ Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/pkg/registry/client.go Resolved
@chlins

chlins commented Jun 10, 2026

Copy link
Copy Markdown
Member

@xrkolovos I've targeted it to v2.16, so please resolve the PR and copilot comments.

@chlins chlins left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

lgtm

@chlins
chlins enabled auto-merge (squash) June 11, 2026 07:03
@wy65701436
wy65701436 requested a review from Copilot June 11, 2026 08:23

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

auto-merge was automatically disabled June 11, 2026 10:00

Head branch was pushed to by a user without write access

When replicating images from Harbor to Azure Container Registry, blob
uploads larger than ~20MB fail with HTTP 413 (Request Entity Too Large).

Root cause analysis revealed three issues:

1. The Azure ACR adapter did not declare SupportedCopyByChunk in its
   Info() method, so the replication flow always used monolithic
   (single PUT) uploads for ACR destinations.

2. The copy flow only checked the policy-level CopyByChunk flag and
   ignored the destination adapter's declared capability. This meant
   even if an adapter declared chunk support, users had to manually
   enable it per replication policy.

3. The registry client's PushBlobChunk() set Content-Length via
   req.Header.Set() but did not set req.ContentLength on the
   http.Request struct. Go's HTTP client ignores manually set
   Content-Length headers and relies on req.ContentLength to decide
   between Content-Length and Transfer-Encoding: chunked. As a result,
   Go sent the request with Transfer-Encoding: chunked (HTTP-level),
   which Azure ACR rejects with CONTENT_LENGTH_INVALID.

Changes:
- Set SupportedCopyByChunk: true in the Azure ACR adapter's Info()
- Auto-enable chunked upload in the copy flow when the destination
  adapter declares support via SupportedCopyByChunk
- Set req.ContentLength in PushBlobChunk() to ensure Go sends a
  proper Content-Length header instead of Transfer-Encoding: chunked

Validated with an integration test that performs a real 25MB chunked
blob upload (5 x 5MB chunks) against a live Azure ACR instance.

Fixes goharbor#23015
Related: goharbor#21640

Signed-off-by: Chrysostomos Kolovos <xrkolovos@egritosgroup.gr>
Per review feedback on goharbor#23016, drop the auto-enabling of chunked
upload when the destination adapter declares SupportedCopyByChunk.
Whether a replication uses chunked upload is the user's choice via
the replication policy setting; an adapter declaring support must
not force the behavior, as that would also silently change the
default for Harbor-to-Harbor replications.

The Azure ACR adapter still declares SupportedCopyByChunk: true,
which exposes the "Copy by chunk" option in the replication rule UI
for ACR endpoints, and PushBlobChunk() still sets req.ContentLength
so chunked uploads work against ACR when the user enables the
option.

Also remove TestCopyByChunkAutoEnabled, which validated the removed
behavior.

Signed-off-by: Chrysostomos Kolovos <xrkolovos@egritosgroup.gr>
Signed-off-by: Chrysostomos Kolovos <xrkolovos@egritosgroup.gr>
- move the ACR chunked upload integration test into adapter_test.go
- drop redundant Content-Length header now that req.ContentLength is set
- fix documented go test command path (run from the src module root)
- use a unique repository name per test run to avoid collisions
- add best-effort blob cleanup via t.Cleanup

Signed-off-by: Chrysostomos Kolovos <xrkolovos@egritosgroup.gr>
Signed-off-by: Chrysostomos Kolovos <xrkolovos@egritosgroup.gr>
@chlins
chlins force-pushed the fix/azurecr-chunked-upload branch from 9a9f629 to 40b4c6a Compare June 15, 2026 08:46
@chlins
chlins enabled auto-merge (squash) June 15, 2026 08:46

@wy65701436 wy65701436 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

lgtm

@wy65701436

Copy link
Copy Markdown
Contributor

thanks @xrkolovos , the code change looks good to me, cc @Vad1mo

@chlins
chlins merged commit 6e4d8ad into goharbor:main Jun 15, 2026
11 of 12 checks passed
bupd added a commit to container-registry/8gcr that referenced this pull request Jun 23, 2026
Upstream-PR: goharbor/harbor#23016

Upstream-Author: @xrkolovos
Co-authored-by: Prasanth Baskar <bupdprasanth@gmail.com>
Signed-off-by: Chrysostomos Kolovos <xrkolovos@egritosgroup.gr>
Signed-off-by: Prasanth Baskar <bupdprasanth@gmail.com>
bupd added a commit to container-registry/8gcr that referenced this pull request Jun 23, 2026
Upstream-PR: goharbor/harbor#23016

Upstream-Author: @xrkolovos
Co-authored-by: Prasanth Baskar <bupdprasanth@gmail.com>
Signed-off-by: Chrysostomos Kolovos <xrkolovos@egritosgroup.gr>
Signed-off-by: Prasanth Baskar <bupdprasanth@gmail.com>
bupd added a commit to container-registry/8gcr that referenced this pull request Jun 23, 2026
Upstream-PR: goharbor/harbor#23016

Upstream-Author: @xrkolovos
Co-authored-by: Prasanth Baskar <bupdprasanth@gmail.com>
Signed-off-by: Chrysostomos Kolovos <xrkolovos@egritosgroup.gr>
Signed-off-by: Prasanth Baskar <bupdprasanth@gmail.com>
bupd added a commit to container-registry/8gcr that referenced this pull request Jul 2, 2026
Upstream-PR: goharbor/harbor#23016

Upstream-Author: @xrkolovos
Co-authored-by: Prasanth Baskar <bupdprasanth@gmail.com>
Signed-off-by: Chrysostomos Kolovos <xrkolovos@egritosgroup.gr>
Signed-off-by: Prasanth Baskar <bupdprasanth@gmail.com>
bupd added a commit to container-registry/8gcr that referenced this pull request Jul 2, 2026
Upstream-PR: goharbor/harbor#23016

Upstream-Author: @xrkolovos
Co-authored-by: Prasanth Baskar <bupdprasanth@gmail.com>
Signed-off-by: Chrysostomos Kolovos <xrkolovos@egritosgroup.gr>
Signed-off-by: Prasanth Baskar <bupdprasanth@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/replication release-note/enhancement Label to mark PR to be added under release notes as enhancement replication/adapters related to replication adapters target/2.16.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Azure ACR replication adapter does not support chunked/resumable blob uploads (413 error)

7 participants