A lightweight, high-performance external authorization service for Envoy, written in Go.
It allows or denies requests based on the peer remote address provided by Envoy, using a YAML-defined list of CIDR ranges mapped to organizational units.
β οΈ Note: This repository contains example configurations. Replace all department names, CIDR ranges, and registry references with your actual values before deployment.
- Go: 1.23 or higher
- gRPC: 1.73+ (included in dependencies)
- Docker: 20.10+ (optional, for containerized deployment)
- Kubernetes: 1.20+ (optional, for k8s deployment)
- β
gRPC-based ExtAuthz service (
envoy.service.auth.v3.Authorization) - β
Reads Envoyβs source remote address (
AttributeContext.Source.Address.SocketAddress.Address) - β
CIDR matching support for
/32,/24,/16, etc. - β
Optimized IP matching using Goβs
netpackage - β Secure default-deny policy
- β Verbose logging: Allowed/denied, matched department, and source IP
- β
Works with real Envoy deployments or
grpcurltesting
# Example configuration - replace with your actual values
departments:
- name: "team-alpha"
cidrs:
- "192.168.1.0/24"
- "10.0.1.100/32"
- name: "team-beta"
cidrs:
- "192.168.2.0/24"
- name: "team-gamma"
cidrs:
- "172.16.0.0/16"Each incoming request's peer remote address is compared to the organizational unit CIDRs.
If there's no match: β request denied.
If there's a match: β
request allowed with unit name logged.
go build -o ext-authz ../ext-authzOr:
go run .Make sure the service is listening on port 50051.
grpcurl -plaintext -d '{
"attributes": {
"source": {
"address": {
"socketAddress": {
"address": "10.0.42.77"
}
}
}
}
}' localhost:50051 envoy.service.auth.v3.Authorization/Checkgrpcurl -plaintext -d '{
"attributes": {
"source": {
"address": {
"socketAddress": {
"address": "8.8.8.8"
}
}
}
}
}' localhost:50051 envoy.service.auth.v3.Authorization/Checkdocker build -t ext-authz-service:latest .docker run -p 50051:50051 -v $(pwd)/config.yaml:/app/config.yaml ext-authz-service:latest# Run all tests
go test -v
# Run tests with coverage
go test -cover
# Generate detailed coverage report
go test -coverprofile=coverage.out
go tool cover -html=coverage.out -o coverage.htmlCurrent test coverage: 65.9%
| Function | Coverage | Status |
|---|---|---|
LoadCIDRs |
100.0% | β Perfect |
Check |
100.0% | β Perfect |
allow |
100.0% | β Perfect |
deny |
100.0% | β Perfect |
watchConfig |
72.7% | β Good |
runServer |
33.3% |
- β Unit Tests: Core authorization logic
- β Integration Tests: Full gRPC server workflow
- β Error Handling: Malformed requests, invalid IPs
- β Edge Cases: IPv6, large CIDR ranges, boundary conditions
- β Concurrency Tests: Race conditions, thread safety
- β Configuration Tests: YAML parsing, file watching
- β Performance Tests: Benchmarks for authorization checks
# Run performance benchmarks
go test -bench=.
# Example results:
# BenchmarkCheck_Allowed-8 5000000 250 ns/op
# BenchmarkCheck_Denied-8 3000000 400 ns/opBefore deploying to production:
- Update module name in
go.modto match your repository - Replace department/team names in config files with your actual organizational units
- Update CIDR ranges with your real network ranges
- Change Docker registry in
k8s/deployment.yamlto your container registry - Modify namespace in Kubernetes manifests if needed
# Clone the repository
git clone https://github.com/kevin-shelaga/envoy-ext-auth.git
cd envoy-ext-auth
# Install dependencies
go mod download
# Run tests
go test -v
# Build and run
go build -o ext-authz .
./ext-authzThis project includes a comprehensive Makefile for common development tasks:
# Development workflow
make deps # Download dependencies
make test # Run tests
make coverage # Run tests with coverage report
make lint # Run linter
make build # Build binary
make run # Build and run
# Quality assurance
make fmt # Format code
make security # Security scan
make bench # Run benchmarks
# Docker operations
make docker # Build Docker image
make docker-run # Build and run container
# Cross-platform builds
make build-all # Build for all platforms
# Kubernetes
make k8s-deploy # Deploy to Kubernetes
make k8s-clean # Clean up K8s resources
# Utilities
make clean # Clean build artifacts
make help # Show all available commands- Set breakpoints in
Check()handler - Use
log.Printf()to trace config parsing and request flow - Confirm CIDRs are loaded via
LoadCIDRs()logs - Use
grpcurlwithattributes.source.address.socketAddress.addressfield - Monitor file system events for config reloading
# Format code
go fmt ./...
# Run linter
golangci-lint run
# Security scan
make security
# Dependency check
go mod verifyThe project uses Gosec for security analysis. All security issues have been addressed:
- G304 (File Inclusion): Previously flagged for
os.ReadFile(path)in config loading- Status: β
Resolved - Added path validation and
#nosecannotation - Mitigation: Config paths are validated for safety (YAML files only, path traversal prevention)
- Status: β
Resolved - Added path validation and
# Build production image
docker build -t ext-authz-service:v1.0.0 .
# Run with custom config
docker run -d \
--name ext-authz \
-p 50051:50051 \
-v /path/to/your/config.yaml:/app/config.yaml \
ext-authz-service:v1.0.0# Apply all manifests
kubectl apply -k k8s/
# Check deployment status
kubectl get pods -n default
kubectl logs -f deployment/ext-auth-service- Config File:
/etc/ext-authz/config.yaml(default) - Environment Variables:
PORT: Server port (default: 50051)
- Health Check: gRPC health check service enabled
- Metrics: Built-in logging for monitoring
- Latency: ~250ns per authorization check
- Throughput: 5M+ requests/second (single core)
- Memory: ~10MB baseline memory usage
- CPU: Minimal CPU overhead for CIDR matching
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
- Maintain test coverage above 65%
- Follow Go best practices and conventions
- Add tests for new features
- Update documentation for API changes
This project is licensed under the MIT License - see the LICENSE file for details.
- Envoy Proxy for the external authorization API
- gRPC for high-performance RPC framework
- Go for excellent standard library networking support
- π Documentation: Check this README and inline code comments
- π Issues: GitHub Issues
- π¬ Discussions: GitHub Discussions
β Star this repository if it helped you! β
Made with β€οΈ for the Envoy community