-
Notifications
You must be signed in to change notification settings - Fork 149
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-780: Unsafe improvements #1504
Conversation
"$checkArg" | "$checkArg"=*) | ||
return 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.
[shfmt] reported by reviewdog 🐶
"$checkArg" | "$checkArg"=*) | |
return 0 | |
;; | |
"$checkArg" | "$checkArg"=*) | |
return 0 | |
;; |
"$checkArg") | ||
echo "$1" | ||
return 0 | ||
;; | ||
"$checkArg"=*) | ||
echo "${arg#"$checkArg"=}" | ||
return 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.
[shfmt] reported by reviewdog 🐶
"$checkArg") | |
echo "$1" | |
return 0 | |
;; | |
"$checkArg"=*) | |
echo "${arg#"$checkArg"=}" | |
return 0 | |
;; | |
"$checkArg") | |
echo "$1" | |
return 0 | |
;; | |
"$checkArg"=*) | |
echo "${arg#"$checkArg"=}" | |
return 0 | |
;; |
"$ensureNoArg") | ||
shift # also skip the value | ||
continue | ||
;; | ||
"$ensureNoArg"=*) | ||
# value is already included | ||
continue | ||
;; |
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.
[shfmt] reported by reviewdog 🐶
"$ensureNoArg") | |
shift # also skip the value | |
continue | |
;; | |
"$ensureNoArg"=*) | |
# value is already included | |
continue | |
;; | |
"$ensureNoArg") | |
shift # also skip the value | |
continue | |
;; | |
"$ensureNoArg"=*) | |
# value is already included | |
continue | |
;; |
*.sh | *.js) # this should match the set of files we check for below | ||
shouldPerformInitdb="$f" | ||
break | ||
;; |
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.
[shfmt] reported by reviewdog 🐶
*.sh | *.js) # this should match the set of files we check for below | |
shouldPerformInitdb="$f" | |
break | |
;; | |
*.sh | *.js) # this should match the set of files we check for below | |
shouldPerformInitdb="$f" | |
break | |
;; |
*.sh) | ||
echo "$0: running $f" | ||
# shellcheck source=/dev/null | ||
. "$f" | ||
;; | ||
*.js) | ||
echo "$0: running $f" | ||
"${mongo[@]}" "$MONGO_INITDB_DATABASE" "$f" | ||
echo | ||
;; | ||
*) echo "$0: ignoring $f" ;; |
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.
[shfmt] reported by reviewdog 🐶
*.sh) | |
echo "$0: running $f" | |
# shellcheck source=/dev/null | |
. "$f" | |
;; | |
*.js) | |
echo "$0: running $f" | |
"${mongo[@]}" "$MONGO_INITDB_DATABASE" "$f" | |
echo | |
;; | |
*) echo "$0: ignoring $f" ;; | |
*.sh) | |
echo "$0: running $f" | |
# shellcheck source=/dev/null | |
. "$f" | |
;; | |
*.js) | |
echo "$0: running $f" | |
"${mongo[@]}" "$MONGO_INITDB_DATABASE" "$f" | |
echo | |
;; | |
*) echo "$0: ignoring $f" ;; |
10ecc42
to
52ddcce
Compare
These changes attempt to fix the overloaded `allowUnsafeConfigurations` flag. In previous implementation, `allowUnsafeConfigurations` wasn't just allow unsafe configuration but make everything unsafe by disabling TLS, allowing backups in unhealthy clusters, etc... without user's explicit intent. With these changes, we decouple those things from the unsafe flag and remove all implicit behaviors. We introduce a new section called `unsafeFlags`: ``` unsafeFlags: tls: false replsetSize: false mongosSize: false terminationGracePeriod: false backupIfUnhealthy: false ``` Starting from `v1.16.0`, `allowUnsafeConfigurations` is deprecated and won't have any affect. **TLS Mode** This decoupling required a special attention to the TLS configuration. Before these changes only way to disable TLS is setting `allowUnsafeConfigurations` to true. Now, we introduce a new field: ``` spec: tls: mode: disabled ``` This field accepts the following values: `disabled`, `allowTLS`, `preferTLS` and `requireTLS`. If user sets mode to `disabled`, the operator will throw an error: `TLS must be enabled. Set spec.unsafeFlags.tls to true to disable this check.` Since the use of TLS flags and reconciling TLS secrets depends on `tls.mode` field, we need to block users to set `net.tls.mode` in custom MongoDB configuration. If user sets a custom configuration like: ``` spec: replsets: - name: rs0 size: 3 configuration: | net: tls: mode: allowTLS ``` the operator will throw an error: `tlsMode must be set using spec.tls.mode`.
e2e-tests/scaling/run
Outdated
cat_config "$conf_dir/$cluster.yml" | | ||
yq eval '.spec.replsets[0].expose.enabled=true' | | ||
yq eval '.spec.replsets[0].expose.exposeType="ClusterIP"' | | ||
kubectl_bin apply -f - |
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.
[shfmt] reported by reviewdog 🐶
cat_config "$conf_dir/$cluster.yml" | | |
yq eval '.spec.replsets[0].expose.enabled=true' | | |
yq eval '.spec.replsets[0].expose.exposeType="ClusterIP"' | | |
kubectl_bin apply -f - | |
cat_config "$conf_dir/$cluster.yml" \ | |
| yq eval '.spec.replsets[0].expose.enabled=true' \ | |
| yq eval '.spec.replsets[0].expose.exposeType="ClusterIP"' \ | |
| kubectl_bin apply -f - |
cat_config "$conf_dir/$cluster.yml" | | ||
yq eval '.spec.unsafeFlags.replsetSize=true' | | ||
yq eval '.spec.replsets[0].expose.enabled=true' | | ||
yq eval '.spec.replsets[0].expose.exposeType="ClusterIP"' | | ||
kubectl_bin apply -f - |
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.
[shfmt] reported by reviewdog 🐶
cat_config "$conf_dir/$cluster.yml" | | |
yq eval '.spec.unsafeFlags.replsetSize=true' | | |
yq eval '.spec.replsets[0].expose.enabled=true' | | |
yq eval '.spec.replsets[0].expose.exposeType="ClusterIP"' | | |
kubectl_bin apply -f - | |
cat_config "$conf_dir/$cluster.yml" \ | |
| yq eval '.spec.unsafeFlags.replsetSize=true' \ | |
| yq eval '.spec.replsets[0].expose.enabled=true' \ | |
| yq eval '.spec.replsets[0].expose.exposeType="ClusterIP"' \ | |
| kubectl_bin apply -f - |
pkg/psmdb/container.go
Outdated
} else { | ||
args = append(args, "--clusterAuthMode=x509") | ||
} | ||
} else if (cr.CompareVersion("1.16.0") >= 0 && cr.Spec.Unsafe.TLS) || (cr.CompareVersion("1.16.0") < 0 && cr.Spec.UnsafeConf) { |
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.
What do you think about creating a cr.UnsafeTLSDisabled()
method to replace this long condition check?
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.
pkg/psmdb/pmm.go
Outdated
if cr.CompareVersion("1.13.0") >= 0 && !cr.Spec.UnsafeConf { | ||
if cr.CompareVersion("1.13.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.
Why it was removed?
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.
good catch, we need to check if tls enabled there: 6badccf
@@ -226,7 +226,7 @@ func TestSetSafeDefault(t *testing.T) { | |||
cr := &api.PerconaServerMongoDB{ | |||
ObjectMeta: metav1.ObjectMeta{Name: "psmdb-mock", Namespace: "psmdb"}, | |||
Spec: api.PerconaServerMongoDBSpec{ | |||
CRVersion: version.Version, | |||
CRVersion: "1.15.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.
I think we should add or update this unit tests to cover these new unsafe flags for 1.16.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.
@egegunes I think we need to comment it by default https://github.com/percona/percona-server-mongodb-operator/pull/1504/files#diff-66e2e64739b6c9fbb1f1f10431f083ab8ab642cf5049f8033e0bcae5afd1ea1aR29-R34
commit: 660460a |
CHANGE DESCRIPTION
These changes attempt to fix the overloaded
allowUnsafeConfigurations
flag.
In previous implementation,
allowUnsafeConfigurations
wasn't justallow unsafe configuration but make everything unsafe by disabling TLS,
allowing backups in unhealthy clusters, etc... without user's explicit
intent.
With these changes, we decouple those things from the unsafe flag and
remove all implicit behaviors. We introduce a new section called
unsafeFlags
:Starting from
v1.16.0
,allowUnsafeConfigurations
is deprecated andwon't have any affect.
TLS Mode
This decoupling required a special attention to the TLS configuration.
Before these changes only way to disable TLS is setting
allowUnsafeConfigurations
to true. Now, we introduce a new field:This field accepts the following values:
disabled
,allowTLS
,preferTLS
andrequireTLS
.If user sets mode to
disabled
, the operator will throw an error:TLS must be enabled. Set spec.unsafeFlags.tls to true to disable this check.
Since the use of TLS flags and reconciling TLS secrets depends on
tls.mode
field, we need to block users to setnet.tls.mode
in customMongoDB configuration. If user sets a custom configuration like:
the operator will throw an error:
tlsMode must be set using spec.tls.mode
.CHECKLIST
Jira
Needs Doc
) and QA (Needs QA
)?Tests
compare/*-oc.yml
)?Config/Logging/Testability