You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Invalid argument error by requesting packages for an organization #9606
If i would like to list packages for an organization with package type container, i get an error about an invalid argument. This happens in a GitHub action workflow. I don't think it's an authorization issue, because i tried with other package types (npm, docker) and it works just like fine. What am i missing?
$ gh --version
gh version 2.55.0 (2024-08-20)
https://github.com/cli/cli/releases/tag/v2.55.0
Steps to reproduce the behavior
Workflow job:
get-images:
runs-on: ubuntu-latest
steps:
- name: Get iamges
run: |
gh api -H "Accept: application/vnd.github+json" -H "X-GitHub-Api-Version: 2022-11-28" "/orgs/${ORG}/packages?package_type=container"
Error:
gh: Invalid argument. (HTTP 400)
{"message":"Invalid argument.","documentation_url":"https://docs.github.com/rest/packages/packages#list-packages-for-an-organization","status":"400"}
Error: Process completed with exit code 1.
Expected vs actual behavior
The container type packages should be listed correctly.
Logs
Paste the activity from your command line. Redact if needed.
Also having the same issue, although I'm performing the request via curl, but I have the same value on the X-GitHub-Api-Version header
The strange thing is that by performing the exact same command on my local computer I get a 200
@pukanszkypeter-x @andre-s-pedrosa-alb : thanks for following up on this issue! let's see how we can set your straight. 🤔
Questions
What happens if you change ${ORG} in your example?
This looks like an env var within a shell environment, however I don't know where you're setting this. You can try creating the env var via env field on the step from the GitHub Actions github context
How are you authenticating to gh when trying to access this information? What scopes are available in gh auth status?
GitHub Packages is somewhat an umbrella for the various package managers that GitHub supports, each with different degree of permissions based on org-based or repo-based packages. I want to make sure you have the necessary permissions.
OAuth app tokens and personal access tokens (classic) need the read:packages scope to use this endpoint. If the package_type belongs to a GitHub Packages registry that only supports repository-scoped permissions, the repo scope is also required. For the list of these registries, see "About permissions for GitHub Packages."
@Mathieu-Ferraton : Thank you for the additional details, this definitely does help!
Good news, bad news time:
This apparently is a known limitation behind this endpoint using the GitHub Actions automatic token
There is an issue on the package registry team's backlog but no idea on timeframe when it will be addressed
Cases like this have required a workaround of using a PAT when working with GitHub Packages
Sadly, the endpoint doesn't provide a helpful response for the type of token used. 😞
Beyond this bit of help, I don't think there is anything the GitHub CLI through gh api can do to improve the situation as this is a pure GitHub API endpoint issue.
Reacted by Mark Iannucci, depado, Leonid Lunin, Dave Smits, Bart Guijt and John Naef
@andyfeller , thank you for the honesty here. Do you know if we will run into the same error if we use a GH App token as recommended instead of the PAT?
Reacted by Andy Feller, Leonid Lunin and John Naef
I also tried using a fine grained access token and there isn't a scope for packages which is tracked in github/roadmap#558. So it looks like the only way to do this is to use a classic PAT :-[
To use or manage a package hosted by a package registry, you must use a personal access token (classic) with the appropriate scope, and your personal account must have appropriate permissions.
Self answering my question above... I tested it out and received the same error. Can you share this feedback with the registry team?
Activity
andre-s-pedrosa-alb commentedon Sep 16, 2024
Also having the same issue, although I'm performing the request via curl, but I have the same value on the X-GitHub-Api-Version header
The strange thing is that by performing the exact same command on my local computer I get a 200
andyfeller commentedon Sep 16, 2024
@pukanszkypeter-x @andre-s-pedrosa-alb : thanks for following up on this issue! let's see how we can set your straight. 🤔
Questions
What happens if you change
${ORG}in your example?This looks like an env var within a shell environment, however I don't know where you're setting this. You can try creating the env var via
envfield on the step from the GitHub ActionsgithubcontextHow are you authenticating to
ghwhen trying to access this information? What scopes are available ingh auth status?GitHub Packages is somewhat an umbrella for the various package managers that GitHub supports, each with different degree of permissions based on org-based or repo-based packages. I want to make sure you have the necessary permissions.
For the List packages for an organization, it mentions specifics too:
For more information, see https://docs.github.com/en/packages/learn-github-packages/about-permissions-for-github-packages
What happens if you execute
gh api -X GET /orgs/aws/packages -f package_type=containereliot-pitman-bah commentedon Sep 17, 2024
I am getting the same issue via curl
Mathieu-Ferraton commentedon Oct 21, 2024
@andyfeller
Same issue with both curl and gh api:
Answers to your questions:
Deleting packages using this token works just fine, so I would expect listing to be OK
-> works
All requests performed from my local workstation using PAT work just fine.
I hope this helps...
andyfeller commentedon Oct 23, 2024
@Mathieu-Ferraton : Thank you for the additional details, this definitely does help!
Good news, bad news time:
Sadly, the endpoint doesn't provide a helpful response for the type of token used. 😞
Beyond this bit of help, I don't think there is anything the GitHub CLI through
gh apican do to improve the situation as this is a pure GitHub API endpoint issue.MarkIannucci commentedon Nov 7, 2024
@andyfeller , thank you for the honesty here. Do you know if we will run into the same error if we use a GH App token as recommended instead of the PAT?
MarkIannucci commentedon Nov 7, 2024
Self answering my question above... I tested it out and received the same error. Can you share this feedback with the registry team?
MarkIannucci commentedon Nov 7, 2024
I also tried using a fine grained access token and there isn't a scope for packages which is tracked in github/roadmap#558. So it looks like the only way to do this is to use a classic PAT :-[
andyfeller commentedon Nov 8, 2024
@MarkIannucci : I'm pretty sure this is limited to only classic PATs at the moment as explained in About scopes and permissions for package registries; so no fine-grained PAT, no automatic token in GitHub Actions, no GitHub or OAuth app.
🖖 I'm sure this is a well known limitation but will do. Sadly, I don't know where this is on their priority as all of the Packages items on the public roadmap are in the Future column.
ci(retention): sweep packages named by the published nightly tree (#4826