Skip to content

Add namespace support for S3 bucket naming and configuration#166

Merged
jfrench9 merged 5 commits into
mainfrom
chore/even-more-bootstrap-refinements
Jan 10, 2026
Merged

Add namespace support for S3 bucket naming and configuration#166
jfrench9 merged 5 commits into
mainfrom
chore/even-more-bootstrap-refinements

Conversation

@jfrench9
Copy link
Copy Markdown
Member

Summary

This PR introduces namespace support across the AWS infrastructure to enable better resource isolation and multi-environment deployments. The changes primarily focus on S3 bucket naming conventions and related configuration management.

Key Accomplishments

  • Enhanced S3 bucket naming: Added namespace prefixing to ensure unique bucket names across different environments and deployments
  • Improved workflow configuration: Updated GitHub Actions workflows (deploy-s3, prod, staging) to support namespace-aware deployments
  • Bootstrap enhancements: Extended the bootstrap process to handle namespace configuration during initial setup
  • CloudFormation updates: Modified S3 CloudFormation template to incorporate namespace parameters
  • Configuration management: Updated environment and secrets manager modules to properly handle namespace-scoped resources

Infrastructure Considerations

  • S3 bucket names will now include namespace prefixes to prevent naming conflicts
  • Existing deployments may require migration to adopt the new naming convention
  • The bootstrap process now supports namespace configuration for new environments
  • Secrets and environment variables are now namespace-aware for better isolation

Breaking Changes

  • S3 bucket naming convention has changed - existing buckets may need to be migrated
  • Environment configuration now requires namespace parameters
  • CloudFormation stack parameters have been updated to include namespace support

Testing Notes

  • Verify that new S3 buckets are created with proper namespace prefixes
  • Ensure existing functionality works with namespace-scoped resources
  • Test bootstrap process with different namespace configurations
  • Validate that secrets and configuration are properly isolated by namespace

This change improves the system's ability to support multiple isolated environments while maintaining clear resource boundaries.


🤖 Generated with Claude Code

Branch Info:

  • Source: chore/even-more-bootstrap-refinements
  • Target: main
  • Type: chore

Co-Authored-By: Claude noreply@anthropic.com

…tion

Enhanced the deployment workflows (`deploy-s3.yml`, `prod.yml`, `staging.yml`) to include a namespace parameter for S3 bucket names, ensuring uniqueness for forks. Updated the CloudFormation template (`s3.yaml`) to conditionally create bucket names based on the namespace. Modified the AWS setup scripts (`aws.sh`, `bootstrap.sh`) to handle the new namespace configuration and adjusted the environment configuration (`env.py`, `secrets_manager.py`) to reflect these changes. Updated documentation to clarify the new namespace behavior for forks.
@jfrench9
Copy link
Copy Markdown
Member Author

@claude please review this PR

@chatgpt-codex-connector
Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, you can upgrade your account or add credits to your account and enable them for code reviews in your settings.

@claude
Copy link
Copy Markdown

claude Bot commented Jan 10, 2026

Claude finished @jfrench9's task in 1m 36s —— View job


PR Review: Namespace Support for S3 Bucket Naming

Conducting a comprehensive review of the namespace implementation across all changed files.

Progress

  • Read and analyze all changed files
  • Review namespace implementation consistency
  • Check for security issues and best practices
  • Verify CloudFormation template changes
  • Review workflow modifications
  • Assess breaking change handling and migration path
  • Post comprehensive review feedback

Review Summary

This PR successfully implements namespace support for S3 bucket naming to enable better resource isolation between the main RoboSystems deployment and forks. The implementation is generally solid with good consistency across infrastructure and application layers.

Overall Assessment: Approve with minor suggestions


Strengths

  1. Excellent auto-detection logic in workflows (prod.yml:202, staging.yml:201) - automatically uses AWS account ID for forks while keeping main repo clean
  2. Consistent implementation - namespace flows from workflows → CloudFormation → bootstrap → secrets → application config
  3. Backward compatibility - handles both namespaced and non-namespaced bucket names via conditional logic
  4. Good security practices - namespace included in secrets manager for persistence
  5. Clear documentation in storage README about namespace purpose and usage

Issues & Recommendations

1. CloudFormation Pattern Inconsistency (cloudformation/s3.yaml)

Issue: The namespace parameter allows hyphens but the computed bucket names insert the namespace with a hyphen, which could create double-hyphens if someone passes a namespace with trailing/leading hyphens.

Location: cloudformation/s3.yaml:15-19

AllowedPattern: "^[a-z0-9-]*$"

Location: cloudformation/s3.yaml:70-71

- !Sub "robosystems-${Namespace}-shared-raw-${Environment}"

Recommendation:

  • Either change the pattern to ^[a-z0-9]*$ (no hyphens allowed) since namespace is typically an AWS account ID
  • Or add validation logic to trim hyphens from the namespace value
  • For AWS account IDs specifically, use pattern: ^[0-9]{12}$|^$ (empty or exactly 12 digits)

Example fix:

AllowedPattern: "^[0-9]{12}$|^$"
ConstraintDescription: Must be empty or a 12-digit AWS account ID

2. Missing Error Handling in Bootstrap (bin/setup/bootstrap.sh)

Issue: The S3_NAMESPACE is exported and used in aws.sh script, but there's no validation that the script actually received it.

Location: bin/setup/bootstrap.sh:504-508

else
    export S3_NAMESPACE="$AWS_ACCOUNT_ID"
    print_success "Fork detected - using account ID as namespace"

Recommendation: Add validation in bin/setup/aws.sh to ensure S3_NAMESPACE is set when expected:

# After line 82 in aws.sh
if [ "$full_repo" != "RoboFinSystems/robosystems" ] && [ -z "${S3_NAMESPACE:-}" ]; then
    echo "ERROR: S3_NAMESPACE must be set for forked deployments"
    exit 1
fi

3. Potential Configuration Drift (robosystems/config/env.py)

Issue: The bucket name computation logic exists in three places with slightly different implementations:

  1. CloudFormation (uses conditions and intrinsic functions)
  2. Python config (lines 702-729, uses string formatting)
  3. secrets_manager.py (lines 186-193, duplicates the logic)

Location: Multiple files

  • env.py:702-729
  • secrets_manager.py:186-193
  • cloudformation/s3.yaml:68-71, 110-113, etc.

Recommendation:
While the logic is currently consistent, consider extracting bucket name computation to a single helper function that all modules use:

# In robosystems/config/storage/buckets.py (new file)
def compute_bucket_name(purpose: str, namespace: str = "", environment: str = "dev") -> str:
    """
    Compute S3 bucket name with consistent logic.
    
    Args:
        purpose: Bucket purpose (shared-raw, shared-processed, user, etc.)
        namespace: Optional namespace (AWS account ID for forks)
        environment: Environment name (dev, staging, prod)
    
    Returns:
        Computed bucket name following the pattern:
        robosystems-{namespace}-{purpose}-{env} or robosystems-{purpose}-{env}
    """
    suffix = "" if environment == "dev" else f"-{environment}"
    prefix = f"robosystems-{namespace}" if namespace else "robosystems"
    return f"{prefix}-{purpose}{suffix}"

This would eliminate duplication and reduce drift risk.


4. Documentation Gap in Workflows

Issue: The namespace auto-detection logic is clever but not well-documented in the workflow files themselves.

Location:

  • .github/workflows/prod.yml:201-202
  • .github/workflows/staging.yml:200-201

Current:

# Namespace Configuration (auto: main repo = none, forks = account ID)
namespace: ${{ github.repository == 'RoboFinSystems/robosystems' && '' || vars.AWS_ACCOUNT_ID }}

Recommendation: Expand the comment to explain the S3 uniqueness requirement:

# Namespace Configuration (auto-computed for S3 global uniqueness)
# Main repo (RoboFinSystems/robosystems): empty namespace → robosystems-shared-raw-prod
# Forks: AWS account ID → robosystems-{account-id}-shared-raw-prod
# This ensures globally unique S3 bucket names across all AWS accounts
namespace: ${{ github.repository == 'RoboFinSystems/robosystems' && '' || vars.AWS_ACCOUNT_ID }}

5. Minor: Unused Variable in aws.sh

Issue: The s3_namespace_entry variable construction could be simplified.

Location: bin/setup/aws.sh:82-86, 162-167

Current:

local s3_namespace_entry=""
if [ -n "${S3_NAMESPACE:-}" ]; then
    s3_namespace_entry="\"S3_NAMESPACE\": \"${S3_NAMESPACE}\","
    echo "Including S3_NAMESPACE: ${S3_NAMESPACE}"
fi

Recommendation: This is actually well-implemented. No change needed - the echo is useful for user feedback.


Testing Recommendations

Given the breaking changes to S3 bucket naming:

  1. Test fork deployment - Verify a fork can deploy from scratch with namespaced buckets
  2. Test main repo deployment - Verify main repo still works without namespace
  3. Test CloudFormation update - Verify updating an existing stack handles the new namespace parameter gracefully (should be no-op for existing deployments)
  4. Test bootstrap flow - Run through just bootstrap on both main repo and a fork
  5. Verify bucket access - After deployment, confirm application can read/write to computed bucket names

Migration Considerations

Breaking Change Impact: This PR changes the default bucket naming convention. For existing deployments:

  • Main repo (RoboFinSystems/robosystems): No impact - namespace is empty, bucket names unchanged
  • Existing forks: Breaking change - bucket names will include account ID namespace on next deployment

Migration Path for Existing Forks:

  1. Before deploying this PR: Back up data from existing buckets
  2. Deploy this PR (creates new namespaced buckets)
  3. Copy data from old buckets to new namespaced buckets
  4. Delete old buckets

Consider adding a migration script or at least a clear migration guide in the PR description.


Security Review

✅ No security issues identified:

  • Namespace is properly validated (alphanumeric with hyphens)
  • No secrets exposed in bucket names (AWS account ID is not sensitive)
  • IAM policies correctly reference bucket names via CloudFormation outputs
  • Secrets manager properly stores namespace for persistence

Code Quality

Strengths:

  • Consistent naming conventions
  • Good use of CloudFormation conditions
  • Proper environment variable fallbacks
  • Clear separation of concerns

Minor Improvements:


Conclusion

This is a well-executed feature that addresses a real need for fork deployments. The implementation is consistent and follows AWS best practices for resource naming. The suggested improvements are minor and don't block merging.

Recommendation: Approve and merge with the understanding that the CloudFormation parameter validation should be tightened in a follow-up PR if needed.

Great work on maintaining consistency across all the layers! 🎉


| Branch: chore/even-more-bootstrap-refinements

Updated the `test_secrets_manager.py` to include additional assertions for S3 bucket names in both dev and staging environments. Added tests for handling namespace in bucket names for fork deployments, ensuring correct naming conventions based on the environment and namespace settings. This improves coverage and validation of the S3 bucket naming logic.
Simplified the `LOGS_BUCKET` assignment in `env.py` for better readability by condensing the multi-line statement into a single line. This change enhances the clarity of the environment configuration. Additionally, updated assertions in `test_secrets_manager.py` to format the `shared_processed` bucket name check for consistency and readability.
Added validation for the S3_NAMESPACE environment variable in the AWS setup script to ensure it is a 12-digit AWS account ID. Updated the CloudFormation template to enforce this format. Refactored bucket name generation logic into a new helper module to centralize and simplify the computation of S3 bucket names across the application, ensuring consistency in naming conventions for different environments and deployments.
Modified the AWS setup script to replace hardcoded redirect URIs and user agent strings with placeholders for better configurability. Refactored S3 bucket naming logic to remove deprecated aliases and improve clarity in purpose mapping. Updated tests to reflect these changes, ensuring consistency in bucket name assertions across environments.
@jfrench9 jfrench9 merged commit 0f8dd81 into main Jan 10, 2026
6 checks passed
@jfrench9 jfrench9 deleted the chore/even-more-bootstrap-refinements branch January 11, 2026 06:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant