Skip to content

Add basic authentication#1683

Merged
SuperQ merged 2 commits intoprometheus:masterfrom
roidelapluie:basicauth
May 1, 2020
Merged

Add basic authentication#1683
SuperQ merged 2 commits intoprometheus:masterfrom
roidelapluie:basicauth

Conversation

@roidelapluie
Copy link
Member

WIP - To gather initial feedback.

Fully working.

Signed-off-by: Julien Pivotto roidelapluie@inuits.eu

@roidelapluie roidelapluie force-pushed the basicauth branch 2 times, most recently from 68ce902 to 1fe1da7 Compare April 25, 2020 13:35
@SuperQ
Copy link
Member

SuperQ commented Apr 26, 2020

Thanks for working on this.

What do you think about putting the user list into the same file as a first iteration. This would simplify the standard use case of config management deployed exporters having to manage multiple files.

tls_config:
  ...
users:
  alice: "$2y$BCRYPTHASH"

@roidelapluie roidelapluie force-pushed the basicauth branch 2 times, most recently from 948241f to f529d9c Compare April 26, 2020 22:51
@roidelapluie roidelapluie marked this pull request as ready for review April 26, 2020 23:08
@roidelapluie
Copy link
Member Author

ready for review.

In particular: do we want to use bcrypt here?

Pros:

  • Avoid / Limit bruteforce because it is slow
  • not cleartext password in file
    Cons:
  • slows down every request

@brian-brazil
Copy link
Contributor

Bcrypt is the current best practice, I'd be very wary of using anything else.

You can adjust how long it takes by changing the number of rounds. How long are we actually talking here?

Copy link
Member

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nits.

Can you add an entry to the top level CHANGELOG?

* [FEATURE] Add basic authentication #1673

@roidelapluie
Copy link
Member Author

Yes, I'll also add WWW-Authenticate header

@roidelapluie
Copy link
Member Author

Bcrypt is the current best practice, I'd be very wary of using anything else.

You can adjust how long it takes by changing the number of rounds. How long are we actually talking here?

70ms for 'test1234' with 10 rounds.

@brian-brazil
Copy link
Contributor

70ms isn't too bad overall, maybe just mention it in the docs as a note? It's up to the user how many rounds to use when generating the hash.

@SuperQ
Copy link
Member

SuperQ commented Apr 27, 2020

I agree, we should support bcrypt to start. Apache 2.4 htpasswd still defaults to 5 rounds, which is pretty small.

It seems like basic auth is getting hashed on every scrape. Is there a way to cache this?

Setting bcrypt cost to 16 causes each scrape to take 3.9s.

We should document this in the README.

@roidelapluie
Copy link
Member Author

Added README

Added ability to use basic auth without TLS

Added empty web config file support

Use Strict Unmarshal ( fix #1691 )

@roidelapluie roidelapluie force-pushed the basicauth branch 3 times, most recently from 241cc97 to 06d6447 Compare April 27, 2020 22:59
@roidelapluie
Copy link
Member Author

I have pushed further commits.

@roidelapluie roidelapluie force-pushed the basicauth branch 2 times, most recently from 1e7beee to 3c513c6 Compare April 28, 2020 16:24
@roidelapluie
Copy link
Member Author

I have squashed, rebased add added CHANGELOG entry.

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
@roidelapluie
Copy link
Member Author

Another change I made is to allow to use empty usernames / passwords:

basic_auth_users:
  "": "$2y$10$qvD2EZmkSwB0qh004ylOBOQA15KGjqknWM.rxKTAr.7FOxWWyYr/q"
curl -u : http://127.0.0.1:9100
<html>
                        <head><title>Node Exporter</title></head>
                        <body>
                        <h1>Node Exporter</h1>
                        <p><a href="/metrics">Metrics</a></p>
                        </body>
                        </html>

Copy link
Contributor

@brian-brazil brian-brazil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

We might also want a test for an empty username/password.

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
@roidelapluie
Copy link
Member Author

roidelapluie commented Apr 28, 2020

Done.

We do not threat empty username/password differently than anything else. We can add a test later ; but it does not sound like a strong requirement for now.

Copy link
Member

@SuperQ SuperQ left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@SuperQ SuperQ merged commit 202ecf9 into prometheus:master May 1, 2020
@m-yosefpor m-yosefpor mentioned this pull request May 22, 2020
oblitorum pushed a commit to shatteredsilicon/node_exporter that referenced this pull request Apr 9, 2024
* Add basic authentication

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
oblitorum pushed a commit to shatteredsilicon/node_exporter that referenced this pull request Apr 9, 2024
* Add basic authentication

Signed-off-by: Julien Pivotto <roidelapluie@inuits.eu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants