Skip to content

[DRAFT] feat: Phase 2 - implement comprehensive access control system for storage-construct #2871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from

Conversation

rozaychen
Copy link

@rozaychen rozaychen commented Jun 27, 2025

Problem

Phase 1 created the standalone storage-construct package with a placeholder grantAccess method. Phase 2 needs to implement the actual access control logic to generate IAM policies and attach them to appropriate roles based on access definitions.

Issue number, if available: Part of storage L3 construct initiative

Changes

Implemented a comprehensive access control system following the same architectural patterns as the existing backend-storage package:

Core Components Added:

  • StorageAccessPolicyFactory - Generates IAM policies with allow/deny statements for S3 actions
  • StorageAccessOrchestrator - Orchestrates access control logic and policy attachment
  • AuthRoleResolver - Resolves IAM roles from auth constructs (placeholder implementation)

Key Features:

  • Action Mapping: Converts storage actions (read, write, delete) to S3 IAM actions (s3:GetObject, s3:PutObject, etc.)
  • Path Processing: Handles S3 prefix patterns with wildcards (photos/*)
  • Access Types: Supports authenticated, guest, owner, and groups access patterns
  • ID Substitution: Framework for owner-based access with entity ID replacement
  • Allow/Deny Logic: Sophisticated permission management with explicit deny rules

Implementation Details:

  • Follows same architectural patterns as backend-storage for consistency
  • Comprehensive error handling and validation
  • Full TypeScript type safety with proper interfaces
  • ESLint compliant with proper JSDoc documentation

Corresponding docs PR, if applicable: N/A

Validation

Comprehensive Test Coverage (20 tests total):

  • 13 main construct tests - All core functionality including access control scenarios
  • 4 policy factory tests - IAM policy generation with allow/deny permissions
  • 3 auth resolver tests - Role resolution and validation logic

Test Scenarios Covered:

  • ✅ Basic access control with authenticated/guest users
  • ✅ Owner-based access with entity ID substitution
  • ✅ Group-based access control
  • ✅ All storage action types (read, write, delete)
  • ✅ Multiple access rules per path
  • ✅ Error handling for invalid auth constructs
  • ✅ Policy generation with complex permission sets

Build & Quality Checks:

  • ✅ TypeScript compilation successful
  • ✅ All ESLint rules passing
  • ✅ API documentation generated and updated
  • ✅ No breaking changes to existing functionality

Checklist

  • If this PR includes a functional change to the runtime behavior of the code, I have added or updated automated test coverage for this change.
  • If this PR requires a change to the Project Architecture README, I have included that update in this PR.
  • If this PR requires a docs update, I have linked to that docs PR above.
  • If this PR modifies E2E tests, makes changes to resource provisioning, or makes SDK calls, I have run the PR checks with the run-e2e label set.

Note: This is a foundational PR for the AmplifyStorage L3 construct migration project. The implementation follows a phased approach across multiple PRs:

Phase 1Create standalone storage-construct package

  • Create new @aws-amplify/storage-construct package
  • Migrate core AmplifyStorage implementation with CDK-native triggers
  • Add grantAccess(auth, accessDefinition) method pattern
  • Maintain full backward compatibility with existing backend-storage

Phase 2Implement access control logic in grantAccess method(this PR)

  • Add IAM policy generation engine
  • Implement Cognito integration for role resolution
  • Support authenticated/guest/owner access patterns

Phase 3 🔄 Add path-based permission system

  • Implement wildcard path matching (photos/*)
  • Add owner-based access control with entity substitution
  • Support complex permission scenarios

Phase 4 🔄 Add function resource access support

  • Extend StorageAccessRule type to support 'resource' type
  • Add function resource access acceptor resolution
  • Implement grantAccess(functionConstruct, accessConfig) overload
  • Support { type: 'resource', actions: ['read'] } pattern

Phase 5 🔄 Add granular action support

  • Extend actions to support ['get', 'list', 'write', 'delete']
  • Maintain backward compatibility with 'read'['get', 'list'] expansion
  • Update policy factory to handle granular permissions

Phase 6 🔄 Add multi-storage validation

  • Implement default storage detection and validation logic
  • Add error handling for multiple default storage instances
  • Support isDefault flag validation across multiple constructs

Phase 7 🔄 Enhance auth construct discovery

  • Improve automatic discovery of auth resources in construct tree
  • Add robust role resolution for complex auth scenarios
  • Handle edge cases and error conditions

Phase 8 🔄 Update documentation and examples

  • Create comprehensive usage documentation
  • Build sample CDK applications showing function access
  • Provide migration guide from Gen2 factory pattern
  • Document all access patterns and edge cases

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

rozaychen added 15 commits June 26, 2025 15:11
Add new storage-construct package with AmplifyConstruct implementation and test suite
- Add api-extractor.json configuration
- Add build and clean scripts to package.json
- Generate required TypeScript declaration files
…t package

- Create new @aws-amplify/storage-construct package with standalone L3 construct
- Migrate AmplifyStorage class from backend-storage with CDK-native trigger support
- Replace factory-based triggers with direct IFunction references
- Add comprehensive test suite with all original test coverage
- Configure package build, API extraction, and TypeScript compilation
- Maintain full backward compatibility with existing backend-storage package
- Replace constructor-based access control with grantAccess method pattern
- Add StorageAccessDefinition type for access configuration
- Update API to support storage.grantAccess(auth, accessDefinition) pattern
- Add test coverage for new grantAccess method
- Update exports to include StorageAccessDefinition type

Copy
- Bump version from 0.1.0 to 1.0.0 for major release
- Update aws-cdk-lib peer dependency from ^2.158.0 to ^2.189.1 for consistency
- Add missing main field to package.json for lint compliance
- Update changeset with detailed breaking change description
- Update package-lock.json with new version and dependency changes
- Set initial version to 0.1.0 for new package (changeset will bump to 1.0.0)
- Add storage-construct to version check exceptions for 0.x.x versions
- Update changeset description to reflect initial release rather than breaking change
- Update package-lock.json with corrected version
- Fix husky hooks with proper PATH configuration
- Add StorageAccessPolicyFactory for IAM policy generation with allow/deny logic
- Create StorageAccessOrchestrator following backend-storage architecture patterns
- Implement AuthRoleResolver for role extraction from auth constructs
- Support all access types: authenticated, guest, owner, groups
- Add action mapping from storage actions to S3 IAM permissions
- Handle path processing with wildcard patterns and ID substitution
- Add comprehensive test coverage (20 tests) for all components
- Align implementation with existing backend-storage package structure
Copy link

changeset-bot bot commented Jun 27, 2025

🦋 Changeset detected

Latest commit: 8e50857

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@aws-amplify/storage-construct Major

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@rozaychen rozaychen changed the title feat: Phase 2 - implement comprehensive access control system for storage-construct [DRAFT] feat: Phase 2 - implement comprehensive access control system for storage-construct Jun 27, 2025
@rozaychen rozaychen added the run-e2e Label that will include e2e tests in PR checks workflow label Jun 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
run-e2e Label that will include e2e tests in PR checks workflow
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant