2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2021-11-16 18:04:01 +00:00
|
|
|
//go:build !consulent
|
2020-01-24 15:04:58 +00:00
|
|
|
// +build !consulent
|
|
|
|
|
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
2021-02-09 17:37:57 +00:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2022-10-21 19:58:06 +00:00
|
|
|
"github.com/hashicorp/go-memdb"
|
2020-01-24 15:04:58 +00:00
|
|
|
|
2022-04-05 21:10:06 +00:00
|
|
|
"github.com/hashicorp/consul/acl"
|
2022-02-22 16:36:36 +00:00
|
|
|
"github.com/hashicorp/consul/agent/configentry"
|
2021-01-29 01:34:15 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
)
|
2020-01-24 15:04:58 +00:00
|
|
|
|
2021-02-09 17:37:57 +00:00
|
|
|
func indexFromConfigEntryKindName(arg interface{}) ([]byte, error) {
|
2021-03-31 20:21:21 +00:00
|
|
|
var b indexBuilder
|
|
|
|
|
|
|
|
switch n := arg.(type) {
|
2022-04-05 21:10:06 +00:00
|
|
|
case *acl.EnterpriseMeta:
|
2021-03-31 20:21:21 +00:00
|
|
|
return nil, nil
|
2022-04-05 21:10:06 +00:00
|
|
|
case acl.EnterpriseMeta:
|
2021-03-31 20:21:21 +00:00
|
|
|
return b.Bytes(), nil
|
|
|
|
case ConfigEntryKindQuery:
|
|
|
|
b.String(strings.ToLower(n.Kind))
|
|
|
|
return b.Bytes(), nil
|
2022-02-22 16:36:36 +00:00
|
|
|
case configentry.KindName:
|
2021-03-31 20:21:21 +00:00
|
|
|
b.String(strings.ToLower(n.Kind))
|
|
|
|
b.String(strings.ToLower(n.Name))
|
|
|
|
return b.Bytes(), nil
|
2021-02-09 17:37:57 +00:00
|
|
|
}
|
|
|
|
|
2021-03-31 20:21:21 +00:00
|
|
|
return nil, fmt.Errorf("invalid type for ConfigEntryKindName query: %T", arg)
|
2020-01-24 15:04:58 +00:00
|
|
|
}
|
|
|
|
|
2020-08-11 20:31:23 +00:00
|
|
|
func validateConfigEntryEnterprise(_ ReadTxn, _ structs.ConfigEntry) error {
|
2020-05-08 18:24:33 +00:00
|
|
|
return nil
|
2020-01-24 15:04:58 +00:00
|
|
|
}
|
|
|
|
|
2022-04-05 21:10:06 +00:00
|
|
|
func getAllConfigEntriesWithTxn(tx ReadTxn, _ *acl.EnterpriseMeta) (memdb.ResultIterator, error) {
|
2021-03-10 18:37:17 +00:00
|
|
|
return tx.Get(tableConfigEntries, indexID)
|
2020-01-24 15:04:58 +00:00
|
|
|
}
|
|
|
|
|
2021-10-13 14:47:12 +00:00
|
|
|
func getAllConfigEntriesByKindWithTxn(tx ReadTxn, kind string) (memdb.ResultIterator, error) {
|
|
|
|
return getConfigEntryKindsWithTxn(tx, kind, nil)
|
|
|
|
}
|
|
|
|
|
2022-04-05 21:10:06 +00:00
|
|
|
func getConfigEntryKindsWithTxn(tx ReadTxn, kind string, _ *acl.EnterpriseMeta) (memdb.ResultIterator, error) {
|
2021-03-31 20:21:21 +00:00
|
|
|
return tx.Get(tableConfigEntries, indexID+"_prefix", ConfigEntryKindQuery{Kind: kind})
|
2020-01-24 15:04:58 +00:00
|
|
|
}
|
2020-10-06 18:24:05 +00:00
|
|
|
|
2022-04-05 21:10:06 +00:00
|
|
|
func configIntentionsConvertToList(iter memdb.ResultIterator, _ *acl.EnterpriseMeta) structs.Intentions {
|
2020-10-06 18:24:05 +00:00
|
|
|
var results structs.Intentions
|
|
|
|
for v := iter.Next(); v != nil; v = iter.Next() {
|
|
|
|
entry := v.(*structs.ServiceIntentionsConfigEntry)
|
|
|
|
for _, src := range entry.Sources {
|
|
|
|
results = append(results, entry.ToIntention(src))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return results
|
|
|
|
}
|
2022-05-06 19:35:31 +00:00
|
|
|
|
|
|
|
// getExportedServicesMatchServicesNames returns a list of service names that are considered matches when
|
2023-08-23 16:53:44 +00:00
|
|
|
// found in a list of exported-services config entries. For CE, namespace is not considered, so a match is one of:
|
2022-05-06 19:35:31 +00:00
|
|
|
// - the service name matches
|
|
|
|
// - the service name is a wildcard
|
2022-10-21 19:58:06 +00:00
|
|
|
//
|
2022-05-06 19:35:31 +00:00
|
|
|
// This value can be used to filter exported-services config entries for a given service name.
|
|
|
|
func getExportedServicesMatchServiceNames(serviceName string, entMeta *acl.EnterpriseMeta) []structs.ServiceName {
|
|
|
|
return []structs.ServiceName{
|
|
|
|
structs.NewServiceName(serviceName, entMeta),
|
|
|
|
structs.NewServiceName(structs.WildcardSpecifier, entMeta),
|
|
|
|
}
|
|
|
|
}
|
2023-05-25 16:18:55 +00:00
|
|
|
|
|
|
|
func readSourceSamenessIntentionsFromConfigEntriesForServiceTxn(
|
|
|
|
tx ReadTxn,
|
|
|
|
ws memdb.WatchSet,
|
|
|
|
serviceName string,
|
|
|
|
sourceEntMeta *acl.EnterpriseMeta,
|
|
|
|
results structs.Intentions,
|
|
|
|
targetType structs.IntentionTargetType,
|
|
|
|
) (structs.Intentions, error) {
|
|
|
|
return results, nil
|
|
|
|
}
|