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

Backport to 1.3.x: Deployment Status Command Does Not Respect -namespace Wildcard #16876

Merged
merged 1 commit into from
Apr 13, 2023
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
3 changes: 3 additions & 0 deletions .changelog/16792.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:bug
core: the deployment's list endpoint now supports look up by prefix using the wildcard for namespace
```
33 changes: 27 additions & 6 deletions nomad/deployment_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,20 +396,33 @@ func (d *Deployment) List(args *structs.DeploymentListRequest, reply *structs.De

// Check namespace read-job permissions against request namespace since
// results are filtered by request namespace.
if aclObj, err := d.srv.ResolveToken(args.AuthToken); err != nil {
aclObj, err := d.srv.ResolveToken(args.AuthToken)
if err != nil {
return err
} else if aclObj != nil && !aclObj.AllowNsOp(namespace, acl.NamespaceCapabilityReadJob) {
}

if aclObj != nil && !aclObj.AllowNsOp(namespace, acl.NamespaceCapabilityReadJob) {
return structs.ErrPermissionDenied
}

allow := aclObj.AllowNsOpFunc(acl.NamespaceCapabilityReadJob)

// Setup the blocking query
sort := state.SortOption(args.Reverse)
opts := blockingOptions{
queryOpts: &args.QueryOptions,
queryMeta: &reply.QueryMeta,
run: func(ws memdb.WatchSet, store *state.StateStore) error {
allowableNamespaces, err := allowedNSes(aclObj, store, allow)
if err != nil {
if err == structs.ErrPermissionDenied {
reply.Deployments = make([]*structs.Deployment, 0)
return nil
}
return err
}

// Capture all the deployments
var err error
var iter memdb.ResultIterator
var opts paginator.StructsTokenizerOptions

Expand Down Expand Up @@ -437,8 +450,14 @@ func (d *Deployment) List(args *structs.DeploymentListRequest, reply *structs.De

tokenizer := paginator.NewStructsTokenizer(iter, opts)

filters := []paginator.Filter{
paginator.NamespaceFilter{
AllowableNamespaces: allowableNamespaces,
},
}

var deploys []*structs.Deployment
paginator, err := paginator.NewPaginator(iter, tokenizer, nil, args.QueryOptions,
pnator, err := paginator.NewPaginator(iter, tokenizer, filters, args.QueryOptions,
func(raw interface{}) error {
deploy := raw.(*structs.Deployment)
deploys = append(deploys, deploy)
Expand All @@ -449,7 +468,7 @@ func (d *Deployment) List(args *structs.DeploymentListRequest, reply *structs.De
http.StatusBadRequest, "failed to create result paginator: %v", err)
}

nextToken, err := paginator.Page()
nextToken, err := pnator.Page()
if err != nil {
return structs.NewErrRPCCodedf(
http.StatusBadRequest, "failed to read result page: %v", err)
Expand All @@ -468,7 +487,9 @@ func (d *Deployment) List(args *structs.DeploymentListRequest, reply *structs.De
// Set the query response
d.srv.setQueryMeta(&reply.QueryMeta)
return nil
}}
},
}

return d.srv.blockingRPC(&opts)
}

Expand Down
Loading