# Artifact Keeper: Migrating Off Artifactory with Edge Replication

> **TL;DR**: Deploy Artifact Keeper as a drop-in Artifactory/Nexus replacement: hardened UBI9 containers, Trivy/Grype quarantine policy, Borg peer replication, and a zero-downtime cutover checklist.
> **Source**: https://ai.yevrix.com/articles/artifact-keeper-universal-registry-migration-replication

## 1. The real incident: why "just swap the registry" breaks the pipeline

Most teams hit the same class of failure on their first registry cutover: **protocol semantics don't match**. A typical scene — `mvn deploy` suddenly returns `409 Conflict` because the target repo is configured immutable while snapshot versions need repeated writes; `docker push` fails with `manifest blob unknown` because OCI uploads manifest and blobs as two independent operations, and any policy interception in between leaves a dangling reference; `pip install` returns `403` in an air-gapped environment because the PyPI simple index needs anonymous read and the migration script copied package bodies but not ACLs.

The underlying mechanism is worth unpacking. An artifact registry is really **three things glued together**: content-addressed storage (blobs keyed by sha256, naturally deduplicated), a protocol adaptation layer (Maven/PyPI/NPM/OCI each have their own routing and metadata formats), and a metadata database (who uploaded what, when, permissions, scan results). 90% of migration failures aren't about moving bytes — they're about **metadata and protocol semantics not lining up**: Maven's `maven-metadata.xml` must be merged rather than overwritten, NPM's packument is a single JSON document that must be replaced wholesale, and OCI tags point at immutable digests.

Artifact Keeper targets exactly these three layers with native implementations: 45+ package formats with native protocol support, a WASM plugin system (WIT interfaces on the Wasmtime runtime) for custom formats, Trivy/Grype scanning wired into a policy engine with a quarantine workflow, and Borg recursive peer-mesh replication for edge distribution. It's written in Rust, and its images are built on DISA STIG-approved Red Hat UBI 9 base images, running non-root with no shell or package manager at runtime — a meaningful supply-chain property, because an attacker who lands in the container doesn't even have `curl`.

## 2. Production deployment: Compose config with parameter-by-parameter rationale

Here's a minimal production-grade composition you can ship. All secrets come from environment variables, never baked into images.

```yaml
# docker-compose.yml
services:
  keeper:
    image: artifactkeeper/artifact-keeper:latest
    restart: unless-stopped
    read_only: true
    user: "10001:10001"
    ports: ["8080:8080"]
    environment:
      AK_DB_URL: postgres://ak:${PG_PASS}@postgres:5432/keeper?sslmode=disable
      AK_STORAGE_BACKEND: s3
      AK_S3_ENDPOINT: http://minio:9000
      AK_S3_BUCKET: artifacts
      AK_S3_ACCESS_KEY: ${S3_KEY}
      AK_S3_SECRET_KEY: ${S3_SECRET}
      AK_JWT_SECRET: ${JWT_SECRET}
      AK_SCANNER_TRIVY_ENABLED: "true"
      AK_SCANNER_GRYPE_ENABLED: "true"
      AK_POLICY_QUARANTINE: "true"
      AK_REPLICATION_PEER_TOKEN: ${PEER_TOKEN}
    tmpfs: ["/tmp:size=512m,mode=1777"]
    volumes: ["ak-data:/var/lib/artifact-keeper"]
    depends_on: [postgres, minio]
    healthcheck:
      test: ["CMD", "/usr/bin/ak", "health", "--url", "http://127.0.0.1:8080/healthz"]
      interval: 15s
      timeout: 3s
      retries: 5
      start_period: 40s
    deploy:
      resources:
        limits: {cpus: "4", memory: 4G}
        reservations: {cpus: "1", memory: 1G}

  postgres:
    image: postgres:16-alpine
    environment:
      POSTGRES_USER: ak
      POSTGRES_PASSWORD: ${PG_PASS}
      POSTGRES_DB: keeper
    volumes: ["pg-data:/var/lib/postgresql/data"]

  minio:
    image: minio/minio:latest
    command: server /data --console-address ":9001"
    environment:
      MINIO_ROOT_USER: ${S3_KEY}
      MINIO_ROOT_PASSWORD: ${S3_SECRET}
    volumes: ["minio-data:/data"]

volumes: {ak-data: {}, pg-data: {}, minio-data: {}}
```

Key parameters, item by item:

- `read_only: true` plus a `tmpfs` at `/tmp`: the root filesystem is immutable; the only writable path is in-memory. Combined with a shell-less UBI9 runtime, even RCE can't drop a persistent backdoor.
- `user: "10001:10001"`: forces non-root. If your volume permissions are wrong the container fails to start with `permission denied` — that's expected behavior, don't "fix" it by running as root.
- `AK_STORAGE_BACKEND: s3`: puts blobs in object storage rather than local disk, which is a prerequisite for Borg edge replication; local-disk mode can't do incremental sync across sites.
- `AK_POLICY_QUARANTINE: "true"`: when scanning hits a high-severity vulnerability, the artifact moves to quarantine instead of being deleted. Deletion is irreversible; quarantine allows human review and release.
- `start_period: 40s`: the Rust service needs time for DB migrations and scanner initialization; an early health check triggers restart loops in the orchestrator.

## 3. Runnable migration and replication scripts

Don't hand-roll loops for Artifactory migration. Use the built-in tooling with a dry run first, then batch it:

```bash
# 1) Read-only probe: list source repos and artifact counts, write nothing
docker exec -it keeper /usr/bin/ak migrate artifactory \
  --source-url https://jfrog.internal \
  --source-token "$JFROG_TOKEN" \
  --dry-run

# 2) Migrate a single repo (validate protocol semantics on a small one first)
docker exec -it keeper /usr/bin/ak migrate artifactory \
  --source-url https://jfrog.internal \
  --source-token "$JFROG_TOKEN" \
  --repo libs-release-local \
  --include-permissions \
  --concurrency 8

# 3) Verify: compare artifact counts and checksums on both sides
docker exec -it keeper /usr/bin/ak repo verify libs-release-local --checksum sha256
```

`--concurrency 8` is a practical value: higher saturates the source Artifactory connection pool and times out other teams' CI; lower means a large repo takes all night. `--include-permissions` is mandatory — skip it and anonymous read disappears, producing a fleet-wide `pip install` 403.

Borg replication is a recursive peer mesh; the important knobs are **direction and filtering**:

```bash
# Establish a peer relationship (run once on each side for bidirectional)
docker exec -it keeper /usr/bin/ak replication peer add \
  --name edge-sha \
  --endpoint https://edge-sha.internal:8080 \
  --token "$PEER_TOKEN"

# Replicate production repos only; exclude snapshots and scratch repos
docker exec -it keeper /usr/bin/ak replication rule create \
  --peer edge-sha \
  --include "libs-release-*,docker-prod" \
  --exclude "*-snapshot,*tmp*" \
  --mode pull
```

`--mode pull` means the edge node pulls from the hub rather than the hub pushing. Direction matters: hub-push accumulates retry queues and slows the hub when an edge is offline, while edge-pull gets resumability and backpressure for free.

## 4. Common pitfalls and diagnostic commands

**Pitfall 1: OCI manifest/blob separation leaves half-successful pushes.** If the policy engine intercepts after blob upload but before manifest commit, you get unreferenced blobs. Diagnose:

```bash
# List blobs not referenced by any manifest
docker exec -it keeper /usr/bin/ak gc dangling --repo docker-prod --dry-run
# Clean up after confirming
docker exec -it keeper /usr/bin/ak gc dangling --repo docker-prod --older-than 24h
```

`--older-than 24h` is a safety valve: in-flight pushes briefly look like dangling blobs, and immediate cleanup deletes them.

**Pitfall 2: Maven snapshot overwrites rejected by immutable policy.** You get `409`. Fix it per-snapshot-repo rather than disabling immutability globally:

```bash
/usr/bin/ak repo policy set libs-snapshot-local --allow-overwrite --max-versions 10
```

`--max-versions 10` keeps the last ten snapshots so the snapshot repo doesn't balloon your object storage bill.

**Pitfall 3: Scanner timeouts blocking uploads.** Trivy's first vulnerability DB pull is hundreds of MB; synchronous scanning stalls uploads. Go async:

```bash
/usr/bin/ak scanner config set --async true --timeout 300s --fail-open false
```

`--fail-open false` rejects uploads when the scanner is unavailable rather than letting them through — in supply-chain security you must fail closed.

**Pitfall 4: Replication lag serving stale versions at the edge.** Check the watermark:

```bash
/usr/bin/ak replication status --peer edge-sha --json | jq '.lag_seconds, .pending_artifacts'
```

If `lag_seconds` keeps climbing, inspect edge-to-object-storage bandwidth instead of blindly raising concurrency.

## 5. Production go-live acceptance checklist

1. **Protocol smoke tests**: run a real `deploy` and `install` for Maven/PyPI/NPM/OCI and confirm metadata (`maven-metadata.xml`, packument, manifest) is generated correctly.
2. **Permission regression**: verify anonymous read, token write, and LDAP/OIDC login separately — especially that ACLs survived migration.
3. **Scanning closed loop**: push an image with a known high-severity CVE and confirm it's quarantined, not merely flagged, and that `docker pull` returns an explicit error afterward.
4. **Replication drill**: cut the edge node's network for 10 minutes, restore it, and confirm Borg catches up automatically with no duplicate artifacts.
5. **Container hardening check**: `docker exec` into the container and run `sh` — it should fail (no shell); `id` should show non-root.
6. **Capacity and GC**: configure dangling-blob cleanup and snapshot retention, then watch the object-storage growth curve converge over a week.
7. **Rollback plan**: keep Artifactory in read-only mode for at least two weeks and retain a one-command switch-back at the DNS or reverse-proxy layer.

One last reminder: the registry is a CI/CD single point of failure. Schedule the cutover during low traffic and notify every consumer to update `settings.xml`, `.npmrc`, `pip.conf`, and `daemon.json` in advance. A rock-solid registry is useless if client configs still point at the old host. If you need to compare pre- and post-migration checksum manifests or move config snippets offline, [file-to-base64-and-restore](https://ai.yevrix.com/tools/file-to-base64-and-restore) does bidirectional Base64 conversion entirely in the browser with 0-byte upload, so sensitive manifests never leave your network.
