Skip to content

Unable to authenticate on API #10836

@bleizg

Description

@bleizg

Since the update to Icinga v2.16, the authentication on the Icinga API is not working properly (tested with Perl and Powershell)

To Reproduce

$Username = "user1"
$Password = "Amazing_Password_12345"
$SecuredPassword = Convertto-SecureString -String $Password -AsPlainText -Force
$Credentials = New-Object System.Management.Automation.PSCredential($Username, $SecuredPassword)

$HttpHeaders = @{
    "X-HTTP-Method-Override" = "GET"
    "accept"                 = "application/json"
}

Invoke-RestMethod `
    -Uri "https://api.icinga.company.com:5665/v1/status" `
    -Method "POST" `
    -Credential $Credentials `
    -ContentType "application/json" `
    -Headers $HttpHeaders 

Raised exception:
Invoke-RestMethod : {"error":401,"status":"Unauthorized. Please check your user credentials."}

This is the same issue with Perl if we use the credentials attribute of LWP::UserAgent class.

PERL version

use Data::Dumper;

require URI;
require HTTP::Request;
require HTTP::Headers;
require LWP::UserAgent;
require IO::Socket::SSL;
require MIME::Base64;

use JSON qw{ encode_json decode_json };

my $endpoint = 'api.icinga.company.com';
my $user = 'user1';
my $pass = 'Amazing_Password_12345';

my $Request = HTTP::Request->new( 'POST', "https://$endpoint:5665/v1/status" );
$Request->header( 'Accept'                 => 'application/json' );
$Request->header( 'X-HTTP-Method-Override' => 'GET' );
$Request->content_type( 'application/json' );

my $Agent = LWP::UserAgent->new(
        ssl_opts => {
                verify_hostname => 0,
                SSL_verify_callback => sub { 1 },
        },
);
!$Agent and return $Agent;

$Agent->credentials( "$endpoint:5665", 'Icinga 2', $user, $pass );

my $Response = $Agent->request( $Request );

print Dumper $Response->content;

What is working

Powershell

$HttpHeaders = @{
    "X-HTTP-Method-Override" = "GET"
    "accept"                 = "application/json"
    "Authorization"          = "Basic " + $([Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("$($Username):$($Password)")))
}

Invoke-RestMethod `
    -Uri "https://api.icinga.company.com:5665/v1/status" `
    -Method "POST" `
    -ContentType "application/json" `
    -Headers $HttpHeaders

Perl

use Data::Dumper;

require URI;
require HTTP::Request;
require HTTP::Headers;
require LWP::UserAgent;
require IO::Socket::SSL;
require MIME::Base64;

use JSON qw{ encode_json decode_json };

my $endpoint = 'api.icinga.company.com';
my $user = 'user1';
my $pass = 'Amazing_Password_12345';

my $Request = HTTP::Request->new( 'POST', "https://$endpoint:5665/v1/status" );
$Request->header( 'Accept'                 => 'application/json' );
$Request->header( 'X-HTTP-Method-Override' => 'GET' );
$Request->header( 'Authorization'          => 'Basic ' . MIME::Base64::encode_base64( "$user:$pass", '' ) );
$Request->content_type( 'application/json' );

my $Agent = LWP::UserAgent->new(
        ssl_opts => {
                verify_hostname => 0,
                SSL_verify_callback => sub { 1 },
        },
);
!$Agent and return $Agent;

my $Response = $Agent->request( $Request );

print Dumper $Response->content;

To Reproduce

Provide a link to a live example, or an unambiguous set of steps to reproduce this bug. Include configuration, logs, etc. to reproduce, if relevant.

  1. Update to Icinga2 v2.16
  2. Call the Icinga2 API (TCP/5665) with -credential parameter

Expected behavior

Icinga API should returns a 200 http code.

Your Environment

Include as many relevant details about the environment you experienced the problem in

Version used
# icinga2 --version
icinga2 - The Icinga 2 network monitoring daemon (version: r2.16.0-1)

Copyright (c) 2012-2026 Icinga GmbH (https://icinga.com/)
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl-3.0.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

System information:
  Platform: Debian GNU/Linux
  Platform version: 12 (bookworm)
  Kernel: Linux
  Kernel version: 5.15.203-vps-grsec-zfs-classid
  Architecture: x86_64

Build information:
  Compiler: GNU 12.2.0
  Build host: runner-aa2jha3hm-project-575-concurrent-1
  OpenSSL version: OpenSSL 3.0.19 27 Jan 2026

Application information:

General paths:
  Config directory: /etc/icinga2
  Data directory: /var/lib/icinga2
  Log directory: /var/log/icinga2
  Cache directory: /var/cache/icinga2
  Spool directory: /var/spool/icinga2
  Run directory: /run/icinga2

Old paths (deprecated):
  Installation root: /usr
  Sysconf directory: /etc
  Run directory (base): /run
  Local state directory: /var

Internal paths:
  Package data directory: /usr/share/icinga2
  State path: /var/lib/icinga2/icinga2.state
  Modified attributes path: /var/lib/icinga2/modified-attributes.conf
  Objects path: /var/cache/icinga2/icinga2.debug
  Vars path: /var/cache/icinga2/icinga2.vars
  PID path: /run/icinga2/icinga2.pid
Operating System and version:
# cat /etc/os-release
PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"
NAME="Debian GNU/Linux"
VERSION_ID="12"
VERSION="12 (bookworm)"
VERSION_CODENAME=bookworm
ID=debian
HOME_URL="https://www.debian.org/"
SUPPORT_URL="https://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
Enabled features (`icinga2 feature list`):

icinga2 feature list

Disabled features: command compatlog debuglog elasticsearch gelf graphite influxdb influxdb2 journald opentsdb perfdata statusdata syslog
Enabled features: api checker icingadb livestatus mainlog notification

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions