-
Notifications
You must be signed in to change notification settings - Fork 146
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
K8SPSMDB-813: Fail TLS configuration if provided certificates do not exist #1254
Changes from 13 commits
38b94d0
24b77a9
0ec0f3f
bca1337
be3e0fa
791f8ef
2f868de
1abca95
44150f6
8881c07
49dbd51
06c966e
7d8974c
770935c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
package db | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
) | ||
|
||
const ( | ||
notExistingFilePath = "not-existing-file-path" | ||
) | ||
|
||
func TestSSLNotEnabled(t *testing.T) { | ||
cfg := &Config{ | ||
SSL: &SSLConfig{ | ||
Enabled: false, | ||
}, | ||
} | ||
|
||
if err := cfg.configureTLS(); err != nil { | ||
t.Fatalf("TLS configuration failed: %s", err) | ||
} | ||
|
||
if cfg.TLSConf != nil { | ||
t.Error("Expected TLSConf to be nil") | ||
} | ||
} | ||
|
||
func TestSSLEnabled(t *testing.T) { | ||
cfg := &Config{ | ||
SSL: &SSLConfig{ | ||
Enabled: true, | ||
}, | ||
} | ||
|
||
if err := cfg.configureTLS(); err != nil { | ||
t.Fatalf("TLS configuration failed: %s", err) | ||
} | ||
|
||
if cfg.TLSConf == nil { | ||
t.Error("Expected TLSConf to not be nil") | ||
} | ||
} | ||
|
||
func TestPEMKeyFileDoesNotExists(t *testing.T) { | ||
cfg := &Config{ | ||
SSL: &SSLConfig{ | ||
Enabled: true, | ||
PEMKeyFile: notExistingFilePath, | ||
}, | ||
} | ||
|
||
err := cfg.configureTLS() | ||
if err == nil { | ||
t.Fatal("Expected TLS config to fail, but it returned no error") | ||
} | ||
|
||
expectedErrorMessage := fmt.Sprintf( | ||
"check if file with name %s exists: stat %s: no such file or directory", | ||
notExistingFilePath, notExistingFilePath, | ||
) | ||
if err.Error() != expectedErrorMessage { | ||
t.Errorf("error message '%s' does not match expected '%s'", err.Error(), expectedErrorMessage) | ||
} | ||
} | ||
|
||
func TestCAFileDoesNotExists(t *testing.T) { | ||
cfg := &Config{ | ||
SSL: &SSLConfig{ | ||
Enabled: true, | ||
CAFile: notExistingFilePath, | ||
}, | ||
} | ||
|
||
err := cfg.configureTLS() | ||
if err == nil { | ||
t.Fatal("Expected TLS config to fail, but it returned no error") | ||
} | ||
|
||
expectedErrorMessage := fmt.Sprintf( | ||
"check if file with name %s exists: stat %s: no such file or directory", | ||
notExistingFilePath, notExistingFilePath, | ||
) | ||
if err.Error() != expectedErrorMessage { | ||
t.Errorf("error message '%s' does not match expected '%s'", err.Error(), expectedErrorMessage) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -191,7 +191,8 @@ func (cr *PerconaServerMongoDB) CheckNSetDefaults(platform version.Platform, log | |
}, | ||
} | ||
|
||
if cr.CompareVersion("1.7.0") >= 0 { | ||
if (cr.CompareVersion("1.7.0") >= 0 && cr.CompareVersion("1.15.0") < 0) || | ||
cr.CompareVersion("1.15.0") >= 0 && !cr.Spec.UnsafeConf { | ||
cr.Spec.Sharding.Mongos.LivenessProbe.Exec.Command = | ||
append(cr.Spec.Sharding.Mongos.LivenessProbe.Exec.Command, | ||
"--ssl", "--sslInsecure", | ||
|
@@ -236,7 +237,8 @@ func (cr *PerconaServerMongoDB) CheckNSetDefaults(platform version.Platform, log | |
}, | ||
} | ||
|
||
if cr.CompareVersion("1.7.0") >= 0 { | ||
if (cr.CompareVersion("1.7.0") >= 0 && cr.CompareVersion("1.15.0") < 0) || | ||
cr.CompareVersion("1.15.0") >= 0 && !cr.Spec.UnsafeConf { | ||
cr.Spec.Sharding.Mongos.ReadinessProbe.Exec.Command = | ||
append(cr.Spec.Sharding.Mongos.ReadinessProbe.Exec.Command, | ||
"--ssl", "--sslInsecure", | ||
|
@@ -362,7 +364,8 @@ func (cr *PerconaServerMongoDB) CheckNSetDefaults(platform version.Platform, log | |
|
||
if cr.CompareVersion("1.6.0") >= 0 { | ||
replset.LivenessProbe.Probe.Exec.Command[0] = "/data/db/mongodb-healthcheck" | ||
if cr.CompareVersion("1.7.0") >= 0 { | ||
if (cr.CompareVersion("1.7.0") >= 0 && cr.CompareVersion("1.15.0") < 0) || | ||
cr.CompareVersion("1.15.0") >= 0 && !cr.Spec.UnsafeConf { | ||
replset.LivenessProbe.Probe.Exec.Command = | ||
append(replset.LivenessProbe.Probe.Exec.Command, | ||
"--ssl", "--sslInsecure", | ||
|
@@ -643,14 +646,14 @@ func (nv *NonVotingSpec) SetDefaults(cr *PerconaServerMongoDB, rs *ReplsetSpec) | |
} | ||
if nv.LivenessProbe.ProbeHandler.Exec == nil { | ||
nv.LivenessProbe.Probe.ProbeHandler.Exec = &corev1.ExecAction{ | ||
Command: []string{ | ||
"/data/db/mongodb-healthcheck", | ||
"k8s", | ||
"liveness", | ||
"--ssl", "--sslInsecure", | ||
"--sslCAFile", "/etc/mongodb-ssl/ca.crt", | ||
"--sslPEMKeyFile", "/tmp/tls.pem", | ||
}, | ||
Command: []string{"/data/db/mongodb-healthcheck", "k8s", "liveness"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @egegunes, maybe we need to do it only for cr >= 1.15? |
||
} | ||
|
||
if !cr.Spec.UnsafeConf || cr.CompareVersion("1.15.0") < 0 { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is it correct? before we were adding ssl flags if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Before the PR, we had this code without any checks:
We should add these flags to crs with < 1.15.0 versions to maintain the old behavior |
||
nv.LivenessProbe.Probe.ProbeHandler.Exec.Command = append( | ||
nv.LivenessProbe.Probe.ProbeHandler.Exec.Command, | ||
"--ssl", "--sslInsecure", "--sslCAFile", "/etc/mongodb-ssl/ca.crt", "--sslPEMKeyFile", "/tmp/tls.pem", | ||
) | ||
} | ||
|
||
if cr.CompareVersion("1.14.0") >= 0 { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we seem to changed the behavior, with these we'll add these flags to probe command for all clusters <1.15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should check for unsafe option only for clusters with >=1.15.0 version to maintain the old behavior for older cluster versions.
It seems that you checked the diff of only my changes, and not those of the entire pull request.