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

fix(access): make validate list aware of the mesh - WIP #5280

Merged
merged 1 commit into from
Nov 8, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/api-server/dataplane_overview_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ func (r *dataplaneOverviewEndpoints) inspectDataplanes(request *restful.Request,
meshName := request.PathParameter("mesh")

if err := r.resourceAccess.ValidateList(
meshName,
mesh.NewDataplaneOverviewResource().Descriptor(),
user.FromCtx(request.Request.Context()),
); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/api-server/resource_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func (r *resourceEndpoints) listResources(request *restful.Request, response *re
meshName := r.meshFromRequest(request)

if err := r.resourceAccess.ValidateList(
meshName,
r.descriptor,
user.FromCtx(request.Request.Context()),
); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/api-server/zone_overview_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (r *zoneOverviewEndpoints) fetchOverview(ctx context.Context, name string)

func (r *zoneOverviewEndpoints) inspectZones(request *restful.Request, response *restful.Response) {
if err := r.resourceAccess.ValidateList(
"",
system.NewZoneResource().Descriptor(),
user.FromCtx(request.Request.Context()),
); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/api-server/zoneegressoverview_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ func (r *zoneEgressOverviewEndpoints) inspectZoneEgresses(
response *restful.Response,
) {
if err := r.resourceAccess.ValidateList(
"",
mesh.NewZoneEgressOverviewResource().Descriptor(),
user.FromCtx(request.Request.Context()),
); err != nil {
Expand Down
1 change: 1 addition & 0 deletions pkg/api-server/zoneingress_overview_endpoints.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ func (r *zoneIngressOverviewEndpoints) fetchOverview(ctx context.Context, name s

func (r *zoneIngressOverviewEndpoints) inspectZoneIngresses(request *restful.Request, response *restful.Response) {
if err := r.resourceAccess.ValidateList(
"",
mesh.NewZoneIngressOverviewResource().Descriptor(),
user.FromCtx(request.Request.Context()),
); err != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/resources/access/admin_resource_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (a *adminResourceAccess) ValidateDelete(_ model.ResourceKey, _ model.Resour
return a.validateAdminAccess(user, descriptor)
}

func (a *adminResourceAccess) ValidateList(descriptor model.ResourceTypeDescriptor, user user.User) error {
func (a *adminResourceAccess) ValidateList(_ string, descriptor model.ResourceTypeDescriptor, user user.User) error {
return a.validateAdminAccess(user, descriptor)
}

Expand Down
2 changes: 2 additions & 0 deletions pkg/core/resources/access/admin_resource_access_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ var _ = Describe("Admin Resource Access", func() {
It("should allow admin to access List", func() {
// when
err := resourceAccess.ValidateList(
"",
system.NewSecretResource().Descriptor(),
user.Admin,
)
Expand All @@ -136,6 +137,7 @@ var _ = Describe("Admin Resource Access", func() {
It("should deny user to access List", func() {
// when
err := resourceAccess.ValidateList(
"",
system.NewSecretResource().Descriptor(),
user.User{Name: "john doe", Groups: []string{"users"}},
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/core/resources/access/resource_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ type ResourceAccess interface {
ValidateCreate(key model.ResourceKey, spec model.ResourceSpec, desc model.ResourceTypeDescriptor, user user.User) error
ValidateUpdate(key model.ResourceKey, currentSpec model.ResourceSpec, newSpec model.ResourceSpec, desc model.ResourceTypeDescriptor, user user.User) error
ValidateDelete(key model.ResourceKey, spec model.ResourceSpec, desc model.ResourceTypeDescriptor, user user.User) error
ValidateList(desc model.ResourceTypeDescriptor, user user.User) error
ValidateList(mesh string, desc model.ResourceTypeDescriptor, user user.User) error
ValidateGet(key model.ResourceKey, desc model.ResourceTypeDescriptor, user user.User) error
}