s3

package
v0.12.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 13, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package s3 is a MINIMAL, standard-library-only S3 client for pushing encrypted backup blobs to S3-compatible object storage (AWS S3, MinIO, Cloudflare R2, Backblaze B2). It exists so Mooring can offer off-box backups WITHOUT pulling the AWS SDK — or any third-party module — into a security-first project's dependency set. Everything here is net/http + crypto/{hmac,sha256} + encoding/{hex,xml}.

Security posture:

  • Request signing is AWS Signature Version 4, hand-implemented in sign.go and pinned by a known-answer test against the AWS-documented example vectors, so a signing regression fails the build rather than silently corrupting auth.
  • Uploads use x-amz-content-sha256: UNSIGNED-PAYLOAD, which is valid over TLS and lets Put STREAM the body — the backup is never hashed or buffered in RAM. Upload is a SINGLE PUT (no multipart yet), so objects over 5 GiB are rejected on AWS; MinIO/R2/B2 have higher/no single-PUT caps.
  • The secret key and the Authorization header are never logged (this package logs nothing at all) and never appear in returned errors.
  • HTTPS by default; plain http is opt-in (Config.Insecure) for MinIO on a trusted private network.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client is a signing S3 client bound to one bucket. Safe for concurrent use (it holds only immutable config plus an *http.Client).

func New

func New(cfg Config, hc *http.Client) (*Client, error)

New validates cfg and returns a Client. A nil hc gets a sane default transport with per-phase timeouts (dial/TLS/response-header) but NO whole-request Timeout: a multi-GB upload legitimately streams for many minutes, so request cancellation is left to the caller's context instead of a blunt deadline that would abort big Puts.

func (*Client) Delete

func (c *Client) Delete(ctx context.Context, key string) error

Delete removes key. It is idempotent: a 404 (already gone) is not an error.

func (*Client) List

func (c *Client) List(ctx context.Context, prefix string) ([]Object, error)

List returns every object under prefix, following ListObjectsV2 continuation tokens across as many pages as needed. prefix "" lists the whole bucket.

func (*Client) Put

func (c *Client) Put(ctx context.Context, key string, r io.Reader, size int64, contentType string) error

Put uploads exactly size bytes read from r to key. The body is streamed (never fully buffered) using UNSIGNED-PAYLOAD signing. contentType may be "". Objects over 5 GiB are rejected (single PUT only; no multipart yet).

type Config

type Config struct {
	Endpoint        string // host[:port], e.g. "s3.us-east-1.amazonaws.com" or "minio.example.com:9000"
	Region          string // e.g. "us-east-1"
	Bucket          string
	AccessKeyID     string
	SecretAccessKey string
	UsePathStyle    bool // true (recommended) for MinIO/most S3-compatible; virtual-host when false
	Insecure        bool // allow http:// (MinIO on a private network); default false = https
}

Config describes the target bucket and credentials. UsePathStyle defaults the caller toward path-style URLs (https://endpoint/bucket/key), which every S3-compatible server understands; virtual-host style is secondary.

type Object

type Object struct {
	Key          string
	Size         int64
	LastModified time.Time
}

Object is one listed object.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL