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
35 changes: 23 additions & 12 deletions .ado/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,23 @@ All repository resources pin `ref: refs/tags/release`.
## Package feed and network isolation

ISS agents run under 1ES **Network Isolation**, which blocks egress to public CDNs.
The pipelines source packages only from the `ms/react-native-public` Azure Artifacts
feed and neutralize three background egress attempts that green builds would
otherwise hide:

- **Feed registry:** `variables/shared.yml` points npm and Yarn at the
`ms/react-native-public` feed (`NPM_CONFIG_REGISTRY` / `YARN_NPM_REGISTRY_SERVER`).
On CI, `templates/auth-npm-feed.yml` mints a managed-identity token and writes it
to `~/.npmrc` and `~/.yarnrc.yml` before any install.
The pipelines use approved package feeds and neutralize three background egress
attempts that green builds would otherwise hide:

- **NuGet restores:** the root `NuGet.Config` maps NuGet.org dependencies to
`https://packagefeedproxy.microsoft.io/nuget/v3/index.json` anonymously.
Only `ReactNative.V8Jsi.Windows*` and `Microsoft.JavaScript.V8*` use the
`ms/react-native-public` ADO feed, where these V8 packages are published.
CI imports this policy for generated apps/libraries and third-party configs;
CLI-init tests also retain their local feed for freshly built RNW packages.
NuGet 6.0 or later is required to enforce these source mappings.
BinSkim downloads use the same proxy instead of nuget.org.
- **Package registries:** `variables/shared.yml` routes npm/npx and Yarn through
the anonymous PackageFeedProxy (`NPM_CONFIG_REGISTRY` /
`YARN_NPM_REGISTRY_SERVER`) in both PR and Continuous validation.
`templates/auth-npm-feed.yml` keeps the managed-identity token scoped to direct
Azure Artifacts requests in `~/.npmrc` and passes it to the Verdaccio uplink;
Yarn does not send the token to the proxy.
- **Verdaccio (CLI init tests):** `verdaccio/generate-config.js` emits the config at
runtime, so the uplink targets the feed (with the CI token when present) while
local packages still publish offline. The former static `config.yaml` was removed.
Expand All @@ -100,10 +109,12 @@ otherwise hide:
reapplies the same policy per job as an interim belt until the updated image
ships; it can be dropped once a rebuilt image is confirmed clean.

Public PR builds read this feed **anonymously**, so they can only restore versions
an authenticated identity has already saved. A scheduled feed warm-up maintained on
`main` re-pulls the latest patch of every npm/NuGet line already in the feed to keep
those anonymous restores working.
Public PR Verdaccio requests to the Azure Artifacts feed remain **anonymous** and
can only restore versions an authenticated identity has already saved. The
scheduled feed warm-up maintained on `main` keeps that feed populated.
PackageFeedProxy restores do not depend on that warm-up. Publishing and
authenticated feed maintenance keep their existing endpoints; NuGet defaults
shipped in generated apps/libraries are unchanged.

## SDL and Component Governance

Expand Down
3 changes: 1 addition & 2 deletions .ado/build-template.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ extends:
version: '24.x'
displayName: Use Node.js 24.x

# CI is network-isolated; authenticate to the package feed before any npm/Yarn use.
# CI is network-isolated; acquire the feed token used by the Verdaccio uplink.
- ${{ if eq(parameters.buildEnvironment, 'Continuous') }}:
- template: .ado/templates/auth-npm-feed.yml@self

Expand Down Expand Up @@ -551,4 +551,3 @@ extends:
parameters:
buildEnvironment: ${{ parameters.buildEnvironment }}
AgentPool: ${{ parameters.AgentPool }}

2 changes: 1 addition & 1 deletion .ado/scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const sourcesPath = path.resolve(__dirname, "..", "..");

const binskimPackageName = "Microsoft.CodeAnalysis.BinSkim";
const binskimVersion = "4.4.9";
const binskimNuGetSource = "https://api.nuget.org/v3/index.json";
const binskimNuGetSource = "https://packagefeedproxy.microsoft.io/nuget/v3/index.json";

const options = {
help: { type: "boolean", default: false },
Expand Down
3 changes: 1 addition & 2 deletions .ado/templates/auth-npm-feed.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Authenticates npm and Yarn 4 to the ms/react-native-public feed with the build's managed identity.
# Acquires a managed-identity token for direct npm requests and the Verdaccio feed uplink.
steps:
- task: AzureCLI@2
displayName: Authenticate to the package feed
Expand All @@ -13,4 +13,3 @@ steps:
Write-Host "##vso[task.setvariable variable=RNW_NPM_FEED_TOKEN;issecret=true]$token"
$reg = '//pkgs.dev.azure.com/ms/react-native/_packaging/react-native-public/npm/registry/'
Set-Content -Path (Join-Path $env:USERPROFILE '.npmrc') -Encoding ascii -Value "${reg}:_authToken=$token"
Set-Content -Path (Join-Path $env:USERPROFILE '.yarnrc.yml') -Encoding ascii -Value @('npmAlwaysAuth: true', "npmAuthToken: $token")
30 changes: 28 additions & 2 deletions .ado/templates/prepare-build-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,37 @@ steps:
Get-Process -Name BackgroundDownload -ErrorAction SilentlyContinue | Stop-Process -Force -ErrorAction SilentlyContinue
displayName: Disable VS Installer background download

# The commit tag in the nuspec requires that we use at least nuget 5.8 (because things break with nuget versions before and Vs 16.8 or later)
# NuGet 6.0 or later is required to enforce package source mappings.
- task: NuGetToolInstaller@1
displayName: Set NuGet version
inputs:
versionSpec: ">=5.8.0"
versionSpec: ">=6.0.0"

# Third-party configs must retain the repository's sources and mappings under network isolation.
- pwsh: |
[xml] $repoConfig = Get-Content -LiteralPath '$(Build.SourcesDirectory)\NuGet.Config'
$root = Join-Path '$(Build.SourcesDirectory)' 'node_modules'
$globs = @((Join-Path $root '*\windows\NuGet.Config'), (Join-Path $root '@*\*\windows\NuGet.Config'))
$configs = Get-ChildItem -Path $globs -File -ErrorAction SilentlyContinue |
Where-Object { Select-String -Path $_.FullName -Pattern 'api\.nuget\.org' -Quiet -ErrorAction SilentlyContinue }
if (-not $configs) {
Write-Host 'No non-compliant node_modules NuGet.Config files found.'
return
}
foreach ($file in $configs) {
[xml] $config = Get-Content -LiteralPath $file.FullName
if (-not $config.configuration.packageSources) { continue }
foreach ($name in @('packageSources', 'packageSourceMapping')) {
$existing = $config.configuration.SelectSingleNode($name)
if ($existing) {
[void] $config.configuration.RemoveChild($existing)
}
[void] $config.configuration.AppendChild($config.ImportNode($repoConfig.configuration.SelectSingleNode($name), $true))
}
$config.Save($file.FullName)
Write-Host "Rewrote $($file.FullName) to use the approved NuGet source mappings."
}
displayName: Enforce compliant NuGet feed in node_modules

- template: set-appx-platforms.yml
parameters:
Expand Down
2 changes: 1 addition & 1 deletion .ado/templates/prepare-js-env.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ steps:
displayName: Ensure npm directory for npx commands
condition: eq(variables['Agent.OS'], 'Windows_NT')

# CI is network-isolated; authenticate to the package feed before install.
# CI is network-isolated; acquire the feed token used by the Verdaccio uplink.
- ${{ if eq(parameters.buildEnvironment, 'Continuous') }}:
- template: auth-npm-feed.yml

Expand Down
17 changes: 16 additions & 1 deletion .ado/templates/react-native-init-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,12 @@ steps:
$configPaths += 'example\NuGet.config'
}

[xml] $repoConfig = Get-Content -LiteralPath '$(Build.SourcesDirectory)\NuGet.Config'
$sources = [ordered]@{
TestFeed = '$(System.DefaultWorkingDirectory)\NugetTestFeed'
'react-native' = 'https://pkgs.dev.azure.com/ms/react-native/_packaging/react-native-public/nuget/v3/index.json'
}
foreach ($source in $repoConfig.configuration.packageSources.add) {
$sources[$source.key] = $source.value
}

foreach ($configPath in $configPaths) {
Expand All @@ -131,6 +134,18 @@ steps:
$element.SetAttribute('value', $source.Value)
[void] $packageSources.AppendChild($element)
}
$existingMapping = $config.configuration.packageSourceMapping
if ($existingMapping) {
[void] $config.configuration.RemoveChild($existingMapping)
}
$mapping = $config.ImportNode($repoConfig.configuration.packageSourceMapping, $true)
$localSource = $config.CreateElement('packageSource')
$localSource.SetAttribute('key', 'TestFeed')
$pattern = $config.CreateElement('package')
$pattern.SetAttribute('pattern', '*')
[void] $localSource.AppendChild($pattern)
[void] $mapping.AppendChild($localSource)
[void] $config.configuration.AppendChild($mapping)
$config.Save((Resolve-Path -LiteralPath $configPath))
Write-Host "Updated $configPath"
}
Expand Down
6 changes: 3 additions & 3 deletions .ado/variables/shared.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ variables:
NPM_CONFIG_YES: false
NPM_CONFIG_CACHE: $(Agent.TempDirectory)/.npmCache

# Route npm/Yarn through the ms/react-native-public feed (npmjs upstream) on isolated agents
NPM_CONFIG_REGISTRY: https://pkgs.dev.azure.com/ms/react-native/_packaging/react-native-public/npm/registry/
YARN_NPM_REGISTRY_SERVER: https://pkgs.dev.azure.com/ms/react-native/_packaging/react-native-public/npm/registry/
# Route npm and Yarn through the anonymous proxy so validation does not require feed authentication.
NPM_CONFIG_REGISTRY: https://packagefeedproxy.microsoft.io/npm/
YARN_NPM_REGISTRY_SERVER: https://packagefeedproxy.microsoft.io/npm/

# Stop React Native DevTools from fetching its standalone shell binary via DotSlash from a
# Facebook CDN on dev-server start, which is blocked under network isolation. The 'dev'
Expand Down
19 changes: 14 additions & 5 deletions NuGet.Config
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,21 @@
</packageRestore>
<packageSources>
<clear />
<!-- Warning: Do not add/change the NuGet feeds here. To be compliant this repo must only rely on this single ADO feed. -->
<!-- Use PackageFeedProxy for nuget.org packages and restrict the ADO feed to the V8 mappings below. -->
<add key="PackageFeedProxy" value="https://packagefeedproxy.microsoft.io/nuget/v3/index.json" />
<add key="react-native" value="https://pkgs.dev.azure.com/ms/react-native/_packaging/react-native-public/nuget/v3/index.json" />

<!-- For local internal development only, this will allow usage of internal WindowsApp.Sdk builds -->
<!--
<add key="Project.Reunion.nuget.internal" value="https://microsoft.pkgs.visualstudio.com/ProjectReunion/_packaging/Project.Reunion.nuget.internal/nuget/v3/index.json" />
-->
<!-- For local internal WindowsAppSDK builds, run vnext\Scripts\EnableInternalWinAppSDKFeed.ps1
to add both the internal source and its package mapping. -->
</packageSources>
<packageSourceMapping>
Comment thread
vmoroz marked this conversation as resolved.
Resolved
<clear />
<packageSource key="PackageFeedProxy">
<package pattern="*" />
</packageSource>
<packageSource key="react-native">
<package pattern="ReactNative.V8Jsi.Windows*" />
<package pattern="Microsoft.JavaScript.V8*" />
</packageSource>
</packageSourceMapping>
</configuration>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"type": "patch",
"comment": "Route repository and CI package restores through PackageFeedProxy",
"packageName": "react-native-windows",
"email": "vmorozov@microsoft.com",
"dependentChangeType": "patch"
}
3 changes: 2 additions & 1 deletion vnext/PropertySheets/WinUI.props
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

<!--
Internal versions are typically only located at: https://microsoft.visualstudio.com/DefaultCollection/ProjectReunion/_artifacts/feed/Project.Reunion.nuget.internal/NuGet/Microsoft.WindowsAppSDK/versions
For local testing of internal versions, modify WinUI3ExperimentalVersion, and comment out the additional nuget source in NuGet.Config
For local testing of internal versions, set WinUI3ExperimentalVersion and run
vnext\Scripts\EnableInternalWinAppSDKFeed.ps1 to add the internal source and its package mapping.
When this version is updated, be sure to update the default for the enableInternalFeed parameter of /.ado/templates/enable-experimental-winui3.yml
-->
<WinUI3ExperimentalVersion Condition="'$(WinUI3ExperimentalVersion)'==''">2.0.0-experimental3</WinUI3ExperimentalVersion>
Expand Down
17 changes: 12 additions & 5 deletions vnext/Scripts/EnableInternalWinAppSDKFeed.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,18 @@ Set-Location -Path $RepoRoot
try
{
[xml] $nugetConfig = Get-Content "NuGet.Config"
$newFeed = $nugetConfig.configuration.packageSources.add.clone()
$newFeed.key = "Project.Reunion.nuget.internal";
$newFeed.value = "https://microsoft.pkgs.visualstudio.com/ProjectReunion/_packaging/Project.Reunion.nuget.internal/nuget/v3/index.json";
$nugetConfig.configuration.packageSources.AppendChild($newFeed)
$nugetConfig.Save("NuGet.Config")
$feedKey = "Project.Reunion.nuget.internal"
$newFeed = $nugetConfig.CreateElement("add")
$newFeed.SetAttribute("key", $feedKey)
$newFeed.SetAttribute("value", "https://microsoft.pkgs.visualstudio.com/ProjectReunion/_packaging/Project.Reunion.nuget.internal/nuget/v3/index.json")
[void] $nugetConfig.configuration.packageSources.AppendChild($newFeed)
$mapping = $nugetConfig.CreateElement("packageSource")
$mapping.SetAttribute("key", $feedKey)
$pattern = $nugetConfig.CreateElement("package")
$pattern.SetAttribute("pattern", "*")
[void] $mapping.AppendChild($pattern)
[void] $nugetConfig.configuration.packageSourceMapping.AppendChild($mapping)
$nugetConfig.Save("$RepoRoot\NuGet.Config")
}
finally
{
Expand Down
4 changes: 2 additions & 2 deletions vnext/Scripts/NuGetRestoreForceEvaluateAllSolutions.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ function Restore-Solution([string] $solution, [string[]] $extraArgs) {

try {
# Some node_modules packages ship a NuGet.Config that re-adds the public nuget.org feed. That
# breaks the repo's single-ADO-feed compliance and trips corporate network blocks on api.nuget.org.
# Strip any nuget.org source so restore only uses the repo's ADO feed.
# bypasses the approved source policy and trips corporate network blocks on api.nuget.org.
# Strip any nuget.org source so restore uses the approved sources and mappings in the root NuGet.Config.
Get-ChildItem -File -Recurse -Path $RepoRoot -Filter NuGet.Config -ErrorAction SilentlyContinue |
Where-Object { $_.FullName -match '\\node_modules\\' } | ForEach-Object {
$configPath = $_.FullName
Expand Down