Skip to content

Secure AWS remote account access patterns demonstrating modern alternatives to access keys. Includes cross-account roles for SaaS services and intelligent authentication for CLI tools.

License

Notifications You must be signed in to change notification settings

scttfrdmn/aws-remote-access-patterns

Repository files navigation

AWS Remote Account Access Patterns

License: MIT Go Report Card

A comprehensive demonstration of secure AWS remote account access patterns, showcasing industry best practices for both cross-account access (SaaS services) and external tool access (CLI tools, desktop applications).

🎯 Problem This Solves

Modern applications need secure access to customer AWS accounts, but traditional approaches have significant issues:

  • Long-lived access keys - Security risk, hard to rotate, often leaked
  • Overly broad permissions - Tools ask for admin access "to be safe"
  • Poor user experience - "Here's some JSON policy, figure it out yourself"
  • No clear boundaries - Setup vs ongoing permissions mixed together

πŸ—οΈ Our Approach

This project demonstrates two proven patterns used by successful companies like Coiled, Datadog, and others:

Pattern 1: Cross-Account Access (SaaS Services)

  • Use case: Your service runs in AWS and needs access to customer AWS accounts
  • Method: IAM cross-account roles with external IDs
  • Security: Temporary credentials, least-privilege permissions
  • UX: One-click CloudFormation deployment with progressive disclosure

Pattern 2: External Tool Access (CLI/Desktop Tools)

  • Use case: Your tool runs on workstations/laptops and needs AWS access
  • Method: AWS SSO + IAM roles with intelligent fallbacks
  • Security: Temporary SSO credentials with automatic refresh
  • UX: Guided setup with multiple authentication options

πŸš€ Quick Start

For Cross-Account Access (SaaS Services)

package main

import (
    "context"
    "log"
    
    "github.com/scttfrdmn/aws-remote-access-patterns/pkg/crossaccount"
)

func main() {
    client, err := crossaccount.New(&crossaccount.Config{
        ServiceName:      "MyDataPlatform",
        ServiceAccountID: "123456789012", 
        TemplateS3Bucket: "my-platform-templates",
        OngoingPermissions: []crossaccount.Permission{
            {
                Sid:    "S3DataAccess",
                Effect: "Allow",
                Actions: []string{"s3:GetObject", "s3:PutObject"},
                Resources: []string{"arn:aws:s3:::customer-data-*/*"},
            },
        },
    })
    if err != nil {
        log.Fatal(err)
    }

    // Generate integration URL for customer
    resp, err := client.GenerateIntegrationURL(context.Background(), &crossaccount.IntegrationRequest{
        CustomerID:   "acme-corp",
        CustomerName: "Acme Corp",
        Region:       "us-west-2",
    })
    if err != nil {
        log.Fatal(err)
    }

    // Customer clicks this URL to set up the integration
    fmt.Printf("Integration URL: %s\n", resp.LaunchURL)
    
    // Later, assume the customer's role to perform operations
    awsConfig, err := client.AssumeCustomerRole(context.Background(), "acme-corp")
    if err != nil {
        log.Fatal(err)
    }
    
    // Use AWS services with customer's permissions
    s3Client := s3.NewFromConfig(awsConfig)
    // ... perform operations
}

For External Tool Access (CLI Tools)

package main

import (
    "context"
    "log"
    
    "github.com/scttfrdmn/aws-remote-access-patterns/pkg/awsauth"
)

func main() {
    client, err := awsauth.New(&awsauth.Config{
        ToolName: "my-awesome-cli",
        RequiredActions: []string{
            "ec2:DescribeInstances",
            "s3:ListBuckets",
        },
    })
    if err != nil {
        log.Fatal(err)
    }

    // Get AWS credentials (handles all authentication complexity)
    awsConfig, err := client.GetAWSConfig(context.Background())
    if err != nil {
        log.Fatal(err)
    }

    // Use AWS services normally
    ec2Client := ec2.NewFromConfig(awsConfig)
    result, err := ec2Client.DescribeInstances(context.Background(), &ec2.DescribeInstancesInput{})
    if err != nil {
        log.Fatal(err)
    }
    
    fmt.Printf("Found %d reservations\n", len(result.Reservations))
}

πŸ“ Project Structure

aws-remote-access-patterns/
β”œβ”€β”€ README.md                  # This file
β”œβ”€β”€ LICENSE                    # MIT License
β”œβ”€β”€ go.mod                     # Go module definition
β”œβ”€β”€ go.sum                     # Go module checksums
β”‚
β”œβ”€β”€ pkg/                       # Core library packages
β”‚   β”œβ”€β”€ crossaccount/          # Cross-account access pattern (SaaS services)
β”‚   β”‚   β”œβ”€β”€ client.go          # Main client implementation
β”‚   β”‚   β”œβ”€β”€ config.go          # Configuration structures
β”‚   β”‚   β”œβ”€β”€ templates.go       # CloudFormation generation
β”‚   β”‚   β”œβ”€β”€ validation.go      # Role validation
β”‚   β”‚   └── storage.go         # Credential storage interfaces
β”‚   └── awsauth/               # External tool access pattern (CLI/desktop)
β”‚       β”œβ”€β”€ client.go          # Main authentication client
β”‚       β”œβ”€β”€ config.go          # Configuration structures
β”‚       β”œβ”€β”€ sso.go             # AWS SSO integration
β”‚       β”œβ”€β”€ setup.go           # Interactive setup process
β”‚       └── credentials.go     # Credential management
β”‚
β”œβ”€β”€ examples/                  # Complete working examples
β”‚   β”œβ”€β”€ simple-cli/            # Basic CLI tool (current)
β”‚   β”œβ”€β”€ simple-saas/           # Basic SaaS service (current)
β”‚   β”œβ”€β”€ saas-service/          # Complete SaaS service example (planned)
β”‚   β”œβ”€β”€ cli-tool/              # Advanced CLI tool example (planned)
β”‚   β”œβ”€β”€ desktop-app/           # Desktop application example (planned)
β”‚   └── lambda-function/       # AWS Lambda example (planned)
β”‚
β”œβ”€β”€ templates/                 # CloudFormation templates
β”‚   β”œβ”€β”€ cross-account-role.yaml # Production cross-account role template
β”‚   └── iam-user-policy.yaml   # IAM user policy template
β”‚
β”œβ”€β”€ docs/                      # Comprehensive documentation
β”‚   β”œβ”€β”€ cross-account.md       # Cross-account pattern complete guide
β”‚   β”œβ”€β”€ external-tool.md       # External tool pattern complete guide
β”‚   β”œβ”€β”€ security.md            # Security analysis and best practices
β”‚   β”œβ”€β”€ deployment.md          # Production deployment guide
β”‚   └── api-reference.md       # Complete API documentation
β”‚
└── scripts/                   # Automation and setup scripts
    β”œβ”€β”€ setup.sh               # Development environment setup
    └── deploy.sh              # Production deployment script

πŸ” Security Features

Built-in Security Best Practices

  • Least Privilege: Generate minimal IAM policies based on actual requirements
  • External IDs: Cryptographically secure external IDs for cross-account roles
  • Temporary Credentials: No long-lived access keys stored or transmitted
  • Two-Phase Permissions: Separate setup vs ongoing permissions
  • Credential Rotation: Automatic handling of credential refresh and rotation
  • Audit Logging: Comprehensive logging of all authentication events

Security Validations

  • Permission boundary validation
  • Cross-account role testing
  • Credential expiration handling
  • Failed authentication alerting

πŸ“š Documentation

Core Concepts & Patterns

Working Examples

πŸš€ Getting Started

Prerequisites

  • Go 1.21 or later
  • AWS CLI v2 configured with appropriate permissions
  • Basic understanding of AWS IAM roles and policies

Installation

  1. Clone the repository:
git clone https://github.com/scttfrdmn/aws-remote-access-patterns.git
cd aws-remote-access-patterns
  1. Install dependencies:
go mod download
  1. Run the setup script:
./scripts/setup.sh
  1. Try the examples:
# Run the CLI tool example
cd examples/simple-cli
go run main.go --setup

# Run the SaaS service example  
cd examples/simple-saas
go run main.go

✨ Features

Cross-Account Pattern (SaaS Services)

  • πŸš€ One-click CloudFormation deployment for customers
  • πŸ”’ Cryptographically secure external ID generation
  • πŸ“‹ Two-phase permission strategy (setup vs ongoing)
  • ⚑ Automatic credential refresh and caching
  • 🎯 Least-privilege permission templates
  • 🌍 Multi-region support
  • πŸ“Š Comprehensive audit logging

External Tool Pattern (CLI/Desktop)

  • πŸ” AWS SSO device flow integration
  • πŸ”„ Multiple authentication fallbacks (SSO β†’ Profile β†’ IAM User)
  • πŸ§™β€β™‚οΈ Interactive setup wizard with clear guidance
  • πŸ’Ύ Secure credential caching with expiration
  • πŸ› οΈ CI/CD environment optimization
  • πŸ–₯️ Desktop application support with web UI
  • πŸ“± Cross-platform compatibility

🀝 Contributing

We welcome contributions! Please see our Contributing Guide for details.

Development Setup

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes
  4. Add tests for new functionality
  5. Run tests: go test ./...
  6. Commit changes: git commit -m 'Add amazing feature'
  7. Push to branch: git push origin feature/amazing-feature
  8. Open a pull request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ™ Acknowledgments

This project is inspired by the excellent work of:

  • Coiled - for pioneering user-friendly AWS integration UX
  • Datadog - for cross-account role best practices
  • AWS - for providing the underlying security primitives

⭐ Show Your Support

If this project helps you build secure AWS integrations, please give it a star! It helps others discover these patterns.

πŸ“ž Support

About

Secure AWS remote account access patterns demonstrating modern alternatives to access keys. Includes cross-account roles for SaaS services and intelligent authentication for CLI tools.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •