![]() |
3 өдөр өмнө | |
---|---|---|
.. | ||
data | 3 өдөр өмнө | |
internal | 4 өдөр өмнө | |
pkg | 4 өдөр өмнө | |
uploads | 4 өдөр өмнө | |
.gitignore | 4 өдөр өмнө | |
ARCHITECTURE.md | 4 өдөр өмнө | |
DEPLOYMENT.md | 4 өдөр өмнө | |
DSC01472 copy.jpg | 4 өдөр өмнө | |
Dockerfile | 4 өдөр өмнө | |
Makefile | 4 өдөр өмнө | |
PROJECT_SUMMARY.md | 4 өдөр өмнө | |
QUICKSTART.md | 4 өдөр өмнө | |
README.md | 4 өдөр өмнө | |
START_HERE.md | 4 өдөр өмнө | |
docker-compose.yml | 4 өдөр өмнө | |
downloaded.txt | 4 өдөр өмнө | |
go.mod | 4 өдөр өмнө | |
go.sum | 4 өдөр өмнө | |
main.go | 4 өдөр өмнө | |
main_test.go | 4 өдөр өмнө | |
output.txt | 4 өдөр өмнө | |
s3.json | 4 өдөр өмнө | |
td.bat | 3 өдөр өмнө | |
test.bat | 4 өдөр өмнө | |
test.txt | 4 өдөр өмнө | |
w.bat | 3 өдөр өмнө |
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=GetCallerIdentity
Version=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.go
main_test.go
Example:
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