-
Notifications
You must be signed in to change notification settings - Fork 450
/
etcd_encryption_key.go
56 lines (47 loc) · 1.39 KB
/
etcd_encryption_key.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
// SPDX-FileCopyrightText: 2024 SAP SE or an SAP affiliate company and Gardener contributors
//
// SPDX-License-Identifier: Apache-2.0
package secrets
import (
"fmt"
)
const (
// DataKeyEncryptionKeyName is the key in a secret data holding the key.
DataKeyEncryptionKeyName = "key"
// DataKeyEncryptionSecret is the key in a secret data holding the secret.
DataKeyEncryptionSecret = "secret"
)
// ETCDEncryptionKeySecretConfig contains the specification for a to-be-generated random key.
type ETCDEncryptionKeySecretConfig struct {
Name string
SecretLength int
}
// ETCDEncryptionKey contains the generated key.
type ETCDEncryptionKey struct {
Name string
Key string
Secret string
}
// GetName returns the name of the secret.
func (s *ETCDEncryptionKeySecretConfig) GetName() string {
return s.Name
}
// Generate implements ConfigInterface.
func (s *ETCDEncryptionKeySecretConfig) Generate() (DataInterface, error) {
secret, err := GenerateRandomString(s.SecretLength)
if err != nil {
return nil, err
}
return &ETCDEncryptionKey{
Name: s.Name,
Key: fmt.Sprintf("key%d", Clock.Now().Unix()),
Secret: secret,
}, nil
}
// SecretData computes the data map which can be used in a Kubernetes secret.
func (b *ETCDEncryptionKey) SecretData() map[string][]byte {
return map[string][]byte{
DataKeyEncryptionKeyName: []byte(b.Key),
DataKeyEncryptionSecret: []byte(b.Secret),
}
}