Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion NuGet.config
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<clear />
<!--Begin: Package sources managed by Dependency Flow automation. Do not edit the sources below.-->
<!-- Begin: Package sources from dotnet-dotnet -->
<add key="darc-pub-dotnet-dotnet-48adeb7" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-dotnet-48adeb74/nuget/v3/index.json" />
<add key="darc-pub-dotnet-dotnet-127cfac" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/darc-pub-dotnet-dotnet-127cfacc/nuget/v3/index.json" />
<add key="darc-int-dotnet-dotnet-f7d9079" value="https://pkgs.dev.azure.com/dnceng/internal/_packaging/darc-int-dotnet-dotnet-f7d90799/nuget/v3/index.json" />
<!-- End: Package sources from dotnet-dotnet -->
<!-- Begin: Package sources from microsoft-testfx -->
Expand Down
246 changes: 123 additions & 123 deletions eng/Version.Details.props

Large diffs are not rendered by default.

518 changes: 259 additions & 259 deletions eng/Version.Details.xml

Large diffs are not rendered by default.

46 changes: 17 additions & 29 deletions eng/common/core-templates/job/onelocbuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,10 @@ parameters:
# Optional: A defined YAML pool - https://docs.microsoft.com/en-us/azure/devops/pipelines/yaml-schema?view=vsts&tabs=schema#pool
pool: ''

CeapexPat: $(dn-bot-ceapex-package-r) # PAT for the loc AzDO instance https://dev.azure.com/ceapex
GithubPat: $(BotAccount-dotnet-bot-repo-PAT)

# Service connection for WIF-based Entra authentication to ceapex feeds (replaces CeapexPat).
# The `internal` and `DevDiv` System.TeamProject values have same-named, project-scoped
# connections. Other values, and any pipeline that sets this to '', use the CeapexPat parameter.
# Project-scoped WIF service connection for Ceapex feed authentication.
CeapexServiceConnection: 'dnceng-onelocbuild-ceapex'

# GitHub App authentication for the OneLoc check-in PR.
# dnceng/internal and DevDiv/DevDiv are enabled by default with their project-scoped service
# connections. Other projects must explicitly opt in after provisioning equivalent infrastructure.
UseGitHubAppAuthentication: true
UseGitHubAppAuthenticationInOtherProjects: false
GitHubAppServiceConnection: 'dnceng-oneloc-githubapp'
GitHubAppClientId: 'Iv23lijBU8x3gc9lDOc9'
GitHubAppKeyVaultName: 'EngKeyVault'
Expand Down Expand Up @@ -48,7 +39,6 @@ jobs:
displayName: OneLocBuild${{ parameters.JobNameSuffix }}

variables:
- group: OneLocBuildVariables # Contains the CeapexPat and GithubPat
- name: _GenerateLocProjectArguments
value: -SourcesDirectory ${{ parameters.SourcesDirectory }}
-LanguageSet "${{ parameters.LanguageSet }}"
Expand Down Expand Up @@ -79,6 +69,12 @@ jobs:
steps:
- ${{ if eq(parameters.is1ESPipeline, '') }}:
- 'Illegal entry point, is1ESPipeline is not defined. Repository yaml should not directly reference templates in core-templates folder.': error
- ${{ if and(ne(variables['System.TeamProject'], 'internal'), ne(variables['System.TeamProject'], 'DevDiv')) }}:
- 'OneLocBuild is supported only in dnceng/internal and DevDiv/DevDiv.': error
- ${{ if eq(parameters.CeapexServiceConnection, '') }}:
- 'CeapexServiceConnection must identify a WIF service connection.': error
- ${{ if and(eq(parameters.RepoType, 'gitHub'), eq(parameters.GitHubAppServiceConnection, '')) }}:
- 'GitHubAppServiceConnection must identify a WIF service connection for GitHub repositories.': error

- ${{ if ne(parameters.SkipLocProjectJsonGeneration, 'true') }}:
- task: Powershell@2
Expand All @@ -88,17 +84,15 @@ jobs:
displayName: Generate LocProject.json
condition: ${{ parameters.condition }}

# Acquire an Entra token when System.TeamProject is `internal` or `DevDiv`.
- ${{ if and(ne(parameters.CeapexServiceConnection, ''), or(eq(variables['System.TeamProject'], 'internal'), eq(variables['System.TeamProject'], 'DevDiv'))) }}:
- template: /eng/common/templates/steps/get-federated-access-token.yml
parameters:
federatedServiceConnection: ${{ parameters.CeapexServiceConnection }}
outputVariableName: 'CeapexEntraToken'
condition: ${{ parameters.condition }}
# Acquire a short-lived Entra token for Ceapex feed access.
- template: /eng/common/templates/steps/get-federated-access-token.yml
parameters:
federatedServiceConnection: ${{ parameters.CeapexServiceConnection }}
outputVariableName: 'CeapexEntraToken'
condition: ${{ parameters.condition }}

# Mint a short-lived GitHub App installation token for the loc check-in PR. Use the connection
# provisioned in each supported project; other projects must explicitly opt in and override it.
- ${{ if and(eq(parameters.RepoType, 'gitHub'), eq(parameters.UseGitHubAppAuthentication, true), or(eq(variables['System.TeamProject'], 'internal'), eq(variables['System.TeamProject'], 'DevDiv'), eq(parameters.UseGitHubAppAuthenticationInOtherProjects, true))) }}:
# Mint a short-lived GitHub App installation token for the loc check-in PR.
- ${{ if eq(parameters.RepoType, 'gitHub') }}:
- template: /eng/common/core-templates/steps/get-github-app-token.yml
parameters:
is1ESPipeline: ${{ parameters.is1ESPipeline }}
Expand Down Expand Up @@ -128,16 +122,10 @@ jobs:
isUseLfLineEndingsSelected: ${{ parameters.UseLfLineEndings }}
isShouldReusePrSelected: ${{ parameters.ReusePr }}
packageSourceAuth: patAuth
${{ if and(ne(parameters.CeapexServiceConnection, ''), or(eq(variables['System.TeamProject'], 'internal'), eq(variables['System.TeamProject'], 'DevDiv'))) }}:
patVariable: $(CeapexEntraToken)
${{ if or(eq(parameters.CeapexServiceConnection, ''), and(ne(variables['System.TeamProject'], 'internal'), ne(variables['System.TeamProject'], 'DevDiv'))) }}:
patVariable: ${{ parameters.CeapexPat }}
patVariable: $(CeapexEntraToken)
${{ if eq(parameters.RepoType, 'gitHub') }}:
repoType: ${{ parameters.RepoType }}
${{ if and(eq(parameters.UseGitHubAppAuthentication, true), or(eq(variables['System.TeamProject'], 'internal'), eq(variables['System.TeamProject'], 'DevDiv'), eq(parameters.UseGitHubAppAuthenticationInOtherProjects, true))) }}:
gitHubPatVariable: "$(GitHubAppInstallationToken)"
${{ else }}:
gitHubPatVariable: "${{ parameters.GithubPat }}"
gitHubPatVariable: "$(GitHubAppInstallationToken)"
${{ if ne(parameters.MirrorRepo, '') }}:
isMirrorRepoSelected: true
gitHubOrganization: ${{ parameters.GitHubOrg }}
Expand Down
8 changes: 4 additions & 4 deletions global.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"$host$"
],
"errorMessage": "The .NET SDK is not installed or is not configured correctly. Please run ./build to install the correct SDK version locally.",
"version": "10.0.400"
"version": "10.0.401"
},
"tools": {
"dotnet": "10.0.400",
"dotnet": "10.0.401",
"runtimes": {
"dotnet": [
"$(MicrosoftNETCorePlatformsPackageVersion)"
Expand All @@ -22,8 +22,8 @@
}
},
"msbuild-sdks": {
"Microsoft.DotNet.Arcade.Sdk": "10.0.0-beta.26453.103",
"Microsoft.DotNet.Helix.Sdk": "10.0.0-beta.26453.103",
"Microsoft.DotNet.Arcade.Sdk": "10.0.0-beta.26464.102",
"Microsoft.DotNet.Helix.Sdk": "10.0.0-beta.26464.102",
"Microsoft.Build.NoTargets": "3.7.0",
"Microsoft.Build.Traversal": "3.4.0",
"Microsoft.WixToolset.Sdk": "6.0.3-dotnet.6"
Expand Down
27 changes: 27 additions & 0 deletions src/Dotnet.Watch/HotReloadAgent.Host/Listener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ private async Task ReceiveAndApplyUpdatesAsync(bool initialUpdates, Cancellation
var payloadType = (RequestType)await request.Stream.ReadByteAsync(cancellationToken).ConfigureAwait(false);
switch (payloadType)
{
case RequestType.SetEnvironmentVariables:
await SetEnvironmentVariablesAsync(request.Stream, cancellationToken).ConfigureAwait(false);
break;

case RequestType.ManagedCodeUpdate:
await ReadAndApplyManagedCodeUpdateAsync(request.Stream, cancellationToken).ConfigureAwait(false);
break;
Expand All @@ -113,6 +117,29 @@ private async Task ReceiveAndApplyUpdatesAsync(bool initialUpdates, Cancellation
}
}

private async Task SetEnvironmentVariablesAsync(Stream stream, CancellationToken cancellationToken)
{
var environmentVariableCount = await stream.ReadInt32Async(cancellationToken).ConfigureAwait(false);

log($"Setting environment variables ({environmentVariableCount})");

for (var i = 0; i < environmentVariableCount; i++)
{
var name = await stream.ReadStringAsync(cancellationToken).ConfigureAwait(false);
var value = await stream.ReadStringAsync(cancellationToken).ConfigureAwait(false);
try
{
Environment.SetEnvironmentVariable(name, value);
}
catch (Exception e)
{
log($"Unable to set environment variable '{name}': {e.Message}");
}
}

await SendResponseAsync(new SetEnvironmentVariablesResponse(), cancellationToken).ConfigureAwait(false);
}

private async ValueTask ReadAndApplyManagedCodeUpdateAsync(Stream stream, CancellationToken cancellationToken)
{
var request = await ManagedCodeUpdateRequest.ReadAsync(stream, cancellationToken).ConfigureAwait(false);
Expand Down
2 changes: 2 additions & 0 deletions src/Dotnet.Watch/HotReloadAgent.Host/WebSocketTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ public override async ValueTask SendAsync(IResponse response, CancellationToken
_webSocket.Options.AddSubProtocol(encryptedSecret);
}

_webSocket.Options.SetRequestHeader("Origin", (serverPublicKey != null ? "wss" : "ws") + "://localhost");

Log($"Connecting to {serverUrl}...");
await _webSocket.ConnectAsync(new Uri(serverUrl), connectCts.Token).ConfigureAwait(false);
Log("Connected.");
Expand Down
20 changes: 15 additions & 5 deletions src/Dotnet.Watch/HotReloadAgent.PipeRpc/NamedPipeContract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,26 @@ internal interface IUpdateRequest : IRequest

internal enum RequestType : byte
{
ManagedCodeUpdate = 1,
StaticAssetUpdate = 2,
InitialUpdatesCompleted = 3,
SetEnvironmentVariables = 1,
ManagedCodeUpdate = 2,
StaticAssetUpdate = 3,
InitialUpdatesCompleted = 4,
}

internal enum ResponseType : byte
{
InitializationResponse = 1,
UpdateResponse = 2,
HotReloadExceptionNotification = 3,
EnvironmentVariablesSet = 2,
UpdateResponse = 3,
HotReloadExceptionNotification = 4,
}

internal readonly struct SetEnvironmentVariablesResponse() : IResponse
{
public ResponseType Type => ResponseType.EnvironmentVariablesSet;

public ValueTask WriteAsync(Stream stream, CancellationToken cancellationToken)
=> default;
}

internal readonly struct ManagedCodeUpdateRequest(IReadOnlyList<RuntimeManagedCodeUpdate> updates, ResponseLoggingLevel responseLoggingLevel) : IUpdateRequest
Expand Down
32 changes: 31 additions & 1 deletion src/Dotnet.Watch/HotReloadClient/DefaultHotReloadClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public override void Dispose()
/// </summary>
internal ClientTransport Transport => transport;

public override void InitiateConnection(CancellationToken cancellationToken)
public override void InitiateConnection(IReadOnlyCollection<(string name, string value)> environmentVariables, CancellationToken cancellationToken)
{
// It is important to establish the connection (WaitForConnectionAsync) before we return,
// otherwise the client wouldn't be able to connect.
Expand Down Expand Up @@ -73,6 +73,9 @@ async Task<ImmutableArray<string>> ConnectAsync()

Logger.Log(LogEvents.Capabilities, string.Join(" ", result));

// Initialize process:
await SetEnvironmentVariablesAsync(environmentVariables, cancellationToken);

// fire and forget:
_ = ListenForResponsesAsync(cancellationToken);

Expand Down Expand Up @@ -164,6 +167,33 @@ public override Task<ImmutableArray<string>> GetUpdateCapabilitiesAsync(Cancella
private ResponseLoggingLevel ResponseLoggingLevel
=> Logger.IsEnabled(LogLevel.Debug) ? ResponseLoggingLevel.Verbose : ResponseLoggingLevel.WarningsAndErrors;

public async ValueTask SetEnvironmentVariablesAsync(IReadOnlyCollection<(string name, string value)> environmentVariables, CancellationToken cancellationToken)
{
if (environmentVariables.Count == 0)
{
return;
}

// Send a request to set environment variables:
await transport.WriteAsync((byte)RequestType.SetEnvironmentVariables, async (stream, cancellationToken) =>
{
await stream.WriteAsync(environmentVariables.Count, cancellationToken);

foreach (var (name, value) in environmentVariables)
{
await stream.WriteAsync(name, cancellationToken);
await stream.WriteAsync(value, cancellationToken);
}
}, cancellationToken);

// Wait until the environment variables are set in the target process:
var response = await transport.ReadAsync(cancellationToken);
if (response != null && response.Value.Type != ResponseType.EnvironmentVariablesSet)
{
throw new InvalidOperationException($"Unexpected response received from the agent: {response.Value.Type}");
}
}

public async override Task<Task<bool>> ApplyManagedCodeUpdatesAsync(ImmutableArray<HotReloadManagedCodeUpdate> updates, CancellationToken applyOperationCancellationToken, CancellationToken cancellationToken)
{
RequireReadyForUpdates();
Expand Down
3 changes: 2 additions & 1 deletion src/Dotnet.Watch/HotReloadClient/HotReloadClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ protected static ImmutableArray<string> AddImplicitCapabilities(IEnumerable<stri
/// <summary>
/// Initiates connection with the agent in the target process.
/// </summary>
/// <param name="environmentVariables">Environment variable to be set by the agent in the target process.</param>
/// <param name="cancellationToken">Cancellation token. The cancellation should trigger on process terminatation.</param>
public abstract void InitiateConnection(CancellationToken cancellationToken);
public abstract void InitiateConnection(IReadOnlyCollection<(string name, string value)> environmentVariables, CancellationToken cancellationToken);

/// <summary>
/// Waits until the connection with the agent is established.
Expand Down
5 changes: 3 additions & 2 deletions src/Dotnet.Watch/HotReloadClient/HotReloadClients.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,13 @@ internal void ConfigureLaunchEnvironment(IDictionary<string, string> environment
browserRefreshServer?.ConfigureLaunchEnvironment(environmentBuilder, enableHotReload: true);
}

/// <param name="environmentVariables">Environment variable to be set by the agent in the target process.</param>
/// <param name="cancellationToken">Cancellation token. The cancellation should trigger on process terminatation.</param>
internal void InitiateConnection(CancellationToken cancellationToken)
internal void InitiateConnection(IReadOnlyCollection<(string name, string value)> environmentVariables, CancellationToken cancellationToken)
{
foreach (var client in clients)
{
client.InitiateConnection(cancellationToken);
client.InitiateConnection(environmentVariables, cancellationToken);
}
}

Expand Down
11 changes: 10 additions & 1 deletion src/Dotnet.Watch/HotReloadClient/Web/BrowserRefreshServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
using System.Threading.Tasks;
using Microsoft.AspNetCore.Http;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Primitives;

namespace Microsoft.DotNet.HotReload;

Expand Down Expand Up @@ -52,7 +53,15 @@ private async Task WebSocketRequestAsync(HttpContext context)
{
if (!context.WebSockets.IsWebSocketRequest)
{
context.Response.StatusCode = 400;
context.Response.StatusCode = StatusCodes.Status400BadRequest;
return;
}

// check the domain of the Origin header:
if (!Uri.TryCreate(context.Request.Headers.Origin.FirstOrDefault(), UriKind.Absolute, out var originUri) ||
!webSocketConfig.GetAllowedOriginDomains().Contains(originUri.Host, StringComparer.OrdinalIgnoreCase))
{
context.Response.StatusCode = StatusCodes.Status403Forbidden;
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public override void ConfigureLaunchEnvironment(IDictionary<string, string> envi
// the environment is configued via browser refesh server
}

public override void InitiateConnection(CancellationToken cancellationToken)
public override void InitiateConnection(IReadOnlyCollection<(string name, string value)> environmentVariables, CancellationToken cancellationToken)
{
}

Expand Down
22 changes: 20 additions & 2 deletions src/Dotnet.Watch/HotReloadClient/Web/WebSocketConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#nullable enable

using System.Collections.Generic;
using System.Collections.Immutable;

namespace Microsoft.DotNet.HotReload;

internal readonly struct WebSocketConfig(int port, int? securePort, string? hostName)
internal readonly struct WebSocketConfig(int port, int? securePort, string? hostName, ImmutableArray<string> additionalAllowedOrigins)
{
/// <summary>
/// 0 to auto-assign.
Expand All @@ -34,6 +35,23 @@ public IEnumerable<string> GetHttpUrls()
}
}

public IEnumerable<string> GetAllowedOriginDomains()
{
yield return "localhost";
yield return "127.0.0.1";
yield return "[::1]";

foreach (var origin in additionalAllowedOrigins)
{
yield return origin;
}

if (hostName != null)
{
yield return hostName;
}
}

public WebSocketConfig WithSecurePort(int? value)
=> new(port, value, hostName);
=> new(port, value, hostName, additionalAllowedOrigins);
}
Loading