Documentation
¶
Index ¶
- Constants
- func BucketTokenCount() int
- func BucketTokenExpiryWarnings(now time.Time, within time.Duration) (expired []string, expiringSoon []string)
- func BucketTokenMatches(bucketName, secret string) bool
- func BucketTokenMatchesAt(bucketName, secret string, now time.Time) bool
- func GetEnvAsBoolOrDefault(key string, defaultValue bool) bool
- func GetEnvAsIntOrDefault(key string, defaultValue int) int
- func GetEnvOrDefault(key, defaultValue string) string
- func LoadBucketTokens(path string) (int, error)
- func ValidateGeneralToken(token string) error
- type AWSConfig
- type AppConfig
- type BucketToken
- type Config
- type FeatureConfig
- type MinioConfig
- type RedisConfig
- type TokenConfig
- type WorkerConfig
Constants ¶
const MinBucketTokenLength = 32
MinBucketTokenLength is the minimum accepted length of a bucket-scoped token secret. Bucket tokens are machine-generated credentials, so there is no reason for a short one and a weak entry would silently widen the write surface.
Variables ¶
This section is empty.
Functions ¶
func BucketTokenCount ¶ added in v1.8.0
func BucketTokenCount() int
BucketTokenCount returns the number of loaded bucket-scoped tokens.
func BucketTokenExpiryWarnings ¶ added in v1.9.0
func BucketTokenExpiryWarnings(now time.Time, within time.Duration) (expired []string, expiringSoon []string)
BucketTokenExpiryWarnings reports which loaded tokens have already expired and which expire within the given window.
Returned rather than logged so that this package stays free of a logging dependency; the caller logs them at boot. An expired token is not an error: the deployment is still safe, it is the callers who will start failing, and an operator should hear about that before they do.
func BucketTokenMatches ¶ added in v1.8.0
BucketTokenMatches reports whether secret is the configured, unexpired token for bucketName.
func BucketTokenMatchesAt ¶ added in v1.9.0
BucketTokenMatchesAt is BucketTokenMatches with an explicit clock, so expiry can be tested without waiting for it.
Expiry is evaluated here, per request, rather than at load time. The file is only read at boot, so checking it there would mean a token stayed valid until the next restart; checking it here makes it stop working at the moment it expires.
The comparison is constant time, and an unknown bucket still runs a full comparison against a zero digest so that "no token configured for this bucket" and "wrong secret" cost the same.
func GetEnvAsBoolOrDefault ¶
func GetEnvAsIntOrDefault ¶
func GetEnvOrDefault ¶
func LoadBucketTokens ¶ added in v1.8.0
LoadBucketTokens reads bucket-scoped tokens from path and returns how many were loaded.
The line this draws is between "no scoped tokens" and "scoped tokens that cannot be read", not between "no file" and "some file".
Boot succeeds with zero bucket tokens when the file is missing, empty, or holds no entries ({}, {"buckets":[]}, {"buckets":null}). All of those are an operator saying there are none yet, which is the normal state of a deployment running on the general TOKEN alone, and none of them can be hiding a credential.
Boot fails when the file has content that cannot be parsed, or entries that fail validation. There the operator wrote definitions and believes they are active; starting anyway would serve with fewer credentials than configured and the callers using them would get "invalid token" with nothing to explain it.
Neither outcome affects the general TOKEN, which is validated separately and is accepted on every route regardless of what this file contains.
func ValidateGeneralToken ¶ added in v1.9.0
ValidateGeneralToken reports whether the general TOKEN is fit to authenticate with. It is enforced at boot, not per request, so a bad value fails loudly at deploy time instead of quietly weakening every authenticated endpoint.
The same floor as bucket-scoped tokens applies: MinBucketTokenLength. A general token is strictly more powerful than a scoped one, since it is accepted on the operator routes as well, so it cannot reasonably be held to a weaker standard.
Errors never contain the token itself: they end up in the boot log.
Types ¶
type BucketToken ¶ added in v1.8.0
type BucketToken struct {
Bucket string `json:"bucket"`
Token string `json:"token"`
// Label is an optional free-text note (who or what uses this token). It is
// never used for authorization.
Label string `json:"label,omitempty"`
// ExpiresAt is an optional RFC 3339 timestamp. Empty means the token never
// expires, which is what every entry written before this field existed means.
ExpiresAt string `json:"expires_at,omitempty"`
}
BucketToken is one entry of the token file.
type Config ¶
type Config struct {
App AppConfig
Minio MinioConfig
AWS AWSConfig
Redis RedisConfig
Worker WorkerConfig
Features FeatureConfig
}
type FeatureConfig ¶
type MinioConfig ¶
type RedisConfig ¶
type RedisConfig struct {
URL string
}
type TokenConfig ¶ added in v1.8.0
type TokenConfig struct {
Buckets []BucketToken `json:"buckets"`
}
TokenConfig is the on-disk shape of the token file.