Skip to content

Commit

Permalink
fix sessions removed early when using kerberos authentication
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Jun 10, 2024
1 parent 95203c6 commit 1ef49df
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 2 deletions.
1 change: 1 addition & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ This file documents the revision history for the Monitoring Webinterface Thruk.

next:
- fix recurring downtimes crontab entry for 2nd/3rd days of month
- fix sessions removed early when using kerberos authentication
- Rest:
- add transformation and disaggregation functions
- add support for timeperiod / time queries in where clause
Expand Down
21 changes: 19 additions & 2 deletions lib/Thruk/Context.pm
Original file line number Diff line number Diff line change
Expand Up @@ -357,7 +357,9 @@ sub authenticate {
# set session id for all requests
if(!$sessiondata && !$internal) {
if(!Thruk::Base->mode_cli()) {
($sessionid,$sessiondata) = Thruk::Utils::get_fake_session($c, undef, $username, undef, $c->req->address);
my $extra = {};
$extra->{'fake'} = 0 if _is_browser_request($c);
($sessionid,$sessiondata) = Thruk::Utils::get_fake_session($c, undef, $username, undef, $c->req->address, $extra);
if(!$options{'keep_session'}) {
$c->cookie('thruk_auth', $sessionid, { httponly => 1 });
}
Expand Down Expand Up @@ -454,7 +456,7 @@ sub _request_username {
# kerberos authentication
elsif(($env->{'AUTH_TYPE'}//'') eq 'Negotiate' && ($env->{'GSS_NAME'}//'') ne '' ) {
$username = $env->{'REMOTE_USER'} // $env->{'GSS_NAME'};
$auth_src = "Negotiate";
$auth_src = "negotiate";
}
# basic authentication
elsif(defined $env->{'REMOTE_USER'} && $env->{'REMOTE_USER'} ne '' ) {
Expand Down Expand Up @@ -1123,6 +1125,21 @@ sub _is_ssl_request {
return;
}

###################################################
# return true if request is from a browser and not scripted, for example from curl / wget
sub _is_browser_request {
my($c) = @_;

# theme cookie is a good indicator for a user request
my $cookies = $c->env->{'HTTP_COOKIE'};
if($cookies) {
return 1 if($cookies =~ m/thruk_theme|thruk_screen/gmx);
}

# everything else assumed to be not a browser
return;
}

###################################################

1;
2 changes: 2 additions & 0 deletions lib/Thruk/Utils.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1790,6 +1790,8 @@ sub get_fake_session {
$sessiondata->{$key} = $extra->{$key};
}
}
delete $sessiondata->{'fake'} unless $sessiondata->{'fake'}; # make it possible to create non-fake sessions via extra data

require Thruk::Utils::CookieAuth;
$sessiondata = Thruk::Utils::CookieAuth::store_session($c->config, $id, $sessiondata);
$c->stash->{'fake_session_id'} = $sessiondata->{'private_key'};
Expand Down

0 comments on commit 1ef49df

Please sign in to comment.