POC/Provisioning: Find admin user (#98076)

* find admin user

* find admin user

* find admin user
This commit is contained in:
Ryan McKinley authored and GitHub committed 2024-12-17 10:06:25 +03:00
1 parent efc0b6802f
commit 8ea7f3a6ca
1 file changed
+29 -2
@@ -12,6 +12,7 @@ import (
"github.com/grafana/authlib/claims"
"github.com/grafana/grafana/pkg/apimachinery/identity"
"github.com/grafana/grafana/pkg/services/accesscontrol"
"github.com/grafana/grafana/pkg/services/apiserver"
"github.com/grafana/grafana/pkg/services/authn"
"github.com/grafana/grafana/pkg/services/org"
@@ -79,8 +80,34 @@ func (o *backgroundIdentities) WorkerIdentity(ctx context.Context, namespace str
id, ok := o.accounts[info.OrgID]
if !ok {
// HACK, use the global admin!!!
id = "user:1"
// HACK -- find an admin user
res, err := o.users.Search(context.Background(), &user.SearchUsersQuery{
SignedInUser: &identity.StaticRequester{
IsGrafanaAdmin: true,
OrgID: info.OrgID,
Permissions: map[int64]map[string][]string{
info.OrgID: {
accesscontrol.ActionUsersRead: {"*"},
},
},
},
OrgID: info.OrgID,
})
if err != nil {
return nil, err
}
found := false
for _, v := range res.Users {
if v.IsAdmin {
id = fmt.Sprintf("user:%d", v.ID)
found = true
break
}
}
if !found {
return nil, fmt.Errorf("unable to find admin user")
}
// HACK -- (if false) and still allow lint
switch o.serviceAccountNamePrefix {