mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
K8s/Authorizer: Move allow from fallback to org_role (#77235)
This commit is contained in:
@@ -4,10 +4,11 @@ import (
|
||||
"context"
|
||||
"fmt"
|
||||
|
||||
"k8s.io/apiserver/pkg/authorization/authorizer"
|
||||
|
||||
"github.com/grafana/grafana/pkg/infra/appcontext"
|
||||
"github.com/grafana/grafana/pkg/infra/log"
|
||||
"github.com/grafana/grafana/pkg/services/org"
|
||||
"k8s.io/apiserver/pkg/authorization/authorizer"
|
||||
)
|
||||
|
||||
var _ authorizer.Authorizer = &OrgIDAuthorizer{}
|
||||
@@ -28,18 +29,18 @@ func (auth OrgRoleAuthorizer) Authorize(ctx context.Context, a authorizer.Attrib
|
||||
|
||||
switch signedInUser.OrgRole {
|
||||
case org.RoleAdmin:
|
||||
return authorizer.DecisionNoOpinion, "", nil
|
||||
return authorizer.DecisionAllow, "", nil
|
||||
case org.RoleEditor:
|
||||
switch a.GetVerb() {
|
||||
case "get", "list", "watch", "create", "update", "patch", "delete", "put", "post":
|
||||
return authorizer.DecisionNoOpinion, "", nil
|
||||
return authorizer.DecisionAllow, "", nil
|
||||
default:
|
||||
return authorizer.DecisionDeny, errorMessageForGrafanaOrgRole(string(signedInUser.OrgRole), a), nil
|
||||
}
|
||||
case org.RoleViewer:
|
||||
switch a.GetVerb() {
|
||||
case "get", "list", "watch":
|
||||
return authorizer.DecisionNoOpinion, "", nil
|
||||
return authorizer.DecisionAllow, "", nil
|
||||
default:
|
||||
return authorizer.DecisionDeny, errorMessageForGrafanaOrgRole(string(signedInUser.OrgRole), a), nil
|
||||
}
|
||||
|
||||
@@ -28,11 +28,8 @@ func ProvideAuthorizer(
|
||||
authorizers = append(authorizers, orgIDAuthorizer)
|
||||
}
|
||||
|
||||
authorizers = append(authorizers,
|
||||
orgRoleAuthorizer,
|
||||
|
||||
// Add this last so that if nothing says authorizer.DecisionDeny, it will pass
|
||||
authorizerfactory.NewAlwaysAllowAuthorizer(),
|
||||
)
|
||||
// org role is last -- and will return allow for verbs that match expectations
|
||||
// Ideally FGAC happens earlier and returns an explicit answer
|
||||
authorizers = append(authorizers, orgRoleAuthorizer)
|
||||
return union.New(authorizers...)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user