Skip to content
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

feat(key-auth) skip authenticating preflight OPTIONS requests #1535

Closed

Conversation

ecmendenhall
Copy link

@ecmendenhall ecmendenhall commented Aug 23, 2016

Summary

Preflight OPTIONS requests explicitly exclude user credentials and custom headers. The key-auth plugin should not attempt to authenticate OPTIONS requests, since browsers will strip Kong's apiKey header.

(Worked on this one with @nicksamps)

Full changelog

  • Check request method in KeyAuthHandler:access, short-circuit auth if type is "OPTIONS."
  • Add unit test.

Issues resolved

Fix #1292

@ecmendenhall ecmendenhall changed the title fix(plugin/key-auth): stop authenticating preflight OPTIONS requests Do not authenticate preflight OPTIONS requests in key-auth plugin Aug 23, 2016
if ngx.req.get_method() == OPTIONS then
return
end

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not an expert on this, but this completely disables the key-auth for options requests. Shouldn't this at least be configurable?

Copy link
Author

@ecmendenhall ecmendenhall Aug 23, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In principle, I don't think OPTIONS requests should be authenticated. In practice, upstream APIs probably handle OPTIONS differently, so maybe there's a case for making this configurable. I'd be interested in other opinions here, I'm not sure!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think there is ever a point in authenticating OPTIONS requests... Could be wrong, would love to see a use-case for it.
It would be worth adding a debug log when this plugin receives an OPTIONS request maybe?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Considering this comment and linked question I'd prefer a defensive approach; make it an option and default to authenticating OPTIONS requests.

@thibaultcha thibaultcha added the pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. label Aug 23, 2016
@thibaultcha
Copy link
Member

Marked as incomplete for now until comments are addressed + configuration capability for this behavior, as discussed.

@thibaultcha thibaultcha changed the title Do not authenticate preflight OPTIONS requests in key-auth plugin feat(key-auth) skip authenticating preflight OPTIONS requests Aug 23, 2016
@ecmendenhall ecmendenhall force-pushed the fix/key-auth-cors-options-requests branch 2 times, most recently from 30d7542 to 0efc446 Compare August 24, 2016 14:11
Preflight OPTIONS requests explicitly exclude user credentials
and custom headers. The key-auth plugin should not attempt to
authenticate OPTIONS requests, since browsers will strip Kong's
apiKey header.

Fix Kong#1292
@ecmendenhall ecmendenhall force-pushed the fix/key-auth-cors-options-requests branch from 0efc446 to 6e13a15 Compare August 24, 2016 14:34
new config variable authenticate_preflight to control whether or not to
authenticate OPTIONS requests.
@nicksamps nicksamps force-pushed the fix/key-auth-cors-options-requests branch from a75ab8f to 7b75b71 Compare August 24, 2016 22:09
@Tieske
Copy link
Member

Tieske commented Aug 25, 2016

Just a thought; instead of calling the option authenticate_preflight, wouldn't it be more flexible to provide a list of methods not to be authenticated.

As in; skip_authentication_on = { "OPTIONS", "GET" }

or; authenticate_methods = {} which then defaults to all methods if empty

@subnetmarco
Copy link
Member

@ecmendenhall if we can get this PR updated by today we can include it in 0.9.1

@thibaultcha thibaultcha added pr/status/needs review and removed pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. labels Dec 6, 2016
@patrickml
Copy link

any updates?

@p0pr0ck5 p0pr0ck5 added pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. and removed pr/status/please review labels Apr 18, 2017
@p0pr0ck5
Copy link
Contributor

@ecmendenhall can you please rebase your PR? There are a number of merge conflicts here. Thanks!

@p0pr0ck5
Copy link
Contributor

Going to close this, as the PR is stale and cannot be merged currently. Thanks for the initial contribution and discussion!

In the future, Kong's plugin architecture will likely be adjusted and expanded such that authentication plugins will already have this sort of logic built in, so that individual plugins do not need to worry about handling this logic. For now, one could workaround this by creating a separate API that forwards to the same upstream, handling only OPTIONS requests, that does not have this plugin enabled.

Thank you again for the initial thought for the patch here!

@p0pr0ck5 p0pr0ck5 closed this Apr 27, 2017
@ecmendenhall
Copy link
Author

@p0pr0ck5 Hi Robert! Just want to say that upgrading to 0.10.x and setting up a separate API for OPTIONS requests worked perfectly for us. I think it's a much better solution anyways. Thanks for the suggestion!

@p0pr0ck5
Copy link
Contributor

Awesome, thanks for the report!

thibaultcha pushed a commit that referenced this pull request Oct 5, 2017
PRs #2744 and #2857 implemented the preflight options (for a minor
release). This adds the migrations including defaults (for a
major release).

From #2883
See #2643 #1292 #1535
thibaultcha pushed a commit that referenced this pull request Jan 16, 2018
PRs #2744 and #2857 implemented the preflight options (for a minor
release). This adds the migrations including defaults (for a
major release).

From #2883
See #2643 #1292 #1535
thibaultcha pushed a commit that referenced this pull request Jan 19, 2018
PRs #2744 and #2857 implemented the preflight options (for a minor
release). This adds the migrations including defaults (for a
major release).

From #2883
See #2643 #1292 #1535
@yoavi2
Copy link

yoavi2 commented Jun 4, 2018

Hi guys, is setting up a seperate api still the way to go? Should the cors plugin be used instead?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants