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: adds redis auth. #1626

Closed
wants to merge 8 commits into from
Closed
34 changes: 23 additions & 11 deletions cmd/backfill-redis/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ package main
import (
"bytes"
"context"
"crypto/tls"
"encoding/base64"
"errors"
"flag"
Expand Down Expand Up @@ -64,14 +65,17 @@ import (
)

var (
redisHostname = flag.String("hostname", "", "Hostname for Redis application")
redisPort = flag.String("port", "", "Port to Redis application")
startIndex = flag.Int("start", -1, "First index to backfill")
endIndex = flag.Int("end", -1, "Last index to backfill")
rekorAddress = flag.String("rekor-address", "", "Address for Rekor, e.g. https://rekor.sigstore.dev")
versionFlag = flag.Bool("version", false, "Print the current version of Backfill Redis")
concurrency = flag.Int("concurrency", 1, "Number of workers to use for backfill")
dryRun = flag.Bool("dry-run", false, "Dry run - don't actually insert into Redis")
redisHostname = flag.String("hostname", "", "Hostname for Redis application")
redisPort = flag.String("port", "", "Port to Redis application")
redisUsername = flag.String("username", "", "Username for Redis authentication")
redisPassword = flag.String("password", "", "Password for Redis authentication")
insecureSkipVerify = flag.Bool("insecure-skip-verify", false, "Whether to skip TLS verification or not")
startIndex = flag.Int("start", -1, "First index to backfill")
endIndex = flag.Int("end", -1, "Last index to backfill")
rekorAddress = flag.String("rekor-address", "", "Address for Rekor, e.g. https://rekor.sigstore.dev")
versionFlag = flag.Bool("version", false, "Print the current version of Backfill Redis")
concurrency = flag.Int("concurrency", 1, "Number of workers to use for backfill")
dryRun = flag.Bool("dry-run", false, "Dry run - don't actually insert into Redis")
)

func main() {
Expand Down Expand Up @@ -101,10 +105,18 @@ func main() {

log.Printf("running backfill redis Version: %s GitCommit: %s BuildDate: %s", versionInfo.GitVersion, versionInfo.GitCommit, versionInfo.BuildDate)

// TLS configuration
tlsConfig := &tls.Config{
InsecureSkipVerify: *insecureSkipVerify,
}

redisClient := redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%s:%s", *redisHostname, *redisPort),
Network: "tcp",
DB: 0, // default DB
Addr: fmt.Sprintf("%s:%s", *redisHostname, *redisPort),
Username: *redisUsername,
Password: *redisPassword,
TLSConfig: tlsConfig,
Network: "tcp",
DB: 0, // default DB
})

rekorClient, err := client.GetRekorClient(*rekorAddress)
Expand Down
9 changes: 8 additions & 1 deletion pkg/api/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package api
import (
"context"
"crypto/sha256"
"crypto/tls"
"crypto/x509"
"encoding/hex"
"fmt"
Expand Down Expand Up @@ -139,8 +140,14 @@ func ConfigureAPI(treeID uint) {
}
if viper.GetBool("enable_retrieve_api") || viper.GetBool("enable_stable_checkpoint") ||
slices.Contains(viper.GetStringSlice("enabled_api_endpoints"), "searchIndex") {

redisClient = redis.NewClient(&redis.Options{
Addr: fmt.Sprintf("%v:%v", viper.GetString("redis_server.address"), viper.GetUint64("redis_server.port")),
Addr: fmt.Sprintf("%v:%v", viper.GetString("redis_server.address"), viper.GetUint64("redis_server.port")),
Username: viper.GetString("redis_server.username"),
Password: viper.GetString("redis_server.password"),
TLSConfig: &tls.Config{
InsecureSkipVerify: viper.GetBool("redis_server.insecure-skip-verify"),
},
Network: "tcp",
DB: 0, // default DB
})
Expand Down