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

CSI: add support for wildcard namespaces on plugin status #20551

Merged
merged 2 commits into from
May 13, 2024
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/20551.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:improvement
csi: Added support for wildcard namespace to `plugin status` command
```
15 changes: 10 additions & 5 deletions nomad/csi_endpoint.go
Original file line number Diff line number Diff line change
Expand Up @@ -1795,7 +1795,8 @@ func (v *CSIPlugin) Get(args *structs.CSIPluginGetRequest, reply *structs.CSIPlu
return structs.ErrPermissionDenied
}

withAllocs := aclObj.AllowNsOp(args.RequestNamespace(), acl.NamespaceCapabilityReadJob)
ns := args.RequestNamespace()
withAllocs := aclObj.AllowNsOp(ns, acl.NamespaceCapabilityReadJob)

if args.ID == "" {
return fmt.Errorf("missing plugin ID")
Expand All @@ -1819,18 +1820,22 @@ func (v *CSIPlugin) Get(args *structs.CSIPluginGetRequest, reply *structs.CSIPlu
return nil
}

// if we're not allowed access to the namespace at all, we skip this
// copy as an optimization. withAllocs will be true for the wildcard
// namespace
if withAllocs {
plug, err = snap.CSIPluginDenormalize(ws, plug.Copy())
if err != nil {
return err
}

// Filter the allocation stubs by our namespace. withAllocs
// means we're allowed
// Filter the allocation stubs by allowed namespace
var as []*structs.AllocListStub
for _, a := range plug.Allocations {
if a.Namespace == args.RequestNamespace() {
as = append(as, a)
if ns == structs.AllNamespacesSentinel || a.Namespace == ns {
if aclObj.AllowNsOp(a.Namespace, acl.NamespaceCapabilityReadJob) {
as = append(as, a)
}
}
}
plug.Allocations = as
Expand Down
14 changes: 14 additions & 0 deletions nomad/csi_endpoint_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2478,10 +2478,24 @@ func TestCSIPluginEndpoint_ACLNamespaceFilterAlloc(t *testing.T) {
must.Eq(t, structs.DefaultNamespace, a.Namespace)
}

// filter out all allocs
p2 := mock.PluginPolicy("read")
t2 := mock.CreatePolicyAndToken(t, s, 1004, "plugin-read2", p2)
req.AuthToken = t2.SecretID
err = msgpackrpc.CallWithCodec(codec, "CSIPlugin.Get", req, resp)
must.NoError(t, err)
must.Eq(t, 0, len(resp.Plugin.Allocations))

// wildcard namespace filter
p3 := mock.PluginPolicy("read") +
mock.NamespacePolicy(ns1.Name, "", []string{acl.NamespaceCapabilityReadJob})
t3 := mock.CreatePolicyAndToken(t, s, 1005, "plugin-read", p3)

req.Namespace = structs.AllNamespacesSentinel
req.AuthToken = t3.SecretID
resp = &structs.CSIPluginGetResponse{}
err = msgpackrpc.CallWithCodec(codec, "CSIPlugin.Get", req, resp)
must.NoError(t, err)
must.Eq(t, 1, len(resp.Plugin.Allocations))
must.Eq(t, ns1.Name, resp.Plugin.Allocations[0].Namespace)
}