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

fix(plugins): multiple auth fix in an OR scenario #2222

Merged
merged 5 commits into from
Apr 20, 2017
Merged

Conversation

Tieske
Copy link
Member

@Tieske Tieske commented Mar 17, 2017

The last auth plugin running would overwrite the results of the previous ones.
So if the first authenticates successfully, and the second fails, then the
second one would overwrite the consumer details with the details of the
anonymous consumer.

WIP: 2 failing oauth2 tests
Reason: the oauth2 endpoint is also authenticated by the configured
plugins. Hence in the AND scenario, the key-auth plugin returns a 40x, which
in turn makes the oauth2 fail

The last auth plugin running would overritw the results of the previous ones.
So if the first authenticates succesfully, and the second fails, then the
second one would overwrite the consumer details with the details of the
anonymous consumer

WIP: 2 failing oauth2 tests
Reason: the oauth2 endpoint is also authenticated by the configured
plugins. Hence in the AND scenario, the key-auth plugin returns a 40x, which
in turn makes the oauth2 fail
@Tieske Tieske self-assigned this Mar 17, 2017
@Tieske Tieske added the pr/changes requested Changes were requested to this PR by a maintainer. Please address them and ping back once done. label Mar 17, 2017
@Tieske Tieske 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 Mar 18, 2017
@Tieske Tieske requested a review from thibaultcha March 18, 2017 22:55
@Tieske
Copy link
Member Author

Tieske commented Mar 18, 2017

The oauth2 has some peculiarities when used in an AND fashion. The token endpoints also fall within the api, hence when a token is requested, the other configured auth methods kick in. So to make this pass, the token endpoints also require credentials for the other auth methods.

Discussed this with @thefosk and we agreed on this solution.

…tipleauth

Resolved merge conflicts and fixed linter errors
@Tieske Tieske modified the milestones: 0.10.1, 0.10.2 Mar 27, 2017
@@ -4,7 +4,9 @@ local meta = require "kong.meta"
local utils = require "kong.tools.utils"

describe("Plugin: basic-auth (access)", function()

Copy link
Contributor

Choose a reason for hiding this comment

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

are these newlines necessary? we could fix style here in a separate commit. these changes are outside the scope of this PR, dirtying the commit history.

Copy link
Member Author

Choose a reason for hiding this comment

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

will keep them separate next time

@bungle
Copy link
Member

bungle commented Apr 20, 2017

Only comment from me is that all the authentication plugins seems to share this:

function _M.execute(conf)

  if ngx.ctx.authenticated_credential and conf.anonymous ~= "" then
    -- we're already authenticated, and we're configured for using anonymous, 
    -- hence we're in a logical OR between auth methods and we're already done.
    return
  end

  local ok, err = do_authentication(conf)
  if not ok then
    if conf.anonymous ~= "" then
      -- get anonymous user
      local consumer, err = cache.get_or_set(cache.consumer_key(conf.anonymous),
                       nil, load_consumer_into_memory, conf.anonymous, true)
      if err then
        return responses.send_HTTP_INTERNAL_SERVER_ERROR(err)
      end
      set_consumer(consumer, nil)
    else
      return responses.send(err.status, err.message)
    end
  end
end

So I was thinking could we generalize this somewhere, e.g. AuthPlugin. We discussed this already with @Tieske and I don't feel strongly about this if this is about to happen with new plugin api. Can this wait until that?

Note: this is far from the only thing repeating, though.

@bungle
Copy link
Member

bungle commented Apr 20, 2017

Another thing is the usablity:

anonymous ~= "" → logical OR (anonymous)
anonymous == "" → logical AND (non-anonymous)
anonymous ~= "" + request_termination plugin → logical OR (anonymous, but terminates on anonymous)

If I'm correct? Pretty hard to wrap this in your head.

But what this already does is better than we had, so LGTM.

@Tieske Tieske merged commit 202a985 into master Apr 20, 2017
@Tieske Tieske deleted the fix/multipleauth branch April 20, 2017 17:54
@thibaultcha
Copy link
Member

@bungle The long term plan is to rewrite the plugins runloop in such a way that:

  • we get rid of the OOP pattern plugins have
  • it can run plugins or sets of plugins
  • it can distinguish "types" of plugins, in this case, "Authentication", and such plugins follow an interface and have special return values.

imo, spending time getting rid of some code duplication we currently have would be a waste of time, due to this plugins runloop rewrite and the Public Lua API (that will have functions dedicated to Authentication plugins).

@@ -112,6 +112,9 @@
- Relax multipart MIME type parsing. A space is allowed in between values
of the Content-Type header.
[#2215](https://github.com/Mashape/kong/pull/2215)
- Multiple auth plugins would overwrite eachothers results, causing
false negatives in an OR scenario.
[#2222](https://github.com/Mashape/kong/pull/2222)
Copy link
Member

Choose a reason for hiding this comment

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

This was not moved to the correct version this was merged against. Be extra wary when merging PRs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants