-
Notifications
You must be signed in to change notification settings - Fork 526
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
Add password protection to NATS #6259
Conversation
…hange + added more tests
One interesting behavior is that now that the NATS Hosting has a health check, I am getting the user name and password printed out in my console log: Is this expected behavior? That doesn't seem right. cc @mtmk |
Yes, this is an issue, but not one that has a good solution. With MongoDB we decided to go with option (a) keep it like it currently is, not breaking, but inconsistent. This decision was made because we don't make breaking changes to public APIs we've already shipped. |
tests/Aspire.Hosting.Tests/Utils/CommandLineArgumentsEvaluator.cs
Outdated
Show resolved
Hide resolved
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
Co-authored-by: Eric Erhardt <eric.erhardt@microsoft.com>
So should I also use a) for Nats?. The password to mongodb was only introduced in aspire 9 RC, so not yet released, so could still be changed to c). Or is having an new amibguity for AddNats/Mongo("name", default) such a problem? Or (for mongo) is breaking change not possible even in RC? |
I might be missing something here but there is no reason to pass user:pass in the url since it won't be used by the client, plus the client doesn't have safeguards to redact the password since it's not a supported method of passing username/password or tokens. |
It is used because that's how aspire forwards information between resources. Environmental variables would also be possible, but the default aspire approach is using connection strings. The username and password are parsed out in the Aspire.NATS.Net integration package. The user/password information could be stripped out before passing the URL to NATS.Net. An advantage of having this connection string is also easy interopability with clients in other languages that already support this format. It would be nice if NATS.Net would also support it directly. |
@Mrxx99 thanks for the explanation 👍 |
@Mrxx99 NATS .NET with URL auth support released in v2.5.3 thank you for your contribution 👍 |
@eerhardt The 2.5.3 version of Nats.NET (https://www.nuget.org/packages/NATS.Net/2.5.3) needs to be added to the dotnet-public feed so I can use it in this PR. |
Started job, should be done in 10 minutes |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for the contribution!
Description
This adds parameter support to NATS. The postgres implementation was used as inspiration for the implementation.
It uses the user info of the connection string URL to add user name and password, so the connections string looks like
nats://nats:MGBKxjTAjX2stg2wzzjtVW@localhost:52166
.Some NATS clients support this form natively (as can bee seen here) but the .NET one unfortunately does not. It would be nice if this support would be added directly to NATS.Net then that code could be removed from here again.
Contributes to: #6155
TheNatsServerResource
constructor is changed from(string name)
to(string name, ParameterResource? userName, ParameterResource password)
to be the same as thePostgresServerResource
Currently there is a inconsistency between the parameters of
AddNats(...)
andAddPostgres(...)
.The postgres method looks like
(name, userName = null, password = null, port = null)
and the Nats one is changed from(name, port = null)
to (name, port = null, userName = null, password = null)', otherwiseAddNats("nats", 4222)
would break.So there are 3 options:
a) keep it like it currently is, not breaking, but inconsistent to postgres and forces to use named arguments when user wants to specify password but no port.
b) change the order to be consistent with postgres, breaks existing code that specifies the port without named arguments, but is nicer to use when specifying password and no port
c) keep the existing constructor and add a new one that mimics the postgres one, the existing one would call into that. This would have all the benefits of the two options above and will only break on
AddNats("nats", default)
(which is unlikely to be used I think).Edit: seems like all resources have the port at the end in this scenario, except MongoDb which has two constructors, but both have the ports after the name. Maybe it would make sense to also make it consistent for MongoDb and to change MongoDb to option c), should still be possible as the second constructor is not yet shipped.
Checklist
<remarks />
and<code />
elements on your triple slash comments?