Skip to content

Commit 6f0732f

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 8b68b8b commit 6f0732f

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

internal/operator/cluster/upgrade.go

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

1818
import (
19+
"crypto/sha256"
1920
"errors"
2021
"fmt"
2122
"io/ioutil"
23+
"path"
2224
"strconv"
2325
"time"
2426

@@ -50,6 +52,10 @@ const (
5052
// store the replica postfix string
5153
const replicaServicePostfix = "-replica"
5254

55+
// legacyS3CASHA256Digest informs us if we should override the S3 CA with the
56+
// new bundle
57+
const legacyS3CASHA256Digest = "d1c290ea1e4544dec1934931fbfa1fb2060eb3a0f2239ba191f444ecbce35cbb"
58+
5359
// AddUpgrade implements the upgrade workflow in accordance with the received pgtask
5460
// the general process is outlined below:
5561
// 1) get the existing pgcluster CRD instance that matches the name provided in the pgtask
@@ -433,6 +439,19 @@ func recreateBackrestRepoSecret(clientset kubernetes.Interface, clustername, nam
433439
if err == nil {
434440
if b, ok := secret.Data["aws-s3-ca.crt"]; ok {
435441
config.BackrestS3CA = b
442+
443+
// if this matches the old AWS S3 CA bundle, update to the new one.
444+
if fmt.Sprintf("%x", sha256.Sum256(config.BackrestS3CA)) == legacyS3CASHA256Digest {
445+
file := path.Join("/default-pgo-backrest-repo/aws-s3-ca.crt")
446+
447+
// if we can't read the contents of the file for whatever reason, warn,
448+
// otherwise, update the entry in the Secret
449+
if contents, err := ioutil.ReadFile(file); err != nil {
450+
log.Warn(err)
451+
} else {
452+
config.BackrestS3CA = contents
453+
}
454+
}
436455
}
437456
if b, ok := secret.Data["aws-s3-key"]; ok {
438457
config.BackrestS3Key = string(b)

internal/operator/common.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,9 @@ package operator
1717

1818
import (
1919
"bytes"
20+
"crypto/sha256"
2021
"encoding/json"
22+
"fmt"
2123
"io/ioutil"
2224
"os"
2325
"path"
@@ -40,6 +42,9 @@ const (
4042
defaultBackrestRepoConfigPath = "/default-pgo-backrest-repo/"
4143
// defaultRegistry is the default registry to pull the container images from
4244
defaultRegistry = "registry.developers.crunchydata.com/crunchydata"
45+
// legacyS3CASHA256Digest informs us if we should override the S3 CA with the
46+
// new bundle
47+
legacyS3CASHA256Digest = "d1c290ea1e4544dec1934931fbfa1fb2060eb3a0f2239ba191f444ecbce35cbb"
4348
)
4449

4550
var CRUNCHY_DEBUG bool
@@ -397,9 +402,18 @@ func initializeOperatorBackrestSecret(clientset kubernetes.Interface, namespace
397402

398403
// set any missing defaults
399404
for _, filename := range defaultBackrestRepoConfigKeys {
400-
// skip if there is already content
405+
// skip if there is already content, unless this is aws-s3-ca.crt due to
406+
// the change in the CA bundle
401407
if len(secret.Data[filename]) != 0 {
402-
continue
408+
if filename != "aws-s3-ca.crt" {
409+
continue
410+
}
411+
412+
// in the case of aws-s3-ca.crt, check that this is the default
413+
// certificate. if it is, override it
414+
if fmt.Sprintf("%x", sha256.Sum256(secret.Data[filename])) != legacyS3CASHA256Digest {
415+
continue
416+
}
403417
}
404418

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

0 commit comments

Comments
 (0)