Repository navigation
Expose the N2N TLS setting in the NooBaa ConfigMap #2220
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
base: master
Are you sure you want to change the base?
Changes from all commits
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,80 @@ | ||
| # N2N TLS Configuration | ||
|
|
||
| NooBaa uses N2N for block traffic between endpoints, core, and storage agents. | ||
| Storage agents run in pv-pool pods or inside core. N2N uses `wss://` by default. | ||
|
|
||
| Set `N2N_TLS_DISABLED` to `"true"` to use `ws://` and avoid the CPU cost of N2N TLS. | ||
| Review the [security considerations](#security-considerations) before enabling it. | ||
| S3, IAM, STS, core RPC on port 5443, and database connections use their own TLS settings. | ||
|
|
||
| ## Configuration | ||
|
|
||
| Set the `N2N_TLS_DISABLED` key in the `noobaa-config` ConfigMap. The operator | ||
| defaults missing values to `"false"` and preserves an existing value across | ||
| operator restarts and upgrades. | ||
|
|
||
| ```bash | ||
| # disable TLS on N2N | ||
| oc patch configmap noobaa-config -n openshift-storage --type merge \ | ||
| -p '{"data":{"N2N_TLS_DISABLED":"true"}}' | ||
|
|
||
| # back to the default | ||
| oc patch configmap noobaa-config -n openshift-storage --type merge \ | ||
| -p '{"data":{"N2N_TLS_DISABLED":"false"}}' | ||
| ``` | ||
|
|
||
| | Pod | Delivery | | ||
| |---|---| | ||
| | `noobaa-core` | `configMapKeyRef` in `statefulset-core.yaml` | | ||
| | `noobaa-endpoint` | `configMapKeyRef` in `deployment-endpoint.yaml` | | ||
| | `noobaa-bg-workers` | `envFrom` imports the ConfigMap | | ||
| | pv-pool agents | The BackingStore reconciler copies the ConfigMap value into the environment | | ||
|
|
||
| The `noobaa.io/configmap-hash` annotation triggers a rollout for core, endpoints, | ||
| and background workers when the value changes. The BackingStore reconciler | ||
| recreates pv-pool agent pods whose environment differs from the ConfigMap. The | ||
| first reconcile after upgrading can also recreate pods that lack the new variable. | ||
|
|
||
| ### Verifying | ||
|
|
||
| ```bash | ||
| oc get configmap noobaa-config -n openshift-storage -o jsonpath='{.data.N2N_TLS_DISABLED}{"\n"}' | ||
| oc exec noobaa-core-0 -n openshift-storage -- printenv N2N_TLS_DISABLED | ||
| oc exec deployment/noobaa-endpoint -n openshift-storage -- printenv N2N_TLS_DISABLED | ||
| oc get pods -n openshift-storage -l pool | ||
| # Replace agent-pod with the name of a pv-pool agent pod. | ||
| oc exec agent-pod -n openshift-storage -- printenv N2N_TLS_DISABLED | ||
| ``` | ||
|
|
||
| Expect the agent logs to report the listen scheme (`ws` instead of `wss`) after the | ||
| agent pods are recreated. | ||
|
|
||
| ### ODF | ||
|
|
||
| Use the same ConfigMap patch on ODF. The NooBaa operator owns these keys, so | ||
| the patch persists when `ocs-operator` reconciles the `StorageCluster`. | ||
|
|
||
| ## Rollout and mixed versions | ||
|
|
||
| **Enable the flag after all core, background worker, endpoint, and pv-pool agent | ||
| pods have upgraded.** Older dialers reject `ws://` N2N endpoints, which can cause | ||
| reads and writes against pv-pool BackingStores to fail. | ||
|
|
||
| Each agent advertises the scheme it serves. Updated WebSocket dialers accept both | ||
| schemes, so peers can connect while agents start with the new setting in either | ||
| direction. Pod replacement can still interrupt existing connections. | ||
|
|
||
| With `ROLLBACK_N2N_TO_ICE=true`, both peers must agree on TCP TLS. Toggle | ||
| `N2N_TLS_DISABLED` during a period without N2N traffic and wait for the affected | ||
| pods to restart before resuming traffic. | ||
|
|
||
| ## Security considerations | ||
|
|
||
| With `N2N_TLS_DISABLED=true`, **observers on the pod network can read N2N RPC | ||
| metadata and any auth tokens carried in requests.** Chunk payloads retain their | ||
| own encryption and digest checks. The default chunk cipher is AES-256-GCM. | ||
| With transport TLS enabled, N2N uses self-signed certificates and skips peer | ||
| certificate verification. | ||
|
|
||
| The `noobaa-pvpool` NetworkPolicy permits ingress to ports 60101–60600 from pods | ||
| in the NooBaa namespace. Restrict plaintext N2N to a trusted pod network. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| package backingstore | ||
|
|
||
| import ( | ||
| "context" | ||
| "os" | ||
| "testing" | ||
|
|
||
| nbv1 "github.com/noobaa/noobaa-operator/v5/pkg/apis/noobaa/v1alpha1" | ||
| "github.com/noobaa/noobaa-operator/v5/pkg/bundle" | ||
| "github.com/noobaa/noobaa-operator/v5/pkg/util" | ||
| "github.com/sirupsen/logrus" | ||
| corev1 "k8s.io/api/core/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/apimachinery/pkg/types" | ||
| "k8s.io/client-go/kubernetes/scheme" | ||
| "sigs.k8s.io/controller-runtime/pkg/client/fake" | ||
| ) | ||
|
|
||
| const n2nTestNamespace = "test-ns" | ||
|
|
||
| // clearProxyEnv makes needUpdate() independent of the proxy variables of the machine | ||
| // running the test. | ||
| func clearProxyEnv(t *testing.T) { | ||
| t.Helper() | ||
| for _, name := range []string{"HTTP_PROXY", "HTTPS_PROXY", "NO_PROXY"} { | ||
| if val, ok := os.LookupEnv(name); ok { | ||
| if err := os.Unsetenv(name); err != nil { | ||
| t.Fatalf("unset %s: %v", name, err) | ||
| } | ||
| t.Cleanup(func() { _ = os.Setenv(name, val) }) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func newN2NTestReconciler(t *testing.T, configMapData map[string]string) *Reconciler { | ||
| t.Helper() | ||
| cm := util.KubeObject(bundle.File_deploy_internal_configmap_empty_yaml).(*corev1.ConfigMap) | ||
| cm.Name = util.CoreAppConfigMapName | ||
| cm.Namespace = n2nTestNamespace | ||
| if cm.Data == nil { | ||
| cm.Data = map[string]string{} | ||
| } | ||
| for k, v := range configMapData { | ||
| cm.Data[k] = v | ||
| } | ||
|
|
||
| nb := util.KubeObject(bundle.File_deploy_crds_noobaa_io_v1alpha1_noobaa_cr_yaml).(*nbv1.NooBaa) | ||
| nb.Namespace = n2nTestNamespace | ||
| nb.Status.ActualImage = "noobaa-core:test" | ||
| nb.Spec.Tolerations = nil | ||
| nb.Spec.Affinity = nil | ||
|
|
||
| bs := util.KubeObject(bundle.File_deploy_crds_noobaa_io_v1alpha1_backingstore_cr_yaml).(*nbv1.BackingStore) | ||
| bs.Namespace = n2nTestNamespace | ||
| bs.Labels = nil | ||
| bs.Spec.PVPool = nil | ||
|
|
||
| return &Reconciler{ | ||
| Request: types.NamespacedName{Name: bs.Name, Namespace: n2nTestNamespace}, | ||
| Ctx: context.TODO(), | ||
| Scheme: scheme.Scheme, | ||
| Logger: logrus.WithField("test", t.Name()), | ||
| NooBaa: nb, | ||
| BackingStore: bs, | ||
| CoreAppConfig: cm, | ||
| PodAgentTemplate: util.KubeObject(bundle.File_deploy_internal_pod_agent_yaml).(*corev1.Pod), | ||
| } | ||
| } | ||
|
|
||
| // agentPod builds the pod that the reconciler would create from the template, | ||
| // without the parts of updatePodTemplate that need a live cluster. | ||
| func (r *Reconciler) agentPodForTest() *corev1.Pod { | ||
| pod := r.PodAgentTemplate.DeepCopy() | ||
| r.setCoreConfigEnv(&pod.Spec.Containers[0]) | ||
| pod.Spec.Containers[0].Image = r.NooBaa.Status.ActualImage | ||
| return pod | ||
| } | ||
|
|
||
| // The pod-agent template must declare every key the reconciler reflects, otherwise | ||
| // setCoreConfigEnv has nothing to fill and the agents silently keep the core default. | ||
| func TestPodAgentTemplateDeclaresCoreConfigEnvKeys(t *testing.T) { | ||
| pod := util.KubeObject(bundle.File_deploy_internal_pod_agent_yaml).(*corev1.Pod) | ||
| env := pod.Spec.Containers[0].Env | ||
| for _, name := range coreConfigPodAgentEnvKeys { | ||
| if util.GetEnvVariable(&env, name) == nil { | ||
| t.Fatalf("pod-agent.yaml does not declare the %s env variable", name) | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func TestSetCoreConfigEnvAppliesN2NTLSDisabled(t *testing.T) { | ||
| for _, want := range []string{"true", "false"} { | ||
| t.Run(want, func(t *testing.T) { | ||
| r := newN2NTestReconciler(t, map[string]string{"N2N_TLS_DISABLED": want}) | ||
| c := &r.PodAgentTemplate.Spec.Containers[0] | ||
| r.setCoreConfigEnv(c) | ||
| env := util.GetEnvVariable(&c.Env, "N2N_TLS_DISABLED") | ||
| if env == nil { | ||
| t.Fatal("N2N_TLS_DISABLED env is missing from the agent container") | ||
| } | ||
| if env.Value != want { | ||
| t.Fatalf("N2N_TLS_DISABLED = %q, want %q", env.Value, want) | ||
| } | ||
| }) | ||
| } | ||
| } | ||
|
|
||
| // A change of N2N_TLS_DISABLED in noobaa-config must recreate the pv-pool agent pods, | ||
| // since the agent decides the N2N scheme it advertises at listen time. | ||
| func TestNeedUpdateOnN2NTLSDisabledChange(t *testing.T) { | ||
| clearProxyEnv(t) | ||
| // no service account object -> the image pull secret check is skipped without a cluster | ||
| prev := util.SetKubeClientForTest(fake.NewClientBuilder().WithScheme(scheme.Scheme).Build()) | ||
| t.Cleanup(func() { util.SetKubeClientForTest(prev) }) | ||
|
|
||
| r := newN2NTestReconciler(t, map[string]string{"N2N_TLS_DISABLED": "false"}) | ||
| pod := r.agentPodForTest() | ||
|
|
||
| if r.needUpdate(pod) { | ||
| t.Fatal("needUpdate() = true for an up to date pod, want false") | ||
| } | ||
|
|
||
| r.CoreAppConfig.Data["N2N_TLS_DISABLED"] = "true" | ||
| if !r.needUpdate(pod) { | ||
| t.Fatal("needUpdate() = false after N2N_TLS_DISABLED changed to true, want true") | ||
| } | ||
| } | ||
|
|
||
| // MapConfigMapToBackingStores is what actually enqueues the reconciles above: | ||
| // noobaa-config is controller-owned by the NooBaa CR, so an owner handler on | ||
| // BackingStore produces nothing for it. | ||
| func TestMapConfigMapToBackingStores(t *testing.T) { | ||
| pvPool := &nbv1.BackingStore{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: "local-pool", Namespace: n2nTestNamespace}, | ||
| Spec: nbv1.BackingStoreSpec{Type: nbv1.StoreTypePVPool}, | ||
| } | ||
| otherNamespace := pvPool.DeepCopy() | ||
| otherNamespace.Namespace = "another-namespace" | ||
| cloudStore := &nbv1.BackingStore{ | ||
| ObjectMeta: metav1.ObjectMeta{Name: "cloud-store", Namespace: n2nTestNamespace}, | ||
| Spec: nbv1.BackingStoreSpec{Type: nbv1.StoreTypeS3Compatible}, | ||
| } | ||
| cl := fake.NewClientBuilder().WithScheme(scheme.Scheme).WithObjects(pvPool, otherNamespace, cloudStore).Build() | ||
| prev := util.SetKubeClientForTest(cl) | ||
| t.Cleanup(func() { util.SetKubeClientForTest(prev) }) | ||
|
|
||
| reqs := MapConfigMapToBackingStores(types.NamespacedName{ | ||
| Name: util.CoreAppConfigMapName, Namespace: n2nTestNamespace, | ||
| }) | ||
| want := types.NamespacedName{Name: pvPool.Name, Namespace: pvPool.Namespace} | ||
| if len(reqs) != 1 || reqs[0].NamespacedName != want { | ||
| t.Fatalf("noobaa-config mapped to %v, want one request for %s", reqs, want) | ||
| } | ||
|
|
||
| // any other noobaa owned config map must not fan out to all the backingstores | ||
| if reqs := MapConfigMapToBackingStores(types.NamespacedName{ | ||
| Name: "noobaa-ca-inject", Namespace: n2nTestNamespace, | ||
| }); len(reqs) != 0 { | ||
| t.Fatalf("unrelated config map mapped to %d requests, want 0: %v", len(reqs), reqs) | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import ( | |
| "os" | ||
| "reflect" | ||
| "regexp" | ||
| "slices" | ||
| "strings" | ||
| "time" | ||
|
|
||
|
|
@@ -32,6 +33,17 @@ import ( | |
| "sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
| ) | ||
|
|
||
| // coreConfigPodAgentEnvKeys are the noobaa-config keys that are reflected as env variables | ||
| // into the pv-pool agent pods. Keep in sync with deploy/internal/pod-agent.yaml, which must | ||
| // declare each of these names with an empty value: setCoreConfigEnv fills the value from the | ||
| // config map, and needUpdate compares it so that changing the key recreates the agent pods. | ||
| var coreConfigPodAgentEnvKeys = []string{ | ||
| "NOOBAA_LOG_LEVEL", | ||
| "NOOBAA_LOG_COLOR", | ||
| "ROLLBACK_N2N_TO_ICE", | ||
| "N2N_TLS_DISABLED", | ||
| } | ||
|
|
||
| // ModeInfo holds local information for a backing store mode. | ||
| type ModeInfo struct { | ||
| Phase nbv1.BackingStorePhase | ||
|
|
@@ -134,7 +146,7 @@ func NewReconciler( | |
| r.BackingStore.Name = r.Request.Name | ||
| r.NooBaa.Name = options.SystemName | ||
| r.ServiceAccount.Name = options.SystemName | ||
| r.CoreAppConfig.Name = "noobaa-config" | ||
| r.CoreAppConfig.Name = util.CoreAppConfigMapName | ||
|
|
||
| // Set secret names to empty | ||
| r.Secret.Namespace = "" | ||
|
|
@@ -1226,12 +1238,12 @@ func (r *Reconciler) needUpdate(pod *corev1.Pod) bool { | |
| return true | ||
| } | ||
|
|
||
| for _, name := range []string{"NOOBAA_LOG_LEVEL", "NOOBAA_LOG_COLOR", "ROLLBACK_N2N_TO_ICE"} { | ||
| for _, name := range coreConfigPodAgentEnvKeys { | ||
|
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. Keep serving agents available during configuration replacement. If an administrator changes The new Limit replacement to a bounded number of agents. Wait for each replacement to attach before deleting another agent. Returning after one deletion without checking replacement attachment does not prevent the same outage across successive reconciles.
|
||
| configMapValue := r.CoreAppConfig.Data[name] | ||
| noobaaLogEnvVar := util.GetEnvVariable(&c.Env, name) | ||
| envVar := util.GetEnvVariable(&c.Env, name) | ||
|
|
||
| if (noobaaLogEnvVar == nil && configMapValue != "") || (noobaaLogEnvVar != nil && configMapValue != noobaaLogEnvVar.Value) { | ||
| r.Logger.Warnf("%s Env variable change detected: (%v) on the config map (%v)", name, noobaaLogEnvVar, configMapValue) | ||
| if (envVar == nil && configMapValue != "") || (envVar != nil && configMapValue != envVar.Value) { | ||
| r.Logger.Warnf("%s Env variable change detected: (%v) on the config map (%v)", name, envVar, configMapValue) | ||
| return true | ||
| } | ||
| } | ||
|
|
@@ -1340,19 +1352,20 @@ func (r *Reconciler) isPodinNoobaa(pod *corev1.Pod) bool { | |
| return false | ||
| } | ||
|
|
||
| func (r *Reconciler) updatePodTemplate() error { | ||
| log := r.Logger.WithField("func", "updatePodTemplate") | ||
| c := &r.PodAgentTemplate.Spec.Containers[0] | ||
| // setCoreConfigEnv copies the noobaa-config values of coreConfigPodAgentEnvKeys | ||
| // into the matching env variables of the agent container. | ||
| func (r *Reconciler) setCoreConfigEnv(c *corev1.Container) { | ||
| for j := range c.Env { | ||
| switch c.Env[j].Name { | ||
| case "NOOBAA_LOG_LEVEL": | ||
| c.Env[j].Value = r.CoreAppConfig.Data["NOOBAA_LOG_LEVEL"] | ||
| case "NOOBAA_LOG_COLOR": | ||
| c.Env[j].Value = r.CoreAppConfig.Data["NOOBAA_LOG_COLOR"] | ||
| case "ROLLBACK_N2N_TO_ICE": | ||
| c.Env[j].Value = r.CoreAppConfig.Data["ROLLBACK_N2N_TO_ICE"] | ||
| if slices.Contains(coreConfigPodAgentEnvKeys, c.Env[j].Name) { | ||
| c.Env[j].Value = r.CoreAppConfig.Data[c.Env[j].Name] | ||
| } | ||
| } | ||
| } | ||
|
|
||
| func (r *Reconciler) updatePodTemplate() error { | ||
| log := r.Logger.WithField("func", "updatePodTemplate") | ||
| c := &r.PodAgentTemplate.Spec.Containers[0] | ||
| r.setCoreConfigEnv(c) | ||
| util.ReflectEnvVariable(&c.Env, "HTTP_PROXY") | ||
| util.ReflectEnvVariable(&c.Env, "HTTPS_PROXY") | ||
| util.ReflectEnvVariable(&c.Env, "NO_PROXY") | ||
|
|
||
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.
The endpoint env reference can fail for joined systems that lack the new key.
The endpoint Deployment reads
N2N_TLS_DISABLEDfromnoobaa-configwithoutoptional: true. The operator adds the key only on the main-cluster path, inReconcilePhaseCreatingForMainClustersandSetDesiredCoreAppConfig. The joined-system path returns before that code runs. Anoobaa-configthat predates this PR and belongs to a joined system therefore may not contain the key. The endpoint pod can then fail to start with a missing-key error.Confirm whether any joined-system path creates or updates
noobaa-configwithN2N_TLS_DISABLED. If none does, either add the default on that path or mark the referenceoptional: truewith thefalsebehavior as the fallback.