Skip to content

Security: S3 access control must sync with repository visibility #88

Closed

Description

@neuromechanist

Problem

Currently, there is no mechanism to control S3 object access based on repository visibility. This creates a security gap:

  1. All repositories are created as private (backend/src/routes/datasets.ts:138)
  2. No visibility change mechanism: No code to change repos from private → public
  3. S3 access is decoupled from repo visibility:
    • Private repos should have private S3 data (only accessible with credentials)
    • Public repos should have public S3 data (accessible via publicurl)

Current State

  • Repos: Created as private: true
  • S3 bucket policy: According to .context/access_control.md, has PublicReadAccess for all objects
  • Git-annex: Uses publicurl for all datasets

This means private dataset data files are potentially publicly accessible via S3, which violates the privacy model.

Required Solution

1. Repository Visibility Management

Add admin command to publish a dataset:

nemar admin publish <dataset-id>

This should:

  • Change GitHub repo from private → public
  • Update dataset status in database (is_public field)
  • Trigger S3 access control update

2. S3 Access Control

Implement two approaches based on visibility:

For Private Datasets:

  • No bucket-level public read policy for that prefix
  • Use presigned URLs for access (already implemented for uploads)
  • Git-annex should not use publicurl parameter
  • Only dataset owner can access via presigned URLs

For Public Datasets:

  • Apply S3 object ACL or bucket policy allowing public read for that prefix
  • Git-annex can use publicurl for downloads
  • Anyone can access via public URL

3. Implementation Tasks

  • Add is_public boolean field to datasets table
  • Create updateRepositoryVisibility() in backend/src/services/github.ts
  • Create updateS3ObjectAccess() in backend/src/services/s3.ts
  • Add POST /admin/datasets/:id/publish endpoint
  • Implement nemar admin publish <dataset-id> command
  • Update git-annex remote config based on visibility:
    • Private: no publicurl, require credentials
    • Public: include publicurl for web remote access
  • Update S3 bucket policy to deny public read by default
  • Add S3 object ACL/policy update on publish

4. S3 Bucket Policy Pattern

Current (INSECURE - public read for all):

{
  "Sid": "PublicReadAccess",
  "Effect": "Allow",
  "Principal": "*",
  "Action": "s3:GetObject",
  "Resource": "arn:aws:s3:::nemar/*"
}

Proposed (default deny, allow per-prefix):

{
  "Sid": "PublicReadOnlyForPublicDatasets",
  "Effect": "Allow",
  "Principal": "*",
  "Action": "s3:GetObject",
  "Resource": "arn:aws:s3:::nemar/${PublicDatasetPrefix}/*"
}

Or use S3 object-level ACLs when publishing.

Testing

  • Verify private dataset data is NOT accessible via public URL
  • Verify public dataset data IS accessible via public URL
  • Verify git-annex can download from public datasets without credentials
  • Verify git-annex requires credentials for private datasets

Security Impact

HIGH - Private datasets may currently expose data files publicly if the bucket policy allows it.

References

  • .context/access_control.md - Current (potentially insecure) bucket policy
  • backend/src/routes/datasets.ts:138 - Repos created as private
  • backend/src/services/s3.ts - Presigned URL generation (upload only)

Activity

  1. added
    security
    P0
    backend
    on Feb 1, 2026
  2. neuromechanist commented on Feb 2, 2026

    @neuromechanist
    ContributorAuthor

    addressed by 91

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

    P0backendsecurity

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions