Skip to content

Commit

Permalink
[api] Introduce a configuration option to enable and disable kerberos…
Browse files Browse the repository at this point in the history
… mode easily

Before this was handled via the principal configuration. With this
change OBS admins can keep the principal configuration and use the
'kerberos_mode' flag instead.
  • Loading branch information
bgeuken committed Apr 19, 2017
1 parent 77644b3 commit f828d0c
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/api/app/controllers/application_controller.rb
Expand Up @@ -306,7 +306,7 @@ def gather_exception_defaults(opt)

if @status == 401
unless response.headers["WWW-Authenticate"]
if CONFIG['kerberos_service_principal']
if CONFIG['kerberos_mode']
response.headers["WWW-Authenticate"] = 'Negotiate'
else
response.headers["WWW-Authenticate"] = 'basic realm="API login"'
Expand Down
4 changes: 2 additions & 2 deletions src/api/app/controllers/webui/webui_controller.rb
Expand Up @@ -104,7 +104,7 @@ def valid_xml_id(rawid)
protected

def require_login
if CONFIG['kerberos_service_principal']
if CONFIG['kerberos_mode']
kerberos_auth
else
if User.current.nil? || User.current.is_nobody?
Expand Down Expand Up @@ -165,7 +165,7 @@ def authenticator
end

def kerberos_auth
return true unless CONFIG['kerberos_service_principal'] && (User.current.nil? || User.current.is_nobody?)
return true unless CONFIG['kerberos_mode'] && (User.current.nil? || User.current.is_nobody?)

authorization = authenticator.authorization_infos || []
if authorization[0].to_s != "Negotiate"
Expand Down
2 changes: 1 addition & 1 deletion src/api/app/helpers/webui/webui_helper.rb
Expand Up @@ -379,7 +379,7 @@ def possibly_empty_ul(html_opts, &block)
end

def can_register
return false if CONFIG['kerberos_service_principal']
return false if CONFIG['kerberos_mode']
return true if User.current.try(:is_admin?)

begin
Expand Down
15 changes: 10 additions & 5 deletions src/api/config/options.yml.example
Expand Up @@ -34,11 +34,6 @@ frontend_protocol: https
#external_frontend_port: 443
#external_frontend_protocol: https

# Kerberos authentication
#kerberos_keytab: "/etc/krb5.keytab"
#kerberos_service_principal: "HTTP/hostname.example.com@EXAMPLE.COM"
#kerberos_realm: "EXAMPLE.COM"

extended_backend_log: false

# proxy_auth_mode can be :off, :on or :simulate
Expand All @@ -50,6 +45,16 @@ proxy_auth_mode: :off
proxy_auth_test_user: coolguy
proxy_auth_test_email: coolguy@example.com

### Kerberos configuration

# can be true or false
kerberos_mode: false

#kerberos_keytab: "/etc/krb5.keytab"
#kerberos_service_principal: "HTTP/hostname.example.com@EXAMPLE.COM"
#kerberos_realm: "EXAMPLE.COM"


#schema_location

#version
Expand Down
7 changes: 5 additions & 2 deletions src/api/lib/authenticator.rb
Expand Up @@ -104,6 +104,10 @@ def authorization_infos
def initialize_krb_session
principal = CONFIG['kerberos_service_principal']

if principal.blank?
raise AuthenticationRequiredError, 'Kerberos configuration is broken. Principal is empty.'
end

unless CONFIG['kerberos_realm']
CONFIG['kerberos_realm'] = principal.rpartition("@")[2]
end
Expand Down Expand Up @@ -202,13 +206,12 @@ def extract_proxy_user

def extract_auth_user
authorization = authorization_infos

# privacy! logger.debug( "AUTH: #{authorization.inspect}" )
if authorization
# logger.debug( "AUTH2: #{authorization}" )
if authorization[0] == "Basic"
extract_basic_user authorization
elsif authorization[0] == "Negotiate" && CONFIG['kerberos_service_principal']
elsif authorization[0] == "Negotiate" && CONFIG['kerberos_mode']
extract_krb_user authorization
else
Rails.logger.debug "Unsupported authentication string '#{authorization[0]}' received."
Expand Down

0 comments on commit f828d0c

Please sign in to comment.