Skip to content

Fix guest AppHost secret store resolution - #15220

Merged
Sébastien Ros (sebastienros) merged 2 commits into
release/13.2from
sebros/issue-14788-secret-path
Mar 16, 2026
Merged

Sébastien Ros (sebastienros) merged 2 commits into
release/13.2from
sebros/issue-14788-secret-path

Conversation

@sebastienros

Copy link
Copy Markdown
Contributor

Description

Fixes guest/polyglot AppHost user secrets handling on release/13.2 and adds a CLI command to show the resolved secrets file path.

  • adds aspire secret path to print the user secrets file used for a given AppHost
  • updates DistributedApplicationBuilder so an explicit ASPIRE_USER_SECRETS_ID fully replaces the generated server project's user-secrets store, while empty values still fall back to the assembly user secrets ID
  • updates the save-to-user-secrets interaction text to be AppHost-generic and refreshes the corresponding XLF entries for translators
  • adds focused CLI and hosting tests for the new command and the guest AppHost secrets precedence behavior

Fixes #14788

Validation:

  • ./dotnet.sh test tests/Aspire.Hosting.Tests/Aspire.Hosting.Tests.csproj -v quiet -- --filter-method "*.PolyglotAppHostUsesAspireUserSecretsIdForUserSecretsManager" --filter-method "*.AspireUserSecretsIdOverridesAppHostAssemblyUserSecretsId" --filter-method "*.EmptyAspireUserSecretsIdFallsBackToAppHostAssemblyUserSecretsId" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
  • ./dotnet.sh test tests/Aspire.Cli.Tests/Aspire.Cli.Tests.csproj -v quiet -- --filter-method "*.SecretPath*" --filter-not-trait "quarantined=true" --filter-not-trait "outerloop=true"
  • manual verification with temporary TypeScript AppHosts running persistent SQL Server and RabbitMQ resources across two runs to confirm container reuse and inspect the resolved secret store behavior

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?

Add `aspire secret path` to show the resolved secrets file path, update guest AppHost user-secrets precedence to honor ASPIRE_USER_SECRETS_ID over the generated server project store, and refresh the related UX text and tests.\n\nCo-authored-by: Copilot <[email protected]>
Copilot AI review requested due to automatic review settings March 13, 2026 17:30
@github-actions

github-actions Bot commented Mar 13, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Dogfood this PR with:

⚠️ WARNING: Do not do this without first carefully reviewing the code of this PR to satisfy yourself it is safe.

curl -fsSL https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.sh | bash -s -- 15220

Or

  • Run remotely in PowerShell:
iex "& { $(irm https://raw.githubusercontent.com/dotnet/aspire/main/eng/scripts/get-aspire-cli-pr.ps1) } 15220"

Copilot AI 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.

Pull request overview

Fixes guest/polyglot AppHost user-secrets resolution/precedence and adds a CLI command to display the resolved secrets file path.

Changes:

  • Add aspire secret path subcommand and wire it into DI/command hierarchy.
  • Update hosting logic to let an explicitly configured ASPIRE_USER_SECRETS_ID override the assembly UserSecretsId store (and remove the previous store source when overriding).
  • Refresh interaction text and localization entries; add targeted hosting + CLI tests.

Reviewed changes

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

Show a summary per file
File Description
src/Aspire.Hosting/DistributedApplicationBuilder.cs Implements new user-secrets precedence and removes overridden secrets configuration sources.
tests/Aspire.Hosting.Tests/DistributedApplicationBuilderTests.cs Adds tests for guest/polyglot secrets path/precedence behavior.
src/Aspire.Cli/Commands/SecretPathCommand.cs Adds secret path command to print resolved secrets file path.
src/Aspire.Cli/Commands/SecretCommand.cs Registers path as a secret subcommand.
src/Aspire.Cli/Program.cs Registers SecretPathCommand in DI.
tests/Aspire.Cli.Tests/Utils/CliTestHelper.cs Registers SecretPathCommand in test DI container.
tests/Aspire.Cli.Tests/Commands/SecretCommandTests.cs Adds CLI tests validating secret path output for .NET and guest AppHosts.
src/Aspire.Cli/Resources/SecretCommandStrings.resx Adds localized description string for secret path.
src/Aspire.Cli/Resources/xlf/SecretCommandStrings.*.xlf Adds XLF entries for the new PathDescription string.
src/Aspire.Hosting/Resources/InteractionStrings.resx Updates interaction text to be AppHost-generic.
src/Aspire.Hosting/Resources/xlf/InteractionStrings.*.xlf Refreshes XLF entries for the updated interaction text.
Files not reviewed (1)
  • src/Aspire.Cli/Resources/SecretCommandStrings.Designer.cs: Language not supported
Comments suppressed due to low confidence (1)

tests/Aspire.Hosting.Tests/DistributedApplicationBuilderTests.cs:1

  • DeleteUserSecretsFile recreates the secrets directory after deleting the file. Since this helper is also called from finally blocks, it will leave behind empty per-test directories under the user-secrets root. Consider splitting this into two helpers (e.g., one to ensure the directory exists before writing, and one to delete/cleanup), or add a flag to skip directory creation during cleanup (and optionally delete the directory if empty).

@github-actions

github-actions Bot commented Mar 13, 2026 •

Copy link
Copy Markdown
Contributor

🎬 CLI E2E Test Recordings

The following terminal recordings are available for commit f49bcca:

Test Recording
AddPackageInteractiveWhileAppHostRunningDetached ▶️ View Recording
AddPackageWhileAppHostRunningDetached ▶️ View Recording
AgentCommands_AllHelpOutputs_AreCorrect ▶️ View Recording
AgentInitCommand_DefaultSelection_InstallsSkillOnly ▶️ View Recording
AgentInitCommand_MigratesDeprecatedConfig ▶️ View Recording
AspireAddPackageVersionToDirectoryPackagesProps ▶️ View Recording
AspireUpdateRemovesAppHostPackageVersionFromDirectoryPackagesProps ▶️ View Recording
Banner_DisplayedOnFirstRun ▶️ View Recording
Banner_DisplayedWithExplicitFlag ▶️ View Recording
CertificatesClean_RemovesCertificates ▶️ View Recording
CertificatesTrust_WithNoCert_CreatesAndTrustsCertificate ▶️ View Recording
CertificatesTrust_WithUntrustedCert_TrustsCertificate ▶️ View Recording
ConfigSetGet_CreatesNestedJsonFormat ▶️ View Recording
CreateAndDeployToDockerCompose ▶️ View Recording
CreateAndDeployToDockerComposeInteractive ▶️ View Recording
CreateAndPublishToKubernetes ▶️ View Recording
CreateAndRunAspireStarterProject ▶️ View Recording
CreateAndRunAspireStarterProjectWithBundle ▶️ View Recording
CreateAndRunJsReactProject ▶️ View Recording
CreateAndRunPythonReactProject ▶️ View Recording
CreateAndRunTypeScriptStarterProject ▶️ View Recording
CreateEmptyAppHostProject ▶️ View Recording
CreateStartAndStopAspireProject ▶️ View Recording
CreateTypeScriptAppHostWithViteApp ▶️ View Recording
DescribeCommandResolvesReplicaNames ▶️ View Recording
DescribeCommandShowsRunningResources ▶️ View Recording
DetachFormatJsonProducesValidJson ▶️ View Recording
DoctorCommand_DetectsDeprecatedAgentConfig ▶️ View Recording
DoctorCommand_WithSslCertDir_ShowsTrusted ▶️ View Recording
DoctorCommand_WithoutSslCertDir_ShowsPartiallyTrusted ▶️ View Recording
GlobalMigration_HandlesCommentsAndTrailingCommas ▶️ View Recording
GlobalMigration_HandlesMalformedLegacyJson ▶️ View Recording
GlobalMigration_PreservesAllValueTypes ▶️ View Recording
GlobalMigration_SkipsWhenNewConfigExists ▶️ View Recording
GlobalSettings_MigratedFromLegacyFormat ▶️ View Recording
InvalidAppHostPathWithComments_IsHealedOnRun ▶️ View Recording
LogsCommandShowsResourceLogs ▶️ View Recording
PsCommandListsRunningAppHost ▶️ View Recording
PsFormatJsonOutputsOnlyJsonToStdout ▶️ View Recording
PublishWithDockerComposeServiceCallbackSucceeds ▶️ View Recording
RestoreGeneratesSdkFiles ▶️ View Recording
RunWithMissingAwaitShowsHelpfulError ▶️ View Recording
SecretCrudOnDotNetAppHost ▶️ View Recording
SecretCrudOnTypeScriptAppHost ▶️ View Recording
StagingChannel_ConfigureAndVerifySettings_ThenSwitchChannels ▶️ View Recording
StopAllAppHostsFromAppHostDirectory ▶️ View Recording
StopAllAppHostsFromUnrelatedDirectory ▶️ View Recording
StopNonInteractiveMultipleAppHostsShowsError ▶️ View Recording
StopNonInteractiveSingleAppHost ▶️ View Recording
StopWithNoRunningAppHostExitsSuccessfully ▶️ View Recording
TypeScriptAppHostWithProjectReferenceIntegration ▶️ View Recording

📹 Recordings uploaded automatically from CI run #23154876633

return ExitCodeConstants.FailedToFindProject;
}

InteractionService.DisplayPlainText(result.Store.FilePath);

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.

Does this render as a clickable path in the CLI output?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think we can even get file paths to be clickable, urls only I think.


if (filePath is not null && PathsEqual(filePath, userSecretsFilePath))
{
configuration.Sources.RemoveAt(i);

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.

Does this remove the full configuration source (for secrets), meaning secrets capabilities all up? We might want to add some sort of note here, as when I first read this code, I was concerned it was removing more than it should.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Just removing one source. Added a comment right above to clarify the intent.

@sebastienros
Sébastien Ros (sebastienros) merged commit c8916ce into release/13.2 Mar 16, 2026
744 of 751 checks passed
@sebastienros
Sébastien Ros (sebastienros) deleted the sebros/issue-14788-secret-path branch March 16, 2026 18:21
@dotnet-policy-service dotnet-policy-service Bot added this to the 13.2 milestone Mar 16, 2026
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 16, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants