Skip to content

Commit 66649c6

Browse files
Jonathan S. Katzjkatz
authored andcommitted
Allow for seamless upgrade to new AWS S3 CA bundle
This updates the autodetection logic to add the new AWS S3 CA bundle to the general PGO Secret, which is then applied to clusters on upgrade. The logic is such that it will only overwrite the default template if it is unmodified, i.e. it is using the CA bundle that is provided.
1 parent 9d886d4 commit 66649c6

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

internal/operator/cluster/upgrade.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,11 @@ package cluster
1717

1818
import (
1919
"context"
20+
"crypto/sha256"
2021
"errors"
2122
"fmt"
2223
"io/ioutil"
24+
"path"
2325
"regexp"
2426
"strconv"
2527
"strings"
@@ -57,6 +59,10 @@ const (
5759
const nssWrapperForceCommand = `# ensure nss_wrapper env vars are set when executing commands as needed for OpenShift compatibility
5860
ForceCommand NSS_WRAPPER_SUBDIR=ssh . /opt/crunchy/bin/nss_wrapper_env.sh && $SSH_ORIGINAL_COMMAND`
5961

62+
// legacyS3CASHA256Digest informs us if we should override the S3 CA with the
63+
// new bundle
64+
const legacyS3CASHA256Digest = "d1c290ea1e4544dec1934931fbfa1fb2060eb3a0f2239ba191f444ecbce35cbb"
65+
6066
// the following regex expressions are used when upgrading the sshd_config file for a PG cluster
6167
var (
6268
// nssWrapperRegex is the regular expression that is utilized to determine if the nss_wrapper
@@ -485,6 +491,19 @@ func recreateBackrestRepoSecret(clientset kubernetes.Interface, clustername, nam
485491
if err == nil {
486492
if b, ok := secret.Data["aws-s3-ca.crt"]; ok {
487493
config.BackrestS3CA = b
494+
495+
// if this matches the old AWS S3 CA bundle, update to the new one.
496+
if fmt.Sprintf("%x", sha256.Sum256(config.BackrestS3CA)) == legacyS3CASHA256Digest {
497+
file := path.Join("/default-pgo-backrest-repo/aws-s3-ca.crt")
498+
499+
// if we can't read the contents of the file for whatever reason, warn,
500+
// otherwise, update the entry in the Secret
501+
if contents, err := ioutil.ReadFile(file); err != nil {
502+
log.Warn(err)
503+
} else {
504+
config.BackrestS3CA = contents
505+
}
506+
}
488507
}
489508
if b, ok := secret.Data["aws-s3-key"]; ok {
490509
config.BackrestS3Key = string(b)

internal/operator/common.go

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package operator
1818
import (
1919
"bytes"
2020
"context"
21+
"crypto/sha256"
2122
"encoding/json"
2223
"fmt"
2324
"io/ioutil"
@@ -50,6 +51,9 @@ const (
5051
defaultBackrestRepoConfigPath = "/default-pgo-backrest-repo/"
5152
// defaultRegistry is the default registry to pull the container images from
5253
defaultRegistry = "registry.developers.crunchydata.com/crunchydata"
54+
// legacyS3CASHA256Digest informs us if we should override the S3 CA with the
55+
// new bundle
56+
legacyS3CASHA256Digest = "d1c290ea1e4544dec1934931fbfa1fb2060eb3a0f2239ba191f444ecbce35cbb"
5357
)
5458

5559
var (
@@ -525,9 +529,18 @@ func initializeOperatorBackrestSecret(clientset kubernetes.Interface, namespace
525529

526530
// set any missing defaults
527531
for _, filename := range defaultBackrestRepoConfigKeys {
528-
// skip if there is already content
532+
// skip if there is already content, unless this is aws-s3-ca.crt due to
533+
// the change in the CA bundle
529534
if len(secret.Data[filename]) != 0 {
530-
continue
535+
if filename != "aws-s3-ca.crt" {
536+
continue
537+
}
538+
539+
// in the case of aws-s3-ca.crt, check that this is the default
540+
// certificate. if it is, override it
541+
if fmt.Sprintf("%x", sha256.Sum256(secret.Data[filename])) != legacyS3CASHA256Digest {
542+
continue
543+
}
531544
}
532545

533546
file := path.Join(defaultBackrestRepoConfigPath, filename)

0 commit comments

Comments
 (0)