Repository navigation
Not using "token" on github server #229
Description
Describe the bug
Hi I am using actions/setup-python on a private github server. When I run curl https://github.com/proxy/api.github.com/rate_limit in the self-hosted runner I have 60 remaining resources. When I run the curl command again after uses: actions/setup-python I see that the resource counter goes down to 58. Since I am running this action a lot I eventually exceed my api call limit.
I tried using the key token under the with section with a token I created from github cloud but that did not work. I saw that when we are running on github server we are setting the AUTH variable to undefined. Link to code.
I know we are using ${{ github.token }} by default from the actions.yml file. So I believe the check for github server was added so that tokens from the private github server don't get sent to github cloud. Could we add a second input for the token so that people running on private github servers don't run into the api call limit error? Or if we detect that we are running on a private github server, could we try to use actions/python-versions on the github server instead?
Which version of the action are you using?
-
v1 -
v2 - Some other tag (such as
v2.0.1ormaster)
Environment
- [ x ] self-hosted
- Linux
- Windows
- Mac
If applicable, please specify if you're using a container
Python Versions
- 3.8
- 3.9
To Reproduce
Steps to reproduce the behavior:
- Run github actions with
actions/setup-python@v2on github server a lot - Then we run into
Error: API rate limit exceeded for <IP address>. (But here's the good news: Authenticated requests get a higher rate limit. Check out the documentation for more details.)
github actions yaml file:
name: CI
on:
push:
branches: [ master ]
jobs:
sample_build:
runs-on: [ self-hosted ]
steps:
- name: "rate limit"
run: |
curl -H "Accept: application/vnd.github.v3+json" https://github.com/proxy/api.github.com/rate_limit
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
token: ${{ secrets.GH_CLOUD_TOKEN }}
python-version: 3.9
- name: "rate limit"
run: |
curl -H "Accept: application/vnd.github.v3+json" https://github.com/proxy/api.github.com/rate_limit
Activity
brcrista commentedon Jun 10, 2022
When people are hitting the rate limit, is it from a single self-hosted runner being reused for multiple jobs that call
actions/setup-python? Or is it possible that multiple self-hosted runners are interacting with each other?The action will look for a previously installed version of Python before fetching the manifest file (line 50 of the same file). Given that the rate limit is 60/hr for unauthenticated requests, that seems like a lot of different versions for one runner.
If it is one runner, I think the right fix is just to cache the manifest file (which changes relatively infrequently) with an expiry of 1 hour rather than fetching it every time.
ecs-jnguyen commentedon Jun 10, 2022
In my case, I am running from multiple self-hosted runners. However they are behind a NAT in AWS. This is resulting in their source IP address being the same.
brcrista commentedon Jun 10, 2022
Thanks, makes sense. Caching the manifest file won't work then.
GitHub Connect is the preferred mechanism for linking GHES to github.com. However, it seems clear to me that we won't have time to do that any time soon.
So I think the best approach is just to remove the nulling-out of the
tokeninput for GHES. The description already states that it's for fetching the manifest file, but we should update that to make it clear that the token is always for github.com.brcrista commentedon Jun 15, 2022
Reopening; unfortunately we found a flaw in the approach #437
ecs-jnguyen commentedon Jun 15, 2022
Thanks for keeping me updated.
Do you think we could add a second input parameter that can be used for GHES to pass in the
github.comtoken?brcrista commentedon Jun 21, 2022
That's one way to do it, but having separate
tokenandghes-tokeninputs means one is just going to no-op depending on your endpoint. Actions such assetup-nodewould have to do the same thing.It's clear that there's a feature gap in the
@actions/corepackage -- we're not able to tell whether an input is coming from a default value or if it was passed in. If we had that information, we could checkif (isGhes() && !isDefault), use the token in that case, and continue not to send it otherwise.cc @thboop
brcrista commentedon Aug 30, 2022
Ok, this should be fixed now in
main. If you don't want to wait for the next version update, you can useactions/setup-python@98c991dactions/setup-python@98c991d13f3149457a7c1ac4083885d0d9db98e1.kasuteru commentedon Sep 26, 2022
@brcrista what do you mean by fixed? Our organisation is running into the same problem - multiple runners behind the same IP requesting this and getting the rate limit error. How do I fix this?
brcrista commentedon Sep 26, 2022
@kasuteru can you confirm that you're:
tokeninput?kasuteru commentedon Sep 27, 2022
@brcrista I am using action v4, which is the newest one and should include the fix I think.
But there is a lot of information missing regarding what exactly is needed by this action:
My code is now as follows:
Thanks!
kasuteru commentedon Sep 27, 2022
Update: I realized I can turn on verbosity by setting a secret. Will evaluate further.
brcrista commentedon Sep 27, 2022
@kasuteru
v4doesn't have it yet.(The PR with the fix was merged on Aug 30, but the latest release,
v4.2.0, was released on Aug 2. @marko-zivic-93, could you see about getting a new version released with this fix?)So, you'll have to pull the latest
mainonto your GHES instance from github.com and use that (actions/setup-python@98c991dactions/setup-python@98c991d13f3149457a7c1ac4083885d0d9db98e1).None; you're just making the call as an authenticated user instead of an anonymous user.
There's a rate limit API. This YAML snippet has an example.
You should see some logging if it has to make the request.
kasuteru commentedon Sep 27, 2022
Thank you for the reply. I didn't realize v4 didn't have it yet - that explains it.
With your help, I was able to verify that caching indeed usually works, but not always, and when it doesn't work, it almost always runs into the rate limit. I suspect this is because our company has a lot of runners hidden behind the same IP.
When trying to use your version, the following error came up - looks like one needs to always specify the full version.
After specifying the full hash, I was able to confirm that it now works! Thank you!
I will write a separate post-mortem post for anyone stumbling upon this at a later time.
brcrista commentedon Sep 27, 2022
Thanks! I've updated my previous comments with the full SHA.
If you'd like to add anything that tripped you up to our docs for GHES, that would be very helpful!
kasuteru commentedon Sep 27, 2022
Okay, I'll write a PR with a bit more information on how to tackle this.