Skip to content

Commit 27540db

Browse files
dougkirkleyAgalin
authored andcommitted
feat: support multiple AWS key types
Signed-off-by: Douglass Kirkley <[email protected]>
1 parent 402c15e commit 27540db

File tree

4 files changed

+59
-27
lines changed

4 files changed

+59
-27
lines changed

config/crd/bases/pgbackrest.cnpg.opera.com_archives.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,11 @@ spec:
254254
- key
255255
- name
256256
type: object
257+
keyType:
258+
default: shared
259+
description: KeyType specifies the type of key used
260+
for S3 credentials
261+
type: string
257262
region:
258263
description: |-
259264
The reference to the secret containing the region name.

internal/pgbackrest/api/config.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,13 +59,30 @@ const (
5959
CompressionTypeZstd = CompressionType("zst")
6060
)
6161

62+
// KeyType is the type of key used for S3 credentials
63+
type KeyType string
64+
65+
const (
66+
// KeyTypeShared Shared keys
67+
KeyTypeShared = KeyType("shared")
68+
// KeyTypeAuto Automatically retrieve temporary credentials
69+
KeyTypeAuto = KeyType("auto")
70+
// KeyTypeWebID Automatically retrieve web identity credentials
71+
KeyTypeWebID = KeyType("web-id")
72+
)
73+
6274
// S3Credentials is the type for the credentials to be used to upload
6375
// files to S3. It can be provided in two alternative ways:
6476
//
6577
// - explicitly passing accessKeyId and secretAccessKey
6678
//
6779
// - inheriting the role from the pod environment by setting inheritFromIAMRole to true
6880
type S3Credentials struct {
81+
// KeyType specifies the type of key used for S3 credentials
82+
// +optional
83+
// +kubebuilder:default:=shared
84+
KeyType KeyType `json:"keyType,omitempty"`
85+
6986
// The reference to the access key ID
7087
// +optional
7188
AccessKeyIDReference *machineryapi.SecretKeySelector `json:"accessKeyId,omitempty"`

internal/pgbackrest/credentials/credentials.go

Lines changed: 32 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -138,37 +138,42 @@ func envSetAWSCredentials(
138138
return nil, fmt.Errorf("missing S3 credentials")
139139
}
140140

141-
// Get access key ID
142-
if s3credentials.AccessKeyIDReference == nil {
143-
return nil, fmt.Errorf("missing access key ID")
144-
}
145-
accessKeyID, accessKeyErr := extractValueFromSecret(
146-
ctx,
147-
client,
148-
s3credentials.AccessKeyIDReference,
149-
namespace,
150-
)
151-
if accessKeyErr != nil {
152-
return nil, accessKeyErr
153-
}
141+
// only check for AWS credential secrets if the key type is shared
142+
if s3credentials.KeyType == pgbackrestApi.KeyTypeShared {
143+
// Get access key ID
144+
if s3credentials.AccessKeyIDReference == nil {
145+
return nil, fmt.Errorf("missing access key ID")
146+
}
147+
accessKeyID, accessKeyErr := extractValueFromSecret(
148+
ctx,
149+
client,
150+
s3credentials.AccessKeyIDReference,
151+
namespace,
152+
)
153+
if accessKeyErr != nil {
154+
return nil, accessKeyErr
155+
}
154156

155-
// Get secret access key
156-
if s3credentials.SecretAccessKeyReference == nil {
157-
return nil, fmt.Errorf("missing secret access key")
158-
}
159-
secretAccessKey, secretAccessErr := extractValueFromSecret(
160-
ctx,
161-
client,
162-
s3credentials.SecretAccessKeyReference,
163-
namespace,
164-
)
165-
if secretAccessErr != nil {
166-
return nil, secretAccessErr
157+
// Get secret access key
158+
if s3credentials.SecretAccessKeyReference == nil {
159+
return nil, fmt.Errorf("missing secret access key")
160+
}
161+
secretAccessKey, secretAccessErr := extractValueFromSecret(
162+
ctx,
163+
client,
164+
s3credentials.SecretAccessKeyReference,
165+
namespace,
166+
)
167+
if secretAccessErr != nil {
168+
return nil, secretAccessErr
169+
}
170+
171+
env = append(env, utils.FormatRepoEnv(repoIndex, "S3_KEY", string(accessKeyID)))
172+
env = append(env, utils.FormatRepoEnv(repoIndex, "S3_KEY_SECRET", string(secretAccessKey)))
167173
}
168174

175+
env = append(env, utils.FormatRepoEnv(repoIndex, "S3_KEY_TYPE", string(s3credentials.KeyType)))
169176
env = append(env, utils.FormatRepoEnv(repoIndex, "S3_REGION", s3credentials.Region))
170-
env = append(env, utils.FormatRepoEnv(repoIndex, "S3_KEY", string(accessKeyID)))
171-
env = append(env, utils.FormatRepoEnv(repoIndex, "S3_KEY_SECRET", string(secretAccessKey)))
172177

173178
return env, nil
174179
}

manifest.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,11 @@ spec:
253253
- key
254254
- name
255255
type: object
256+
keyType:
257+
default: shared
258+
description: KeyType specifies the type of key used
259+
for S3 credentials
260+
type: string
256261
region:
257262
description: |-
258263
The reference to the secret containing the region name.

0 commit comments

Comments
 (0)