Skip to content

Commit 9f49d7b

Browse files
authored
adds redis_auth (#1627)
Signed-off-by: ianhundere <[email protected]>
1 parent 1f00b2d commit 9f49d7b

File tree

7 files changed

+22
-13
lines changed

7 files changed

+22
-13
lines changed

cmd/backfill-redis/main.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ import (
6666
var (
6767
redisHostname = flag.String("hostname", "", "Hostname for Redis application")
6868
redisPort = flag.String("port", "", "Port to Redis application")
69+
redisPassword = flag.String("password", "", "Password for Redis authentication")
6970
startIndex = flag.Int("start", -1, "First index to backfill")
7071
endIndex = flag.Int("end", -1, "Last index to backfill")
7172
rekorAddress = flag.String("rekor-address", "", "Address for Rekor, e.g. https://rekor.sigstore.dev")
@@ -102,9 +103,10 @@ func main() {
102103
log.Printf("running backfill redis Version: %s GitCommit: %s BuildDate: %s", versionInfo.GitVersion, versionInfo.GitCommit, versionInfo.BuildDate)
103104

104105
redisClient := redis.NewClient(&redis.Options{
105-
Addr: fmt.Sprintf("%s:%s", *redisHostname, *redisPort),
106-
Network: "tcp",
107-
DB: 0, // default DB
106+
Addr: fmt.Sprintf("%s:%s", *redisHostname, *redisPort),
107+
Password: *redisPassword,
108+
Network: "tcp",
109+
DB: 0, // default DB
108110
})
109111

110112
rekorClient, err := client.GetRekorClient(*rekorAddress)

cmd/rekor-server/app/root.go

+1
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ Memory and file-based signers should only be used for testing.`)
113113
`Index Storage provider to use. Valid options are: [redis].`)
114114
rootCmd.PersistentFlags().String("redis_server.address", "127.0.0.1", "Redis server address")
115115
rootCmd.PersistentFlags().Uint16("redis_server.port", 6379, "Redis server port")
116+
rootCmd.PersistentFlags().String("redis_server.password", "", "Redis server password")
116117

117118
rootCmd.PersistentFlags().Bool("enable_attestation_storage", false, "enables rich attestation storage")
118119
rootCmd.PersistentFlags().String("attestation_storage_bucket", "", "url for attestation storage bucket")

docker-compose.test.yml

+1
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ services:
3030
"--trillian_log_server.port=8090",
3131
"--redis_server.address=redis-server",
3232
"--redis_server.port=6379",
33+
"--redis_server.password=test",
3334
"--rekor_server.address=0.0.0.0",
3435
"--rekor_server.signer=memory",
3536
"--enable_attestation_storage",

docker-compose.yml

+5-2
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,15 @@ services:
3636
"--bind",
3737
"0.0.0.0",
3838
"--appendonly",
39-
"yes"
39+
"yes",
40+
"--requirepass",
41+
"test"
4042
]
4143
ports:
4244
- "6379:6379"
4345
restart: always # keep the redis server running
4446
healthcheck:
45-
test: ["CMD", "redis-cli", "ping"]
47+
test: ["CMD", "redis-cli", "-a", "test", "ping"]
4648
interval: 10s
4749
timeout: 3s
4850
retries: 3
@@ -91,6 +93,7 @@ services:
9193
"--trillian_log_server.address=trillian-log-server",
9294
"--trillian_log_server.port=8090",
9395
"--redis_server.address=redis-server",
96+
"--redis_server.password=test",
9497
"--redis_server.port=6379",
9598
"--rekor_server.address=0.0.0.0",
9699
"--rekor_server.signer=memory",

pkg/api/api.go

+4-3
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,10 @@ func ConfigureAPI(treeID uint) {
176176

177177
if viper.GetBool("enable_stable_checkpoint") {
178178
redisClient = redis.NewClient(&redis.Options{
179-
Addr: fmt.Sprintf("%v:%v", viper.GetString("redis_server.address"), viper.GetUint64("redis_server.port")),
180-
Network: "tcp",
181-
DB: 0, // default DB
179+
Addr: fmt.Sprintf("%v:%v", viper.GetString("redis_server.address"), viper.GetUint64("redis_server.port")),
180+
Password: viper.GetString("redis_server.password"),
181+
Network: "tcp",
182+
DB: 0, // default DB
182183
})
183184
checkpointPublisher := witness.NewCheckpointPublisher(context.Background(), api.logClient, api.logRanges.ActiveTreeID(),
184185
viper.GetString("rekor_server.hostname"), api.signer, redisClient, viper.GetUint("publish_frequency"), CheckpointPublishCount)

pkg/indexstorage/indexstorage.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ type IndexStorage interface {
3131
func NewIndexStorage(providerType string) (IndexStorage, error) {
3232
switch providerType {
3333
case redis.ProviderType:
34-
return redis.NewProvider(viper.GetString("redis_server.address"), viper.GetString("redis_server.port"))
34+
return redis.NewProvider(viper.GetString("redis_server.address"), viper.GetString("redis_server.port"), viper.GetString("redis_server.password"))
3535
default:
3636
return nil, fmt.Errorf("invalid index storage provider type: %v", providerType)
3737
}

pkg/indexstorage/redis/redis.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,13 @@ type IndexStorageProvider struct {
3030
client *redis.Client
3131
}
3232

33-
func NewProvider(address, port string) (*IndexStorageProvider, error) {
33+
func NewProvider(address, port, password string) (*IndexStorageProvider, error) {
3434
provider := &IndexStorageProvider{}
3535
provider.client = redis.NewClient(&redis.Options{
36-
Addr: fmt.Sprintf("%v:%v", address, port),
37-
Network: "tcp",
38-
DB: 0, // default DB
36+
Addr: fmt.Sprintf("%v:%v", address, port),
37+
Network: "tcp",
38+
Password: password,
39+
DB: 0, // default DB
3940
})
4041
return provider, nil
4142
}

0 commit comments

Comments
 (0)