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

User name is not updated right away after updating "X-WEBAUTH-NAME" value #34225

Open
GaryZengTurbo opened this issue May 17, 2021 · 6 comments
Labels
area/auth/authproxy area/auth area/backend/api good first issue Good for newcomers help wanted prio/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough interest in it. type/bug

Comments

@GaryZengTurbo
Copy link

What happened:
Same user with updated "X-WEBAUTH-NAME" value, the name is not updated right away.

What you expected to happen:
The name should always matches the "X-WEBAUTH-NAME" value.
On the third time, the returned name is user2, but the "X-WEBAUTH-NAME" value is user1.

How to reproduce it (as minimally and precisely as possible):

  1. curl -H "X-WEBAUTH-USER: user" -H "X-WEBAUTH-NAME: user1" http://localhost:3000/api/user
    {"id":4,"email":"user","name":"user1","login":"user","theme":"","orgId":1,"isGrafanaAdmin":false,"isDisabled":false,"isExternal":true,"authLabels":["OAuth"],"updatedAt":"2021-05-17T14:56:53Z","createdAt":"2021-05-17T14:56:53Z","avatarUrl":"/reports/avatar/ee11cbb19052e40b07aac0ca060c23ee"}%
  2. curl -H "X-WEBAUTH-USER: user" -H "X-WEBAUTH-NAME: user2" http://localhost:3000/api/user
    {"id":4,"email":"user","name":"user2","login":"user","theme":"","orgId":1,"isGrafanaAdmin":false,"isDisabled":false,"isExternal":true,"authLabels":["OAuth"],"updatedAt":"2021-05-17T14:57:02Z","createdAt":"2021-05-17T14:56:53Z","avatarUrl":"/reports/avatar/ee11cbb19052e40b07aac0ca060c23ee"}%
  3. curl -H "X-WEBAUTH-USER: user" -H "X-WEBAUTH-NAME: user1" http://localhost:3000/api/user
    {"id":4,"email":"user","name":"user2","login":"user","theme":"","orgId":1,"isGrafanaAdmin":false,"isDisabled":false,"isExternal":true,"authLabels":["OAuth"],"updatedAt":"2021-05-17T14:57:02Z","createdAt":"2021-05-17T14:56:53Z","avatarUrl":"/reports/avatar/ee11cbb19052e40b07aac0ca060c23ee"}%

Anything else we need to know?:
After waiting a while, the name will be updated eventually.

Environment:
Grafana version: v7.3.8 (1e26164)

@marefr
Copy link
Member

marefr commented May 31, 2021

This code

func (auth *AuthProxy) GetSignedInUser(userID int64) (*models.SignedInUser, error) {

is calling this code which caches the signed in user data for 5 seconds

ss.CacheService.Set(cacheKey, query.Result, time.Second*5)

However, when handling the actual request via

grafana/pkg/api/user.go

Lines 14 to 17 in 355be15

// GET /api/user (current authenticated user)
func GetSignedInUser(c *models.ReqContext) response.Response {
return getUserUserProfile(c.UserId)
}
this code is called which doesn't have a cache so not sure what's going on:
func GetUserProfile(query *models.GetUserProfileQuery) error {

@marefr marefr added needs investigation for unconfirmed bugs. use type/bug for confirmed bugs, even if they "need" more investigating and removed type/bug labels May 31, 2021
@marefr marefr moved this from Inbox to Investigations in Backend Platform Backlog May 31, 2021
@ying-jeanne
Copy link
Contributor

ying-jeanne commented Jun 7, 2021

i am able to reproduce the bug, seems when we fallback the name change as user2 -> user1, it doesn't take the change, but when we update user2 -> user3, it takes the change immediately, probably somewhere when we cache, we "ignore" the fallback behavior since we think it is an "outdated" data. It is a bit weird how it should work, that means a Get action would actually update the db user name.

@ying-jeanne ying-jeanne added the pr/needs-discussion This PR needs a bigger discussion label Jun 7, 2021
@ying-jeanne ying-jeanne added this to To do in Grafana Backend (DO NOT USE!) via automation Jun 7, 2021
@ying-jeanne
Copy link
Contributor

hey @GaryZengTurbo, thanks for reporting issue. As described before, the expected behavior is a bit confusing since we need to modify the user info in a get action, would you mind to share with us the use case when you would need to do above transactions? could you use user API to do the user info modification instead?

@GaryZengTurbo
Copy link
Author

Hi @ying-jeanne ,

Thanks for following up.

could you use user API to do the user info modification instead?

We are using auth-proxy, and trying to avoid directly modifying user.

Here are the details our Grafana integration use case:

  1. we use Grafana’s auth-proxy to feature.
  2. In some case, we have same X-WEBAUTH-USER user with different X-WEBAUTH-NAME name.
 proxy_set_header   X-WEBAUTH-USER $webauth_user;
 proxy_set_header   X-WEBAUTH-NAME $webauth_name;
  1. when the name is not updated, we will have wrong user name on the UI. For example, in the screenshot, the X-WEBAUTH-NAME value was test2, but the UI show test1.
    screenshot_user

@marefr marefr added type/bug prio/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough interest in it. and removed pr/needs-discussion This PR needs a bigger discussion needs investigation for unconfirmed bugs. use type/bug for confirmed bugs, even if they "need" more investigating labels Aug 26, 2021
@marefr marefr removed this from Investigations in Backend Platform Backlog Aug 26, 2021
@marefr
Copy link
Member

marefr commented Aug 26, 2021

This feels like an edge case. We'll keep this open, but are currently not planning to work on it. If anyone is interested to work on it and open a PR we're gladly helping out reviewing it.

@Rohxn16
Copy link

Rohxn16 commented Sep 30, 2023

Hey, is this issue still open? If it is I will take a look into this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/auth/authproxy area/auth area/backend/api good first issue Good for newcomers help wanted prio/awaiting-more-evidence Lowest priority. Possibly useful, but not yet enough interest in it. type/bug
Projects
None yet
Development

No branches or pull requests

6 participants