Skip to content

SHA-256 basic authentication returns 401 while plaintext password works #1460

Description

@lckrspirit

Hello,

I am trying to configure HTTP basic authentication for JMX Exporter using the SHA-256 password hash mode described in the documentation:

https://prometheus.github.io/jmx_exporter/1.5.0/http-mode/authentication/

However, authentication always returns 401 Unauthorized when using algorithm: SHA-256, while the same username/password works correctly when using plaintext password.

Configuration that does not work

httpServer:
  authentication:
    basic:
      username: prometheus
      algorithm: SHA-256
      salt: 'U9i%=N+m]#i9yvUV:bA/3n4X9JdPXf=n'
      passwordHash: '2bf7ed4906ac065bde39f7508d6102a6cdd7153a929ea883ff6cd04442772c99'

According to the documentation, this hash should correspond to:

SHA-256("U9i%=N+m]#i9yvUV:bA/3n4X9JdPXf=n:secret")

I verified it with:

printf '%s' 'U9i%=N+m]#i9yvUV:bA/3n4X9JdPXf=n:secret' | sha256sum

Output:

2bf7ed4906ac065bde39f7508d6102a6cdd7153a929ea883ff6cd04442772c99

Request:

curl --basic -u 'prometheus:secret' http://localhost:9404/metrics -v

Response:

*   Trying 127.0.0.1:9404...
* Connected to localhost (127.0.0.1) port 9404
* Server auth using Basic with user 'prometheus'
> GET /metrics HTTP/1.1
> Host: localhost:9404
> Authorization: Basic cHJvbWV0aGV1czpzZWNyZXQ=
> User-Agent: curl/7.76.1
> Accept: */*
>
< HTTP/1.1 401 Unauthorized
< Www-authenticate: Basic realm="/", charset="UTF-8"
< Content-length: 0

Configuration that works

If I change the configuration to plaintext password, authentication works:

httpServer:
  authentication:
    basic:
      username: prometheus
      password: secret

This succeeds and returns metrics.

Could you please point out what I am doing wrong here?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions