Skip to content

Conversation

adamint
Copy link
Member

@adamint adamint commented Feb 18, 2025

Description

Took the opportunity to clean up my code in GetSourceViewModel as well to add a type CommandLineInfo instead of relying on a tuple. Hides secrets in tooltips using the same masking characters as appear in the GridValue.

Also removes logic in ExpressionResolver that resolves some types of expressions only for containers. All expressions except EndpointReferenceExpression and EndpointReference should be resolved for all resource types. The only other difference between containers and other types of resources is how HostUrl is resolved (special-cased for containers).

Fixes #7634, fixes #7632

Checklist

  • Is this feature complete?
    • Yes. Ready to ship.
    • No. Follow-up changes expected.
  • Are you including unit tests for the changes and scenario tests if relevant?
    • Yes
    • No
  • Did you add public API?
    • Yes
      • If yes, did you have an API Review for it?
        • Yes
        • No
      • Did you add <remarks /> and <code /> elements on your triple slash comments?
        • Yes
        • No
    • No
  • Does the change make any security assumptions or guarantees?
    • Yes
      • If yes, have you done a threat model and had a security review?
        • Yes
        • No
    • No
  • Does the change require an update in our Aspire docs?

Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment on lines 159 to 160
ConnectionStringReference cs => await ResolveInternalAsync(cs.Resource.ConnectionStringExpression).ConfigureAwait(false),
IResourceWithConnectionString cs => await ResolveInternalAsync(cs.ConnectionStringExpression).ConfigureAwait(false),
Copy link
Member

Choose a reason for hiding this comment

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

@davidfowl @mitchdenny @davidebbo - do we even need these 2 cases? Since ConnectionStringReference and IResourceWithConnectionString implement IValueProvider, shouldn't this just fall to that case?

(Note we don't necessarily need to change this in this PR, but I'm just trying to understand if I have the logic correct. If we are going to backport this to 9.1, we may not want to risk a change here.)

Copy link
Member

Choose a reason for hiding this comment

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

Nevermind, I think I understand why this is necessary - because we want to intercept any "host" references inside the ConnectionString and redirect them to the containerHostName.

Would it ever work if someone implemented an IValueProvider that contained a "host" reference, but wasn't one of these?

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

LGTM. I just had some questions for my learning.

@adamint
Copy link
Member Author

adamint commented Feb 18, 2025

Example with a connection string, like in @DamianEdwards's example in #7632 -
image
image

Adam Ratzman added 2 commits February 18, 2025 17:26
…, to prevent non-optional but missing value from resolving
@adamint adamint requested a review from eerhardt February 18, 2025 23:32
@adamint
Copy link
Member Author

adamint commented Feb 18, 2025

@eerhardt I added some additional special cases for certain resource kinds in ExpressionEvaluator, enough changes that need a re-review

@danmoseley
Copy link
Member

@adamint please get this in 9.1 today if possible.

@danmoseley danmoseley added this to the 9.1 milestone Feb 19, 2025
@adamint
Copy link
Member Author

adamint commented Feb 19, 2025

@adamint please get this in 9.1 today if possible.

Waiting on re-review. @eerhardt @davidfowl

Copy link
Member

@eerhardt eerhardt left a comment

Choose a reason for hiding this comment

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

The changes look good to me. Just a couple minor comments.

@@ -94,7 +96,7 @@ void AddStringProperty(string propertyName, string? propertyValue)
value: "project",
contentAfterValue: [new LaunchArgument("arg2", true), new LaunchArgument("--key", true), new LaunchArgument("secret", false)],
valueToVisualize: "path/to/project arg2 --key secret",
tooltip: "path/to/project arg2 --key secret"));
tooltip: $"path/to/project arg2 --key {WebUtility.HtmlDecode(DashboardUIHelpers.GetMaskingText(6).Value)}"));
Copy link
Member

@eerhardt eerhardt Feb 19, 2025

Choose a reason for hiding this comment

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

Are there other tests that should be added for this change? Specifically for the case(s) where we are changing ExpressionResolver - to catch secrets inside connection strings.

Copy link
Member Author

Choose a reason for hiding this comment

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

Added those tests in ExpressionResolverTests

Co-authored-by: James Newton-King <james@newtonking.com>
Copy link
Member

@JamesNK JamesNK left a comment

Choose a reason for hiding this comment

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

Dashboard changes look good. Need some tests and a little clean up.

Is there a sample where this can be manually tested?

@JamesNK
Copy link
Member

JamesNK commented Feb 19, 2025

Is there a sample where this can be manually tested?

@adamint
Copy link
Member Author

adamint commented Feb 20, 2025

Is there a sample where this can be manually tested?

There is not, as there is no sample using ef migrate or this feature. We could add one? but I'm unsure exactly how to replicate the use case in #7632 - @DamianEdwards maybe for suggestion, or could you share the app you were referencing there?

I've been manually testing using the following, inspired by #7632 -

Update any service in TestShop.AppHost/Program.cs to include .WithArgs(catalogDb.Resource)

@adamint adamint requested a review from mitchdenny as a code owner February 20, 2025 05:31
@adamint
Copy link
Member Author

adamint commented Feb 20, 2025

/backport to release/9.1

Copy link
Contributor

Started backporting to release/9.1: https://github.com/dotnet/aspire/actions/runs/13428696603

@adamint adamint enabled auto-merge (squash) February 20, 2025 05:40
@adamint adamint merged commit a1136f8 into dotnet:main Feb 20, 2025
70 checks passed
// We are substituting our own logic for ConnectionStringReference's GetValueAsync.
// However, ConnectionStringReference#GetValueAsync will throw if the connection string is not optional but is not present.
// To avoid duplicating that logic, we can defer to ConnectionStringReference#GetValueAsync, which will throw if needed.
await ((IValueProvider)cs).GetValueAsync(cancellationToken).ConfigureAwait(false);
Copy link
Member

Choose a reason for hiding this comment

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

I would be worried about side effects. We should only do this in the null case to avoid double evaluation in the common case.

@mitchdenny
Copy link
Member

mitchdenny commented Feb 20, 2025

@adamint I was taking a closer look at this PR and I noticed a bug. Lets say I do this:

builder.Configuration["ConnectionStrings:connstring"] = "dummyvalue";
var connstring = builder.AddConnectionString("connstring");
builder.AddExecutable("pinger", "path/to/ping", "localhost", connstring);

When this renders in the console it'll look like this. The connectionstring type name itself is being rendered into the source column. I don't think that is the intention? It should just show the secret placeholder value.

image

Scratch that could be an underlying issue with the args handling with executable resources. It happens in 9.0 as well so I'm looking into it. Maybe there is an inconsistency here between containers and executables.

@mitchdenny
Copy link
Member

Also issue #7634 suggests that we should also have a show secrets button in the copy dialog. I'm not 100% sure I agree that we need to do that - but was that a deliberate choice. If it was just skipped for expediency for 9.1 and we still want to do it then we should re-open that issue or open a new one to make sure we don't loose track.

@adamint
Copy link
Member Author

adamint commented Feb 20, 2025

Also issue #7634 suggests that we should also have a show secrets button in the copy dialog. I'm not 100% sure I agree that we need to do that - but was that a deliberate choice. If it was just skipped for expediency for 9.1 and we still want to do it then we should re-open that issue or open a new one to make sure we don't loose track.

It's a deliberate choice, I'll make a comment in #7634 as well - opening the text visualizer is an explicit action. With secret properties in the resource details view, users wouldn't otherwise be able to hide secrets without them being initially masked, of course. Here, secrets are already hidden in the source column; if users want to see all args (masked), they can expand the column or hover to show the (masked) tooltip.

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

Successfully merging this pull request may close these issues.

Secret arguments are displayed in tooltip Password in executable args is shown on the Resources page
6 participants