|
|
1 week ago | |
|---|---|---|
| .. | ||
| data | 1 week ago | |
| internal | 1 week ago | |
| pkg | 1 week ago | |
| uploads | 1 week ago | |
| .gitignore | 1 week ago | |
| ARCHITECTURE.md | 1 week ago | |
| DEPLOYMENT.md | 1 week ago | |
| DSC01472 copy.jpg | 1 week ago | |
| Dockerfile | 1 week ago | |
| Makefile | 1 week ago | |
| PROJECT_SUMMARY.md | 1 week ago | |
| QUICKSTART.md | 1 week ago | |
| README.md | 1 week ago | |
| START_HERE.md | 1 week ago | |
| docker-compose.yml | 1 week ago | |
| downloaded.txt | 1 week ago | |
| go.mod | 1 week ago | |
| go.sum | 1 week ago | |
| main.go | 1 week ago | |
| main_test.go | 1 week ago | |
| output.txt | 1 week ago | |
| s3.json | 1 week ago | |
| test.bat | 1 week ago | |
| test.txt | 1 week ago | |
A Go-based mock implementation of AWS Security Token Service (STS) with AWS Signature Version 4 (SigV4) authentication.
GetCallerIdentity API implementationaws-sts-mock/
├── main.go # HTTP server and request routing
├── pkg/
│ ├── sigv4/
│ │ ├── sigv4.go # SigV4 validation middleware
│ │ └── sigv4_test.go # SigV4 validation tests
│ └── sts/
│ └── types.go # STS response types
├── main_test.go # Integration tests
├── Makefile # Build and test commands
└── README.md # This file
# Clone or create the project
cd aws-sts-mock
# Install dependencies
make install-deps
# Build the project
make build
# Using make
make run
# Or directly with go
go run main.go
# Or with custom port
PORT=8080 go run main.go
The server will start on port 8080 by default.
/Action=GetCallerIdentityVersion=2011-06-15/health# Set up credentials (use the mock credentials)
export AWS_ACCESS_KEY_ID="AKIAIOSFODNN7EXAMPLE"
export AWS_SECRET_ACCESS_KEY="wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
export AWS_DEFAULT_REGION="us-east-1"
# Start the server in one terminal
make run
# In another terminal, test with AWS CLI
aws sts get-caller-identity \
--endpoint-url http://localhost:8080 \
--no-verify-ssl
# Expected output:
# {
# "UserId": "123456789012",
# "Account": "123456789012",
# "Arn": "arn:aws:iam::123456789012:root"
# }
# Use credentials with session token
export AWS_ACCESS_KEY_ID="ASIAUIJXACK3L66H7KB4"
export AWS_SECRET_ACCESS_KEY="test-secret-key"
export AWS_SESSION_TOKEN="test-session-token"
aws sts get-caller-identity \
--endpoint-url http://localhost:8080 \
--no-verify-ssl
# Run all tests
make test
# Run with coverage
make test-coverage
# Run specific package tests
go test -v ./pkg/sigv4/
go test -v ./pkg/sts/
The server implements complete AWS Signature Version 4 validation:
Authorization Header
Request Timestamp
Signature Calculation
Credential Validation
The server returns standard AWS STS error responses:
MissingAuthenticationToken - No Authorization headerInvalidClientTokenId - Invalid access keySignatureDoesNotMatch - Signature validation failedRequestExpired - Request timestamp expiredInvalidRequest - Malformed requestAccessDenied - Permission deniedThe server includes two mock credential sets for testing:
AccessKeyID: AKIAIOSFODNN7EXAMPLE
SecretAccessKey: wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY
AccountID: 123456789012
AccessKeyID: ASIAUIJXACK3L66H7KB4
SecretAccessKey: test-secret-key
SessionToken: test-session-token
AccountID: 292709995190
To disable SigV4 validation for an endpoint, simply don't wrap it with the middleware:
// With SigV4 validation
mux.HandleFunc("POST /", sigv4.ValidateSigV4Middleware(handleSTSRequest))
// Without SigV4 validation
mux.HandleFunc("GET /health", handleHealth)
Edit pkg/sigv4/sigv4.go and add to the mockCredentials map:
var mockCredentials = map[string]AWSCredentials{
"YOUR_ACCESS_KEY_ID": {
AccessKeyID: "YOUR_ACCESS_KEY_ID",
SecretAccessKey: "YOUR_SECRET_KEY",
SessionToken: "OPTIONAL_SESSION_TOKEN",
AccountID: "YOUR_ACCOUNT_ID",
},
}
main.go - HTTP server, routing, and STS request handlingpkg/sigv4/ - SigV4 authentication middlewarepkg/sts/ - STS response type definitions*_test.go - Unit and integration testshandleSTSRequest() switch statementpkg/sts/types.gomain_test.goExample:
case "AssumeRole":
handleAssumeRole(w, r)
# Format code
make fmt
# Run linter
make vet
# Run both
make lint
The project includes comprehensive tests for signature validation:
# Test valid signatures
go test -v -run TestValidateSigV4Middleware/Valid ./pkg/sigv4/
# Test expired requests
go test -v -run TestValidateSigV4Middleware/Expired ./pkg/sigv4/
# Test invalid signatures
go test -v -run TestValidateSigV4Middleware/Invalid ./pkg/sigv4/
MIT License