Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add config param SessionToken #575

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions cmd/litestream/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ type Config struct {
// Global S3 settings
AccessKeyID string `yaml:"access-key-id"`
SecretAccessKey string `yaml:"secret-access-key"`
SessionToken string `yaml:"session-token"`

// Logging
Logging LoggingConfig `yaml:"logging"`
Expand All @@ -191,6 +192,9 @@ func (c *Config) propagateGlobalSettings() {
if rc.SecretAccessKey == "" {
rc.SecretAccessKey = c.SecretAccessKey
}
if rc.SessionToken == "" {
rc.SessionToken = c.SessionToken
}
}
}
}
Expand Down Expand Up @@ -347,6 +351,7 @@ type ReplicaConfig struct {
// S3 settings
AccessKeyID string `yaml:"access-key-id"`
SecretAccessKey string `yaml:"secret-access-key"`
SessionToken string `yaml:"session-token"`
Region string `yaml:"region"`
Bucket string `yaml:"bucket"`
Endpoint string `yaml:"endpoint"`
Expand Down Expand Up @@ -525,6 +530,7 @@ func newS3ReplicaClientFromConfig(c *ReplicaConfig, r *litestream.Replica) (_ *s
client := s3.NewReplicaClient()
client.AccessKeyID = c.AccessKeyID
client.SecretAccessKey = c.SecretAccessKey
client.SessionToken = c.SessionToken
client.Bucket = bucket
client.Path = path
client.Region = region
Expand Down Expand Up @@ -680,6 +686,11 @@ func applyLitestreamEnv() {
os.Setenv("AWS_SECRET_ACCESS_KEY", v)
}
}
if v, ok := os.LookupEnv("LITESTREAM_SESSION_TOKEN"); ok {
if _, ok := os.LookupEnv("AWS_SESSION_TOKEN"); !ok {
os.Setenv("AWS_SESSION_TOKEN", v)
}
}
}

// ParseReplicaURL parses a replica URL.
Expand Down
3 changes: 2 additions & 1 deletion s3/replica_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type ReplicaClient struct {
// AWS authentication keys.
AccessKeyID string
SecretAccessKey string
SessionToken string

// S3 bucket information
Region string
Expand Down Expand Up @@ -108,7 +109,7 @@ func (c *ReplicaClient) config() *aws.Config {
config := &aws.Config{}

if c.AccessKeyID != "" || c.SecretAccessKey != "" {
config.Credentials = credentials.NewStaticCredentials(c.AccessKeyID, c.SecretAccessKey, "")
config.Credentials = credentials.NewStaticCredentials(c.AccessKeyID, c.SecretAccessKey, c.SessionToken)
}
if c.Endpoint != "" {
config.Endpoint = aws.String(c.Endpoint)
Expand Down