Skip to content

Commit bff3537

Browse files
authored
Merge pull request #484 from Icinga:fix/rest_ssl_cert_lookup_custom_hostname
Fix: REST-Api SSL certificate lookup on custom hostname or domain/dns domain mismatch Fixes REST-Api SSL certificate lookup from the Icinga Agent, in case a custom hostname was used or in certain domain environments were domain is not matching DNS domain
2 parents 3c053ec + ffb86ac commit bff3537

File tree

4 files changed

+35
-3
lines changed

4 files changed

+35
-3
lines changed

doc/100-General/10-Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Released closed milestones can be found on [GitHub](https://github.com/Icinga/ic
1717
* [#478](https://github.com/Icinga/icinga-powershell-framework/pull/478) Fixes connection option "Connecting from parent system" which is not asking for ca.crt path
1818
* [#479](https://github.com/Icinga/icinga-powershell-framework/pull/479) Fixes possible exceptions while trying to remove downloaded repository temp files which might still contain a file lock from virusscanners or other tasks
1919
* [#480](https://github.com/Icinga/icinga-powershell-framework/pull/480) Fixes service locking during Icinga Agent upgrade and ensures errors on service management are caught and printed with internal error handling
20+
* [#483](https://github.com/Icinga/icinga-powershell-framework/issues/483) Fixes REST-Api SSL certificate lookup from the Icinga Agent, in case a custom hostname was used or in certain domain environments were domain is not matching DNS domain
2021
* [#490](https://github.com/Icinga/icinga-powershell-framework/pull/490) Fixes the command `Uninstall-IcingaComponent` for the `service` component which is not doing anything
2122

2223
### Enhancements

lib/core/icingaagent/getters/Get-IcingaAgentHostCertificate.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ function Get-IcingaAgentHostCertificate()
1111
# Default for Icinga 2.8.0 and above
1212
[string]$CertDirectory = (Join-Path -Path $Env:ProgramData -ChildPath 'icinga2\var\lib\icinga2\certs\*');
1313
$FolderContent = Get-ChildItem -Path $CertDirectory -Filter '*.crt' -Exclude 'ca.crt';
14-
$Hostname = Get-IcingaHostname -LowerCase $TRUE;
14+
$Hostname = Get-IcingaHostname -ReadConstants;
1515
$CertPath = $null;
1616

1717
foreach ($certFile in $FolderContent) {

lib/core/icingaagent/getters/Get-IcingaHostname.psm1

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,41 @@ function Get-IcingaHostname()
55
[bool]$AutoUseFQDN = $FALSE,
66
[bool]$AutoUseHostname = $FALSE,
77
[bool]$UpperCase = $FALSE,
8-
[bool]$LowerCase = $FALSE
8+
[bool]$LowerCase = $FALSE,
9+
[switch]$ReadConstants = $FALSE
910
);
1011

1112
[string]$UseHostname = '';
13+
14+
if ($ReadConstants) {
15+
if (Test-Path -Path (Join-Path -Path $Env:ProgramData -ChildPath 'icinga2\etc\icinga2\constants.conf')) {
16+
# Read the constants conf
17+
$FileContent = Get-Content -Path (Join-Path -Path $Env:ProgramData -ChildPath 'icinga2\etc\icinga2\constants.conf') -Encoding 'UTF8';
18+
19+
foreach ($line in $FileContent) {
20+
if ($line.Contains('NodeName') -eq $FALSE) {
21+
continue;
22+
}
23+
24+
if ($line.Contains('const') -eq $FALSE -Or $line.Contains('=') -eq $FALSE -Or $line.Contains('"') -eq $FALSE) {
25+
continue;
26+
}
27+
28+
[int]$ValueIndex = $line.IndexOf('"') + 1;
29+
30+
$UseHostname = $line.SubString($ValueIndex, $line.Length - $ValueIndex);
31+
32+
if ($UseHostname[-1] -eq '"') {
33+
$UseHostname = $UseHostname.Substring(0, $UseHostname.Length - 1);
34+
}
35+
36+
break;
37+
}
38+
39+
return $UseHostname
40+
}
41+
}
42+
1243
if ([string]::IsNullOrEmpty($Hostname) -eq $FALSE) {
1344
$UseHostname = $Hostname;
1445
} elseif ($AutoUseFQDN) {

lib/webserver/Get-IcingaSSLCertForSocket.psm1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ function Get-IcingaSSLCertForSocket()
3434
}
3535
}
3636

37-
# If no cert file or thumbprint was specified or simpy as fallback,
37+
# If no cert file or thumbprint was specified or simply as fallback,
3838
# we should use the Icinga 2 Agent certificates
3939
$AgentCertificate = Get-IcingaAgentHostCertificate;
4040

0 commit comments

Comments
 (0)