feat(webui): act in a selected organisation the caller is a member of, enforced at the dashboard and the State Store
This commit is contained in:
1 parent
2cf9d435cc
commit
2fb0084d2c
17 files changed
+356
-69
No files matched your search
@@ -3,6 +3,7 @@ package rpcidentity
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
|
||||
"google.golang.org/grpc"
|
||||
"google.golang.org/grpc/codes"
|
||||
@@ -23,14 +24,22 @@ const CallerKey = "state-store-caller"
|
||||
// for one.
|
||||
const PrincipalKey = "state-store-principal"
|
||||
|
||||
// OrgKey carries the org the principal acts in, which differs from the one it
|
||||
// serves when the caller selected another org it is a member of.
|
||||
const OrgKey = "state-store-org"
|
||||
|
||||
// Outgoing forwards the context's principal, replacing any stale attribution.
|
||||
func Outgoing(ctx context.Context, caller string) context.Context {
|
||||
md, _ := metadata.FromOutgoingContext(ctx)
|
||||
md = md.Copy()
|
||||
md.Set(CallerKey, caller)
|
||||
md.Delete(PrincipalKey)
|
||||
md.Delete(OrgKey)
|
||||
if p, ok := access.PrincipalFromContext(ctx); ok {
|
||||
md.Set(PrincipalKey, string(p.IdentityID))
|
||||
if p.Org != "" {
|
||||
md.Set(OrgKey, string(p.Org))
|
||||
}
|
||||
}
|
||||
return metadata.NewOutgoingContext(ctx, md)
|
||||
}
|
||||
@@ -42,6 +51,9 @@ func Outgoing(ctx context.Context, caller string) context.Context {
|
||||
// org; any other acts in the default org.
|
||||
type Callers struct {
|
||||
Principals access.PrincipalSource
|
||||
// Workspaces lets a call act in an org it selected; without it any
|
||||
// selection other than the principal's own org is refused.
|
||||
Workspaces access.WorkspaceLister
|
||||
}
|
||||
|
||||
func (c Callers) resolve(ctx context.Context) (context.Context, error) {
|
||||
@@ -67,6 +79,15 @@ func (c Callers) resolve(ctx context.Context) (context.Context, error) {
|
||||
if err != nil {
|
||||
return nil, status.Errorf(codes.Unavailable, "resolve principal: %v", err)
|
||||
}
|
||||
// The forwarded org is a claim: the membership check, not the metadata,
|
||||
// decides whether the call may act there.
|
||||
p, err = p.Select(ctx, org.OrgID(first(md, OrgKey)), c.Workspaces)
|
||||
if err != nil {
|
||||
if errors.Is(err, access.ErrNotMember) {
|
||||
return nil, status.Error(codes.PermissionDenied, err.Error())
|
||||
}
|
||||
return nil, status.Errorf(codes.Unavailable, "select org: %v", err)
|
||||
}
|
||||
ctx = org.WithScope(org.WithOrg(access.WithActor(access.WithPrincipal(ctx, p), id), p.Org), p.Org)
|
||||
return ctx, nil
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user