From bca3ce71211f3abee94f02078007fed89d56f2ff Mon Sep 17 00:00:00 2001 From: Michael Insel Date: Mon, 10 Aug 2020 17:51:19 +0200 Subject: [PATCH 1/5] Add Redis password authentication Adds the missing password authentication. refs #204 --- connection/redis.go | 3 ++- main.go | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/connection/redis.go b/connection/redis.go index 8ec7f158..8fbd9da1 100644 --- a/connection/redis.go +++ b/connection/redis.go @@ -112,11 +112,12 @@ func (rdbw *RDBWrapper) CompareAndSetConnected(connected bool) (swapped bool) { } } -func NewRDBWrapper(address string, poolSize int) *RDBWrapper { +func NewRDBWrapper(address string, password string, poolSize int) *RDBWrapper { log.Info("Connecting to Redis") rdb := redis.NewClient(&redis.Options{ Addr: address, + Password: password, DialTimeout: time.Minute / 2, ReadTimeout: time.Minute, WriteTimeout: time.Minute, diff --git a/main.go b/main.go index fbc3ecb8..40aea7e5 100644 --- a/main.go +++ b/main.go @@ -104,7 +104,7 @@ func main() { mysqlInfo := config.GetMysqlInfo() metricsInfo := config.GetMetricsInfo() - redisConn := connection.NewRDBWrapper(redisInfo.Host+":"+redisInfo.Port, redisInfo.PoolSize) + redisConn := connection.NewRDBWrapper(redisInfo.Host+":"+redisInfo.Port, redisInfo.Password,redisInfo.PoolSize) mysqlConn, err := connection.NewDBWrapper( mysqlInfo.User+":"+mysqlInfo.Password+"@tcp("+mysqlInfo.Host+":"+mysqlInfo.Port+")/"+mysqlInfo.Database, From 78d3828ca992b88ee20d78c9ffa6a7eb29bcc34b Mon Sep 17 00:00:00 2001 From: Michael Insel Date: Mon, 10 Aug 2020 17:54:27 +0200 Subject: [PATCH 2/5] Doc: Add Redis password configuration settings This adds the Redis password authentication to the documentation. --- doc/03-Configuration.md | 1 + icingadb.ini | 1 + main.go | 13 +++++++------ 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/doc/03-Configuration.md b/doc/03-Configuration.md index cc0f0d63..ab995ce6 100644 --- a/doc/03-Configuration.md +++ b/doc/03-Configuration.md @@ -14,6 +14,7 @@ Option | Description -------------------------|----------------------------------------------- host | **Optional.** Redis host. Defaults to `127.0.0.1`. port | **Optional.** Redis port. Defaults to `6380`. +password | **Optional.** Redis password. Not set by default. pool\_size | **Optional.** Maximum number of socket connections. Defaults to `64`. ### MySQL Configuration diff --git a/icingadb.ini b/icingadb.ini index ec81038a..4d2a65df 100644 --- a/icingadb.ini +++ b/icingadb.ini @@ -1,6 +1,7 @@ [redis] host="127.0.0.1" ;port=6380 +;password="icingadb" [mysql] host="127.0.0.1" diff --git a/main.go b/main.go index 40aea7e5..523dc879 100644 --- a/main.go +++ b/main.go @@ -5,6 +5,12 @@ package main import ( "flag" "fmt" + "os" + "os/signal" + "regexp" + "sync" + "syscall" + "github.com/Icinga/icingadb/config" "github.com/Icinga/icingadb/configobject" "github.com/Icinga/icingadb/configobject/configsync" @@ -64,11 +70,6 @@ import ( "github.com/Icinga/icingadb/prometheus" "github.com/Icinga/icingadb/supervisor" log "github.com/sirupsen/logrus" - "os" - "os/signal" - "regexp" - "sync" - "syscall" ) var gitVersion = regexp.MustCompile(`\A(.+)-\d+-g([A-Fa-f0-9]+)\z`) @@ -104,7 +105,7 @@ func main() { mysqlInfo := config.GetMysqlInfo() metricsInfo := config.GetMetricsInfo() - redisConn := connection.NewRDBWrapper(redisInfo.Host+":"+redisInfo.Port, redisInfo.Password,redisInfo.PoolSize) + redisConn := connection.NewRDBWrapper(redisInfo.Host+":"+redisInfo.Port, redisInfo.Password, redisInfo.PoolSize) mysqlConn, err := connection.NewDBWrapper( mysqlInfo.User+":"+mysqlInfo.Password+"@tcp("+mysqlInfo.Host+":"+mysqlInfo.Port+")/"+mysqlInfo.Database, From e599b01b5416c1e7a1938218c45bd82d57e8b5a4 Mon Sep 17 00:00:00 2001 From: Michael Insel Date: Mon, 10 Aug 2020 18:35:22 +0200 Subject: [PATCH 3/5] Fix CI/CD tests --- configobject/configsync/configsync_test.go | 2 +- connection/redis_test.go | 4 ++-- ha/ha_test.go | 2 +- ha/heartbeat_test.go | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-) diff --git a/configobject/configsync/configsync_test.go b/configobject/configsync/configsync_test.go index 1e03d105..ce05ff97 100644 --- a/configobject/configsync/configsync_test.go +++ b/configobject/configsync/configsync_test.go @@ -21,7 +21,7 @@ import ( var mysqlTestObserver = connection.DbIoSeconds.WithLabelValues("mysql", "test") func SetupConfigSync(t *testing.T, objectTypes []*configobject.ObjectInformation) (*supervisor.Supervisor, []chan int) { - rdbw := connection.NewRDBWrapper(testbackends.RedisTestAddr, 64) + rdbw := connection.NewRDBWrapper(testbackends.RedisTestAddr, "",64) dbw, err := connection.NewDBWrapper(testbackends.MysqlTestDsn, 50) require.NoError(t, err, "Is the MySQL server running?") diff --git a/connection/redis_test.go b/connection/redis_test.go index 9b38cbea..94f6b49e 100644 --- a/connection/redis_test.go +++ b/connection/redis_test.go @@ -20,10 +20,10 @@ func NewTestRDBW(rdb RedisClient) RDBWrapper { } func TestNewRDBWrapper(t *testing.T) { - rdbw := NewRDBWrapper(testbackends.RedisTestAddr, 64) + rdbw := NewRDBWrapper(testbackends.RedisTestAddr, "",64) assert.True(t, rdbw.CheckConnection(false), "Redis should be connected") - rdbw = NewRDBWrapper("asdasdasdasdasd:5123", 64) + rdbw = NewRDBWrapper("asdasdasdasdasd:5123", "",64) assert.False(t, rdbw.CheckConnection(false), "Redis should not be connected") //TODO: Add more tests here } diff --git a/ha/ha_test.go b/ha/ha_test.go index f0c05448..f4ed8463 100644 --- a/ha/ha_test.go +++ b/ha/ha_test.go @@ -19,7 +19,7 @@ import ( ) func createTestingHA(t *testing.T, redisAddr string) *HA { - redisConn := connection.NewRDBWrapper(redisAddr, 64) + redisConn := connection.NewRDBWrapper(redisAddr, "",64) mysqlConn, err := connection.NewDBWrapper(testbackends.MysqlTestDsn, 50) if err != nil { diff --git a/ha/heartbeat_test.go b/ha/heartbeat_test.go index 82b28413..9eff7082 100644 --- a/ha/heartbeat_test.go +++ b/ha/heartbeat_test.go @@ -23,7 +23,7 @@ const app = "{\"status\": " + const dump = "false" func TestIcingaHeartbeatListener(t *testing.T) { - rdb := connection.NewRDBWrapper(testbackends.RedisTestAddr, 64) + rdb := connection.NewRDBWrapper(testbackends.RedisTestAddr, "",64) assert.True(t, rdb.CheckConnection(false), "This test needs a working Redis connection") chEnv := make(chan *Environment) From 712e737913d8c03171c0d7d29e957545653e1b46 Mon Sep 17 00:00:00 2001 From: Michael Insel Date: Tue, 22 Sep 2020 18:46:51 +0200 Subject: [PATCH 4/5] Fix formatting using go fmt --- configobject/configsync/configsync_test.go | 2 +- connection/redis_test.go | 4 ++-- ha/ha_test.go | 4 ++-- ha/heartbeat_test.go | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/configobject/configsync/configsync_test.go b/configobject/configsync/configsync_test.go index ce05ff97..1276abaf 100644 --- a/configobject/configsync/configsync_test.go +++ b/configobject/configsync/configsync_test.go @@ -21,7 +21,7 @@ import ( var mysqlTestObserver = connection.DbIoSeconds.WithLabelValues("mysql", "test") func SetupConfigSync(t *testing.T, objectTypes []*configobject.ObjectInformation) (*supervisor.Supervisor, []chan int) { - rdbw := connection.NewRDBWrapper(testbackends.RedisTestAddr, "",64) + rdbw := connection.NewRDBWrapper(testbackends.RedisTestAddr, "", 64) dbw, err := connection.NewDBWrapper(testbackends.MysqlTestDsn, 50) require.NoError(t, err, "Is the MySQL server running?") diff --git a/connection/redis_test.go b/connection/redis_test.go index 94f6b49e..c88df610 100644 --- a/connection/redis_test.go +++ b/connection/redis_test.go @@ -20,10 +20,10 @@ func NewTestRDBW(rdb RedisClient) RDBWrapper { } func TestNewRDBWrapper(t *testing.T) { - rdbw := NewRDBWrapper(testbackends.RedisTestAddr, "",64) + rdbw := NewRDBWrapper(testbackends.RedisTestAddr, "", 64) assert.True(t, rdbw.CheckConnection(false), "Redis should be connected") - rdbw = NewRDBWrapper("asdasdasdasdasd:5123", "",64) + rdbw = NewRDBWrapper("asdasdasdasdasd:5123", "", 64) assert.False(t, rdbw.CheckConnection(false), "Redis should not be connected") //TODO: Add more tests here } diff --git a/ha/ha_test.go b/ha/ha_test.go index f4ed8463..bb139b2f 100644 --- a/ha/ha_test.go +++ b/ha/ha_test.go @@ -19,7 +19,7 @@ import ( ) func createTestingHA(t *testing.T, redisAddr string) *HA { - redisConn := connection.NewRDBWrapper(redisAddr, "",64) + redisConn := connection.NewRDBWrapper(redisAddr, "", 64) mysqlConn, err := connection.NewDBWrapper(testbackends.MysqlTestDsn, 50) if err != nil { @@ -149,7 +149,7 @@ func TestHA_setAndInsertEnvironment(t *testing.T) { ha := createTestingHA(t, testbackends.RedisTestAddr) env := Environment{ - ID: utils.EncodeChecksum(utils.Checksum("herp")), + ID: utils.EncodeChecksum(utils.Checksum("herp")), Name: "herp", } diff --git a/ha/heartbeat_test.go b/ha/heartbeat_test.go index 9eff7082..1f80fb66 100644 --- a/ha/heartbeat_test.go +++ b/ha/heartbeat_test.go @@ -23,7 +23,7 @@ const app = "{\"status\": " + const dump = "false" func TestIcingaHeartbeatListener(t *testing.T) { - rdb := connection.NewRDBWrapper(testbackends.RedisTestAddr, "",64) + rdb := connection.NewRDBWrapper(testbackends.RedisTestAddr, "", 64) assert.True(t, rdb.CheckConnection(false), "This test needs a working Redis connection") chEnv := make(chan *Environment) From bdca9747216084f5f023597333483a530b557865 Mon Sep 17 00:00:00 2001 From: Michael Insel Date: Wed, 23 Sep 2020 19:46:03 +0200 Subject: [PATCH 5/5] Adjust import sorting in main.go --- main.go | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/main.go b/main.go index 523dc879..354efa5a 100644 --- a/main.go +++ b/main.go @@ -5,12 +5,6 @@ package main import ( "flag" "fmt" - "os" - "os/signal" - "regexp" - "sync" - "syscall" - "github.com/Icinga/icingadb/config" "github.com/Icinga/icingadb/configobject" "github.com/Icinga/icingadb/configobject/configsync" @@ -70,6 +64,11 @@ import ( "github.com/Icinga/icingadb/prometheus" "github.com/Icinga/icingadb/supervisor" log "github.com/sirupsen/logrus" + "os" + "os/signal" + "regexp" + "sync" + "syscall" ) var gitVersion = regexp.MustCompile(`\A(.+)-\d+-g([A-Fa-f0-9]+)\z`)