Skip to content

Silence creator from HTTP header or Basic Auth username - #2971

Open
gotjosh wants to merge 7 commits into
mainfrom
silence-creator-from-header-or-auth
Open

gotjosh wants to merge 7 commits into
mainfrom
silence-creator-from-header-or-auth

Conversation

@gotjosh

@gotjosh gotjosh commented Jun 29, 2022 •

Copy link
Copy Markdown
Member

The discussion is long as part of #1196, so instead of building this in isolation - I'm putting this out there to gather some feedback as I know there's some historic context and I want people to voice their opinions.

The first step is the building block for the server part (I'd argue this is the easy part):

1. If the header name is configured, we'll only check that and return the value from that.
2. If no basic auth is present, try the header which is specified via a configuration option

  1. If a header is set, use that no matter what.
  2. if no header is set, try basic auth.
  3. if none of the above returns an username, carry on as normal.
  4. if there's a discrepancy between what's in the params the value extracted from 1 and 2 error out.

The other bit is the front-end part (the actual hard one), a couple of thoughts:

  • When the silence form is rendered, there's no HTTP call as part of that and we all know that is not possible to access headers from javascript.
  • There are several approaches to solving the above, it can range from: Including the parsed username as part of the response to every HTTP call, creating a dedicated endpoint e.g. /api/v1/me, including it as part of the status endpoint and calling that as we render the silence form, etc. any opinions on what route should we take? I can start to see what Brian meant that this can very quickly turn into a scope creep for authentication things.
  • The front-end experience that I have in my head is the following:

TODO

  • tests
  • [ ] front-end the front-end part has been handled by @m-masataka and I think it's better discussed through a separate set of PRs.

Signed-off-by: gotjosh josue.abreu@gmail.com

@gotjosh

gotjosh commented Jun 29, 2022

Copy link
Copy Markdown
Member Author

@w0rm is there any chance you can take a quick peek at the above and guide me into how can I achieve the front-end bits?

@gotjosh gotjosh closed this Jun 29, 2022
@gotjosh gotjosh reopened this Jun 29, 2022
Comment thread api/v2/api.go
func (api *API) usernameFromHeaderOrBasicAuth(request *http.Request) string {
// First, let's try getting the username from Basic Authentication.
if user, _, ok := request.BasicAuth(); ok {
return user

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This is not correct, we should have this configured. if a specific header is specified in config, we should always use it, even if a user adds a custom authorization header.

use case for this:

  • you put an open id connect proxy in front of alertmanager, which pass the username as http header
  • communication between the proxy and alertmanager is done via static basic auth and TLS

@m-masataka

Copy link
Copy Markdown
Contributor

This is my sample front-end program with this PR. Here
I'm implementing this based on the following idea

creating a dedicated endpoint e.g. /api/v1/me

However, there are still some points to be discussed.

  • Should the creator be overwritten on the edit silence view?
  • When the front-end get username? (I think it should be called on reload.)
  • How to know whether this auth option is enable or not in front-end?
    • I think we should get the status with the response of api/v../me .

[demo]

sample.UI.Silence.creator.from.HTTP.header.or.Basic.Auth.username.mov

@gotjosh

gotjosh commented Jul 4, 2022

Copy link
Copy Markdown
Member Author

Wow! Thank you so much @m-masataka this looks great. I'm not sure a new API endpoint is the direction we'll take but the front-end changes look 👌

As for your questions:

Should the creator be overwritten on the edit silence view?

Yes, if there is a value available for the creator we should always use it. Validation will fail if the user creating/editing the silence does not match the current value. This effectively turns the feature is a type of last-write wins semantic where the creator is actually a last modified.

When the front-end get username? (I think it should be called on reload.)

Assuming that reload means on every time the silence form is rendered then we agree.

How to know whether this auth option is enabled or not in front-end?

We'll return a 204 status code instead of a 200. 204 non-content basically means we have unable to a value.

gotjosh added a commit that referenced this pull request Jul 6, 2022
As part of #2971, I'm about to extend the test for silences - extract the functions into helpers as part of a separate file and add names to the expectations so that we can easily identify them.

Signed-off-by: gotjosh <josue.abreu@gmail.com>
Signed-off-by: gotjosh <josue.abreu@gmail.com>
@gotjosh
gotjosh force-pushed the silence-creator-from-header-or-auth branch from 39d14f4 to a4025de Compare July 11, 2022 15:14
@gotjosh
gotjosh force-pushed the silence-creator-from-header-or-auth branch from a4025de to af108fe Compare July 11, 2022 15:22
gotjosh added 5 commits July 11, 2022 16:47
As part of #2971, I'm about to extend the test for silences - extract the functions into helpers as part of a separate file and add names to the expectations so that we can easily identify them.

Signed-off-by: gotjosh <josue.abreu@gmail.com>
Signed-off-by: gotjosh <josue.abreu@gmail.com>
Signed-off-by: gotjosh <josue.abreu@gmail.com>
Signed-off-by: gotjosh <josue.abreu@gmail.com>
Signed-off-by: gotjosh <josue.abreu@gmail.com>
@gotjosh
gotjosh force-pushed the silence-creator-from-header-or-auth branch from af108fe to cd8cd33 Compare July 11, 2022 15:47
@gotjosh
gotjosh requested a review from roidelapluie July 11, 2022 16:07
Signed-off-by: gotjosh <josue.abreu@gmail.com>
@gotjosh
gotjosh marked this pull request as ready for review July 11, 2022 16:30
@AakarshitAgarwal

AakarshitAgarwal commented Jul 27, 2022 •

Copy link
Copy Markdown

Can we restrict for many and recheck the Restrictors/Creators by either username or email?

@m-masataka

Copy link
Copy Markdown
Contributor

Can we restrict for many and recheck the Restrictors/Creators by either username or email?

If you means set username or email I think it depends on your identity proxy. @AakarshitAgarwal

We can set one custom header to use restrict Creator in this PR. so we can't set many creators.

@genofire

genofire commented Sep 6, 2023

Copy link
Copy Markdown

Any update, i would really love this feature ;)

@matzarah

matzarah commented Nov 30, 2023 •

Copy link
Copy Markdown

I would like to see this feature as we have a reverse proxy in front Alertmanager for authentication that could easily add a username header for Alertmanager to consume and prefill the author, or even enforce the author.

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.

Feature request: restrict the identity of silence creator to one passed by some HTTP header

6 participants