open-consul/agent/proxycfg-glue/intentions_oss.go
Daniel Upton 21ea217b1d proxycfg: server-local intentions data source
This is the OSS portion of enterprise PR 2141.

This commit provides a server-local implementation of the `proxycfg.Intentions`
interface that sources data from streaming events.

It adds events for the `service-intentions` config entry type, and then consumes
event streams (via materialized views) for the service's explicit intentions and
any applicable wildcard intentions, merging them into a single list of intentions.

An alternative approach I considered was to consume _all_ intention events (via
`SubjectWildcard`) and filter out the irrelevant ones. This would admittedly
remove some complexity in the `agent/proxycfg-glue` package but at the expense
of considerable overhead from waking potentially many thousands of connect
proxies every time any intention is updated.
2022-07-04 10:48:36 +01:00

40 lines
1 KiB
Go

//go:build !consulent
// +build !consulent
package proxycfgglue
import (
"github.com/hashicorp/consul/acl"
"github.com/hashicorp/consul/agent/structs"
"github.com/hashicorp/consul/proto/pbsubscribe"
)
func (s serverIntentions) buildSubjects(serviceName string, entMeta acl.EnterpriseMeta) []*pbsubscribe.NamedSubject {
// Based on getIntentionPrecedenceMatchServiceNames in the state package.
if serviceName == structs.WildcardSpecifier {
return []*pbsubscribe.NamedSubject{
{
Key: structs.WildcardSpecifier,
Namespace: entMeta.NamespaceOrDefault(),
Partition: entMeta.PartitionOrDefault(),
PeerName: structs.DefaultPeerKeyword,
},
}
}
return []*pbsubscribe.NamedSubject{
{
Key: serviceName,
Namespace: entMeta.NamespaceOrDefault(),
Partition: entMeta.PartitionOrDefault(),
PeerName: structs.DefaultPeerKeyword,
},
{
Key: structs.WildcardSpecifier,
Namespace: entMeta.NamespaceOrDefault(),
Partition: entMeta.PartitionOrDefault(),
PeerName: structs.DefaultPeerKeyword,
},
}
}