OCI Authentication Hardcoded for Azure
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 5/5
- Thời gian dự kiến
- Hơn một tuần
- Mức phù hợp với người mới
- 42/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Khá rõ ràng
- Mức độ hoạt động
- Đình trệ
- Công nghệ
- csharp, powershell
- Lĩnh vực
- authentication, cli
Hướng nghiên cứu
Bắt đầu bằng cách đọc src/code/ContainerRegistryServerAPICalls.cs, đặc biệt là GetContainerRegistryAccessToken và các helper yêu cầu token, sau đó tái hiện lỗi GHCR trong issue. So sánh luồng ACR hiện có với ví dụ Get-OciBearerToken được liên kết trong báo cáo. Công việc được xem là hoàn tất khi các lượt cài đặt OCI ẩn danh và có thông tin xác thực hoạt động với các registry tương thích mà không làm hỏng việc xác thực ACR.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
The authentication mechanisms used on OCI/Container Registries is essentially hardcoded to only work for ACR based registries. This makes it impossible to use PSResourceGet with other OCI registries that don't follow the ACR specific auth flow.
For example it is not possible to install from GitHub's Container/OCI repository. I've got a test nupkg published at https://github.com/jborean93/PowerShell-PublishTest/pkgs/container/publishtest and this is what happens when you try to install it with and without a credential with PSResourceGet 1.2.0-rc3
Register-PSResourceRepository -Name GHCR -Uri https://ghcr.io -ApiVersion ContainerRegistry
# Try it with anonymous access/no credential
Install-PSResource -Name jborean93/publishtest -Repository GHCR -Debug -Verbose -TrustRepository
$Error[1] | Select-Object *
DEBUG: Package version parsed as NuGet version: '1.2.0-rc3'
DEBUG: Reading package metadata from: '/home/jborean/.local/share/powershell/Modules/Microsoft.PowerShell.PSResourceGet/1.2.0/PSGetModuleInfo.xml'
DEBUG: In InstallPSResource::ProcessInstallHelper()
DEBUG: In InstallHelper::BeginInstallPackages()
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::GetContainerRegistryAccessToken()
DEBUG: In ContainerRegistryServerAPICalls::IsContainerRegistryUnauthenticated()
DEBUG: Is repository unauthenticated: False
DEBUG: In ContainerRegistryServerAPICalls::GetContainerRegistryRefreshToken()
DEBUG: In ContainerRegistryServerAPICalls::GetHttpResponseJObjectUsingContentHeaders()
Install-PSResource: Response returned error with status code MethodNotAllowed: Method Not Allowed.
VERBOSE: Attempting to delete '/tmp/a36c194f-1a8b-4239-8ec3-ae8c0e2f5038'
VERBOSE: Successfully deleted '/tmp/a36c194f-1a8b-4239-8ec3-ae8c0e2f5038'
Install-PSResource: Package(s) 'jborean93/publishtest' could not be installed from repository 'GHCR'.
# $Error[1]
PSMessageDetails :
Exception : System.Exception: Response returned error with status code MethodNotAllowed: Method Not Allowed.
at Microsoft.PowerShell.PSResourceGet.ContainerRegistryServerAPICalls.SendRequestAsync(HttpRequestMessage
message) in C:\__w\1\s\PSResourceGet\src\code\ContainerRegistryServerAPICalls.cs:line 1170
at Microsoft.PowerShell.PSResourceGet.ContainerRegistryServerAPICalls.GetHttpResponseJObjectUsingContentHead
ers(String url, HttpMethod method, String content, Collection`1 contentHeaders, ErrorRecord& errRecord) in
C:\__w\1\s\PSResourceGet\src\code\ContainerRegistryServerAPICalls.cs:line 1045
TargetObject : Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource
CategoryInfo : InvalidResult: (Microsoft.PowerShel…s.InstallPSResource:InstallPSResource) [Install-PSResource], Exception
FullyQualifiedErrorId : HttpRequestCallFailure,Microsoft.PowerShell.PSResourceGet.Cmdlets.InstallPSResource
ErrorDetails :
InvocationInfo : System.Management.Automation.InvocationInfo
ScriptStackTrace : at <ScriptBlock>, <No file>: line 1
PipelineIterationInfo : {0, 1}
The same error occurs when you use a -Credential with a GitHub username/PAT. The error may vary depending on whether there is an Az context available as PSResourceGet falls back on this for all registries.
The reason is because GetContainerRegistryAccessToken is coded to do the following
- Use a cached token from a previous request (not applicable here)
- Retrieve the Azure AccessToken and TenantId from the SecretStore if a credential is set on the registered repository (not applicable here)
- Checks if the registry allows unauthenticated requests (false here)
- The logic for getting an anonymous token is also ACR specific and won't work for other OCI repositories
- Fallback to getting the Az Access Token from
DefaultAzureCredential- If none available it will fail here
- In my case I do have an az token available
- If we have an Az AccessToken from SecureStore or the environment use an ACR OAuth2 flow to get the ACR bearer token
- This auth flow is ACR specific and fails with the error you see above
- If not AccessToken then it fails
The 3 problems I see here
- The anonymous token workflow needs to be updated to work generically
- The
oauth2/exchangeworkflow that ultimately gets the ACR bearer token from an Az AccessToken needs to be selectively done (some flag on the registered repository maybe?) - If a credential is passed in then the
oauth2/exchangeflow should not be done unless- The incoming credential is an Az AccessToken from something like
Get-AzAccessToken - Not if its an Azure client id and secret as that is just used directly in the token exchange
- The incoming credential is an Az AccessToken from something like
I'm hoping to send through a PR to try and fix this at least for some of the scenarios but wanted to raise the issue to at least summarise what is happening. I've written Get-OciBearerToken to show the workflow that I've found works for ACR, MAR, GHCR, and hopefully any other OCI compliant registry. I've used this function to
- push a new package for ACR, GHCR
- GHCR uses the GitHub username and PAT with
write:packagesset or through the GHAGITHUB_TOKENvalue - ACR can use an app client_id and secret value directly
- ACR can use the AccessToken returned by
Get-AzAccessTokenfor any valid connection using theoauth2/exchangeto get the ACR refresh token
- GHCR uses the GitHub username and PAT with
- pull from ACR, MAR, GHDR
- Using anonymous access
- With the same credential as push
The biggest hiccup is figuring out whether we have an Az AccessToken to do the oauth2/exchange step.
Expected behavior
Module can be installed with no credential when the registry allows it or with a credential when it is private.
Actual behavior
See above (fails)
Error details
See above
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
- Ngôn ngữ chính
- C#
- Star
- 577
- Fork
- 114
- Merge trung bình
- 23 giờ 17 phút
- Pull request đã merge (30 ngày)
- 8
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của PowerShell/PSResourceGet
-
Create parent directories only after the containment check in InstallHelper.TryExtractToDirectoryĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
PowerShell/PSResourceGet#2056 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
feature_request
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
PowerShell/PSResourceGet#2013 · 3 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Needs-Triage
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
PowerShell/PSResourceGet#2059 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Use GitHub app token to authenticate to GitHub resourcesCó thể đã có người làm @adityapatwardhan đã nhận 11 ngày trước. Đang mởfeature_request Needs-Triage
PowerShell/PSResourceGet#2057 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Needs-Triage
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 68/100
PowerShell/PSResourceGet#2055 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của PowerShell/PSResourceGet
Issue tương tự
-
Broken Text debugger displayĐang mởneeds triage
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
spectreconsole/spectre.console#2221 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 92/100
-
area/navigationview 🧭 difficulty/starter 🚀 good first issue kind/bug platform/all project/navigation-lifecycle 🧬 triage/untriaged
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
unoplatform/uno#24925 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
PhilippC/keepass2android#3315 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
DamianEdwards/ghcp-spend-tray#39 ·
Maintainer thường phản hồi trong vòng 1 ngày