Skip to content

Commit 2b70859

Browse files
author
Jonathan S. Katz
committed
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 8e374b7 commit 2b70859

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
// v4.5.2 and v4.4.3)
5860
var usePAMRegex = regexp.MustCompile(`(?im)^UsePAM\s*yes`)
5961

62+
// legacyS3CASHA256Digest informs us if we should override the S3 CA with the
63+
// new bundle
64+
const legacyS3CASHA256Digest = "d1c290ea1e4544dec1934931fbfa1fb2060eb3a0f2239ba191f444ecbce35cbb"
65+
6066
// AddUpgrade implements the upgrade workflow in accordance with the received pgtask
6167
// the general process is outlined below:
6268
// 1) get the existing pgcluster CRD instance that matches the name provided in the pgtask
@@ -465,6 +471,19 @@ func recreateBackrestRepoSecret(clientset kubernetes.Interface, clustername, nam
465471
if err == nil {
466472
if b, ok := secret.Data["aws-s3-ca.crt"]; ok {
467473
config.BackrestS3CA = b
474+
475+
// if this matches the old AWS S3 CA bundle, update to the new one.
476+
if fmt.Sprintf("%x", sha256.Sum256(config.BackrestS3CA)) == legacyS3CASHA256Digest {
477+
file := path.Join("/default-pgo-backrest-repo/aws-s3-ca.crt")
478+
479+
// if we can't read the contents of the file for whatever reason, warn,
480+
// otherwise, update the entry in the Secret
481+
if contents, err := ioutil.ReadFile(file); err != nil {
482+
log.Warn(err)
483+
} else {
484+
config.BackrestS3CA = contents
485+
}
486+
}
468487
}
469488
if b, ok := secret.Data["aws-s3-key"]; ok {
470489
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"
@@ -47,6 +48,9 @@ const (
4748
defaultBackrestRepoConfigPath = "/default-pgo-backrest-repo/"
4849
// defaultRegistry is the default registry to pull the container images from
4950
defaultRegistry = "registry.developers.crunchydata.com/crunchydata"
51+
// legacyS3CASHA256Digest informs us if we should override the S3 CA with the
52+
// new bundle
53+
legacyS3CASHA256Digest = "d1c290ea1e4544dec1934931fbfa1fb2060eb3a0f2239ba191f444ecbce35cbb"
5054
)
5155

5256
var (
@@ -484,9 +488,18 @@ func initializeOperatorBackrestSecret(clientset kubernetes.Interface, namespace
484488

485489
// set any missing defaults
486490
for _, filename := range defaultBackrestRepoConfigKeys {
487-
// skip if there is already content
491+
// skip if there is already content, unless this is aws-s3-ca.crt due to
492+
// the change in the CA bundle
488493
if len(secret.Data[filename]) != 0 {
489-
continue
494+
if filename != "aws-s3-ca.crt" {
495+
continue
496+
}
497+
498+
// in the case of aws-s3-ca.crt, check that this is the default
499+
// certificate. if it is, override it
500+
if fmt.Sprintf("%x", sha256.Sum256(secret.Data[filename])) != legacyS3CASHA256Digest {
501+
continue
502+
}
490503
}
491504

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

0 commit comments

Comments
 (0)