-
Notifications
You must be signed in to change notification settings - Fork 745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OAuth2: don't use oauth when an empty token is set #191
Conversation
Would it make sense to print something even if it's only an info or debug level log message to "warn" people. I see the value in making it optional but in all of my use cases across multiple orgs they would be needed and this does not give any feedback to the user that they are not properly configured. Also I would like to point out that while it may be true that its not needed in some small or edgecases an unauthenticated user request gets a max of 60 requests in an hour due to their rate limiting which for many use cases is not enough. |
Could you please provide the output of the case, when the token is required? Which HTTP code does github return? I believe terraform should print the error message in case in the auth is required. |
@kayrus the doc says (accurately) that they both are optional, in the sense that while they must be provided, they can also be sourced from environment variables (GITHUB_TOKEN, GITHUB_ORGANIZATION). Marking them optional in the API allows me to use environment variables without complaint from my IDE. This is different from saying that a token is optional in order to use the API. That seems like a different change. In my experience a token is required. |
I have not done it recently but anytime you do anything to a private repo without auth you will get a 404 indicating it does not exist when really its lack of authentication. This is similar to how aws gives a 403 to people obscuring if its lack of permission or missing with s3.
You can just make an ENV var with the prefix of I am not entirely opposed to allowing it to be optional but I think given that it will more likely negatively impact use cases than it helps I think it minimally needs to be printed out to warn the user that no auth is detected. |
I can't say for sure how it works for github enterprise as I dont currently have one to look at but it seems that it can be enabled for authenticated users: https://help.github.com/en/enterprise/2.16/admin/installation/configuring-rate-limits my gut feeling is that if github enterprise allows unauthenticated requests at all then its probably enabled. You could probably hit:
Replacing the hostname with your github enterprise url |
Here is what I get with the GitHub enterprise.
What about keeping the UPD: this is bizarre. Calling the |
That would work for me, allow people to opt into disabling authentication as its I think more common to need auth then not. If someone explicitly configures no auth and they need it that's on them. |
dd7c8aa
to
13fae7b
Compare
We should probably update the docs to indicate that setting this to an empty string will disable oauth |
Does it look fine?
|
@majormoses Marking them optional in the API allows me to use environment variables without complaint from my IDE. Otherwise, the IDE is prompting me to create some means other than the env vars for providing these (even though the env vars will still work). For the token, especially, the env var is the best option. The provider and doc should be in agreement. |
Terraform docs or Github's docs? Personally I think that its ok to put guardrails in place that are helpful to users even at the cost of not matching the default of the upstream but that is an opinion and neither are right or wrong. I think this should be up to the community consensus but I don't really like introducing breaking changes that will harm more users than it helps is a good idea. With the proposed implementation setting it to an empty string as a default will work in your editor and you can always override it via an ENV var. |
@majormoses How is downgrading from Required to Optional a breaking change? Assigning the token to |
Are you using the required
By still "requiring" it but discarding if it's empty seems the best compromise to me as it allows you to opt in of using it without auth but for the 99% of use cases will get prompted for credentials should they forget rather than getting a misleading error. It's breaking in the sense of providing false information back to the user when their authentication is not set and instead tells them that the resource does not exist for example or other rate limit issues outlined without helpful feedback. |
I'm using GITHUB_TOKEN as documented by the GitHub provider. If the token is absent then GITHUB_TOKEN is used. (In this sense, token is optional.) GITHUB_TOKEN is also used in at least one place in the terraform AWS provider code, by the way. Thanks for pointing out that I can bypass GITHUB_TOKEN by using a different environment variable. I think your suggestion works well in situations where the user may want to run without a token. This option is not available when using GITHUB_TOKEN and running without a token is not something I want to do. I am just annoyed that the IDE thinks token is required. |
By creating your own variable you can choose exactly how you want to handle it, as I would not set an empty string (added that specifically to show its possible) it will require it to come from the ENV or a prompt otherwise it will fail. I think this would also satisfy your editors confusion but I can't say for certain.
Did not know that, from a "quick" search it is only used here other than tests and documentation for the referenced code. It does not use this provider at all, it just uses the same variable to make an auth request. I'd argue it should allowed it to come via a terraform config key or an env var and should not dictate that but that's IMHO out of scope of the discussion as it does not use the provider being referenced here. I think it's worth bringing that up on the aws provider to add flexibility.
What IDE? As I said I think your problem could be addressed with or without this change. I don't think that our motivation for making it optional should be because of an IDE. |
@majormoses As far as I know the IDE is any IDE with intellisense, which will complain because |
I don't see this issue with VScode which has intellisense, but then again as I am configuring it differently I am probably sidestepping your problem entirely.
The motivation for #190 from what I see is to allow you to use it without anything defined for a real use case such as querying a public team on a public github setup. That being said I don't really think there are many real use cases where this actually makes sense as you will very likely hit the 60 requests an hour limit without specifying authentication. It's true that there is a docs mismatch and this happens to bring it into alignment but I see that as a symptom rather than the root of the issue IMHO. I think this looks good in its current state after some updates to the docs to indicate that its required but could be an empty string which disables authentication and uses anonymous calls. |
I thought about this and I suspect the reason for this is that https://api.github.com/users/majormoses/keys is an API request where https://github.com/majormoses.keys is made against the UI (which in turn makes the appropriate api requests) and therefore are not subject to the same API rate limits. As everything in this module is API driven I still think that a vast majority of use cases really will need authentication in order to be useful even if all the requests are read only to public entities. Just my |
@majormoses nevertheless there are cases when github enterprise is used. Could you please give your feedback on the doc text I mentioned in the https://github.com/terraform-providers/terraform-provider-github/pull/191#issuecomment-466530400 ? |
That doc update works for me. |
13fae7b
to
42d3fc5
Compare
@majormoses kindly ping |
@kayrus I can give it a look over but I am not a maintainer for this project just someone who uses it heavily. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
@majormoses there is no maintainer list in the README.md and I don't know who can merge it. |
@radeksimko can you take a look? |
@apparentlymart @aeschright any chance to merge this? |
github/config.go
Outdated
) | ||
|
||
var ts oauth2.TokenSource | ||
if c.Token != "" { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Im wondering if now that we have null
in terraform 0.12 if it might be better to require it to be null
instead of a string, unfortunately this would break backwards compatibility with < 0.12 though 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought more about it and I think its important that its a manual opt in for anonymous mode.
Hi @kayrus ! Thank you for this PR! There have been many requests for this, and I think there are some different ways we can go about solving it. After talking to the team, we thought it might be nice to add an I’ve done a similar thing with Let me know if you have questions or feedback, or if I can help with anything further. Thanks! |
42d3fc5
to
4240e5a
Compare
@megan07 acked. |
@megan07 kindly ping |
Hi @kayrus ! This looks good! Would you be able to add a few acceptance tests, please? Here are a few things it might be nice to test: • token and anonymous not set Please let me know if you don’t have time to do these tests and I would be happy to write them. Thanks! |
@megan07 feel free to add tests |
Closing in favor of #255. |
resolves #190