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).
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
This project demonstrates two proven patterns used by successful companies like Coiled, Datadog, and others:
- 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
- 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
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
}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))
}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
- 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
- Permission boundary validation
- Cross-account role testing
- Credential expiration handling
- Failed authentication alerting
- π Cross-Account Access Pattern - Complete guide for SaaS services accessing customer accounts
- π₯οΈ External Tool Access Pattern - Complete guide for CLI tools and desktop applications
- π‘οΈ Security Analysis - Security comparison: cross-account roles vs access keys
- π Production Deployment - Enterprise deployment with scaling, monitoring, and DR
- π API Reference - Complete API documentation with examples
- Basic CLI: examples/simple-cli/ - Simple command-line tool (current)
- Basic SaaS: examples/simple-saas/ - Simple web service (current)
- Advanced SaaS: examples/saas-service/ - Complete web service with UI (planned)
- Advanced CLI: examples/cli-tool/ - Feature-rich CLI application (planned)
- Desktop App: examples/desktop-app/ - GUI application with visual setup (planned)
- Lambda Function: examples/lambda-function/ - Serverless cross-account access (planned)
- Go 1.21 or later
- AWS CLI v2 configured with appropriate permissions
- Basic understanding of AWS IAM roles and policies
- Clone the repository:
git clone https://github.com/scttfrdmn/aws-remote-access-patterns.git
cd aws-remote-access-patterns- Install dependencies:
go mod download- Run the setup script:
./scripts/setup.sh- 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- π 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
- π 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
We welcome contributions! Please see our Contributing Guide for details.
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes
- Add tests for new functionality
- Run tests:
go test ./... - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a pull request
This project is licensed under the MIT License - see the LICENSE file for details.
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
If this project helps you build secure AWS integrations, please give it a star! It helps others discover these patterns.
- π Documentation
- π Issue Tracker
- π¬ Discussions
- π Security Issues