You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Use a private temporary storage area for the Aspire CLI - #22688
↑ Full ./build.sh --build with the banned-API analyzer at this head: 0 warnings, 0 errors. ↑ Focused temp storage, bootstrap and DCP tests: 36 passed, 1 Linux-only skip, on macOS, including new 0775/0777 home regressions. ↑ Bootstrap regression: storage roots under the CLI execution context home even when a conflicting ASPIRE_HOME configuration value is present. ↑ Previous CI failures (Windows home ACL rejection; Linux /root/.aspire mode rejection) traced to strict home validation, which this head removes. ↓ New Windows regressions (home ACL preserved, permissive tmp rejected, Administrators-owned tmp) compile but have only run in CI, which is pending for this head. ↓ Linux and Windows runtime behavior not run locally. ↓ Session contents are intentionally left in place until follow-up cleanup PRs land.
Description
Builds on #22553, which routed all temporary storage through the internal ITemporaryStorage helper. This PR adds a second implementation that gives the Aspire CLI its own isolated temporary area instead of the shared system temp directory, and switches only the CLI to it. Dashboard and hosting are unchanged and will move in follow-up PRs.
Behavior for the CLI:
Temporary files and directories are allocated in a per-process session folder: <aspire home>/tmp/<random>/. <aspire home> is the CLI's already-resolved home (CliExecutionContext.AspireHomeDirectory), so it matches the rest of the CLI: the install prefix for script, local-hive and PR installs, otherwise ASPIRE_HOME or ~/.aspire.
Each session holds a lease (<random>.lock, next to the session folder) via the shared FileLock, so later cleanup can tell active sessions from abandoned ones. A new FileLock.AcquirePrivate creates the lock file owner-only; the existing Acquire is unchanged.
On Unix, directories are created 0700 and files 0600 at creation time. On Windows, directories are created with an owner-only, non-inherited ACL.
<aspire home> is only checked for links; its existing permissions are left alone, because installers and other tools create it with the user's umask or inherited ACLs. <aspire home>/tmp and everything below are validated strictly rather than silently repaired: links, or permissions wider than owner-only, produce an error with guidance. On Windows, an Administrators owner is accepted alongside the current user (elevated runs). If no usable home directory exists, the CLI reports an error instead of falling back to the system temp directory.
When ASPIRE_PRESERVE_TEMP_FILES is truthy, a .preserve marker is written into the session for later cleanup to honor.
Folder prefixes are kept short so paths under the Aspire home stay short: the redundant aspire- prefix is dropped at CLI call sites (for example dcp-<random> for the aspire doctor DCP check, giving ~/.aspire/tmp/<random>/dcp-<random>). ChildProcess and MsBuildResponseFile keep their aspire- prefixes because Hosting still uses them under system temp.
The DCP check also uses the private area. DCP's notification socket lives in the user cache directory, not in DCP_SESSION_FOLDER, and the probe configures no log socket, so the Unix socket path limit doesn't apply to this folder.
Implementation notes:
src/Shared/PrivateTemporaryStorage.cs is a new internal, instance-based ITemporaryStorage, source-linked directly into Aspire.Cli.csproj and registered in the CLI's DI container.
No public API changes.
Not in this PR (follow-ups): an aspire doctor tidy command for on-demand cleanup, moving the Dashboard and hosting onto the private area, then automatic cleanup of abandoned sessions. Until then, the lease is released on dispose and session contents are left in place.
Security considerations
This changes where the CLI writes temporary files and sets owner-only permissions (Unix modes, Windows ACLs) on them. Review should confirm the permission handling and the link check on ~/.aspire and the strict validation of ~/.aspire/tmp on each platform. Tightening ~/.aspire itself (installers creating it owner-only) is planned as a follow-up.
Fixes # (issue)
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?
Register an instance-based private temporary storage service for the CLI, keeping the system-backed service for the DCP doctor socket probe. Allocate sessions under the configured Aspire home and retain their contents for the follow-up cleanup layer. Link the implementation directly from the CLI project and reuse FileLock for session leases.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Temporary storage uses the wrong home for custom-prefix installations, macOS certificate trust fails when home paths contain spaces, and Windows ACL protections lack regression coverage.
Builds on #22553’s temporary-storage abstraction to give the Aspire CLI private, leased session directories under Aspire home. Dashboard and hosting remain unchanged; session cleanup is deferred.
Changes:
Adds private temporary storage with Unix permissions, Windows access controls, root validation, and preservation markers.
Switches CLI allocation to private storage while keeping DCP connection checks on system temp.
Adds allocation, lifecycle, permission, and dependency-injection tests.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Temporary storage uses the wrong home for custom-prefix installations, rejects valid administrator-owned Windows homes and new homes with trailing separators, and lacks Windows ACL security tests.
Trim trailing separators when validating a new home
src/Shared/PrivateTemporaryStorage.cs:104
A fresh ASPIRE_HOME ending in a directory separator is rejected even when its parent exists: Path.GetDirectoryName("/existing/new-home/") returns /existing/new-home, so the check tests the not-yet-created home instead of /existing. The same override without the trailing separator succeeds. Trim the ending separator before checking the parent, and cover both forms for a previously absent home.
Allow Administrators-owned private homes on Windows
src/Shared/PrivateTemporaryStorage.cs:169
The user-only ownership check rejects an otherwise private Aspire home owned by BUILTIN\Administrators, which Windows can assign when an elevated process creates it. CLI logging can create the home this way before the first temporary allocation, causing that allocation to fail. Accept administrator ownership while retaining the existing access-rule validation, and add a Windows regression test for this case.
Validate only links in the Aspire home while keeping the temporary storage root private, including when the CLI creates its home under a permissive umask.
Co-authored-by: Copilot App <[email protected]>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Unchecked Windows home ownership and permissions let another user replace the temporary directory and defeat storage isolation, while home-resolution and SDK directory-permission mismatches can also cause allocations to fail.
The reason will be displayed to describe this comment to others. Learn more.
The same parent-directory issue applies on Unix. The new test explicitly accepts a non-sticky 0777 home, but 0700 on tmp protects its contents, not its entry in a parent that another user can modify. Please require an Aspire home that other users cannot modify, or choose a separately secured root, and cover that case on Unix.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
The temporary-storage changes can break macOS certificate trust when ASPIRE_HOME contains spaces and cause portable-install failures by bypassing the resolved writable state root.
The reason will be displayed to describe this comment to others. Learn more.
I would hold this until the owner-only boundary is enforced. The review found three isolation issues, three compatibility regressions, one temporary private-key archive retention issue, and one test isolation issue. The writable Unix home and workspace configuration details belong in the existing parent-permissions and home-resolution threads.
The exact-head Windows and Ubuntu CLI smoke tests passed, as did the Ubuntu Doctor suite. Those runs do not establish effective ACLs or lease recovery after abrupt exit; the abrupt-exit fixture still uses system temp.
The reason will be displayed to describe this comment to others. Learn more.
On macOS, inherited ACLs can grant access independently of the Unix mode bits. tmp and its descendants can look owner-only by mode while still inheriting grants from the home. Please check effective ACLs before allocating, and cover a home with inheritable grants.
The reason will be displayed to describe this comment to others. Learn more.
On Linux, mkdir inherits setgid from the parent, so this can reject a tmp directory the CLI just created with mode 02700, even though group and other have no access. Please validate the access bits separately and cover a setgid home.
The reason will be displayed to describe this comment to others. Learn more.
An explicit absolute ASPIRE_HOME under a not-yet-created parent now fails on the first temp allocation. Other CLI paths create missing ancestors recursively. Please support provisioning an explicit home safely while still rejecting a missing user-profile fallback.
The reason will be displayed to describe this comment to others. Learn more.
MacOSCertificateManager.SaveCertificateToUserKeychain() leaves its encrypted PFX in the temp directory after import. This registration moves it into an Aspire session that is retained on exit, outside normal OS-temp cleanup. Please delete the PFX in a finally that covers both the write and the import.
The reason will be displayed to describe this comment to others. Learn more.
When Aspire home is under a Node project, npm can walk up from this directory and load the project .npmrc for view and pack. --registry does not isolate options like offline mode or proxies. Please give those calls an isolated local prefix.
The reason will be displayed to describe this comment to others. Learn more.
BuildApplicationAsync can migrate user settings or normalize workspace settings before it applies this in-memory override. Please run the bootstrap in a child process with the Aspire home and working directory both inside the test fixture.
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
Human assessment is needed because Windows permission inheritance and SDK-first temporary-directory creation can expose session directories or cause private temporary allocations to fail, risks omitted from the published review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Agent assessment
Self-reported assessment, not an independent review.
Assessed revision:
11628d9c24f6eab73cef8508cfda6f7f188416fd./build.sh --buildwith the banned-API analyzer at this head: 0 warnings, 0 errors.↑ Focused temp storage, bootstrap and DCP tests: 36 passed, 1 Linux-only skip, on macOS, including new 0775/0777 home regressions.
↑ Bootstrap regression: storage roots under the CLI execution context home even when a conflicting
ASPIRE_HOMEconfiguration value is present.↑ Previous CI failures (Windows home ACL rejection; Linux
/root/.aspiremode rejection) traced to strict home validation, which this head removes.↓ New Windows regressions (home ACL preserved, permissive tmp rejected, Administrators-owned tmp) compile but have only run in CI, which is pending for this head.
↓ Linux and Windows runtime behavior not run locally.
↓ Session contents are intentionally left in place until follow-up cleanup PRs land.
Description
Builds on #22553, which routed all temporary storage through the internal
ITemporaryStoragehelper. This PR adds a second implementation that gives the Aspire CLI its own isolated temporary area instead of the shared system temp directory, and switches only the CLI to it. Dashboard and hosting are unchanged and will move in follow-up PRs.Behavior for the CLI:
<aspire home>/tmp/<random>/.<aspire home>is the CLI's already-resolved home (CliExecutionContext.AspireHomeDirectory), so it matches the rest of the CLI: the install prefix for script, local-hive and PR installs, otherwiseASPIRE_HOMEor~/.aspire.<random>.lock, next to the session folder) via the sharedFileLock, so later cleanup can tell active sessions from abandoned ones. A newFileLock.AcquirePrivatecreates the lock file owner-only; the existingAcquireis unchanged.0700and files0600at creation time. On Windows, directories are created with an owner-only, non-inherited ACL.<aspire home>is only checked for links; its existing permissions are left alone, because installers and other tools create it with the user's umask or inherited ACLs.<aspire home>/tmpand everything below are validated strictly rather than silently repaired: links, or permissions wider than owner-only, produce an error with guidance. On Windows, an Administrators owner is accepted alongside the current user (elevated runs). If no usable home directory exists, the CLI reports an error instead of falling back to the system temp directory.ASPIRE_PRESERVE_TEMP_FILESis truthy, a.preservemarker is written into the session for later cleanup to honor.aspire-prefix is dropped at CLI call sites (for exampledcp-<random>for theaspire doctorDCP check, giving~/.aspire/tmp/<random>/dcp-<random>).ChildProcessandMsBuildResponseFilekeep theiraspire-prefixes because Hosting still uses them under system temp.DCP_SESSION_FOLDER, and the probe configures no log socket, so the Unix socket path limit doesn't apply to this folder.Implementation notes:
src/Shared/PrivateTemporaryStorage.csis a new internal, instance-basedITemporaryStorage, source-linked directly intoAspire.Cli.csprojand registered in the CLI's DI container.Not in this PR (follow-ups): an
aspire doctor tidycommand for on-demand cleanup, moving the Dashboard and hosting onto the private area, then automatic cleanup of abandoned sessions. Until then, the lease is released on dispose and session contents are left in place.Security considerations
This changes where the CLI writes temporary files and sets owner-only permissions (Unix modes, Windows ACLs) on them. Review should confirm the permission handling and the link check on
~/.aspireand the strict validation of~/.aspire/tmpon each platform. Tightening~/.aspireitself (installers creating it owner-only) is planned as a follow-up.Fixes # (issue)
Checklist
<remarks />and<code />elements on your triple slash comments?