Skip to content

Fix git-annex S3 integration: use S3 special remote instead of fragile registerurl #182

Closed

Description

@neuromechanist

Problem

@PierreGtch uploaded dataset nm000109 (72 EEG files, 174MB) from SDSC Expanse (HPC). The S3 upload succeeded, but all 72 URL registrations failed silently, making downloads completely broken.

What happened

  1. First upload attempt: safe.directory error (HPC ownership issue, expected)
  2. Second attempt (after git config --add safe.directory):
    • Could not switch to unlocked mode; data files will be symlinks
    • S3 upload succeeded (72 files via AWS CLI)
    • "Some URLs could not be registered (72 failed)" -- all files failed
    • Upload reported success anyway
  3. Download attempt: git annex get fails with "No other repository is known to contain the file"

Root cause

The upload workflow has a fragile two-step process:

  1. Upload bytes to S3 via AWS CLI or presigned URLs (bypasses git-annex)
  2. Retroactively register S3 URLs via git annex add -> lookupkey -> registerurl

Step 2 fails when git annex add fails (errors silently swallowed at git-annex.ts:1305-1307). On HPC environments with filesystem quirks (symlink issues, ownership), this step is unreliable.

Design inconsistency

  • Initial upload: presigned URLs + registerurl (fragile, git-annex not in the loop)
  • Subsequent updates (dataset update, dataset push): expects git annex copy --to nemar-s3 (S3 special remote that was never configured during initial upload)

Immediate fix applied

Manually registered S3 URLs for nm000109 by cloning, extracting annex keys from pointer files, and running git annex registerurl for all 72 files. Download now works.

Solution: Use S3 Special Remote from Initial Upload

Replace the presigned URL + registerurl approach with git-annex's native S3 special remote for both upload and download.

How it works

  • git annex initremote nemar-s3 type=S3 encryption=none bucket=nemar fileprefix={id}/objects/ datacenter=us-east-2 signature=v4 publicurl=https://nemar.s3.us-east-2.amazonaws.com
  • Upload: git annex copy --to nemar-s3 with STS temp credentials (already have STS endpoint)
  • Download: git annex get uses publicurl (no credentials needed, S3 bucket is public-read)
  • git-annex handles key-to-URL mapping internally -- no separate registerurl step needed

Workflow scenarios to validate

Scenario 1: Initial dataset creation

  1. git annex init + git annex initremote nemar-s3 ... with STS creds
  2. git annex add . (track data files)
  3. git annex copy --to nemar-s3 -J4 (upload with STS creds)
  4. git push origin main git-annex

Scenario 2: Download

  1. git clone + git annex init
  2. git annex enableremote nemar-s3 (reads config from git-annex branch, uses publicurl for reads)
  3. git annex get . (fetches from S3 public URL)

Scenario 3: Update private dataset (direct push)

  1. Clone or use existing local copy
  2. Make changes, git annex add .
  3. Get STS creds, git annex copy --to nemar-s3 .
  4. git push origin main git-annex

Scenario 4: Update public dataset (PR required)

  1. Clone, create branch
  2. Make changes, git annex add .
  3. Get STS creds, git annex copy --to nemar-s3 . (data goes to final location)
  4. Create PR, push branch + git-annex
  5. On merge: data already in place, CI tags release

Implementation tasks

  1. Replace upload path: After git annex init, configure S3 special remote with STS creds and publicurl. Use git annex copy --to nemar-s3 instead of AWS CLI sync + registerurl.
  2. Fix download path: After clone + git annex init, enableremote nemar-s3 so git-annex knows about the S3 remote. git annex get then fetches via publicurl.
  3. Remove dead code: Delete registerUrlWithGitAnnex, registerUrlsWithGitAnnex, configureWebRemote functions and presigned URL upload path (or keep as emergency fallback).
  4. Validate STS creds with git-annex: Confirm AWS_ACCESS_KEY_ID + AWS_SECRET_ACCESS_KEY + AWS_SESSION_TOKEN env vars work with git annex initremote and git annex copy.
  5. Validate publicurl download: Confirm git annex enableremote nemar-s3 works without credentials when publicurl is set (read-only via public S3).
  6. Test on HPC-like environment: Verify the S3 remote approach works on systems where symlinks/ownership cause issues (the filesystem quirks that broke registerurl).
  7. Ensure dataset update and dataset push work: These commands already expect an S3 remote; verify they work end-to-end after the change.

Fallback consideration

Keep presigned URL upload as emergency fallback (some locked-down environments block STS), but make S3 special remote the primary path.

Files to modify

  • src/lib/git-annex.ts - Wire up configureS3Remote() (already written), remove/deprecate registerurl functions
  • src/commands/dataset.ts - Replace upload Step 9+10 with S3 remote init + git annex copy
  • src/lib/git-annex.ts - Update cloneDataset or getDatasetData to enableremote before git annex get

Activity

  1. added
    bug
    P1
    on Feb 24, 2026
  2. added a commit that references this issue on Feb 24, 2026
    00f041b
  3. neuromechanist commented on Feb 24, 2026

    @neuromechanist
    ContributorAuthor

    Final Design Decisions (from E2E testing)

    1. protocol=https required for S3 special remote

    git-annex defaults to HTTP for S3 operations. With STS temporary credentials, HTTP requests fail with 403 because AWS STS requires HTTPS. Added protocol=https to initremote args.

    2. Clear cached STS credentials after upload

    git-annex caches AWS credentials in .git/annex/creds/ during initremote. When using STS temporary credentials, these expire and cause 403 errors on subsequent downloads instead of falling back to publicurl. Solution: clearAnnexCredentials() removes cached creds after each successful upload so git annex get uses the publicurl for downloads.

    3. Unconditional s3:ListBucket in STS policy

    git-annex runs HeadBucket during initremote to verify the bucket exists. This requires s3:ListBucket without any prefix condition. The original policy had a prefix condition (s3:prefix: [{datasetId}/objects/*]) which blocked HeadBucket. Removed the condition.

    4. Upload flow

    STS creds -> configureS3Remote(protocol=https, autoenable=true, publicurl) 
      -> git annex add . 
      -> git annex copy --to nemar-s3 
      -> clearAnnexCredentials()
    

    5. Download flow

    git clone -> git annex init -> enableS3Remote() 
      -> git annex get (uses publicurl, no creds needed)
    

    Old datasets without S3 remote: enableS3Remote() returns gracefully, download falls back to web remote URLs.

    Verified via E2E testing

    • initremote with protocol=https succeeds
    • copy --to uploads file to S3 with correct key-based layout
    • After clearing creds, git annex get downloads via publicurl without credentials
    • S3 objects are publicly readable via publicurl
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

    P1bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions