Skip to content
Draft
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 .ci/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ stages:
Write-Verbose -Verbose "Importing build utilities (buildtools.psd1)"
Import-Module -Name $(Build.SourcesDirectory)/buildtools.psd1 -Force
#
$(Build.SourcesDirectory)/build.ps1 -Build -Clean -BuildConfiguration Release -BuildFramework 'net472'
$(Build.SourcesDirectory)/build.ps1 -Build -Clean -BuildConfiguration Release -BuildFramework 'net8.0'
displayName: Build Module

- pwsh: |
Expand Down
4 changes: 2 additions & 2 deletions .ci/ci_auto.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ stages:
Write-Verbose -Verbose "Importing build utilities (buildtools.psd1)"
Import-Module -Name $(Build.SourcesDirectory)/buildtools.psd1 -Force
#
# Build for net472 framework
$(Build.SourcesDirectory)/build.ps1 -Build -Clean -BuildConfiguration Release -BuildFramework 'net472'
# Build for net8.0 framework
$(Build.SourcesDirectory)/build.ps1 -Build -Clean -BuildConfiguration Release -BuildFramework 'net8.0'
displayName: Build module

- pwsh: |
Expand Down
4 changes: 2 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ param (
[ValidateSet("Debug", "Release")]
[string] $BuildConfiguration = "Debug",

[ValidateSet("net472")]
[string] $BuildFramework = "net472"
[ValidateSet("net8.0")]
[string] $BuildFramework = "net8.0"
)

Import-Module -Name "$PSScriptRoot/buildtools.psd1" -Force
Expand Down
17 changes: 5 additions & 12 deletions doBuild.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,12 @@ function DoBuild
'Azure.Core'
'Azure.Identity'
'Microsoft.Bcl.AsyncInterfaces'
'Microsoft.Extensions.Caching.Abstractions'
'Microsoft.Extensions.Caching.Memory'
'Microsoft.Extensions.FileProviders.Abstractions'
'Microsoft.Extensions.FileSystemGlobbing'
'Microsoft.Extensions.Logging.Abstractions'
'Microsoft.Extensions.Options'
'Microsoft.Extensions.Primitives'
'Microsoft.Identity.Client'
'Microsoft.Identity.Client.Extensions.Msal'
Expand All @@ -107,20 +111,9 @@ function DoBuild
'NuGet.ProjectModel'
'NuGet.Protocol'
'NuGet.Versioning'
'System.Buffers'
'System.Diagnostics.DiagnosticSource'
'System.IO.FileSystem.AccessControl'
'OrasProject.Oras'
'System.Memory.Data'
'System.Memory'
'System.Numerics.Vectors'
'System.Runtime.CompilerServices.Unsafe'
'System.Security.AccessControl'
'System.Security.Cryptography.ProtectedData'
'System.Security.Principal.Windows'
'System.Text.Encodings.Web'
'System.Text.Json'
'System.Threading.Tasks.Extensions'
'System.ValueTuple'
)

$buildSuccess = $true
Expand Down
1,473 changes: 230 additions & 1,243 deletions src/code/ContainerRegistryServerAPICalls.cs

Large diffs are not rendered by default.

27 changes: 21 additions & 6 deletions src/code/FindHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
using System.Management.Automation;
using System.Net;
using System.Runtime.ExceptionServices;
using System.Runtime.InteropServices;
using System.Text.RegularExpressions;
using System.Threading;

Expand Down Expand Up @@ -188,7 +189,11 @@ public IEnumerable<PSResourceInfo> FindByResourceName(
{
PSRepositoryInfo currentRepository = repositoriesToSearch[i];

bool isAllowed = GroupPolicyRepositoryEnforcement.IsRepositoryAllowed(currentRepository.Uri);
bool isAllowed = true;
if (System.Runtime.InteropServices.RuntimeInformation.IsOSPlatform(System.Runtime.InteropServices.OSPlatform.Windows))
{
isAllowed = GroupPolicyRepositoryEnforcement.IsRepositoryAllowed(currentRepository.Uri);
}

if (!isAllowed)
{
Expand Down Expand Up @@ -376,7 +381,12 @@ public IEnumerable<PSCommandResourceInfo> FindByCommandOrDscResource(
{
PSRepositoryInfo currentRepository = repositoriesToSearch[i];

bool isAllowed = GroupPolicyRepositoryEnforcement.IsRepositoryAllowed(currentRepository.Uri);
bool isAllowed = true;

if (OperatingSystem.IsWindows())
{
isAllowed = GroupPolicyRepositoryEnforcement.IsRepositoryAllowed(currentRepository.Uri);
}

if (!isAllowed)
{
Expand Down Expand Up @@ -583,7 +593,12 @@ public IEnumerable<PSResourceInfo> FindByTag(
{
PSRepositoryInfo currentRepository = repositoriesToSearch[i];

bool isAllowed = GroupPolicyRepositoryEnforcement.IsRepositoryAllowed(currentRepository.Uri);

bool isAllowed = true;
if (OperatingSystem.IsWindows())
{
isAllowed = GroupPolicyRepositoryEnforcement.IsRepositoryAllowed(currentRepository.Uri);
}

if (!isAllowed)
{
Expand Down Expand Up @@ -701,7 +716,7 @@ private IEnumerable<PSResourceInfo> SearchByNames(ServerApiCall currentServer, R
_cmdletPassedIn.WriteDebug("No version specified, package name is '*'");
// Example: Find-PSResource -Name "*"

// Note: Just for resources from V2 servers, specifically PSGallery, if the resource is unlisted and was requested non-explicitly
// Note: Just for resources from V2 servers, specifically PSGallery, if the resource is unlisted and was requested non-explicitly
// (i.e requested name has wildcard) the resource should not be returned and ResponseUtil.ConvertToPSResourceResult() call needs to be informed of this.
// In all other cases, return the resource regardless of whether it was requested explicitly or not.
bool isResourceRequestedWithWildcard = isV2Resource;
Expand Down Expand Up @@ -752,7 +767,7 @@ private IEnumerable<PSResourceInfo> SearchByNames(ServerApiCall currentServer, R
// Example: Find-PSResource -Name "Az*" -Tag "Storage"
_cmdletPassedIn.WriteDebug("No version specified, package name contains a wildcard.");

// Note: Just for resources from V2 servers, specifically PSGallery, if the resource is unlisted and was requested non-explicitly
// Note: Just for resources from V2 servers, specifically PSGallery, if the resource is unlisted and was requested non-explicitly
// (i.e requested name has wildcard) the resource should not be returned and ResponseUtil.ConvertToPSResourceResult() call needs to be informed of this.
// In all other cases, return the resource regardless of whether it was requested explicitly or not.
bool isResourceRequestedWithWildcard = isV2Resource;
Expand Down Expand Up @@ -1173,7 +1188,7 @@ internal IEnumerable<PSResourceInfo> FindDependencyPackages(
}
else if(dep.VersionRange.MaxVersion != null && dep.VersionRange.MinVersion != null && dep.VersionRange.MaxVersion.OriginalVersion.Equals(dep.VersionRange.MinVersion.OriginalVersion))
{
string depPkgVersion = dep.VersionRange.MaxVersion.OriginalVersion;
string depPkgVersion = dep.VersionRange.MaxVersion.OriginalVersion;
FindResults responses = currentServer.FindVersion(dep.Name, version: dep.VersionRange.MaxVersion.ToNormalizedString(), _type, out ErrorRecord errRecord);
if (errRecord != null)
{
Expand Down
14 changes: 13 additions & 1 deletion src/code/GroupPolicyRepositoryEnforcement.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Versioning;
using Microsoft.PowerShell.PSResourceGet.UtilClasses;
using Microsoft.Win32;

Expand All @@ -14,6 +15,7 @@ namespace Microsoft.PowerShell.PSResourceGet.Cmdlets
/// <summary>
/// This class is used to enforce group policy for repositories.
/// </summary>
[SupportedOSPlatform("windows")]
public class GroupPolicyRepositoryEnforcement
{
const string userRoot = "HKEY_CURRENT_USER";
Expand All @@ -29,6 +31,7 @@ private GroupPolicyRepositoryEnforcement()
/// </summary>
///
/// <returns>True if the group policy is enabled, false otherwise.</returns>
[SupportedOSPlatform("windows")]
public static bool IsGroupPolicyEnabled()
{
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
Expand Down Expand Up @@ -57,6 +60,7 @@ public static bool IsGroupPolicyEnabled()
/// </summary>
/// <returns>Array of allowed URIs.</returns>
/// <exception cref="InvalidOperationException">Thrown when the group policy is not enabled.</exception>
[SupportedOSPlatform("windows")]
public static Uri[]? GetAllowedRepositoryURIs()
{
if (Environment.OSVersion.Platform != PlatformID.Win32NT)
Expand Down Expand Up @@ -92,6 +96,7 @@ public static bool IsGroupPolicyEnabled()
}
}

[SupportedOSPlatform("windows")]
internal static bool IsRepositoryAllowed(Uri repositoryUri)
{
bool isAllowed = false;
Expand All @@ -113,6 +118,7 @@ internal static bool IsRepositoryAllowed(Uri repositoryUri)
return isAllowed;
}

[SupportedOSPlatform("windows")]
private static List<KeyValuePair<string, Uri>>? ReadGPFromRegistry()
{
List<KeyValuePair<string, Uri>> allowedRepositories = new List<KeyValuePair<string, Uri>>();
Expand Down Expand Up @@ -169,7 +175,13 @@ internal static bool IsRepositoryAllowed(Uri repositoryUri)
throw new InvalidOperationException("Invalid registry value.");
}

string valueString = value.ToString();
string? valueString = value.ToString();

if (string.IsNullOrEmpty(valueString))
{
throw new InvalidOperationException("Invalid registry value.");
}

var kvRegValue = ConvertRegValue(valueString);
allowedRepositories.Add(kvRegValue);
}
Expand Down
9 changes: 7 additions & 2 deletions src/code/InstallHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -270,7 +270,12 @@ private List<PSResourceInfo> ProcessRepositories(
{
PSRepositoryInfo currentRepository = listOfRepositories[i];

bool isAllowed = GroupPolicyRepositoryEnforcement.IsRepositoryAllowed(currentRepository.Uri);
bool isAllowed = true;

if (OperatingSystem.IsWindows())
{
isAllowed = GroupPolicyRepositoryEnforcement.IsRepositoryAllowed(currentRepository.Uri);
}

if (!isAllowed)
{
Expand Down Expand Up @@ -659,7 +664,7 @@ private List<PSResourceInfo> InstallPackages(
ErrorCategory.InvalidOperation,
_cmdletPassedIn));

throw e;
throw;
}
finally
{
Expand Down
8 changes: 4 additions & 4 deletions src/code/Microsoft.PowerShell.PSResourceGet.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
<AssemblyVersion>1.1.0.1</AssemblyVersion>
<FileVersion>1.1.0.1</FileVersion>
<InformationalVersion>1.1.0.1</InformationalVersion>
<TargetFrameworks>net472</TargetFrameworks>
<LangVersion>9.0</LangVersion>
<TargetFrameworks>net8.0</TargetFrameworks>
<LangVersion>12.0</LangVersion>
<SuppressNETCoreSdkPreviewMessage>true</SuppressNETCoreSdkPreviewMessage>
</PropertyGroup>

Expand All @@ -21,12 +21,12 @@
<PackageReference Include="NuGet.ProjectModel" Version="6.9.1" />
<PackageReference Include="NuGet.Protocol" Version="6.9.1" />
<PackageReference Include="PowerShellStandard.Library" Version="7.0.0-preview.1" />
<PackageReference Include="System.Net.Http" Version="4.3.4" />
<PackageReference Include="System.Text.Json" Version="8.0.6" />
<PackageReference Include="Microsoft.CSharp" Version="4.7.0" />
<PackageReference Include="Azure.Identity" Version="1.14.2" />
<PackageReference Include="OrasProject.Oras" Version="0.5.0" />
<PackageReference Include="Microsoft.Extensions.Caching.Memory" Version="8.0.1" />
<PackageReference Include="System.Security.Cryptography.Pkcs" Version="6.0.5" />
<Reference Include="System.Web" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading
Loading