Hacktoberfest 2026 : les issues que les mainteneurs ont marquées pour octobre, ouvertes et accessibles aux débutants. Parcourir les issues Hacktoberfest

OCI Install Strips Prefix on Package

Ouverte
#1,947 3 commentaires 0 réactions 0 personnes assignées Voir sur GitHub

Les mainteneurs répondent en général sous 1 jour

Personne n'a encore pris cette issue.

Évaluation

Difficulté
3/5
Temps estimé
1-2 jours
Accessibilité débutants
48/100
Type d'issue
Bug
Clarté
Plutôt claire
Activité
À l'abandon
Stack technique
csharp, powershell
Domaine
tooling

Piste de recherche

Commencez par ContainerRegistryServerAPICalls, en suivant InstallPackage et InstallVersion jusqu’à GetContainerRegistryRepositoryManifest et au traitement des métadonnées du manifeste. Reproduisez l’installation de GHCR avec un nom préfixé tel que jborean93/publishtest, puis vérifiez que les requêtes de manifeste suivantes conservent le préfixe tandis que l’artefact local utilise le nom du module.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Description

Container-Galleries Needs-Triage
Prerequisites
  • Write a descriptive title.
  • Make sure you are able to repro it on the latest released version
  • Search the existing issues.
Steps to reproduce

When trying to install a package from an OCI registry that contains a prefix, the package prefix is removed when it goes to download the nupkg blob.

Due to https://github.com/PowerShell/PSResourceGet/issues/1946 I've had to add a hack that fixes up the authentication to GHCR. This uses PSNetDetour to patch the token logic. If/when that is ever fixed then this patch isn't needed to replicate this error.

$repoParams = @{
    Name = 'GHCR'
    Uri = 'https://ghcr.io/'
    ApiVersion = 'ContainerRegistry'
}
Register-PSResourceRepository @repoParams

$psGetCmd = Get-Command -Name Install-PSResource -Module Microsoft.PowerShell.PSResourceGet
$psGetType = $psGetCmd.ImplementingType.Assembly.GetType(
    'Microsoft.PowerShell.PSResourceGet.ContainerRegistryServerAPICalls')

$getRegistryTokenMeth = $psGetType.GetMethod(
    'GetContainerRegistryAccessToken',
    [Reflection.BindingFlags]'Instance, NonPublic',
    [type[]]@([bool], [bool], [System.Management.Automation.ErrorRecord].MakeByRefType()))

$sendRequestMeth = $psGetType.GetMethod(
    'GetHttpResponseJObjectUsingDefaultHeaders',
    [Reflection.BindingFlags]'Instance, NonPublic',
    [type[]]@(
        [string],
        [Net.Http.HttpMethod],
        [Collections.ObjectModel.Collection[System.Collections.Generic.KeyValuePair[string, string]]],
        [System.Management.Automation.ErrorRecord].MakeByRefType(),
        [bool]))

Use-NetDetourContext {
    # Fixes logic for getting anonymous token for GHCR
    New-NetDetourHook -Method $getRegistryTokenMeth -Hook {
        param ([bool]$NeedCatalogAccess, [bool]$IsPushOperation, [ref]$ErrorRecord)

        try {
            $registryUri = "https://ghcr.io/v2/"
            $resp = Invoke-WebRequest -Uri $registryUri -SkipHttpErrorCheck
            $bearer = $resp.Headers['WWW-Authenticate'] | Select-Object -First 1
            if (-not $bearer) {
                throw "No WWW-Authenticate found in response headers for '$registryUri'"
            }

            if ($bearer -match 'realm="([^"]+)"') {
                $realm = $matches[1]
            } else {
                throw "Could not extract realm from WWW-Authenticate header '$bearer'"
            }

            if ($bearer -match 'service="([^"]+)"') {
                $service = $matches[1]
            } else {
                throw "Could not extract service from WWW-Authenticate header '$bearer'"
            }

            $tokenUri = "${realm}?service=${service}&client_id=testclient&scope=repository:jborean93/publishtest:pull"
            $tokenResponse = Invoke-WebRequest -Uri $tokenUri -Method Get
            ($tokenResponse.Content | ConvertFrom-Json).token
        }
        catch {
            $_.ErrorDetails = "Failed to retrieve anonymous token: $_"
            $ErrorRecord.Value = $_
        }
    }

    # Prints the URIs requested to show what the problem is
    New-NetDetourHook -Method $sendRequestMeth -Hook {
        param($Url, $Method, $DefaultHeaders, $ErrRecord, $UsePagination)

         [Console]::WriteLine("$Method -> $Url")
        , $Detour.Invoke($Url, $Method, $DefaultHeaders, $ErrRecord, $UsePagination)
    }

    Install-PSResource -Name jborean93/publishtest -Repository GHCR -TrustRepository -Verbose -Debug
}
Expected behavior
Package is installed
Actual behavior
DEBUG: Parameters passed in >>> Name: 'jborean93/publishtest'; VersionRange: ''; NuGetVersion: ''; VersionType: 'NoVersion'; Version: ''; Prerelease: 'False'; Repository: 'GHCR'; AcceptLicense: 'False'; Quiet: 'False'; Reinstall: 'False'; TrustRepository: 'True'; NoClobber: 'False'; AsNupkg: 'False'; IncludeXml 'True'; SavePackage 'False'; TemporaryPath ''; SkipDependencyCheck: 'False'; AuthenticodeCheck: 'False'; PathsToInstallPkg: '/home/jborean/.local/share/powershell/Modules,/home/jborean/.local/share/powershell/Scripts'; Scope 'CurrentUser'
DEBUG: In InstallHelper::ProcessRepositories()
VERBOSE: Setting Secret Management network credentials
VERBOSE: Attempting to search for packages in 'GHCR'
DEBUG: In InstallHelper::InstallPackages()
DEBUG: In InstallHelper::InstallPackage()
DEBUG: In ContainerRegistryServerAPICalls::FindName()
DEBUG: In ContainerRegistryServerAPICalls::FindPackagesWithVersionHelper()
DEBUG: In ContainerRegistryServerAPICalls::FindContainerRegistryImageTags()                                             
GET -> https://ghcr.io/v2/jborean93/publishtest/tags/list
DEBUG: In ContainerRegistryServerAPICalls::GetHttpResponseJObjectUsingDefaultHeaders()
DEBUG: In ContainerRegistryServerAPICalls::GetPackagesWithRequiredVersion()
DEBUG: 'jborean93/publishtest' version parsed as '0.1.0'
DEBUG: 'jborean93/publishtest' version parsed as '0.1.1'
DEBUG: 'jborean93/publishtest' version parsed as '0.1.2'
DEBUG: In ContainerRegistryServerAPICalls::GetContainerRegistryMetadata()
DEBUG: In ContainerRegistryServerAPICalls::FindContainerRegistryManifest()
DEBUG: GET manifest url:  https://ghcr.io/v2/jborean93/publishtest/manifests/0.1.2
GET -> https://ghcr.io/v2/jborean93/publishtest/manifests/0.1.2
DEBUG: In ContainerRegistryServerAPICalls::GetHttpResponseJObjectUsingDefaultHeaders()
DEBUG: In ContainerRegistryServerAPICalls::GetMetadataProperty()
DEBUG: 'jborean93/publishtest' version parsed as '0.1.2'

Confirm
Are you sure you want to perform this action?
Performing the operation "Install-PSResource" on target "Package to install: 'PublishTest', version: '0.1.2'".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): y
DEBUG: In ContainerRegistryServerAPICalls::InstallPackage()
DEBUG: In ContainerRegistryServerAPICalls::InstallVersion()
VERBOSE: Getting manifest for publishtest - 0.1.2                                                                       
DEBUG: In ContainerRegistryServerAPICalls::GetContainerRegistryRepositoryManifest()
GET -> https://ghcr.io/v2/publishtest/manifests/0.1.2
DEBUG: In ContainerRegistryServerAPICalls::GetHttpResponseJObjectUsingDefaultHeaders()
Use-NetDetourContext: Response returned error with status code BadRequest: Bad Request.
VERBOSE: Attempting to delete '/tmp/43de5d14-17ef-4a1a-9137-b0b3fa84dd3d'
VERBOSE: Successfully deleted '/tmp/43de5d14-17ef-4a1a-9137-b0b3fa84dd3d'
Use-NetDetourContext: Package(s) 'jborean93/publishtest' could not be installed from repository 'GHCR'.

We can see that

  • It is able to find the tags/versions for this package
  • It selects the latest version 0.1.2
    • GET -> https://ghcr.io/v2/jborean93/publishtest/tags/list
  • It is able to retrieve the OCI manifest through
    • GET -> https://ghcr.io/v2/jborean93/publishtest/manifests/0.1.2
  • It derives the module name through that manifest as PublishTest based on the confirmation message
  • The step to gettings the manifest after the confirmation fails with a HTTP 400
    • GET -> https://ghcr.io/v2/publishtest/manifests/0.1.2

This step is failing because the URL used no longer contains the package prefix (jborean93) and thus isn't a valid request. The code when calling InstallPackage after it has found the version now uses the module name contained in the manifest which is just PublishTest rather than the original package name provided with the prefix.

The solution to this is to not update the package name from the manifest details and just use the module name on the downloaded artifact locally.

Error details
Exception             : 
    Type    : Microsoft.PowerShell.PSResourceGet.UtilClasses.ResourceNotFoundException
    Message : Package(s) 'jborean93/publishtest' could not be installed from repository 'GHCR'.
    HResult : -2146233088
TargetObject          : Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource
CategoryInfo          : InvalidData: (Microsoft.PowerShel…s.InstallPSResource:InstallPSResource) [Use-NetDetourContext], 
ResourceNotFoundException
FullyQualifiedErrorId : InstallPackageFailure,PSNetDetour.Commands.UseNetDetourContext
InvocationInfo        : 
    MyCommand        : Use-NetDetourContext
    ScriptLineNumber : 1
    OffsetInLine     : 1
    HistoryId        : 7
    Line             : Use-NetDetourContext {
                       
    Statement        : Use-NetDetourContext {
                       # Fixes logic for getting anonymous token for GHCR
                       New-NetDetourHook -Method $getRegistryTokenMeth -Hook {
                       param ([bool]$NeedCatalogAccess, [bool]$IsPushOperation, [ref]$ErrorRecord)
                       
                       try {
                       $registryUri = "https://ghcr.io/v2/"
                       $resp = Invoke-WebRequest -Uri $registryUri -SkipHttpErrorCheck
                       $bearer = $resp.Headers['WWW-Authenticate'] | Select-Object -First 1
                       if (-not $bearer) {
                       throw "No WWW-Authenticate found in response headers for '$registryUri'"
                       }
                       
                       if ($bearer -match 'realm="([^"]+)"') {
                       $realm = $matches[1]
                       } else {
                       throw "Could not extract realm from WWW-Authenticate header '$bearer'"
                       }
                       
                       if ($bearer -match 'service="([^"]+)"') {
                       $service = $matches[1]
                       } else {
                       throw "Could not extract service from WWW-Authenticate header '$bearer'"
                       }
                       
                       $tokenUri = "${realm}?service=${service}&client_id=testclient&scope=repository:jborean93/publishtest:pull"
                       $tokenResponse = Invoke-WebRequest -Uri $tokenUri -Method Get
                       ($tokenResponse.Content | ConvertFrom-Json).token
                       }
                       catch {
                       $_.ErrorDetails = "Failed to retrieve anonymous token: $_"
                       $ErrorRecord.Value = $_
                       }
                       } -State @{ Name = $Name }
                       
                       Install-PSResource -Name jborean93/publishtest -Repository GHCR -TrustRepository -Verbose -Debug
                       }
    PositionMessage  : At line:1 char:1
                       + Use-NetDetourContext {
                       + ~~~~~~~~~~~~~~~~~~~~~~
    InvocationName   : Use-NetDetourContext
    CommandOrigin    : Internal
ScriptStackTrace      : at <ScriptBlock>, <No file>: line 36
                        at <ScriptBlock>, <No file>: line 1
                        at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : 
      0
      1
Environment data
ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Binary     1.2.0      rc3        Microsoft.PowerShell.PSResourceGet  {Compress-PSResource, Find-PSResource, Get-InstalledPSResource, G…


Name                           Value
----                           -----
PSVersion                      7.5.1
PSEdition                      Core
GitCommitId                    7.5.1
OS                             Fedora Linux 43 (Server Edition)
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Visuals

No response

Langage dominant
C#
Étoiles
577
Forks
114
Merge moyen
23 h 17 min
PR mergées (30 j)
8

Préparer son environnement

Par où commencer

  1. Lisez l'issue en entier, puis le guide de contribution du projet.
  2. Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
  3. Forkez le dépôt et travaillez sur une branche.
  4. Ouvrez une pull request qui référence le numéro de l'issue.

Autres issues de PowerShell/PSResourceGet

Toutes les issues de PowerShell/PSResourceGet

Issues similaires

Plus d'issues C#

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.