mirror of
https://github.com/status-im/consul.git
synced 2025-02-16 15:47:21 +00:00
parent
fae78dcd0a
commit
5480270d11
@ -341,9 +341,14 @@ func (f *aclFilter) allowNode(node string) bool {
|
|||||||
|
|
||||||
// allowService is used to determine if a service is accessible for an ACL.
|
// allowService is used to determine if a service is accessible for an ACL.
|
||||||
func (f *aclFilter) allowService(service string) bool {
|
func (f *aclFilter) allowService(service string) bool {
|
||||||
if service == "" || service == ConsulServiceID {
|
if service == "" {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !f.enforceVersion8 && service == ConsulServiceID {
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
return f.acl.ServiceRead(service)
|
return f.acl.ServiceRead(service)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -903,18 +903,29 @@ func TestACL_filterServices(t *testing.T) {
|
|||||||
services := structs.Services{
|
services := structs.Services{
|
||||||
"service1": []string{},
|
"service1": []string{},
|
||||||
"service2": []string{},
|
"service2": []string{},
|
||||||
|
"consul": []string{},
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try permissive filtering
|
// Try permissive filtering.
|
||||||
filt := newAclFilter(acl.AllowAll(), nil, false)
|
filt := newAclFilter(acl.AllowAll(), nil, false)
|
||||||
filt.filterServices(services)
|
filt.filterServices(services)
|
||||||
if len(services) != 2 {
|
if len(services) != 3 {
|
||||||
t.Fatalf("bad: %#v", services)
|
t.Fatalf("bad: %#v", services)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try restrictive filtering
|
// Try restrictive filtering.
|
||||||
filt = newAclFilter(acl.DenyAll(), nil, false)
|
filt = newAclFilter(acl.DenyAll(), nil, false)
|
||||||
filt.filterServices(services)
|
filt.filterServices(services)
|
||||||
|
if len(services) != 1 {
|
||||||
|
t.Fatalf("bad: %#v", services)
|
||||||
|
}
|
||||||
|
if _, ok := services["consul"]; !ok {
|
||||||
|
t.Fatalf("bad: %#v", services)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Try restrictive filtering with version 8 enforcement.
|
||||||
|
filt = newAclFilter(acl.DenyAll(), nil, true)
|
||||||
|
filt.filterServices(services)
|
||||||
if len(services) != 0 {
|
if len(services) != 0 {
|
||||||
t.Fatalf("bad: %#v", services)
|
t.Fatalf("bad: %#v", services)
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user