Commit 0ad9fc60 authored by Robert Speicher's avatar Robert Speicher

Enable 2FA for LDAP logins

parent 3962d33f
v 7.11.0 v 7.11.0
- Skip git hooks commit validation when pushing new tag. - Skip git hooks commit validation when pushing new tag.
- Add Two-factor authentication (2FA) for LDAP logins
v 7.10.1 v 7.10.1
- Check if comment exists in Jira before sending a reference - Check if comment exists in Jira before sending a reference
......
# == AuthenticatesWithTwoFactor
#
# Controller concern to handle two-factor authentication
#
# Upon inclusion, skips `require_no_authentication` on `:create`.
module AuthenticatesWithTwoFactor
extend ActiveSupport::Concern
included do
# This action comes from DeviseController, but because we call `sign_in`
# manually, not skipping this action would cause a "You are already signed
# in." error message to be shown upon successful login.
skip_before_action :require_no_authentication, only: [:create]
end
# Store the user's ID in the session for later retrieval and render the
# two factor code prompt
#
# The user must have been authenticated with a valid login and password
# before calling this method!
#
# user - User record
#
# Returns nil
def prompt_for_two_factor(user)
session[:otp_user_id] = user.id
render 'devise/sessions/two_factor' and return
end
end
class OmniauthCallbacksController < Devise::OmniauthCallbacksController class OmniauthCallbacksController < Devise::OmniauthCallbacksController
include AuthenticatesWithTwoFactor
protect_from_forgery except: :kerberos protect_from_forgery except: :kerberos
Gitlab.config.omniauth.providers.each do |provider| Gitlab.config.omniauth.providers.each do |provider|
define_method provider['name'] do define_method provider['name'] do
handle_omniauth handle_omniauth
...@@ -26,7 +29,11 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController ...@@ -26,7 +29,11 @@ class OmniauthCallbacksController < Devise::OmniauthCallbacksController
# Do additional LDAP checks for the user filter and EE features # Do additional LDAP checks for the user filter and EE features
if @user.allowed? if @user.allowed?
sign_in_and_redirect(gl_user) if @user.otp_required_for_login?
prompt_for_two_factor(gl_user)
else
sign_in_and_redirect(gl_user)
end
else else
flash[:alert] = "Access denied for your LDAP account." flash[:alert] = "Access denied for your LDAP account."
redirect_to new_user_session_path redirect_to new_user_session_path
......
...@@ -26,33 +26,32 @@ ...@@ -26,33 +26,32 @@
%span You don`t have one yet. Click generate to fix it. %span You don`t have one yet. Click generate to fix it.
= f.submit 'Generate', class: "btn success btn-build-token" = f.submit 'Generate', class: "btn success btn-build-token"
- unless current_user.ldap_user? %fieldset
%fieldset - if current_user.otp_required_for_login
- if current_user.otp_required_for_login %legend.text-success
%legend.text-success = icon('check')
= icon('check') Two-factor Authentication enabled
Two-factor Authentication enabled %div
%div .pull-right
.pull-right = link_to 'Disable Two-factor Authentication', profile_two_factor_auth_path, method: :delete, class: 'btn btn-close btn-sm',
= link_to 'Disable Two-factor Authentication', profile_two_factor_auth_path, method: :delete, class: 'btn btn-close btn-sm', data: { confirm: 'Are you sure?' }
data: { confirm: 'Are you sure?' } %p
%p If you lose your recovery codes you can
If you lose your recovery codes you can %strong
%strong = succeed ',' do
= succeed ',' do = link_to 'generate new ones', codes_profile_two_factor_auth_path, method: :post, data: { confirm: 'Are you sure?' }
= link_to 'generate new ones', codes_profile_two_factor_auth_path, method: :post, data: { confirm: 'Are you sure?' } invalidating all previous codes.
invalidating all previous codes.
- else - else
%legend Two-factor Authentication %legend Two-factor Authentication
%div
%p
Increase your account's security by enabling two-factor authentication (2FA).
%p
Each time you log in you’ll be required to provide your username and
password as usual, plus a randomly-generated code from your phone.
%div %div
%p = link_to 'Enable Two-factor Authentication', new_profile_two_factor_auth_path, class: 'btn btn-success'
Increase your account's security by enabling two-factor authentication (2FA).
%p
Each time you log in you’ll be required to provide your username and
password as usual, plus a randomly-generated code from your phone.
%div
= link_to 'Enable Two-factor Authentication', new_profile_two_factor_auth_path, class: 'btn btn-success'
- if show_profile_social_tab? - if show_profile_social_tab?
%fieldset %fieldset
......
...@@ -24,7 +24,9 @@ module Gitlab ...@@ -24,7 +24,9 @@ module Gitlab
update_user_attributes update_user_attributes
end end
# instance methods delegate :otp_required_for_login?, :otp_backup_codes, :otp_attempt,
to: :gl_user
def gl_user def gl_user
@gl_user ||= find_by_uid_and_provider || find_by_email || build_new_user @gl_user ||= find_by_uid_and_provider || find_by_email || build_new_user
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment