harbor icon indicating copy to clipboard operation
harbor copied to clipboard

Flattening not working with empty namespace (Replication rule for ECR)

Open NicoForce opened this issue 1 year ago • 13 comments

Expected behavior and actual behavior: I expect flattening to work regardless of if a namespace is specified or not.

Actual behavior is that no matter which level of flatenning is chosen, the project name is always being appended to the image, except when a namespace is given, then the project name is properly replaced by the namespace.

Let's take this replication rule for example where the namespace is empty and the flattening is on: image

In the following screenshot, I have pushed an image to harbor, which we will try to replicate to ECR in the next step: image

After activating manual replication, we can see it fails with the following error: image

In the error image, we can observe that it adds the namespace dev to the image repository, even if we specified empty namespace and flattening in the replication rule. Here's what the repository looks like in AWS with no namespace. image

In summary we expect harbor to push to repository atlas and not dev/atlas when namespace is empty in the replication rule.

Steps to reproduce the problem: Following these steps, when one starts replication, if my ecr repo is named SOFTWARE, and I create a non-proxy project named DEV, even if I specify Flatten all, harbor will try to push the image as DEV/SOFTWARE, and fail as that repo does not exist in ecr.

If I specify a namespace as TEST in replication, and specify a flatenning level, such as Flatten 1 Level, then the image that's being pushed into ecr is TEST/SOFTWARE, which also fails because no such repo exists, as the repo SOFTWARE is the one in ecr.

I would guess flatten and no namespace would give one the ability to push just SOFTWARE to ecr, without either the project or namespace being attached.

Versions:

  • harbor version: 2.9.0
  • Deployed by helm chart 1.13.0

NicoForce avatar Sep 06 '23 19:09 NicoForce

I'm guessing the issue comes from this section of the code https://github.com/goharbor/harbor/blob/main/src/controller/replication/flow/stage.go#L161-L164

Following my example, the function replaceNamespace receives the variable repository as DEV/SOFTWARE, but because namespace is empty, it just returns the variable as is, without flatenning.

NicoForce avatar Sep 06 '23 19:09 NicoForce

Created PR to improve that behavior, let me know if it looks ok: https://github.com/goharbor/harbor/pull/19321

NicoForce avatar Sep 06 '23 20:09 NicoForce

In the meanwhile is there a workaround? This is seriously messing with our promotion scheme...

TFKIA avatar Oct 16 '23 16:10 TFKIA

In the meanwhile is there a workaround? This is seriously messing with our promotion scheme...

There's none, I tried to find one, but my PR should fix it, haven't heard back from them about a review tho.

NicoForce avatar Oct 16 '23 17:10 NicoForce

In the meanwhile is there a workaround? This is seriously messing with our promotion scheme...

There's none, I tried to find one, but my PR should fix it, haven't heard back from them about a review tho.

Shoot. Well, I appreciate the response and the PR.

TFKIA avatar Oct 16 '23 17:10 TFKIA

This issue is being marked stale due to a period of inactivity. If this issue is still relevant, please comment or remove the stale label. Otherwise, this issue will close in 30 days.

github-actions[bot] avatar Dec 16 '23 09:12 github-actions[bot]

Commenting to remove stale label

NicoForce avatar Dec 17 '23 16:12 NicoForce

This issue is being marked stale due to a period of inactivity. If this issue is still relevant, please comment or remove the stale label. Otherwise, this issue will close in 30 days.

github-actions[bot] avatar Feb 17 '24 09:02 github-actions[bot]

Commenting to remove stale label

NicoForce avatar Feb 19 '24 13:02 NicoForce

This issue is being marked stale due to a period of inactivity. If this issue is still relevant, please comment or remove the stale label. Otherwise, this issue will close in 30 days.

github-actions[bot] avatar Apr 29 '24 09:04 github-actions[bot]

Commenting to remove stale label

NicoForce avatar May 07 '24 23:05 NicoForce

This issue is being marked stale due to a period of inactivity. If this issue is still relevant, please comment or remove the stale label. Otherwise, this issue will close in 30 days.

github-actions[bot] avatar Jul 07 '24 09:07 github-actions[bot]

This issue was closed because it has been stalled for 30 days with no activity. If this issue is still relevant, please re-open a new issue.

github-actions[bot] avatar Aug 07 '24 09:08 github-actions[bot]