Add authorized actions output on resources (#870)
This commit is contained in:
1 parent
ec6151d174
commit
dcb15cffbd
93 files changed
+2475
-1038
No files matched your search
@@ -10,6 +10,7 @@ import (
|
||||
pbs "github.com/hashicorp/boundary/internal/gen/controller/api/services"
|
||||
"github.com/hashicorp/boundary/internal/iam"
|
||||
"github.com/hashicorp/boundary/internal/iam/store"
|
||||
"github.com/hashicorp/boundary/internal/perms"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/common"
|
||||
"github.com/hashicorp/boundary/internal/servers/controller/handlers"
|
||||
"github.com/hashicorp/boundary/internal/types/action"
|
||||
@@ -20,7 +21,27 @@ import (
|
||||
"google.golang.org/protobuf/types/known/wrapperspb"
|
||||
)
|
||||
|
||||
var maskManager handlers.MaskManager
|
||||
var (
|
||||
maskManager handlers.MaskManager
|
||||
|
||||
// IdActions contains the set of actions that can be performed on
|
||||
// individual resources
|
||||
IdActions = action.ActionSet{
|
||||
action.Read,
|
||||
action.Update,
|
||||
action.Delete,
|
||||
action.AddMembers,
|
||||
action.SetMembers,
|
||||
action.RemoveMembers,
|
||||
}
|
||||
|
||||
// CollectionActions contains the set of actions that can be performed on
|
||||
// this collection
|
||||
CollectionActions = action.ActionSet{
|
||||
action.Create,
|
||||
action.List,
|
||||
}
|
||||
)
|
||||
|
||||
func init() {
|
||||
var err error
|
||||
@@ -59,10 +80,19 @@ func (s Service) ListGroups(ctx context.Context, req *pbs.ListGroupsRequest) (*p
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
finalItems := make([]*pb.Group, 0, len(gl))
|
||||
res := &perms.Resource{
|
||||
ScopeId: authResults.Scope.Id,
|
||||
Type: resource.Group,
|
||||
}
|
||||
for _, item := range gl {
|
||||
item.Scope = authResults.Scope
|
||||
item.AuthorizedActions = authResults.FetchActionSetForId(ctx, item.Id, IdActions, auth.WithResource(res)).Strings()
|
||||
if len(item.AuthorizedActions) > 0 {
|
||||
finalItems = append(finalItems, item)
|
||||
}
|
||||
}
|
||||
return &pbs.ListGroupsResponse{Items: gl}, nil
|
||||
return &pbs.ListGroupsResponse{Items: finalItems}, nil
|
||||
}
|
||||
|
||||
// GetGroups implements the interface pbs.GroupServiceServer.
|
||||
@@ -79,6 +109,7 @@ func (s Service) GetGroup(ctx context.Context, req *pbs.GetGroupRequest) (*pbs.G
|
||||
return nil, err
|
||||
}
|
||||
u.Scope = authResults.Scope
|
||||
u.AuthorizedActions = authResults.FetchActionSetForId(ctx, u.Id, IdActions).Strings()
|
||||
return &pbs.GetGroupResponse{Item: u}, nil
|
||||
}
|
||||
|
||||
@@ -96,6 +127,7 @@ func (s Service) CreateGroup(ctx context.Context, req *pbs.CreateGroupRequest) (
|
||||
return nil, err
|
||||
}
|
||||
u.Scope = authResults.Scope
|
||||
u.AuthorizedActions = authResults.FetchActionSetForId(ctx, u.Id, IdActions).Strings()
|
||||
return &pbs.CreateGroupResponse{Item: u, Uri: fmt.Sprintf("groups/%s", u.GetId())}, nil
|
||||
}
|
||||
|
||||
@@ -113,6 +145,7 @@ func (s Service) UpdateGroup(ctx context.Context, req *pbs.UpdateGroupRequest) (
|
||||
return nil, err
|
||||
}
|
||||
u.Scope = authResults.Scope
|
||||
u.AuthorizedActions = authResults.FetchActionSetForId(ctx, u.Id, IdActions).Strings()
|
||||
return &pbs.UpdateGroupResponse{Item: u}, nil
|
||||
}
|
||||
|
||||
@@ -146,6 +179,7 @@ func (s Service) AddGroupMembers(ctx context.Context, req *pbs.AddGroupMembersRe
|
||||
return nil, err
|
||||
}
|
||||
g.Scope = authResults.Scope
|
||||
g.AuthorizedActions = authResults.FetchActionSetForId(ctx, g.Id, IdActions).Strings()
|
||||
return &pbs.AddGroupMembersResponse{Item: g}, nil
|
||||
}
|
||||
|
||||
@@ -163,6 +197,7 @@ func (s Service) SetGroupMembers(ctx context.Context, req *pbs.SetGroupMembersRe
|
||||
return nil, err
|
||||
}
|
||||
g.Scope = authResults.Scope
|
||||
g.AuthorizedActions = authResults.FetchActionSetForId(ctx, g.Id, IdActions).Strings()
|
||||
return &pbs.SetGroupMembersResponse{Item: g}, nil
|
||||
}
|
||||
|
||||
@@ -180,6 +215,7 @@ func (s Service) RemoveGroupMembers(ctx context.Context, req *pbs.RemoveGroupMem
|
||||
return nil, err
|
||||
}
|
||||
g.Scope = authResults.Scope
|
||||
g.AuthorizedActions = authResults.FetchActionSetForId(ctx, g.Id, IdActions).Strings()
|
||||
return &pbs.RemoveGroupMembersResponse{Item: g}, nil
|
||||
}
|
||||
|
||||
|
||||
@@ -106,6 +106,7 @@ func TestGet(t *testing.T) {
|
||||
ScopeId: u.GetScopeId(),
|
||||
},
|
||||
},
|
||||
AuthorizedActions: []string{"read", "update", "delete", "add-members", "set-members", "remove-members"},
|
||||
}
|
||||
|
||||
wantProjGroup := &pb.Group{
|
||||
@@ -124,6 +125,7 @@ func TestGet(t *testing.T) {
|
||||
ScopeId: u.GetScopeId(),
|
||||
},
|
||||
},
|
||||
AuthorizedActions: []string{"read", "update", "delete", "add-members", "set-members", "remove-members"},
|
||||
}
|
||||
|
||||
cases := []struct {
|
||||
@@ -218,21 +220,23 @@ func TestList(t *testing.T) {
|
||||
for i := 0; i < 10; i++ {
|
||||
og := iam.TestGroup(t, conn, oWithGroups.GetPublicId())
|
||||
wantOrgGroups = append(wantOrgGroups, &pb.Group{
|
||||
Id: og.GetPublicId(),
|
||||
ScopeId: og.GetScopeId(),
|
||||
Scope: &scopes.ScopeInfo{Id: oWithGroups.GetPublicId(), Type: scope.Org.String()},
|
||||
CreatedTime: og.GetCreateTime().GetTimestamp(),
|
||||
UpdatedTime: og.GetUpdateTime().GetTimestamp(),
|
||||
Version: 1,
|
||||
Id: og.GetPublicId(),
|
||||
ScopeId: og.GetScopeId(),
|
||||
Scope: &scopes.ScopeInfo{Id: oWithGroups.GetPublicId(), Type: scope.Org.String()},
|
||||
CreatedTime: og.GetCreateTime().GetTimestamp(),
|
||||
UpdatedTime: og.GetUpdateTime().GetTimestamp(),
|
||||
Version: 1,
|
||||
AuthorizedActions: []string{"read", "update", "delete", "add-members", "set-members", "remove-members"},
|
||||
})
|
||||
pg := iam.TestGroup(t, conn, pWithGroups.GetPublicId())
|
||||
wantProjGroups = append(wantProjGroups, &pb.Group{
|
||||
Id: pg.GetPublicId(),
|
||||
ScopeId: pg.GetScopeId(),
|
||||
Scope: &scopes.ScopeInfo{Id: pWithGroups.GetPublicId(), Type: scope.Project.String()},
|
||||
CreatedTime: pg.GetCreateTime().GetTimestamp(),
|
||||
UpdatedTime: pg.GetUpdateTime().GetTimestamp(),
|
||||
Version: 1,
|
||||
Id: pg.GetPublicId(),
|
||||
ScopeId: pg.GetScopeId(),
|
||||
Scope: &scopes.ScopeInfo{Id: pWithGroups.GetPublicId(), Type: scope.Project.String()},
|
||||
CreatedTime: pg.GetCreateTime().GetTimestamp(),
|
||||
UpdatedTime: pg.GetUpdateTime().GetTimestamp(),
|
||||
Version: 1,
|
||||
AuthorizedActions: []string{"read", "update", "delete", "add-members", "set-members", "remove-members"},
|
||||
})
|
||||
}
|
||||
|
||||
@@ -397,11 +401,12 @@ func TestCreate(t *testing.T) {
|
||||
res: &pbs.CreateGroupResponse{
|
||||
Uri: fmt.Sprintf("groups/%s_", iam.GroupPrefix),
|
||||
Item: &pb.Group{
|
||||
ScopeId: defaultOGroup.GetScopeId(),
|
||||
Scope: &scopes.ScopeInfo{Id: defaultOGroup.GetScopeId(), Type: scope.Org.String()},
|
||||
Name: &wrapperspb.StringValue{Value: "name"},
|
||||
Description: &wrapperspb.StringValue{Value: "desc"},
|
||||
Version: 1,
|
||||
ScopeId: defaultOGroup.GetScopeId(),
|
||||
Scope: &scopes.ScopeInfo{Id: defaultOGroup.GetScopeId(), Type: scope.Org.String()},
|
||||
Name: &wrapperspb.StringValue{Value: "name"},
|
||||
Description: &wrapperspb.StringValue{Value: "desc"},
|
||||
Version: 1,
|
||||
AuthorizedActions: []string{"read", "update", "delete", "add-members", "set-members", "remove-members"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -415,11 +420,12 @@ func TestCreate(t *testing.T) {
|
||||
res: &pbs.CreateGroupResponse{
|
||||
Uri: fmt.Sprintf("groups/%s_", iam.GroupPrefix),
|
||||
Item: &pb.Group{
|
||||
ScopeId: scope.Global.String(),
|
||||
Scope: &scopes.ScopeInfo{Id: scope.Global.String(), Type: scope.Global.String()},
|
||||
Name: &wrapperspb.StringValue{Value: "name"},
|
||||
Description: &wrapperspb.StringValue{Value: "desc"},
|
||||
Version: 1,
|
||||
ScopeId: scope.Global.String(),
|
||||
Scope: &scopes.ScopeInfo{Id: scope.Global.String(), Type: scope.Global.String()},
|
||||
Name: &wrapperspb.StringValue{Value: "name"},
|
||||
Description: &wrapperspb.StringValue{Value: "desc"},
|
||||
Version: 1,
|
||||
AuthorizedActions: []string{"read", "update", "delete", "add-members", "set-members", "remove-members"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -435,11 +441,12 @@ func TestCreate(t *testing.T) {
|
||||
res: &pbs.CreateGroupResponse{
|
||||
Uri: fmt.Sprintf("groups/%s_", iam.GroupPrefix),
|
||||
Item: &pb.Group{
|
||||
ScopeId: defaultPGroup.GetScopeId(),
|
||||
Scope: &scopes.ScopeInfo{Id: defaultPGroup.GetScopeId(), Type: scope.Project.String()},
|
||||
Name: &wrapperspb.StringValue{Value: "name"},
|
||||
Description: &wrapperspb.StringValue{Value: "desc"},
|
||||
Version: 1,
|
||||
ScopeId: defaultPGroup.GetScopeId(),
|
||||
Scope: &scopes.ScopeInfo{Id: defaultPGroup.GetScopeId(), Type: scope.Project.String()},
|
||||
Name: &wrapperspb.StringValue{Value: "name"},
|
||||
Description: &wrapperspb.StringValue{Value: "desc"},
|
||||
Version: 1,
|
||||
AuthorizedActions: []string{"read", "update", "delete", "add-members", "set-members", "remove-members"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -581,6 +588,7 @@ func TestUpdate(t *testing.T) {
|
||||
ScopeId: u.GetScopeId(),
|
||||
},
|
||||
},
|
||||
AuthorizedActions: []string{"read", "update", "delete", "add-members", "set-members", "remove-members"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -611,6 +619,7 @@ func TestUpdate(t *testing.T) {
|
||||
ScopeId: u.GetScopeId(),
|
||||
},
|
||||
},
|
||||
AuthorizedActions: []string{"read", "update", "delete", "add-members", "set-members", "remove-members"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -642,6 +651,7 @@ func TestUpdate(t *testing.T) {
|
||||
ScopeId: u.GetScopeId(),
|
||||
},
|
||||
},
|
||||
AuthorizedActions: []string{"read", "update", "delete", "add-members", "set-members", "remove-members"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -673,6 +683,7 @@ func TestUpdate(t *testing.T) {
|
||||
ScopeId: u.GetScopeId(),
|
||||
},
|
||||
},
|
||||
AuthorizedActions: []string{"read", "update", "delete", "add-members", "set-members", "remove-members"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -735,6 +746,7 @@ func TestUpdate(t *testing.T) {
|
||||
ScopeId: u.GetScopeId(),
|
||||
},
|
||||
},
|
||||
AuthorizedActions: []string{"read", "update", "delete", "add-members", "set-members", "remove-members"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -765,6 +777,7 @@ func TestUpdate(t *testing.T) {
|
||||
ScopeId: u.GetScopeId(),
|
||||
},
|
||||
},
|
||||
AuthorizedActions: []string{"read", "update", "delete", "add-members", "set-members", "remove-members"},
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -795,6 +808,7 @@ func TestUpdate(t *testing.T) {
|
||||
ScopeId: u.GetScopeId(),
|
||||
},
|
||||
},
|
||||
AuthorizedActions: []string{"read", "update", "delete", "add-members", "set-members", "remove-members"},
|
||||
},
|
||||
},
|
||||
},
|
||||
|
||||
Reference in new issue
Block a user