Skip to content

Commit feb5f4c

Browse files
committed
Checkmk BI backend: Add option 'site_internal_auth' for Checkmk 2.4
Can be used to enable the Checkmk 2.4 site internal authentication. This option is configured automatically for the sites local backend ('backend_[site]_bi') which is created automatiocally in Checkmk sites.
1 parent e4b6712 commit feb5f4c

File tree

4 files changed

+71
-11
lines changed

4 files changed

+71
-11
lines changed

ChangeLog

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22
* Feature: add option to verify session cookie via curl. Before when having allow_url_fopen
33
disabled, NagVis was not able to verify the session cookie. Now you can use curl to verify
44
the session cookie. Depending on your distribution the curl extension can be installed differently.
5+
* Checkmk BI backend: Add option 'site_internal_auth' to enable the Checkmk 2.4 site internal
6+
authentication. This option is configured automatically for the sites local
7+
backend ('backend_[site]_bi') which is created automatiocally in Checkmk sites.
58

69
1.9.45
710
* FIX: Fix XSS on support info page (Thanks to jmacario24)

docs/en_US/backend_mkbi.html

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,18 +38,34 @@ <h2>Configuration</h2>
3838
It serves the AJAX-API which the backend connects to. This URL must be reachable
3939
from the host NagVis is running on.</td>
4040
</tr>
41+
<tr>
42+
<td>site_internal_auth</td>
43+
<td>0</td>
44+
<td>Use the so called site internal authentication introduced with Checkmk 2.4. The
45+
site internal secret is automatically derived from the Checkmk sites environment.
46+
</td>
47+
</tr>
4148
<tr>
4249
<td>auth_user</td>
4350
<td></td>
4451
<td>User to use for authentication when accessing the <code>base_url</code>. It
4552
has to be created within Checkmk as &quot;automation&quot; user in order to
46-
configure a backend which is allowed to retrieve Checkmk BI states.</td>
53+
configure a backend which is allowed to retrieve Checkmk BI states.
54+
Used for the automation authentication together with auth_secret or auth_secret_file.
55+
This was the authentication mechanism until Checkmk 2.3.
56+
</td>
4757
</tr>
4858
<tr>
4959
<td>auth_secret</td>
5060
<td></td>
5161
<td>The authentication secret configured within Checkmk for the given user.</td>
5262
</tr>
63+
<tr>
64+
<td>auth_secret_file</td>
65+
<td></td>
66+
<td>Read the authentication secret configured within Checkmk for the given user from this
67+
path.</td>
68+
</tr>
5369
<tr>
5470
<td>verify_peer</td>
5571
<td>1</td>

omd_install.sh

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ backend="$OMD_SITE"
121121
[backend_$OMD_SITE]
122122
backendtype="mklivestatus"
123123
socket="unix:$OMD_ROOT/tmp/run/live"
124+
EOF
125+
126+
# The automation secrets were removed with Checkmk 2.4. Care for both cases for now.
127+
if [ -f "$OMD_ROOT/var/check_mk/web/automation/automation.secret" ]; then
128+
cat >>"$OMD_CFG" <<EOF
124129
125130
[backend_${OMD_SITE}_bi]
126131
backendtype="mkbi"
@@ -129,6 +134,16 @@ auth_user="automation"
129134
auth_secret_file="$OMD_ROOT/var/check_mk/web/automation/automation.secret"
130135
timeout=10
131136
EOF
137+
else
138+
cat >>"$OMD_CFG" <<EOF
139+
140+
[backend_${OMD_SITE}_bi]
141+
backendtype="mkbi"
142+
base_url="http://localhost/$OMD_SITE/check_mk/"
143+
site_internal_auth=1
144+
timeout=10
145+
EOF
146+
fi
132147

133148
# Backup the agvis.conf on first time using omd_install.sh
134149
if ! grep omd_install.sh $OMD_ROOT/etc/apache/conf.d/nagvis.conf >/dev/null 2>&1; then

share/server/core/classes/GlobalBackendmkbi.php

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,16 @@ class GlobalBackendmkbi implements GlobalBackendInterface {
6363
'default' => 'http://localhost/check_mk/',
6464
'match' => MATCH_STRING_URL,
6565
),
66+
// The automation user based authentication was removed in Checkmk 2.4 and replaced by the
67+
// site internal authentication. For the local site backend we make use of it with the
68+
// automatically configured backend.
69+
'site_internal_auth' => Array(
70+
'must' => 0,
71+
'editable' => 1,
72+
'default' => 0,
73+
'match' => MATCH_BOOLEAN,
74+
'field_type' => 'boolean',
75+
),
6676
'auth_user' => Array(
6777
'must' => 0,
6878
'editable' => 1,
@@ -141,12 +151,17 @@ public function __construct($backendId) {
141151
);
142152
}
143153

144-
// Always set the HTTP basic auth header
145-
$username = cfg('backend_'.$backendId, 'auth_user');
146-
$secret = $this->getSecret();
147-
if($username && $secret) {
148-
$authCred = base64_encode($username.':'.$secret);
149-
$httpContext['header'] = 'Authorization: Basic '.$authCred."\r\n";
154+
if ($this->isSiteInternalAuthEnabled()) {
155+
$httpContext['header'] = 'Authorization: InternalToken '
156+
.base64_encode($this->siteInternalAuthSecret())."\r\n";
157+
} else {
158+
// Always set the HTTP basic auth header
159+
$username = cfg('backend_'.$backendId, 'auth_user');
160+
$secret = $this->getSecret();
161+
if($username && $secret) {
162+
$authCred = base64_encode($username.':'.$secret);
163+
$httpContext['header'] = 'Authorization: Basic '.$authCred."\r\n";
164+
}
150165
}
151166

152167
$this->context = stream_context_create(array(
@@ -159,6 +174,14 @@ public function __construct($backendId) {
159174
* HELPERS
160175
*************************************************************************/
161176

177+
private function isSiteInternalAuthEnabled() {
178+
return cfg('backend_'.$this->backendId, 'site_internal_auth') == 1;
179+
}
180+
181+
private function siteInternalAuthSecret() {
182+
return file_get_contents($_SERVER['OMD_ROOT'] . "/etc/site_internal.secret");
183+
}
184+
162185
private function getSecret() {
163186
$secret_file_path = cfg('backend_'.$this->backendId, 'auth_secret_file');
164187
if ($secret_file_path)
@@ -178,10 +201,13 @@ private function aggrUrl($name) {
178201
*/
179202
private function getUrl($params) {
180203
$url = $this->baseUrl.$params.'&output_format=json';
181-
$username = cfg('backend_'.$this->backendId, 'auth_user');
182-
$secret = $this->getSecret();
183-
if ($username && $secret)
184-
$url .= '&_username='.$username.'&_secret='.$secret;
204+
205+
if (!$this->isSiteInternalAuthEnabled()) {
206+
$username = cfg('backend_'.$this->backendId, 'auth_user');
207+
$secret = $this->getSecret();
208+
if ($username && $secret)
209+
$url .= '&_username='.$username.'&_secret='.$secret;
210+
}
185211

186212
// Is there some cache to use? The cache is not persisted. It is available
187213
// until the request has finished.

0 commit comments

Comments
 (0)