Skip to content

Commit 897ca5d

Browse files
Enable encryption in backup test
1 parent 605c898 commit 897ca5d

File tree

6 files changed

+100
-4
lines changed

6 files changed

+100
-4
lines changed

e2e/fixtures/factory.go

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ package fixtures
2222

2323
import (
2424
"context"
25+
cryptorand "crypto/rand"
2526
"fmt"
2627
"io"
2728
"log"
@@ -39,6 +40,7 @@ import (
3940
corev1 "k8s.io/api/core/v1"
4041
storagev1 "k8s.io/api/storage/v1"
4142
k8serrors "k8s.io/apimachinery/pkg/api/errors"
43+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4244
"k8s.io/apimachinery/pkg/util/duration"
4345
"k8s.io/client-go/rest"
4446
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -132,6 +134,33 @@ func (factory *Factory) GetBackupSecretName() string {
132134
return "backup-credentials"
133135
}
134136

137+
// GetEncryptionKeySecretName returns the name for the encryption key secret
138+
func (factory *Factory) GetEncryptionKeySecretName() string {
139+
return "backup-encryption-key"
140+
}
141+
142+
// CreateEncryptionKeySecret creates a 32-byte encryption key secret.
143+
func (factory *Factory) CreateEncryptionKeySecret(namespace string) {
144+
secretName := factory.GetEncryptionKeySecretName()
145+
146+
// Create 32-byte encryption key.
147+
key := make([]byte, 32)
148+
_, err := cryptorand.Read(key)
149+
gomega.Expect(err).NotTo(gomega.HaveOccurred())
150+
151+
secret := &corev1.Secret{
152+
ObjectMeta: metav1.ObjectMeta{
153+
Name: secretName,
154+
Namespace: namespace,
155+
},
156+
Data: map[string][]byte{
157+
"key.bin": key,
158+
},
159+
}
160+
161+
gomega.Expect(factory.CreateIfAbsent(secret)).NotTo(gomega.HaveOccurred())
162+
}
163+
135164
func (factory *Factory) getConfig() *rest.Config {
136165
return factory.config
137166
}

e2e/fixtures/fdb_backup.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,8 @@ type FdbBackup struct {
4646
type FdbBackupConfiguration struct {
4747
// BackupType defines the backup type that should be used for this backup.
4848
BackupType *fdbv1beta2.BackupType
49+
// EncryptionEnabled determines whether backup encryption should be used.
50+
EncryptionEnabled bool
4951
}
5052

5153
// CreateBackupForCluster will create a FoundationDBBackup for the provided cluster.
@@ -122,6 +124,11 @@ func (factory *Factory) CreateBackupForCluster(
122124
ReadOnly: true,
123125
MountPath: "/tmp/backup-credentials",
124126
},
127+
{
128+
Name: "encryption-key",
129+
ReadOnly: true,
130+
MountPath: "/tmp/encryption-key",
131+
},
125132
},
126133
},
127134
},
@@ -142,12 +149,25 @@ func (factory *Factory) CreateBackupForCluster(
142149
},
143150
},
144151
},
152+
{
153+
Name: "encryption-key",
154+
VolumeSource: corev1.VolumeSource{
155+
Secret: &corev1.SecretVolumeSource{
156+
SecretName: factory.GetEncryptionKeySecretName(),
157+
},
158+
},
159+
},
145160
},
146161
},
147162
},
148163
},
149164
}
150165

166+
// Set encryption key path only if encryption is enabled
167+
if config.EncryptionEnabled {
168+
backup.Spec.EncryptionKeyPath = "/tmp/encryption-key/key.bin"
169+
}
170+
151171
gomega.Expect(factory.CreateIfAbsent(backup)).NotTo(gomega.HaveOccurred())
152172

153173
curBackup := &FdbBackup{

e2e/fixtures/fdb_operator_client.go

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,9 @@ spec:
325325
- name: backup-credentials
326326
mountPath: /tmp/backup-credentials
327327
readOnly: true
328+
- name: encryption-key
329+
mountPath: /tmp/encryption-key
330+
readOnly: true
328331
securityContext:
329332
fsGroup: 4059
330333
runAsGroup: 4059
@@ -339,6 +342,9 @@ spec:
339342
- name: backup-credentials
340343
secret:
341344
secretName: {{ .BackupSecretName }}
345+
- name: encryption-key
346+
secret:
347+
secretName: {{ .EncryptionKeySecretName }}
342348
- name: fdb-certs
343349
secret:
344350
secretName: {{ .SecretName }}
@@ -459,6 +465,9 @@ spec:
459465
- name: backup-credentials
460466
mountPath: /tmp/backup-credentials
461467
readOnly: true
468+
- name: encryption-key
469+
mountPath: /tmp/encryption-key
470+
readOnly: true
462471
securityContext:
463472
fsGroup: 4059
464473
runAsGroup: 4059
@@ -473,6 +482,9 @@ spec:
473482
- name: backup-credentials
474483
secret:
475484
secretName: {{ .BackupSecretName }}
485+
- name: encryption-key
486+
secret:
487+
secretName: {{ .EncryptionKeySecretName }}
476488
- name: fdb-certs
477489
secret:
478490
secretName: {{ .SecretName }}
@@ -505,6 +517,8 @@ type operatorConfig struct {
505517
SecretName string
506518
// BackupSecretName represents the secret that should be used to communicate with the backup blobstore.
507519
BackupSecretName string
520+
// EncryptionKeySecretName represents the secret that contains the encryption key for backup operations.
521+
EncryptionKeySecretName string
508522
// SidecarVersions represents the sidecar configurations for different FoundationDB versions.
509523
SidecarVersions []SidecarConfig
510524
// Namespace represents the namespace for the Deployment and all associated resources
@@ -602,10 +616,11 @@ func (factory *Factory) getOperatorConfig(namespace string) *operatorConfig {
602616
}
603617

604618
return &operatorConfig{
605-
OperatorImage: factory.GetOperatorImage(),
606-
SecretName: factory.GetSecretName(),
607-
BackupSecretName: factory.GetBackupSecretName(),
608-
Namespace: namespace,
619+
OperatorImage: factory.GetOperatorImage(),
620+
SecretName: factory.GetSecretName(),
621+
BackupSecretName: factory.GetBackupSecretName(),
622+
EncryptionKeySecretName: factory.GetEncryptionKeySecretName(),
623+
Namespace: namespace,
609624
SidecarVersions: factory.GetSidecarConfigs(),
610625
ImagePullPolicy: factory.getImagePullPolicy(),
611626
CPURequests: cpuRequests,

e2e/fixtures/fdb_restore.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func (factory *Factory) CreateRestoreForCluster(
6060
BlobStoreConfiguration: backup.backup.Spec.BlobStoreConfiguration,
6161
CustomParameters: backup.backup.Spec.CustomParameters,
6262
BackupVersion: backupVersion,
63+
EncryptionKeyPath: backup.backup.Spec.EncryptionKeyPath,
6364
},
6465
},
6566
fdbCluster: backup.fdbCluster,

e2e/fixtures/kubernetes_fixtures.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,9 @@ func (factory *Factory) createNamespace(suffix string) string {
156156
}
157157
gomega.Expect(factory.CreateIfAbsent(backupCredentials)).NotTo(gomega.HaveOccurred())
158158

159+
// Create the encryption key secret for backup encryption operations.
160+
factory.CreateEncryptionKeySecret(namespace)
161+
159162
factory.ensureRBACSetupExists(namespace)
160163
gomega.Expect(factory.ensureFDBOperatorExists(namespace)).ToNot(gomega.HaveOccurred())
161164
log.Printf("using namespace %s for testing", namespace)

e2e/test_operator_backups/operator_backup_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,34 @@ var _ = Describe("Operator Backup", Label("e2e", "pr"), func() {
141141
})
142142
})
143143

144+
When("the default backup system is used with encryption", func() {
145+
BeforeEach(func() {
146+
log.Println("creating backup for cluster")
147+
backup = factory.CreateBackupForCluster(
148+
fdbCluster,
149+
&fixtures.FdbBackupConfiguration{
150+
BackupType: ptr.To(fdbv1beta2.BackupTypeDefault),
151+
EncryptionEnabled: true,
152+
},
153+
)
154+
keyValues = fdbCluster.GenerateRandomValues(10, prefix)
155+
fdbCluster.WriteKeyValues(keyValues)
156+
backup.WaitForRestorableVersion(fdbCluster.GetClusterVersion())
157+
backup.Stop()
158+
fdbCluster.ClearRange([]byte{prefix}, 60)
159+
})
160+
161+
When("no restorable version is specified", func() {
162+
BeforeEach(func() {
163+
restore = factory.CreateRestoreForCluster(backup, nil)
164+
})
165+
166+
It("should restore the cluster successfully with a restorable version", func() {
167+
Expect(fdbCluster.GetRange([]byte{prefix}, 25, 60)).Should(Equal(keyValues))
168+
})
169+
})
170+
})
171+
144172
When("the partitioned backup system is used", func() {
145173
BeforeEach(func() {
146174
// Versions before 7.4 have a few issues and will not work properly with the experimental feature.

0 commit comments

Comments
 (0)