Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

logcli: add support for basic token authentication #2889

Closed
wants to merge 3 commits into from

Conversation

gcotone
Copy link

@gcotone gcotone commented Nov 5, 2020

What this PR does / why we need it:
Add support for basic token authentication in cases where the loki-queriers/frontends are exposed through a reverse proxy doing token/bearer authentication.

Which issue(s) this PR fixes:
Fixes #395 (Partially - it does not implement oauth2)

Special notes for your reviewer:

Checklist

  • Documentation added
  • Tests updated

@CLAassistant
Copy link

CLAassistant commented Nov 5, 2020

CLA assistant check
All committers have signed the CLA.

@achatterjee-grafana
Copy link
Contributor

@grafana/docs-squad, looking at this.

@codecov-io
Copy link

codecov-io commented Nov 5, 2020

Codecov Report

Merging #2889 into master will decrease coverage by 0.03%.
The diff coverage is 0.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2889      +/-   ##
==========================================
- Coverage   61.23%   61.20%   -0.04%     
==========================================
  Files         181      181              
  Lines       14574    14579       +5     
==========================================
- Hits         8925     8923       -2     
- Misses       4829     4836       +7     
  Partials      820      820              
Impacted Files Coverage Δ
pkg/logcli/client/client.go 5.30% <0.00%> (-0.25%) ⬇️
pkg/querier/queryrange/downstreamer.go 95.29% <0.00%> (-2.36%) ⬇️

Copy link
Contributor

@achatterjee-grafana achatterjee-grafana left a comment

Choose a reason for hiding this comment

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

Added some copy-edits.

docs/sources/getting-started/logcli.md Outdated Show resolved Hide resolved
docs/sources/getting-started/logcli.md Outdated Show resolved Hide resolved
docs/sources/getting-started/logcli.md Outdated Show resolved Hide resolved
docs/sources/getting-started/logcli.md Outdated Show resolved Hide resolved
Copy link
Contributor

@achatterjee-grafana achatterjee-grafana left a comment

Choose a reason for hiding this comment

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

LGTM! Thank you for your contribution.

@jgehrcke
Copy link
Contributor

jgehrcke commented Nov 9, 2020

--token

The world of tokens is huge :-). I think the command line flag's name should use the word "bearer" to narrow down the scope a little, semantically.

Adds Authorization header bearer to API requests

I think this sentence can could still be polished, right? :-).

Maybe the most important feedback: personally, I do like the semantics and documentation of bearer_token_file in the Prometheus ecosystem. It's good to enable/encourage setting this sensitive value from a file as the primary method.

From the Prometheus docs:

# Sets the `Authorization` header on every scrape request with the bearer token
# read from the configured file. It is mutually exclusive with `bearer_token`.
[ bearer_token_file: <filename> ]

Related: #2739

What do you think about adding a --bearer-token-file PATH arg instead of --token VALUE?

@@ -195,6 +197,8 @@ Flags:
--key="" Path to the client certificate key. Can also be set using LOKI_CLIENT_KEY_PATH env var.
--org-id="" adds X-Scope-OrgID to API requests for representing tenant ID. Useful for requesting tenant data when
bypassing an auth gateway.
--token="" Adds Authorization header bearer to API requests for authentication purposes. It can also be set

Choose a reason for hiding this comment

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

whitespace is off here

//The token presence overrides basic-auth authentication
if c.Token != "" {
req.Header.Set("Authorization", "Bearer "+c.Token)
req.Header.Add("Accept", "application/json")

Choose a reason for hiding this comment

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

Why does the Accept header get set here?

Copy link
Author

Choose a reason for hiding this comment

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

logcli does not set this header elsewhere. By setting it here, we'd expect a 406 error if the response is not adequate (! application/json").
IMHO it should be set for all request but this PR's scope is to add support for bearer tokens.

Choose a reason for hiding this comment

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

Then leave it out of this PR entirely?

@gcotone
Copy link
Author

gcotone commented Nov 12, 2020

--token

The world of tokens is huge :-). I think the command line flag's name should use the word "bearer" to narrow down the scope a little, semantically.

Adds Authorization header bearer to API requests

I think this sentence can could still be polished, right? :-).

Maybe the most important feedback: personally, I do like the semantics and documentation of bearer_token_file in the Prometheus ecosystem. It's good to enable/encourage setting this sensitive value from a file as the primary method.

From the Prometheus docs:

# Sets the `Authorization` header on every scrape request with the bearer token
# read from the configured file. It is mutually exclusive with `bearer_token`.
[ bearer_token_file: <filename> ]bearer_token_file

Related: #2739

What do you think about adding a --bearer-token-file PATH arg instead of --token VALUE?

@jgehrcke fair point. Prometheus actually supports both bearer_token and bearer_token_file. I'll adapt this PR to implement them following prometheus semantics.

@stale
Copy link

stale bot commented Dec 12, 2020

This issue has been automatically marked as stale because it has not had any activity in the past 30 days. It will be closed in 7 days if no further activity occurs. Thank you for your contributions.

@stale stale bot added the stale A stale issue or PR that will automatically be closed. label Dec 12, 2020
@stale stale bot closed this Dec 20, 2020
@dbluxo
Copy link
Contributor

dbluxo commented Jan 22, 2021

@gcotone We would need that too, do you still plan to work on it?

@gcotone
Copy link
Author

gcotone commented Feb 2, 2021

@dbluxo not in the next month or so.

@dbluxo
Copy link
Contributor

dbluxo commented Apr 7, 2021

@gcotone I have created a new PR: #3585 (based on yours)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/S stale A stale issue or PR that will automatically be closed.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support SSO for Loki Log CLI
7 participants