Skip to content

Commit 4efcba1

Browse files
committed
Adding source code changes for workaround for IPv6 issue in pgBackRest (#1841).
1 parent 607c1b1 commit 4efcba1

File tree

4 files changed

+47
-0
lines changed

4 files changed

+47
-0
lines changed

internal/naming/annotations.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,12 @@ const (
5050
// timestamp), which will be stored in the PostgresCluster status to properly track completion
5151
// of the Job.
5252
PGBackRestRestore = annotationPrefix + "pgbackrest-restore"
53+
54+
// PGBackRestIPVersion is an annotation used to indicate whether an IPv6 wildcard address should be
55+
// used for the pgBackRest "tls-server-address" or not. If the user wants to use IPv6, the value
56+
// should be "IPv6". As of right now, if the annotation is not present or if the annotation's value
57+
// is anything other than "IPv6", the "tls-server-address" will default to IPv4 (0.0.0.0). The need
58+
// for this annotation is due to an issue in pgBackRest (#1841) where using a wildcard address to
59+
// bind all addresses does not work in certain IPv6 environments.
60+
PGBackRestIPVersion = annotationPrefix + "pgbackrest-ip-version"
5361
)

internal/naming/annotations_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,5 @@ func TestAnnotationsValid(t *testing.T) {
2929
assert.Assert(t, nil == validation.IsQualifiedName(PGBackRestConfigHash))
3030
assert.Assert(t, nil == validation.IsQualifiedName(PGBackRestCurrentConfig))
3131
assert.Assert(t, nil == validation.IsQualifiedName(PGBackRestRestore))
32+
assert.Assert(t, nil == validation.IsQualifiedName(PGBackRestIPVersion))
3233
}

internal/pgbackrest/config.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package pgbackrest
1818
import (
1919
"context"
2020
"fmt"
21+
"strings"
2122

2223
corev1 "k8s.io/api/core/v1"
2324
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
@@ -465,6 +466,20 @@ func serverConfig(cluster *v1beta1.PostgresCluster) iniSectionSet {
465466
// - https://releases.k8s.io/v1.23.0/pkg/kubelet/kubelet_pods.go#L345
466467
global.Set("tls-server-address", "0.0.0.0")
467468

469+
// NOTE (dsessler7): As pointed out by Chris above, there is an issue in
470+
// pgBackRest (#1841), where using a wildcard address to bind all addresses
471+
// does not work in certain IPv6 environments. Until this is fixed, we are
472+
// going to workaround the issue by allowing the user to add an annotation to
473+
// enable IPv6. We will check for that annotation here and override the
474+
// "tls-server-address" setting accordingly.
475+
annotations := cluster.GetAnnotations()
476+
if annotations != nil {
477+
if ipVersion, exists := annotations[naming.PGBackRestIPVersion]; exists &&
478+
strings.ToLower(ipVersion) == "ipv6" {
479+
global.Set("tls-server-address", "::")
480+
}
481+
}
482+
468483
// The client certificate for this cluster is allowed to connect for any stanza.
469484
// Without the wildcard "*", the "pgbackrest info" and "pgbackrest repo-ls"
470485
// commands fail with "access denied" when invoked without a "--stanza" flag.

internal/pgbackrest/config_test.go

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,26 @@ log-level-stderr = error
337337
log-timestamp = n
338338
`)
339339
}
340+
341+
func TestServerConfigIPv6(t *testing.T) {
342+
cluster := &v1beta1.PostgresCluster{}
343+
cluster.UID = "shoe"
344+
annotations := map[string]string{}
345+
annotations[naming.PGBackRestIPVersion] = "IPv6"
346+
cluster.ObjectMeta.Annotations = annotations
347+
348+
assert.Equal(t, serverConfig(cluster).String(), `
349+
[global]
350+
tls-server-address = ::
351+
tls-server-auth = pgbackrest@shoe=*
352+
tls-server-ca-file = /etc/pgbackrest/conf.d/~postgres-operator/tls-ca.crt
353+
tls-server-cert-file = /etc/pgbackrest/server/server-tls.crt
354+
tls-server-key-file = /etc/pgbackrest/server/server-tls.key
355+
356+
[global:server]
357+
log-level-console = detail
358+
log-level-file = off
359+
log-level-stderr = error
360+
log-timestamp = n
361+
`)
362+
}

0 commit comments

Comments
 (0)