Skip to content

Add metadata overrides for sensitive connection string values (URL and DSN support) #3825

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Conversation

nelson-parente
Copy link
Contributor

@nelson-parente nelson-parente commented May 20, 2025

Description

This introduces support for overriding sensitive connection string values via metadata. Both URL-style and DSN-style connection strings are supported.

Currently supported overrides asked in the issue:

  • host
  • database
  • user
  • password
  • sslrootcert

Happy to add support for additional fields if needed.

Docs PR: dapr/docs#4664

Issue reference

#3809

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation / Created issue in the https://github.com/dapr/docs/ repo: dapr/docs#[issue number]

@nelson-parente nelson-parente force-pushed the oss-125-postgresql-state-store-add-separate-metadata-options-for branch from ca9e8e6 to c7fef3d Compare May 20, 2025 20:51
@nelson-parente nelson-parente marked this pull request as ready for review May 20, 2025 21:00
@nelson-parente nelson-parente requested review from a team as code owners May 20, 2025 21:00
@nelson-parente nelson-parente changed the title feat: add auth metadata options and connectionstring builder Add metadata overrides for sensitive connection string values (URL and DSN support) May 20, 2025
@nelson-parente nelson-parente force-pushed the oss-125-postgresql-state-store-add-separate-metadata-options-for branch 3 times, most recently from 4d7d390 to 16901ee Compare May 21, 2025 08:44
Comment on lines 108 to 111
func (m *PostgresAuthMetadata) buildConnectionString() (string, error) {
if m.ConnectionString == "" {
return "", errors.New("connection string is required")
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is an error here intended? The below method buildDSNConnectionString appears to build a suitable connection string

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Initially, I didn't add all the props so you couldn't build a valid connection with metadata only. Since I've now added more props to the metadata we can allow to build only from meta.

@alicejgibbons
Copy link

So the logic here should be the broken out (potentially sensitive) values can be used along with values in the dns connection string. If the values are present in their own metadata property then they should overwrite the same value in the DNS connection string. Of course we hope the user won't provide them twice but the precedence should always be the individual value over the connection string one. Looking at the other potential connection string values, we should also add hostaddr, looking here - this is c lib but assuming its similar.

We also don't have to support this in v1, only v2 for State.

@nelson-parente nelson-parente force-pushed the oss-125-postgresql-state-store-add-separate-metadata-options-for branch from a6e6bfe to 790af47 Compare May 22, 2025 10:01
@@ -87,6 +102,117 @@ func (m *PostgresAuthMetadata) InitWithMetadata(meta map[string]string, opts Ini
return nil
}

// buildConnectionString builds the connection string from the metadata.
// It supports both DSN-style and URL-style connection strings.
Copy link

@alicejgibbons alicejgibbons May 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yeah ignore me - deleted

Signed-off-by: nelson.parente <[email protected]>
Copy link
Member

@mikeee mikeee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

Copy link

@alicejgibbons alicejgibbons left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Logic lgtm, only im unsure if we want to continue to support v1, would confirm with the community

@nelson-parente
Copy link
Contributor Author

Logic lgtm, only im unsure if we want to continue to support v1, would confirm with the community

Logic is the same for v1/v2 I don't think there is harm in adding this to v1 too

@yaron2 yaron2 added this pull request to the merge queue May 27, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 27, 2025
@nelson-parente
Copy link
Contributor Author

@yaron2 can we merge this? I don't think merge queue is working so we need manual merge.

@yaron2 yaron2 merged commit 3525032 into dapr:main Jun 3, 2025
122 of 124 checks passed
@marcduiker
Copy link
Contributor

@holopin-bot @nelson-parente Thank you! Here's a digital badge as a small token of appreciation.

Copy link

holopin-bot bot commented Jun 11, 2025

Congratulations @nelson-parente, the maintainer of this repository has issued you a badge! Here it is: https://holopin.io/claim/cmbs0d6sr1630907l5s58im4e2

This badge can only be claimed by you, so make sure that your GitHub account is linked to your Holopin account. You can manage those preferences here: https://holopin.io/account.
Or if you're new to Holopin, you can simply sign up with GitHub, which will do the trick!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants