Skip to content

Dynamic Passwords in NpgsqlConnection - #2502

Merged
roji merged 13 commits into
npgsql:devfrom
williamdenton:dynamic-passwords
Jun 29, 2019
Merged

roji merged 13 commits into
npgsql:devfrom
williamdenton:dynamic-passwords

Conversation

@williamdenton

Copy link
Copy Markdown
Contributor

See #2500

William Denton added 3 commits June 21, 2019 14:18
New connections will execute the delegate to obtain a password. This allows the use of dynamic passwords or tokens such as those used by Amazon RDS IAM Authentication.
#2500
It's possible that the username is not directly taken from the connection string, so flow the computed username down so it is available in the delegate.
#2500
@williamdenton

Copy link
Copy Markdown
Contributor Author

The critical design decision here is to not allow fallback to the password specified on the connection string or to a PassFile. I think that if you are defining the delegate and you want to return null that is your responsibility to handle. Falling back into other authentication methods would be confusing in this case i believe

@YohDeadfall YohDeadfall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good start!

Comment thread src/Npgsql/NpgsqlConnection.cs Resolved
Comment thread src/Npgsql/NpgsqlConnector.Auth.cs Resolved
Comment thread src/Npgsql/NpgsqlConnector.Auth.cs Resolved
Comment thread src/Npgsql/NpgsqlConnector.Auth.cs Resolved
Comment thread src/Npgsql/NpgsqlConnector.cs Resolved
Comment thread src/Npgsql/NpgsqlConnection.cs Resolved

@roji roji left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looks good! See below comments in addition to @YohDeadfall:

  • I don't really see the reason to call this a "dynamic" password - it's just a callback-based mechanism.
  • Is there a specific reason to ignore Password on the connection string if a delegate is provided? Why not have the delegate just be a fallback when the password isn't specified, just like PgPass is handled? I could imagine scenarios where some fallback delegate is wired up, but a user may want to provide a password manually...

Comment thread src/Npgsql/NpgsqlConnection.cs Resolved
Comment thread src/Npgsql/NpgsqlConnector.Auth.cs Resolved
Comment thread src/Npgsql/NpgsqlConnector.Auth.cs Resolved
Comment thread test/Npgsql.Tests/ConnectionTests.cs Resolved
Comment thread test/Npgsql.Tests/ConnectionTests.cs Resolved
@roji roji assigned williamdenton and unassigned williamdenton Jun 26, 2019
William Denton added 4 commits June 27, 2019 16:04
This aligns this property with the existing delegates ProvideClientCertificatesCallback and RemoteCertificateValidationCallback
#2500
Comment thread doc/security.md Resolved
Comment thread src/Npgsql/NpgsqlConnector.Auth.cs Resolved
Comment thread src/Npgsql/NpgsqlConnector.Auth.cs Resolved
Comment thread test/Npgsql.Tests/ConnectionTests.cs Resolved
Comment thread test/Npgsql.Tests/ConnectionTests.cs Resolved
Comment thread src/Npgsql/NpgsqlConnector.Auth.cs Resolved

@roji roji left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Looking very close, thanks for your work. Let me know if anything is unclear.

Comment thread src/Npgsql/NpgsqlConnector.Auth.cs Resolved
@williamdenton

Copy link
Copy Markdown
Contributor Author

no problem, these tweaks are all very easy

@williamdenton

williamdenton commented Jun 29, 2019 •

Copy link
Copy Markdown
Contributor Author

let me know if you would like all these commits rebased and squashed to have a sane linear history, rather than showing the journey we came on

@roji roji left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm good to merge. @YohDeadfall can you please give this a quick review?

@roji

roji commented Jun 29, 2019

Copy link
Copy Markdown
Member

@williamdenton yeah please squash this to a single commit in preparation for merge.

@YohDeadfall YohDeadfall left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Looks good except a few nits which I can't comment in the code (Windows Phone Edge is no more supported supported by GitHub), so will write my comments here.

  • In line 385 in the GetPassword method GetDynamicPassword mentioned, but there is no such delegate.
  • In the same method in line 392 there is a naming issue too. Probably you want to say Obtaining password using {nameof(GetPasswordCallback)} delegate failed.?

@williamdenton

Copy link
Copy Markdown
Contributor Author

@roji do you want a single commit, or two or three with the critical steps split out.

For example we have made some changes to the passfile implementation that were done as we're in the vicinity, not directly related to this issue.

@YohDeadfall

Copy link
Copy Markdown
Contributor

Personally I prefer to separate fixes from features to keep things clear, but as I know Shay likes to squash everything into a single commit.

@roji
roji merged this pull request into npgsql:dev Jun 29, 2019
roji pushed a commit that referenced this pull request Jun 29, 2019
New connections will execute the delegate to obtain a password.
This allows the use of dynamic passwords or tokens such as those used by Amazon RDS IAM Authentication.

Fixes #2500
@roji

roji commented Jun 29, 2019

Copy link
Copy Markdown
Member

I think things here are related and small enough to make a single commit reasonable... Merged via d78f3d6.

@williamdenton thanks for your contribution! It's a nice new feature for Npgsql, hope we'll see more from you in the future :)

@YohDeadfall

Copy link
Copy Markdown
Contributor

As I said, Shay likes single commit changes (:

Yep, thank you! And it's great to see documentation changes.

@roji

roji commented Jun 29, 2019

Copy link
Copy Markdown
Member

@YohDeadfall knows me too well :)

@austindrenski austindrenski left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A bit late to the party, but awesome to see this merged. Thanks for your contribution! 🎉

@williamdenton

Copy link
Copy Markdown
Contributor Author

When will this likely make it into a nuget? Guessing it's in the 4.1 release.

I might prepare a blog post to go with this.

@austindrenski

Copy link
Copy Markdown
Contributor

When will this likely make it into a nuget? Guessing it's in the 4.1 release.

It'll definitely be part of the 4.1 release, which I would expect to see this calendar year. (@roji may have a more specific timeline in mind.) Of course, in the meantime, it should already be available from the npgsql-unstable feed.

I might prepare a blog post to go with this.

Please let us know if you do! We've linked to related blog posts in past release notes, so I'm sure we could take a look at whatever you put together.

@YohDeadfall

Copy link
Copy Markdown
Contributor

(@roji may have a more specific timeline in mind.)

Currently I'm a blocker here because of unfinished work on type handlers.

@roji

roji commented Jul 1, 2019

Copy link
Copy Markdown
Member

The idea is to more or less synchronize the next release (which we may end up calling 5.0) with .NET Core 3.0, which is due this year.

@williamdenton

Copy link
Copy Markdown
Contributor Author

which we may end up calling 5.0

Semver wise 0af8c1d is a breaking change which means this isn't 4.1 - its definitely 5.x.

@roji

roji commented Jul 2, 2019

Copy link
Copy Markdown
Member

Oh, there are other more important ones for sure :)

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.

4 participants