From 3fb3b22a841cb974ec12cd5de9fbbab3fe990743 Mon Sep 17 00:00:00 2001 From: Joep de Jong Date: Thu, 7 Sep 2023 15:38:54 +0200 Subject: [PATCH] Disable logging for kube probe and health checks --- src/plugins/authiapconnect2/auth.php | 33 ++++++++++++++++++---------- 1 file changed, 21 insertions(+), 12 deletions(-) diff --git a/src/plugins/authiapconnect2/auth.php b/src/plugins/authiapconnect2/auth.php index 645eed9..fd22c2a 100644 --- a/src/plugins/authiapconnect2/auth.php +++ b/src/plugins/authiapconnect2/auth.php @@ -39,6 +39,15 @@ private function getIapToken() if ($devToken) { return $devToken; } + + if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'GoogleHC') !== false) { + return 'GoogleHC'; + } + + if (isset($_SERVER['HTTP_USER_AGENT']) && strpos($_SERVER['HTTP_USER_AGENT'], 'kube-probe') !== false) { + return 'kube-probe'; + } + throw new Exception('No token found'); } @@ -47,14 +56,14 @@ public function trustExternal($user, $pass, $sticky = false) global $USERINFO; $sticky ? $sticky = true : $sticky = false; //sanity check - - if (!empty($_SESSION[DOKU_COOKIE]['auth']['info'])) { - $USERINFO['name'] = $_SESSION[DOKU_COOKIE]['auth']['info']['name']; - $USERINFO['mail'] = $_SESSION[DOKU_COOKIE]['auth']['info']['mail']; - $USERINFO['grps'] = $_SESSION[DOKU_COOKIE]['auth']['info']['grps']; - $_SERVER['REMOTE_USER'] = $_SESSION[DOKU_COOKIE]['auth']['user']; - return true; - } + + if (!empty($_SESSION[DOKU_COOKIE]['auth']['info'])) { + $USERINFO['name'] = $_SESSION[DOKU_COOKIE]['auth']['info']['name']; + $USERINFO['mail'] = $_SESSION[DOKU_COOKIE]['auth']['info']['mail']; + $USERINFO['grps'] = $_SESSION[DOKU_COOKIE]['auth']['info']['grps']; + $_SERVER['REMOTE_USER'] = $_SESSION[DOKU_COOKIE]['auth']['user']; + return true; + } $token = $this->getIapToken(); @@ -63,16 +72,16 @@ public function trustExternal($user, $pass, $sticky = false) $USERINFO = [ 'name' => $data['gcip']['name'], 'mail' => $data['gcip']['email'], - 'grps' => array_merge(explode(',',$data['gcip']['groups']), ['user']) + 'grps' => array_merge(explode(',', $data['gcip']['groups']), ['user']) ]; - + $_SERVER['REMOTE_USER'] = $USERINFO['name']; $_SESSION[DOKU_COOKIE]['auth']['user'] = $USERINFO['name']; $_SESSION[DOKU_COOKIE]['auth']['info'] = $USERINFO; - + return true; } catch (Exception $e) { return false; - } + } } }