Gitlab and omniauth-pam Authentication

牧云@^-^@ 提交于 2019-12-13 17:26:49

问题


Basically I follow these instructions to add a custom omniauth provider:

https://github.com/gitlabhq/gitlabhq/blob/master/doc/install/installation.md#using-custom-omniauth-providers

I want to use omniauth-pam:

https://github.com/nickcharlton/omniauth-pam

After adding the gem and configuring this in gitlab.yml:

providers:
    - { name: 'pam' }

It does not start anymore with this error:

Received wrong number of arguments. [nil, nil] (ArgumentError)
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/omniauth-1.1.4/lib/omniauth/strategy.rb:143:in `initialize'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.15/lib/action_dispatch/middleware/stack.rb:43:in `new'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.15/lib/action_dispatch/middleware/stack.rb:43:in `build'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.15/lib/action_dispatch/middleware/stack.rb:113:in `block in build'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.15/lib/action_dispatch/middleware/stack.rb:113:in `each'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.15/lib/action_dispatch/middleware/stack.rb:113:in `inject'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/actionpack-3.2.15/lib/action_dispatch/middleware/stack.rb:113:in `build'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-3.2.15/lib/rails/engine.rb:475:in `app'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-3.2.15/lib/rails/application/finisher.rb:31:in `block in <module:Finisher>'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-3.2.15/lib/rails/initializable.rb:30:in `instance_exec'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-3.2.15/lib/rails/initializable.rb:30:in `run'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-3.2.15/lib/rails/initializable.rb:55:in `block in run_initializers'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-3.2.15/lib/rails/initializable.rb:54:in `each'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-3.2.15/lib/rails/initializable.rb:54:in `run_initializers'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-3.2.15/lib/rails/application.rb:136:in `initialize!'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/railties-3.2.15/lib/rails/railtie/configurable.rb:30:in `method_missing'
  /sync1/gitlab/config/environment.rb:5:in `<top (required)>'
  config.ru:3:in `require'
  config.ru:3:in `block in <main>'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/builder.rb:51:in `instance_eval'
  /sync1/gitlab/vendor/bundle/ruby/2.0.0/gems/rack-1.4.5/lib/rack/builder.rb:51:in `initialize'
  config.ru:1:in `new'
  config.ru:1:in `<main>'
  /usr/local/lib64/ruby/gems/2.0.0/gems/passenger-4.0.23/helper-scripts/rack-preloader.rb:105:in `eval'
  /usr/local/lib64/ruby/gems/2.0.0/gems/passenger-4.0.23/helper-scripts/rack-preloader.rb:105:in `preload_app'
  /usr/local/lib64/ruby/gems/2.0.0/gems/passenger-4.0.23/helper-scripts/rack-preloader.rb:150:in `<module:App>'
  /usr/local/lib64/ruby/gems/2.0.0/gems/passenger-4.0.23/helper-scripts/rack-preloader.rb:29:in `<module:PhusionPassenger>'
  /usr/local/lib64/ruby/gems/2.0.0/gems/passenger-4.0.23/helper-scripts/rack-preloader.rb:28:in `<main>'

The documentation of omniauth-pam states that it does not need any config params. So this error is not explainable for me.


回答1:


The problem comes from how config/initializers/devise.rb sets up the providers defined in config/gitlab.yml (by always passing at least two arguments even if they are nil ) AND how omniauth/strategy.rb (from which any provider like 'pam' inherits) processes the given arguments (by checking that the provider's declared arguments matches the number of arguments passed).

This combination makes it so that it expects a provider defined in config/gitlab.yml to declare at least two arguments.

So I had to do the following in my provider to solve this:

require 'omniauth'
module OmniAuth
    module Strategies
        class YourProvider
            include OmniAuth::Strategy
            args [:arg1, :arg2]  # <-- This is the line you need.

This is most probably a bug in gitlab, but the above was my workaround.

You can try this yourself by forking the omniauth-pam project and adding that line to lib/omniauth/strategies/pam.rb.

Then in the gitlab Gemfile, your gem line should look like:

gem 'omniauth-pam', :git => 'https://github.com/vanthome/omniauth-pam.git'

That way it will use the provider with your changes. After that, the rest of the instructions when using custom providers still holds true.

EDIT:

I just realized that there is another way to work around this that does not require you to fork the provider code.

In config/initializers/devise.rb, add the following line at the end of the outermost block:

config.omniauth :pam

And remove the added provider line from config/gitlab.yml.




回答2:


I recommend you to check what this guy did:

https://github.com/raphendyr/gitlabhq/tree/pam

as I use his repository to host GitLab and it's working perfectly fine.

It's a bit outdated, but to make same patch for current version is not a big problem if it's the issue for you.




回答3:


I had to get this working for my university. Take a look at my pull request for Gitlab. I was able to get a working version of Gitlab with PAM on Ubuntu.

Gitlab pull request #4706



来源:https://stackoverflow.com/questions/19938781/gitlab-and-omniauth-pam-authentication

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!