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
We have a GitHub App that we used to authenticate our coder users using OAuth. Since few days ago we are receiving many complaints about hitting rate limits. Whenever we try to sign in with GitHub we receive the following error:
{
"message": "Internal error exchanging Oauth code.",
"detail": "oauth2: cannot fetch token: 429 Too Many Requests .....
}
It seems we are hitting the "secondary rate limit" but we don't have a way to check its status, neither to know what is causing this. Do you know what could be the issue?
After contacting GitHub support, we were able to see a spike in the number of OAuth requests Coder performed against GitHub API. After talking to the whole team, we didn't perform anything special during this period of time.
Can be some edge case in Coder code that performs many OAuth negotiations?
If this scenario happens again, we will share Coder logs.
I don't think there's a scenario where we'd be spamming the API... but maybe we have a bug that could cause a redirect loop or something, and a user just left their browser up?
Has this only happened once? Or is there a way we can seemingly trigger it?
We experienced two times in the last two weeks, but we have not seen any pattern, yet. If we experience again this issue, we will go to Coder logs to retrieve more information and context to be able to understand what is going on.
I am unable to reproduce this locally. We might want to add some debug/logging/instrumentation and then try to figure it out when we hit it in dogfood.
Curiously enough, with the new instrumentation it appears that we're hitting the unauthenticated rate limit:
# HELP coderd_oauth2_external_requests_rate_limit_next_reset_unix Unix timestamp for when the next interval starts
# TYPE coderd_oauth2_external_requests_rate_limit_next_reset_unix gauge
coderd_oauth2_external_requests_rate_limit_next_reset_unix{name="github",resource="core-unauthorized"} 1.704974981e+09
# HELP coderd_oauth2_external_requests_rate_limit_remaining The remaining number of allowed requests in this interval.
# TYPE coderd_oauth2_external_requests_rate_limit_remaining gauge
coderd_oauth2_external_requests_rate_limit_remaining{name="github",resource="core-unauthorized"} 58
# HELP coderd_oauth2_external_requests_rate_limit_reset_in_seconds Seconds until the next interval
# TYPE coderd_oauth2_external_requests_rate_limit_reset_in_seconds gauge
coderd_oauth2_external_requests_rate_limit_reset_in_seconds{name="github",resource="core-unauthorized"} 3599.544220509
# HELP coderd_oauth2_external_requests_rate_limit_total The total number of allowed requests per interval.
# TYPE coderd_oauth2_external_requests_rate_limit_total gauge
coderd_oauth2_external_requests_rate_limit_total{name="github",resource="core-unauthorized"} 60
@Emyrk it could be due to running the coder docs workspace. It runs yarn dev server that calls GitHub API extensively and I hit the rate limit and got blocked multiple times. I can run it again and probably you will see the spikes.
@Emyrk it could be due to running the coder docs workspace. It runs yarn dev server that calls GitHub API extensively and I hit the rate limit and got blocked multiple times. I can run it again and probably you will see the spikes.
@Emyrk it could be due to running the coder docs workspace. It runs yarn dev server that calls GitHub API extensively and I hit the rate limit and got blocked multiple times. I can run it again and probably you will see the spikes.
See this for context.
A lot of positive changes made it into the codebase, but we discovered that at least 1 cause of this was a single workspace that was spamming the external auth api.
This is still possible to do, so the issue still remains that a single workspace can consume the external auth rate limit. In practice, because Coder is deployed within known groups, this isn't the biggest security threat IMO since it's just a DOS attack from inside. It is more likely to just be a mistake in some script (that is what is was on our end).
I think we were really hitting the unauthenticated rate limit before. I drastically reduced it, but it is still possible to abuse our api. Although you'd have to be more deliberate now.
We are not sure if users are triggering this aumount of Token Source code 429 and 200. We started to see this issue when we accidentally corrupt our DB and we had to recover it with a daily backup we had of it. Right after the restore, the following day we start too see the issue of oauth too many requests.
Activity
fcsonline commentedon Nov 24, 2023
After contacting GitHub support, we were able to see a spike in the number of OAuth requests Coder performed against GitHub API. After talking to the whole team, we didn't perform anything special during this period of time.
Can be some edge case in Coder code that performs many OAuth negotiations?
If this scenario happens again, we will share Coder logs.
kylecarbs commentedon Nov 24, 2023
I don't think there's a scenario where we'd be spamming the API... but maybe we have a bug that could cause a redirect loop or something, and a user just left their browser up?
Has this only happened once? Or is there a way we can seemingly trigger it?
fcsonline commentedon Nov 27, 2023
We experienced two times in the last two weeks, but we have not seen any pattern, yet. If we experience again this issue, we will go to Coder logs to retrieve more information and context to be able to understand what is going on.
Emyrk commentedon Jan 8, 2024
@kylecarbs we have experienced this on our deployment today
Emyrk commentedon Jan 9, 2024
I am unable to reproduce this locally. We might want to add some debug/logging/instrumentation and then try to figure it out when we hit it in dogfood.
Emyrk commentedon Jan 9, 2024
I created a PR that will at the very least allow some alerting when this happens from metrics.
I think we still need to add some more debugging code to solve this, as there is a few parts of the code we mess with oauth: login, new/update workspace, provisioners, browser user settings page,
GIT_ASK_PASS(https://github.com/coder/coder/blob/475be73da657c83b2875c8f54b357d0a4a2f97ee/cli/gitaskpass.go#L67-L77), and maybe some more.This will mainly determine if it is external auth or login
Emyrk commentedon Jan 9, 2024
Some notes
Validate Token?
GIT_ASK_PASShas the potential to callValidateTokenrepearedly. Both the api side and the cli side have for loops that constantly try to auth.Checking the response headers for githubs yields:
ValidateToken counts as a
coreresource. If the token is invalid it has different rate limit responses.If it is valid, it looks like this:
We do make quite a few calls
Just navigating around the dashboard triggers some calls.
matifali commentedon Jan 10, 2024
Hitting this again now.
{"message":"Internal error exchanging Oauth code.","detail":"oauth2: cannot fetch token: 429 Too Many Requests"}Emyrk commentedon Jan 10, 2024
My hunch is that we are genuinely hitting the rate limits. I think our webpage and some of our cli functions are just a bit demanding.
5k requests an hour is not that many.
matifali commentedon Jan 11, 2024
johnstcn commentedon Jan 11, 2024
Curiously enough, with the new instrumentation it appears that we're hitting the unauthenticated rate limit:
Emyrk commentedon Jan 12, 2024
@johnstcn This is hit when we try to do a
ValidateTokenwith a bad token. I have a quick fix idea that might help that...3 remaining items
matifali commentedon Jan 13, 2024
I guess most of the tokens also have an expiry. Can't we check expiry before trying to refresh?
Emyrk commentedon Jan 15, 2024
@matifali We should already be doing that, but we should check this on the
ValidateTokenmethod to prevent using tokens we already know are invalid.I am not sure if this will 100% solve it though 🤔
Emyrk commentedon Jan 25, 2024
Just dropping some more info. We are seeing some spikes in "TokenSource" calls. It's very infrequent (once in the past week).
Zooming out to the month is interesting:
It looks like it used to be a lot worse? Or someone is doing something in a workspace or something that used to be running more frequently?
matifali commentedon Jan 25, 2024
@Emyrk it could be due to running the coder docs workspace. It runs
yarn devserver that calls GitHub API extensively and I hit the rate limit and got blocked multiple times. I can run it again and probably you will see the spikes.See this for context.
Emyrk commentedon Jan 25, 2024
Let's sync, run it, and see what happens.
Emyrk commentedon Jan 26, 2024
If that is what is going on, a workspace consuming the rate limit, I wonder how we would solve this. Rate limit the usage by the workspace???
matifali commentedon Jan 26, 2024
I was able to reproduce this. See the screenshot.
bpmct commentedon Feb 15, 2024
Is this still ongoing @Emyrk?
Emyrk commentedon Feb 15, 2024
@bpmct Unfortunately.
A lot of positive changes made it into the codebase, but we discovered that at least 1 cause of this was a single workspace that was spamming the external auth api.
This is still possible to do, so the issue still remains that a single workspace can consume the external auth rate limit. In practice, because Coder is deployed within known groups, this isn't the biggest security threat IMO since it's just a DOS attack from inside. It is more likely to just be a mistake in some script (that is what is was on our end).
Emyrk commentedon Feb 20, 2024
I will confirm if a single workspace can use the entire rate limit of an app across multiple users.
Emyrk commentedon Feb 23, 2024
I just confirmed that authenticated rate limits are per user:
https://docs.github.com/en/apps/oauth-apps/building-oauth-apps/rate-limits-for-oauth-apps
So the rate limit tracking I implemented is a bit moot unless I also label with each user_id. Which feels a bit excessive?
johnstcn commentedon Feb 23, 2024
Agreed, we definitely don't want to label metrics with UUIDs.
Emyrk commentedon Feb 23, 2024
I think we were really hitting the unauthenticated rate limit before. I drastically reduced it, but it is still possible to abuse our api. Although you'd have to be more deliberate now.
The PR has the info.
nano-mata-marin commentedon Oct 4, 2024
We are hitting this issue on Coder v2.10.3
We are not sure if users are triggering this aumount of Token Source code 429 and 200. We started to see this issue when we accidentally corrupt our DB and we had to recover it with a daily backup we had of it. Right after the restore, the following day we start too see the issue of oauth too many requests.