Skip to content

Upload should use backend-provided S3 credentials, not user environment variables #13

Closed

Description

@neuromechanist

Problem

Currently, nemar dataset upload requires users to have AWS credentials set in their environment:

AWS credentials not found in environment
Set AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables

This contradicts the planned architecture in .context/access_control.md, which states:

S3 Access: Presigned URLs - Time-limited uploads

  • Backend generates presigned PUT URLs for each file
  • CLI uploads files directly to S3 using presigned URLs
  • User never sees AWS credentials

Expected Behavior

Users should NOT need AWS credentials. The upload flow should be:

  1. CLI sends file manifest to backend: POST /datasets
  2. Backend validates user, creates repo, and returns temporary S3 credentials (scoped to the dataset prefix)
  3. CLI uses these temporary credentials for the git annex copy --to operation
  4. Credentials expire after upload session

Implementation Notes

Since we use git-annex S3 special remote (not direct HTTP uploads), presigned URLs won't work because git-annex manages its own chunking and bookkeeping. Instead:

Option A: AWS STS Temporary Credentials (Recommended)

  • Backend uses AWS STS AssumeRole to generate temporary credentials
  • Credentials scoped to specific S3 prefix (e.g., s3://nemar/nm000XXX/*)
  • Short TTL (1-4 hours depending on dataset size)
  • Credentials returned in the /datasets create response

Option B: IAM User Per Dataset

  • Backend creates IAM user per dataset with scoped policy
  • More management overhead but simpler for long-running uploads

Changes Required

Backend (backend/)

  • Add AWS STS integration to generate temporary credentials
  • Create IAM role with policy allowing put to specific prefix
  • Return credentials in POST /datasets response
  • Consider credential refresh endpoint for large uploads

CLI (src/)

  • Remove checkAWSCredentials() from upload prerequisites
  • Extract credentials from dataset creation response
  • Pass backend-provided credentials to configureS3Remote() and uploadToS3Remote()

Related Files

  • src/lib/datalad.ts - checkAWSCredentials(), checkUploadPrerequisites(), configureS3Remote(), uploadToS3Remote()
  • src/commands/dataset.ts - Upload command implementation
  • .context/access_control.md - Architecture design document

Priority

High; this is blocking user adoption since users cannot upload without admin-level AWS access.

Activity

  1. neuromechanist commented on Jan 16, 2026

    @neuromechanist
    ContributorAuthor

    Root Cause Analysis

    The disconnect happened because two incompatible approaches were implemented independently:

    Backend (followed access_control.md)

    The backend generates presigned URLs for direct HTTP PUT:

    // backend/src/routes/datasets.ts:87-103
    uploadUrls = await generateDatasetUploadUrls(...);
    return c.json({
      ...
      upload_urls: uploadUrls,  // ← Backend returns these
    }, 201);

    CLI (followed validated_workflows.md)

    The CLI uses git-annex S3 special remote with direct credentials:

    // src/commands/dataset.ts:420-430
    const awsAccessKeyId = process.env.AWS_ACCESS_KEY_ID;  // ← CLI expects env vars
    const awsSecretAccessKey = process.env.AWS_SECRET_ACCESS_KEY;

    Why These Are Incompatible

    1. Presigned URLs = Direct HTTP PUT to specific S3 keys, no chunking, no git-annex tracking
    2. git-annex S3 remote = Uses AWS SDK internally, manages chunking, maintains location database

    git-annex cannot use presigned URLs because:

    • It needs to create its own object keys (with hashing/chunking)
    • It maintains .git/annex/ location tracking
    • It uses initremote/enableremote which require actual credentials

    The Disconnect

    In plan.md, Phase 5 states:

    "Dependencies: ... AWS credentials in environment variables"

    This was implemented as-designed, but it contradicts the security architecture in access_control.md:

    "User never sees AWS credentials"

    The Fix

    The backend should return temporary AWS credentials (via STS AssumeRole) instead of presigned URLs:

    // What backend should return:
    {
      dataset: {...},
      aws_credentials: {
        accessKeyId: "ASIA...",
        secretAccessKey: "...",
        sessionToken: "...",
        expiration: "2026-01-15T20:00:00Z"
      }
    }

    The CLI can then use these temporary credentials for git annex copy --to.

    Files That Need Changes

    Backend:

    • backend/src/services/s3.ts - Replace generateDatasetUploadUrls with generateTemporaryCredentials using AWS STS
    • backend/src/routes/datasets.ts - Return credentials instead of presigned URLs

    CLI:

    • src/lib/api.ts - Add aws_credentials to CreateDatasetResponse interface
    • src/commands/dataset.ts - Use credentials from API response instead of env vars
    • src/lib/datalad.ts - Remove checkAWSCredentials() from prerequisites
  2. added a commit that references this issue on Jan 16, 2026
    be43b06
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