diff --git a/README.md b/README.md index 6c332f3..2ae1141 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ If your configuration is right and Vault is running on the same host as the agen `retain` The number of backups to retain. -`timeout` How often to run the snapshot agent. Examples: `30s`, `1h`. See https://golang.org/pkg/time/#ParseDuration for a full list of valid time units. +`frequency` How often to run the snapshot agent. Examples: `30s`, `1h`. See https://golang.org/pkg/time/#ParseDuration for a full list of valid time units. `role_id` Specifies the role_id used to call the Vault API. See the authentication steps below. @@ -71,7 +71,7 @@ Note that if you specify more than one storage option, *all* options will be wri `local_storage` - Object for writing to a file on disk. -`aws_storage` - Object for writing to an S3 bucket. +`aws_storage` - Object for writing to an S3 bucket (Support AWS S3 but also S3 Compatible Storage). `google_storage` - Object for writing to GCS. @@ -87,6 +87,10 @@ Note that if you specify more than one storage option, *all* options will be wri `secret_access_key` - Recommended to use the standard `SECRET_ACCESS_KEY` env var, but its possible to specify this in the config +`s3_endpoint` - S3 compatible storage endpoint (ex: http://127.0.0.1:9000) + +`s3_force_path_style` - Needed if your S3 Compatible storage support only path-style or you would like to use S3's FIPS Endpoint. + `s3_region` - S3 region as is required for programmatic interaction with AWS `s3_bucket` - bucket to store snapshots in (required for AWS writes to work) diff --git a/config/config.go b/config/config.go index d5073a1..6c6036a 100644 --- a/config/config.go +++ b/config/config.go @@ -11,15 +11,15 @@ import ( // Configuration is the overall config object type Configuration struct { - Address string `json:"addr"` - Retain int64 `json:"retain"` - Timeout string `json:"freq"` - AWS S3Config `json:"aws_storage"` - Local LocalConfig `json:"local_storage"` - GCP GCPConfig `json:"google_storage"` - Azure AzureConfig `json:"azure_storage"` - RoleID string `json:"role_id"` - SecretID string `json:"secret_id"` + Address string `json:"addr"` + Retain int64 `json:"retain"` + Frequency string `json:"frequency"` + AWS S3Config `json:"aws_storage"` + Local LocalConfig `json:"local_storage"` + GCP GCPConfig `json:"google_storage"` + Azure AzureConfig `json:"azure_storage"` + RoleID string `json:"role_id"` + SecretID string `json:"secret_id"` } // AzureConfig is the configuration for Azure blob snapshots @@ -44,11 +44,13 @@ type S3Config struct { Uploader *s3manager.Uploader AccessKeyID string `json:"access_key_id"` SecretAccessKey string `json:"secret_access_key"` + Endpoint string `json:"s3_endpoint"` Region string `json:"s3_region"` Bucket string `json:"s3_bucket"` KeyPrefix string `json:"s3_key_prefix"` SSE bool `json:"s3_server_side_encryption"` StaticSnapshotName string `json:"s3_static_snapshot_name"` + S3ForcePathStyle bool `json:"s3_force_path_style"` } // ReadConfig reads the configuration file diff --git a/main.go b/main.go index 5898fa4..38879fd 100644 --- a/main.go +++ b/main.go @@ -38,10 +38,10 @@ func main() { } snapshotter, err := snapshot_agent.NewSnapshotter(c) - timeout, err := time.ParseDuration(c.Timeout) + frequency, err := time.ParseDuration(c.Frequency) if err != nil { - timeout = time.Hour + frequency = time.Hour } currentIP, err := getInstanceIP() @@ -90,7 +90,7 @@ func main() { } } select { - case <-time.After(timeout): + case <-time.After(frequency): continue case <-done: os.Exit(1) diff --git a/snapshot_agent/agent.go b/snapshot_agent/agent.go index 09d0c1a..afe014e 100644 --- a/snapshot_agent/agent.go +++ b/snapshot_agent/agent.go @@ -93,6 +93,14 @@ func (s *Snapshotter) ConfigureS3(config *config.Configuration) error { awsConfig.Credentials = credentials.NewStaticCredentials(config.AWS.AccessKeyID, config.AWS.SecretAccessKey, "") } + if config.AWS.Endpoint != "" { + awsConfig.Endpoint = aws.String(config.AWS.Endpoint) + } + + if config.AWS.S3ForcePathStyle != false { + awsConfig.S3ForcePathStyle = aws.Bool(config.AWS.S3ForcePathStyle) + } + sess := session.Must(session.NewSession(awsConfig)) s.S3Client = s3.New(sess) s.Uploader = s3manager.NewUploader(sess)