S3Proxy by Intrinsec (forked from constellation)
S3Proxy is a Docker image that enables seamless encryption (AES-256-GCM) for all communications with an S3 provider, adding an extra layer of security. The proxy intercepts PUT and GET requests, encrypting data before sending it to S3 and decrypting it upon retrieval.
- Automatic encryption for all PUT requests before storage on S3
- Transparent decryption of GET requests when retrieving data from S3
- Easy setup: run the proxy and direct your HTTP requests through it.
docker run ghcr.io/intrinsec/s3proxy --rm -p 80:4433 -e AWS_ACCESS_KEY_ID="XXX" -e AWS_SECRET_ACCESS_KEY="XXX" -e S3PROXY_ENCRYPT_KEY="GENERATE_A_RANDOM_STRING" -e S3PROXY_HOST="s3.fr-par.scw.cloud" -e S3PROXY_DEKTAG_NAME="isec"helm ugprade --install s3proxy oci://ghcr.io/intrinsec/s3proxy/charts/s3proxyS3Proxy acts as an intermediary, intercepting S3 PUT and GET requests to provide transparent encryption/decryption.
-
PUT Object Flow:
- S3Proxy intercepts a PUT request.
- A random Data Encryption Key (DEK) is generated.
- The object's data is encrypted using AES-256-GCM with this DEK.
- The DEK itself is encrypted using a Key Encryption Key (KEK), derived from the
S3PROXY_ENCRYPT_KEYenvironment variable. - This encrypted DEK is stored as a metadata tag (named
isecby default, configurable viaS3PROXY_DEKTAG_NAME) on the S3 object. - The encrypted data is then forwarded to the S3 provider.
-
GET Object Flow:
- S3Proxy intercepts a GET request.
- It retrieves the encrypted data and the encrypted DEK from the S3 object's metadata.
- The encrypted DEK is decrypted using the KEK.
- The object's data is decrypted using the recovered DEK.
- The plaintext data is returned to the client.
Key components and their roles:
cmd/main.go: The entry point of the application, responsible for parsing command-line flags, setting up logging (logrus), loading configuration (koanf), and starting the HTTP server.internal/router: Implements the core request interception and routing logic. It dispatches requests to appropriate handlers based on the HTTP method and URL path, distinguishing betweenGetObject,PutObject, and other S3 operations. It also handles health endpoints (/healthz,/readyz) and applies optional request throttling. All AWS requests are re-signed before being forwarded to the S3 backend to comply with AWS signature requirements.internal/s3: Provides a thin wrapper around the AWS S3 client (github.com/aws/aws-sdk-go-v2/service/s3) for seamless interaction with the S3 backend. It includes custom middleware to capture raw HTTP responses, which is crucial for robust error handling.internal/crypto: Contains the cryptographic functions for encryption and decryption. It utilizesgithub.com/tink-crypto/tink-go/v2for AES-256-GCM for data encryption and Key Wrapping (KWP) for DEK encryption.
By default, multipart upload requests (CreateMultipartUpload, UploadPart, CompleteMultipartUpload, AbortMultipartUpload) are blocked for enhanced security, but this behavior can be optionally configured to forward these requests via a command-line flag.
- Configuration:
github.com/knadh/koanffor flexible configuration loading from environment variables (e.g.,S3PROXY_HOSTmaps tos3proxy.host). - Logging:
github.com/sirupsen/logrusfor structured and configurable logging. - AWS SDK:
github.com/aws/aws-sdk-go-v2/service/s3for all interactions with the S3 backend. - Cryptography:
github.com/tink-crypto/tink-go/v2for robust and secure cryptographic operations (AES-256-GCM and Key Wrapping). - UUID Generation:
github.com/google/uuidfor generating unique request identifiers.
S3Proxy can be easily deployed on Kubernetes using its official Helm chart located at charts/s3proxy. The chart provides a flexible way to configure and manage S3Proxy instances.
Key configurable parameters via values.yaml include:
replicaCount: Number of S3Proxy instances to run.deploymentStrategy: Kubernetes Deployment rollout strategy (RollingUpdateby default, orRecreate).image: Docker image repository and tag for S3Proxy.args: Command-line arguments passed to the S3Proxy binary (e.g.,--no-tlsto disable TLS,--levelfor log verbosity).cert: Configuration for CertManager integration to automatically provision TLS certificates.config: Settings for the S3 backend, includinghost,throttling(maximum requests per second),accessKey,secretKey, andencryptKey(the KEK).extraEnv: Additional environment variables, such asS3PROXY_DECRYPTION_FALLBACKfor temporary fallback decryption.service: Kubernetes Service configuration (defaults toClusterIPon port4433).ingress: Optional Ingress configuration for external access.resources: CPU and memory limits and requests for the S3Proxy pods.livenessProbeandreadinessProbe: Health check configurations pointing to/healthzand/readyzendpoints respectively.autoscaling: Horizontal Pod Autoscaler (HPA) settings for automatic scaling based on CPU and memory utilization.
The Helm chart deploys S3Proxy as a Kubernetes Deployment and exposes it via a Service, ensuring high availability and scalability.