Repository navigation
fix: use backend-provided AWS credentials for S3 upload - #14
Conversation
Users no longer need AWS credentials in environment variables. The backend now returns AWS credentials in the create dataset response, which the CLI uses for git-annex S3 operations. Changes: - Backend returns aws_credentials in POST /datasets response - CLI extracts credentials from API response instead of env vars - Removed checkAWSCredentials() from upload prerequisites - Updated tests to reflect new credential flow Fixes #13
PR Review Summary - Security AnalysisCritical Issues (Must Fix Before Merge)1. Shared AWS Credentials Expose Global AccessLocation: The backend returns the same AWS credentials to ALL authenticated users. Any user could access/modify ANY dataset in the bucket. CLAUDE.md Violation: States "API tokens tied to GitHub PAT and S3 credentials per user" Fix Required: Implement per-user scoped credentials (see below) 2. No Backend Validation of Environment VariablesLocation: Backend returns // Add validation before returning
if (!c.env.AWS_ACCESS_KEY_ID || !c.env.AWS_SECRET_ACCESS_KEY) {
return c.json({ error: "Server configuration error" }, 500);
}3. No CLI Validation of API ResponseLocation: CLI blindly trusts if (!response.aws_credentials?.accessKeyId || !response.aws_credentials?.secretAccessKey) {
spinner.fail("Backend did not return valid AWS credentials");
process.exit(1);
}Important Issues
RecommendationDo not merge as-is. Need to:
Generated by pr-review-toolkit |
Security enhancement: users no longer receive shared AWS credentials. Instead, each user gets their own IAM user with credentials scoped to their dataset prefixes via IAM policies. Backend changes: - Add user_s3_permissions table and IAM credential columns (migration) - Add IAM service for managing per-user IAM users and policies - Add encryption service for secure credential storage - Update admin approve to create per-user IAM user and store encrypted credentials - Update admin revoke to delete IAM user and clear credentials - Update dataset creation to use per-user credentials for presigned URLs - Update dataset creation to update user's IAM policy for new dataset prefix - Remove aws_credentials from API response (security fix) New secrets required: - ENCRYPTION_KEY: For encrypting stored credentials Note: CLI changes to use presigned URLs still pending.
Foundation for secure uploads without exposing AWS credentials: - Update CreateDatasetResponse to use s3_config instead of aws_credentials - Add FileInfo interface for file manifest requests - Add requestUploadUrls API function for additional file uploads - Add uploadFileWithPresignedUrl for single file HTTP PUT upload - Add uploadFilesWithPresignedUrls for parallel batch uploads - Add registerUrlWithGitAnnex to track uploaded files in git-annex - Add registerUrlsWithGitAnnex for batch URL registration - Add configureWebRemote for git-annex web remote setup Note: Upload command rewrite to use this flow still pending.
Progress Update - Per-User Scoped CredentialsCompletedBackend (3 commits):
CLI (1 commit):
Still NeededCLI upload command rewrite:
New secrets required:
Database migration: Security ModelEach user's credentials can only access their own dataset prefixes. Credentials are never exposed to the CLI. |
- encryption.ts: use random salt per encryption, add proper error handling - admin.ts: block revocation if IAM cleanup fails (security critical) - datasets.ts: use user credentials for upload-urls endpoint - datasets.ts: return error on IAM policy update failure - datasets.ts: add ENCRYPTION_KEY validation, wrap presigned URL generation - dataset.ts: rewrite upload command to use presigned URL flow - datalad.ts: add file manifest collection and presigned URL upload functions
Summary
POST /datasetsresponseChanges
Backend (
backend/src/routes/datasets.ts):aws_credentialsto create dataset response withaccessKeyId,secretAccessKey,region,bucketCLI:
src/lib/api.ts: Addedaws_credentialstoCreateDatasetResponseinterfacesrc/lib/datalad.ts: RemovedawsCredentialsfromPrerequisitesResult, removed check fromcheckPrerequisites()src/commands/dataset.ts: Use credentials from API response instead of environment variablesTests:
test/e2e-upload.test.ts: Removed AWS credentials from prerequisites checkTest plan
bun run build)bun run lint)Fixes #13