mirror of https://github.com/status-im/consul.git
Make the config entry and leaf cert cache types ns aware (#7256)
This commit is contained in:
parent
6739fe6e83
commit
e231d62bc9
|
@ -10,6 +10,7 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/lib"
|
"github.com/hashicorp/consul/lib"
|
||||||
|
"github.com/mitchellh/hashstructure"
|
||||||
|
|
||||||
"github.com/hashicorp/consul/agent/cache"
|
"github.com/hashicorp/consul/agent/cache"
|
||||||
"github.com/hashicorp/consul/agent/connect"
|
"github.com/hashicorp/consul/agent/connect"
|
||||||
|
@ -654,7 +655,20 @@ func (r *ConnectCALeafRequest) Key() string {
|
||||||
return fmt.Sprintf("agent:%s", r.Agent)
|
return fmt.Sprintf("agent:%s", r.Agent)
|
||||||
}
|
}
|
||||||
|
|
||||||
return fmt.Sprintf("service:%s", r.Service)
|
r.EnterpriseMeta.Normalize()
|
||||||
|
|
||||||
|
v, err := hashstructure.Hash([]interface{}{
|
||||||
|
r.Service,
|
||||||
|
r.EnterpriseMeta,
|
||||||
|
}, nil)
|
||||||
|
if err == nil {
|
||||||
|
return fmt.Sprintf("service:%d", v)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If there is an error, we don't set the key. A blank key forces
|
||||||
|
// no cache for this request so the request is forwarded directly
|
||||||
|
// to the server.
|
||||||
|
return ""
|
||||||
}
|
}
|
||||||
|
|
||||||
func (r *ConnectCALeafRequest) CacheInfo() cache.RequestInfo {
|
func (r *ConnectCALeafRequest) CacheInfo() cache.RequestInfo {
|
||||||
|
|
|
@ -2,6 +2,7 @@ package cachetype
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -1018,8 +1019,15 @@ func (r *testGatedRootsRPC) RPC(method string, args interface{}, reply interface
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestConnectCALeaf_Key(t *testing.T) {
|
func TestConnectCALeaf_Key(t *testing.T) {
|
||||||
r := ConnectCALeafRequest{Service: "web"}
|
r1 := ConnectCALeafRequest{Service: "web"}
|
||||||
require.Equal(t, "service:web", r.Key())
|
r2 := ConnectCALeafRequest{Service: "api"}
|
||||||
r = ConnectCALeafRequest{Agent: "abc"}
|
|
||||||
|
// hashstructure will hash the service name + ent meta to produce this key
|
||||||
|
r1Key := r1.Key()
|
||||||
|
r2Key := r2.Key()
|
||||||
|
require.True(t, strings.HasPrefix(r1Key, "service:"), "Key %s does not start with service:", r1Key)
|
||||||
|
require.True(t, strings.HasPrefix(r2Key, "service:"), "Key %s does not start with service:", r2Key)
|
||||||
|
require.NotEqual(t, r1Key, r2Key, "Cache keys for different services are not equal")
|
||||||
|
r := ConnectCALeafRequest{Agent: "abc"}
|
||||||
require.Equal(t, "agent:abc", r.Key())
|
require.Equal(t, "agent:abc", r.Key())
|
||||||
}
|
}
|
||||||
|
|
|
@ -182,6 +182,7 @@ func (s *ACLServiceIdentity) SyntheticPolicy(entMeta *EnterpriseMeta) *ACLPolicy
|
||||||
policy.Rules = rules
|
policy.Rules = rules
|
||||||
policy.Syntax = acl.SyntaxCurrent
|
policy.Syntax = acl.SyntaxCurrent
|
||||||
policy.Datacenters = s.Datacenters
|
policy.Datacenters = s.Datacenters
|
||||||
|
policy.EnterpriseMeta.Merge(entMeta)
|
||||||
policy.SetHash(true)
|
policy.SetHash(true)
|
||||||
return policy
|
return policy
|
||||||
}
|
}
|
||||||
|
|
|
@ -510,6 +510,7 @@ func (r *ConfigEntryQuery) CacheInfo() cache.RequestInfo {
|
||||||
r.Kind,
|
r.Kind,
|
||||||
r.Name,
|
r.Name,
|
||||||
r.Filter,
|
r.Filter,
|
||||||
|
r.EnterpriseMeta,
|
||||||
}, nil)
|
}, nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// If there is an error, we don't set the key. A blank key forces
|
// If there is an error, we don't set the key. A blank key forces
|
||||||
|
@ -557,11 +558,13 @@ func (r *ServiceConfigRequest) CacheInfo() cache.RequestInfo {
|
||||||
// the slice would affect cache keys if we ever persist between agent restarts
|
// the slice would affect cache keys if we ever persist between agent restarts
|
||||||
// and change it.
|
// and change it.
|
||||||
v, err := hashstructure.Hash(struct {
|
v, err := hashstructure.Hash(struct {
|
||||||
Name string
|
Name string
|
||||||
Upstreams []string `hash:"set"`
|
EnterpriseMeta EnterpriseMeta
|
||||||
|
Upstreams []string `hash:"set"`
|
||||||
}{
|
}{
|
||||||
Name: r.Name,
|
Name: r.Name,
|
||||||
Upstreams: r.Upstreams,
|
EnterpriseMeta: r.EnterpriseMeta,
|
||||||
|
Upstreams: r.Upstreams,
|
||||||
}, nil)
|
}, nil)
|
||||||
if err == nil {
|
if err == nil {
|
||||||
// If there is an error, we don't set the key. A blank key forces
|
// If there is an error, we don't set the key. A blank key forces
|
||||||
|
|
Loading…
Reference in New Issue