Skip to content

Commit d541fda

Browse files
authored
Merge branch 'main' into dapr-state-store-clickhouse
2 parents 3f8679f + dcaa80e commit d541fda

File tree

10 files changed

+32
-82
lines changed

10 files changed

+32
-82
lines changed

.build-tools/builtin-authentication-profiles.yaml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,18 @@ aws:
55
metadata:
66
- name: region
77
type: string
8-
required: true
8+
required: false
99
description: |
1010
The AWS Region where the AWS resource is deployed to.
11+
This will be marked required in Dapr 1.17.
12+
example: '"us-east-1"'
13+
- name: awsRegion
14+
type: string
15+
required: false
16+
description: |
17+
This maintains backwards compatibility with existing fields.
18+
It will be deprecated as of Dapr 1.17. Use 'region' instead.
19+
The AWS Region where the AWS resource is deployed to.
1120
example: '"us-east-1"'
1221
- name: accessKey
1322
description: AWS access key associated with an IAM account
@@ -20,11 +29,13 @@ aws:
2029
sensitive: true
2130
example: '"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"'
2231
- name: sessionToken
32+
type: string
2333
required: false
2434
sensitive: true
2535
description: |
2636
AWS session token to use. A session token is only required if you are using
2737
temporary security credentials.
38+
example: '"TOKEN"'
2839
- title: "AWS: Assume IAM Role"
2940
description: |
3041
Assume a specific IAM role. Note: This is only supported for Kafka and PostgreSQL.

.build-tools/pkg/metadataschema/builtin-authentication-profiles.go

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -32,25 +32,17 @@ func ParseBuiltinAuthenticationProfile(bi BuiltinAuthenticationProfile, componen
3232
for i, profile := range profiles {
3333
res[i] = profile
3434

35-
// convert slice to a slice of pointers to update in place for required -> non-required fields
36-
metadataPtr := make([]*Metadata, len(profile.Metadata))
37-
for j := range profile.Metadata {
38-
metadataPtr[j] = &profile.Metadata[j]
39-
}
35+
// deep copy the metadata slice to avoid side effects when manually updating some req -> non-req fields to deprecate some fields for kafka/postgres
36+
// TODO: rm all of this manipulation in Dapr 1.17!!
37+
originalMetadata := profile.Metadata
38+
metadataCopy := make([]Metadata, len(originalMetadata))
39+
copy(metadataCopy, originalMetadata)
4040

4141
if componentTitle == "Apache Kafka" || strings.ToLower(componentTitle) == "postgresql" {
42-
removeRequiredOnSomeAWSFields(&metadataPtr)
43-
}
44-
45-
// convert back to value slices for merging
46-
updatedMetadata := make([]Metadata, 0, len(metadataPtr))
47-
for _, ptr := range metadataPtr {
48-
if ptr != nil {
49-
updatedMetadata = append(updatedMetadata, *ptr)
50-
}
42+
removeRequiredOnSomeAWSFields(&metadataCopy)
5143
}
5244

53-
merged := mergedMetadata(bi.Metadata, updatedMetadata...)
45+
merged := mergedMetadata(bi.Metadata, metadataCopy...)
5446

5547
// Note: We must apply the removal of deprecated fields after the merge!!
5648

@@ -92,12 +84,14 @@ func mergedMetadata(base []Metadata, add ...Metadata) []Metadata {
9284
// We normally have accessKey, secretKey, and region fields marked required as it is part of the builtin AWS auth profile fields.
9385
// However, as we rm the aws prefixed ones, we need to then mark the normally required ones as not required only for postgres and kafka.
9486
// This way we do not break existing users, and transition them to the standardized fields.
95-
func removeRequiredOnSomeAWSFields(metadata *[]*Metadata) {
87+
func removeRequiredOnSomeAWSFields(metadata *[]Metadata) {
9688
if metadata == nil {
9789
return
9890
}
9991

100-
for _, field := range *metadata {
92+
for i := range *metadata {
93+
field := &(*metadata)[i]
94+
10195
if field == nil {
10296
continue
10397
}
@@ -125,6 +119,10 @@ func removeSomeDeprecatedFieldsOnUnrelatedAuthProfiles(metadata []Metadata) []Me
125119
filteredMetadata := []Metadata{}
126120

127121
for _, field := range metadata {
122+
// region is required in Assume Role auth profile, so this is needed for now.
123+
if field.Name == "region" {
124+
field.Required = true
125+
}
128126
if field.Name == "awsAccessKey" || field.Name == "awsSecretKey" || field.Name == "awsSessionToken" || field.Name == "awsRegion" {
129127
continue
130128
} else {

bindings/kafka/metadata.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,14 +29,6 @@ builtinAuthenticationProfiles:
2929
example: '"awsiam"'
3030
allowedValues:
3131
- "awsiam"
32-
- name: awsRegion
33-
type: string
34-
required: false
35-
description: |
36-
This maintains backwards compatibility with existing fields.
37-
It will be deprecated as of Dapr 1.17. Use 'region' instead.
38-
The AWS Region where the AWS service is deployed to.
39-
example: '"us-east-1"'
4032
- name: awsAccessKey
4133
type: string
4234
required: false

bindings/postgres/metadata.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -73,14 +73,6 @@ builtinAuthenticationProfiles:
7373
If both fields are set, then 'secretKey' value will be used.
7474
The secret key associated with the access key.
7575
example: '"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"'
76-
- name: awsRegion
77-
type: string
78-
required: false
79-
description: |
80-
This maintains backwards compatibility with existing fields.
81-
It will be deprecated as of Dapr 1.17. Use 'region' instead.
82-
The AWS Region where the AWS service is deployed to.
83-
example: '"us-east-1"'
8476
authenticationProfiles:
8577
- title: "Connection string"
8678
description: "Authenticate using a Connection String"

common/authentication/aws/static.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -262,21 +262,8 @@ func (a *StaticAuth) getDatabaseToken(ctx context.Context, poolConfig *pgxpool.C
262262
dbEndpoint := poolConfig.ConnConfig.Host + ":" + strconv.Itoa(int(poolConfig.ConnConfig.Port))
263263

264264
// First, check if there are credentials set explicitly with accesskey and secretkey
265-
var creds credentials.Value
266-
if a.session != nil {
267-
var err error
268-
creds, err = a.session.Config.Credentials.Get()
269-
if err != nil {
270-
a.logger.Infof("failed to get access key and secret key, will fallback to reading the default AWS credentials file: %w", err)
271-
}
272-
}
273-
274-
if creds.AccessKeyID != "" && creds.SecretAccessKey != "" {
275-
creds, err := a.session.Config.Credentials.Get()
276-
if err != nil {
277-
return "", fmt.Errorf("failed to retrieve session credentials: %w", err)
278-
}
279-
awsCfg := v2creds.NewStaticCredentialsProvider(creds.AccessKeyID, creds.SecretAccessKey, creds.SessionToken)
265+
if a.accessKey != nil && a.secretKey != nil {
266+
awsCfg := v2creds.NewStaticCredentialsProvider(*a.accessKey, *a.secretKey, a.sessionToken)
280267
authenticationToken, err := auth.BuildAuthToken(
281268
ctx, dbEndpoint, *a.region, poolConfig.ConnConfig.User, awsCfg)
282269
if err != nil {

common/authentication/aws/x509.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ func (a *x509) Ses() *SesClients {
312312
func (a *x509) getDatabaseToken(ctx context.Context, poolConfig *pgxpool.Config) (string, error) {
313313
dbEndpoint := poolConfig.ConnConfig.Host + ":" + strconv.Itoa(int(poolConfig.ConnConfig.Port))
314314

315-
// First, check if there are credentials set explicitly with accesskey and secretkey
315+
// First, check session credentials.
316+
// This should always be what we use to generate the x509 auth credentials for postgres.
317+
// However, we can leave the Second and Lastly checks as backup for now.
316318
var creds credentials.Value
317319
if a.session != nil {
318320
var err error

configuration/postgres/metadata.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,14 +63,6 @@ builtinAuthenticationProfiles:
6363
If both fields are set, then 'secretKey' value will be used.
6464
The secret key associated with the access key.
6565
example: '"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"'
66-
- name: awsRegion
67-
type: string
68-
required: false
69-
description: |
70-
This maintains backwards compatibility with existing fields.
71-
It will be deprecated as of Dapr 1.17. Use 'region' instead.
72-
The AWS Region where the AWS service is deployed to.
73-
example: '"us-east-1"'
7466
authenticationProfiles:
7567
- title: "Connection string"
7668
description: "Authenticate using a Connection String."

pubsub/kafka/metadata.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,6 @@ builtinAuthenticationProfiles:
2323
example: '"awsiam"'
2424
allowedValues:
2525
- "awsiam"
26-
- name: awsRegion
27-
type: string
28-
required: false
29-
description: |
30-
This maintains backwards compatibility with existing fields.
31-
It will be deprecated as of Dapr 1.17. Use 'region' instead.
32-
The AWS Region where the AWS service is deployed to.
33-
example: '"us-east-1"'
3426
- name: awsAccessKey
3527
type: string
3628
required: false

state/postgresql/v1/metadata.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,14 +70,6 @@ builtinAuthenticationProfiles:
7070
If both fields are set, then 'secretKey' value will be used.
7171
The secret key associated with the access key.
7272
example: '"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"'
73-
- name: awsRegion
74-
type: string
75-
required: false
76-
description: |
77-
This maintains backwards compatibility with existing fields.
78-
It will be deprecated as of Dapr 1.17. Use 'region' instead.
79-
The AWS Region where the AWS service is deployed to.
80-
example: '"us-east-1"'
8173
authenticationProfiles:
8274
- title: "Connection string"
8375
description: "Authenticate using a Connection String"

state/postgresql/v2/metadata.yaml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,6 @@ builtinAuthenticationProfiles:
6969
If both fields are set, then 'secretKey' value will be used.
7070
The secret key associated with the access key.
7171
example: '"wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"'
72-
- name: awsRegion
73-
type: string
74-
required: false
75-
description: |
76-
This maintains backwards compatibility with existing fields.
77-
It will be deprecated as of Dapr 1.17. Use 'region' instead.
78-
The AWS Region where the AWS service is deployed to.
79-
example: '"us-east-1"'
8072
authenticationProfiles:
8173
- title: "Connection string"
8274
description: "Authenticate using a Connection String"

0 commit comments

Comments
 (0)