Skip to content

Copy and move artifacts between hosted repositories #511

Description

@orcamedia

Problem

The only way to put an artifact that is already stored into another repository is a release bundle: create it, add the item, seal it, promote it. That is the right tool for a release, and too heavy for two everyday jobs:

  • Promoting one artifact, such as a jar from libs-dev to libs-staging, or a wheel a team has approved for pypi-prod. Without a bundle, the file has to be downloaded and uploaded again. The new upload loses its properties and scan results, and moves every byte through the client twice.
  • Fixing a publish to the wrong repository. Delete and upload again, from a copy of the file the user still has to find.

Other artifact managers have these as basic operations: Artifactory's copy and move API and UI actions, and Nexus Pro's staging move.

Proposal

Copy and move as a repository operation, for the API, oa and the web UI, built on the promotion engine.

internal/promote already does exactly the copy step. It finds the live source files of a content digest, writes the same rows (new ids) into the destination in one transaction, and never touches the bytes, because blobs are content-addressed. It also reports the same content already present as Existing (idempotent) and different content as a 409 conflict, refuses quarantined sources, applies the target's license policy and immutable releases, charges the target's quota, and queues the metadata regeneration. This proposal exposes that per artifact, without a bundle.

API

POST /api/v1/repositories/{source}/copy
POST /api/v1/repositories/{source}/move
{
  "target": "libs-prod",
  "items": [
    {"package": "com.acme:core", "version": "1.4.0"},
    {"sha256": "<hex>", "path": "com/acme/core/1.4.0/core-1.4.0.jar"}
  ],
  "dry_run": false,
  "force": false
}
  • Selection. An item is either a package version (every live file of that version, the unit people think in) or a content digest with an optional path (the bundle-item form, read with itempath so it resolves the same way). For docker, sha256 is the manifest digest, with an optional tag, handled by the existing docker promoter.
  • All or nothing. Every item is copied in one transaction, as a bundle promotion is. The response is the promotion report per item (copied, existing, replaced).
  • dry_run returns the same report without writing.
  • force replaces conflicting content in the target and moves the replaced files to the target's trash. It is limited to admins, as ?force=true is for promotion.
  • Move is a copy followed, in the same transaction, by moving the source files to the source's trash. A wrong move can then be undone with the existing restore, and retention still applies. A source file that is held by a sealed bundle or protected by immutable releases is not moved (409).

Authorization

Like bundle promotion: the RBAC gate only requires a real principal for these routes, and the handler checks each repository (for bundles, "read on the sources, write on the target"):

  • copy: read on the source at each item's path, and write on the target;
  • move: copy's rules, plus delete on the source.

These routes are not manage, so a CI token scoped to two repositories can promote between them without being an admin. Project roles apply through each repository's project.

Side effects

  • Webhooks: artifact.uploaded for each artifact copied into the target. A move also sends artifact.deleted for each source artifact.
  • Audit: one artifact.copy or artifact.move event with the source, target and items, plus the per-repository upload and delete events the handlers already write.
  • Federation: the target's federation log picks up the new rows as it does for a promotion.
  • Metadata of the target (and of the source on move) is regenerated through RegenQueue, as for a promotion. Groups containing either repository follow.

oa and UI

  • oa cp <source> <target> <package>@<version> [--dry-run] [--force] and oa mv, which also accept --sha256 and --path.
  • On the artifact page, "Copy to…" and "Move to…" list the hosted repositories of the same format that the user can write.

Out of scope

  • Copying out of a proxy cache into a hosted repository ("adopt an upstream artifact"). The promoter reads the generic tables of hosted repositories, while the proxy cache is stored differently, and adopting an upstream artifact raises curation questions of its own.
  • Copying between formats, or into proxy or group repositories (the same errors as promotion: ErrFormatMismatch, ErrNotHosted).
  • Copying a whole repository or a path prefix. A list of items covers that, and a prefix selector can be added later.

Questions for the maintainer

  1. Properties: should a copy carry the artifact's properties? Promotion does not copy them today, as far as I can see. I would copy them, since keeping them is part of the reason to copy instead of re-uploading.
  2. Scan results: copy them, or let the target rescan? OSV matching applies to the target anyway when the mirror is on. Content scans (secrets, image layers) would otherwise need to be run again by hand.
  3. created_at: a promotion dates the copied rows now (clock_timestamp(), so conan's "latest" sees a promoted file as newest). For copy that seems right too: the target's cleanup policies count from when the file arrived. Is there a reason to keep the source's upload time instead, for example so move looks like nothing happened?
  4. Route shape: two routes (/copy, /move) or one (/transfer with "mode")?

Once the design is agreed, I'm happy to implement it, starting with the API and oa, with the UI in a second PR.

Activity

  1. M0Rf30 commented on Nov 27, 2026

    @M0Rf30
    Collaborator

    Thanks, this fills a real gap. I'm implementing it for 0.26.0, API, oa cp/oa mv and the UI together, on top of internal/promote as you describe. A PR will link here.

    Answers to your questions:

    1. Properties: yes, a copy carries the artifact's properties.
    2. Scan results: not copied. A copied artifact is treated as an upload into the target, so the target's own scan-on-upload and policies run. Findings and the quarantine or license decisions they drive belong to the repository that serves the artifact.
    3. created_at: now (clock_timestamp()) for both copy and move, as promotion does, so the target's cleanup policies count from arrival and conan's "latest" stays consistent.
    4. Routes: two, POST /api/v1/repositories/{source}/copy and .../move.

    The rest follows the proposal: one transaction for all items, dry_run, admin-only force (replaced files go to the target's trash), move sends the source files to the source's trash, and a source held by a sealed bundle or immutable releases answers 409. AuthZ is checked per repository in the handler (copy: read on the source paths and write on the target; move adds delete on the source), not manage, so a scoped CI token can promote between its two repositories.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions