Skip to content

Conversation

@gotjosh
Copy link
Member

@gotjosh gotjosh commented Jun 29, 2022

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

Sorry, something went wrong.

@gotjosh
Copy link
Member Author

gotjosh commented Jun 29, 2022

@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
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
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
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
Copy link
Member Author

gotjosh commented Jul 4, 2022

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

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
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.
gotjosh added a commit that referenced this pull request Jul 6, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
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.
gotjosh added a commit that referenced this pull request Jul 6, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
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.
gotjosh added a commit that referenced this pull request Jul 6, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
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.
gotjosh added a commit that referenced this pull request Jul 6, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
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.
gotjosh added a commit that referenced this pull request Jul 6, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
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.
gotjosh added a commit that referenced this pull request Jul 6, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
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.
gotjosh added a commit that referenced this pull request Jul 6, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
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.
gotjosh added a commit that referenced this pull request Jul 6, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
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>

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
Signed-off-by: gotjosh <josue.abreu@gmail.com>
gotjosh added a commit that referenced this pull request Jul 11, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
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>
@gotjosh gotjosh force-pushed the silence-creator-from-header-or-auth branch from 39d14f4 to a4025de Compare July 11, 2022 15:14
gotjosh added a commit that referenced this pull request Jul 11, 2022

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
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>
@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

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
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>

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
Signed-off-by: gotjosh <josue.abreu@gmail.com>
fix lint

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
Signed-off-by: gotjosh <josue.abreu@gmail.com>

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
Signed-off-by: gotjosh <josue.abreu@gmail.com>

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
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

Verified

This commit was signed with the committer’s verified signature. The key has expired.
gotjosh gotjosh
Signed-off-by: gotjosh <josue.abreu@gmail.com>
@gotjosh gotjosh marked this pull request as ready for review July 11, 2022 16:30
@AakarshitAgarwal
Copy link

AakarshitAgarwal commented Jul 27, 2022

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

@m-masataka
Copy link
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.

qinxx108 pushed a commit to qinxx108/alertmanager that referenced this pull request Dec 13, 2022
As part of prometheus#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: Yijie Qin <qinyijie@amazon.com>
@genofire
Copy link

genofire commented Sep 6, 2023

Any update, i would really love this feature ;)

@matzarah
Copy link

matzarah commented Nov 30, 2023

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

7 participants