2023-03-28 18:39:22 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2023-08-11 13:12:13 +00:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-28 18:39:22 +00:00
|
|
|
|
2021-11-16 18:04:01 +00:00
|
|
|
//go:build !consulent
|
2019-10-15 20:58:50 +00:00
|
|
|
|
|
|
|
package structs
|
|
|
|
|
2019-10-24 18:38:09 +00:00
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
"github.com/hashicorp/consul/acl"
|
|
|
|
)
|
|
|
|
|
2019-10-15 20:58:50 +00:00
|
|
|
const (
|
|
|
|
EnterpriseACLPolicyGlobalManagement = ""
|
2023-08-01 17:12:14 +00:00
|
|
|
EnterpriseACLPolicyGlobalReadOnly = ""
|
2019-10-24 18:38:09 +00:00
|
|
|
|
|
|
|
// aclPolicyTemplateServiceIdentity is the template used for synthesizing
|
|
|
|
// policies for service identities.
|
|
|
|
aclPolicyTemplateServiceIdentity = `
|
|
|
|
service "%[1]s" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
service "%[1]s-sidecar-proxy" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
service_prefix "" {
|
|
|
|
policy = "read"
|
|
|
|
}
|
|
|
|
node_prefix "" {
|
|
|
|
policy = "read"
|
|
|
|
}`
|
2020-06-16 16:54:27 +00:00
|
|
|
|
|
|
|
// A typical Consul node requires two permissions for itself.
|
|
|
|
// node:write
|
|
|
|
// - register itself in the catalog
|
|
|
|
// - update its network coordinates
|
|
|
|
// - potentially used to delete services during anti-entropy
|
|
|
|
// service:read
|
|
|
|
// - used during anti-entropy to discover all services that
|
|
|
|
// are registered to the node. That way the node can diff
|
|
|
|
// its local state against an accurate depiction of the
|
|
|
|
// remote state.
|
|
|
|
aclPolicyTemplateNodeIdentity = `
|
|
|
|
node "%[1]s" {
|
|
|
|
policy = "write"
|
|
|
|
}
|
|
|
|
service_prefix "" {
|
|
|
|
policy = "read"
|
|
|
|
}`
|
2019-10-15 20:58:50 +00:00
|
|
|
)
|
2019-10-24 18:38:09 +00:00
|
|
|
|
2020-05-06 18:48:04 +00:00
|
|
|
type ACLAuthMethodEnterpriseFields struct{}
|
|
|
|
|
2020-01-14 15:09:29 +00:00
|
|
|
type ACLAuthMethodEnterpriseMeta struct{}
|
|
|
|
|
2022-03-13 03:55:53 +00:00
|
|
|
func (_ *ACLAuthMethodEnterpriseMeta) FillWithEnterpriseMeta(_ *acl.EnterpriseMeta) {
|
2020-01-14 15:09:29 +00:00
|
|
|
// do nothing
|
|
|
|
}
|
|
|
|
|
2022-03-13 03:55:53 +00:00
|
|
|
func (_ *ACLAuthMethodEnterpriseMeta) ToEnterpriseMeta() *acl.EnterpriseMeta {
|
2021-07-22 18:20:45 +00:00
|
|
|
return DefaultEnterpriseMetaInDefaultPartition()
|
2020-01-14 15:09:29 +00:00
|
|
|
}
|
|
|
|
|
2022-03-13 03:55:53 +00:00
|
|
|
func aclServiceIdentityRules(svc string, _ *acl.EnterpriseMeta) string {
|
2019-10-24 18:38:09 +00:00
|
|
|
return fmt.Sprintf(aclPolicyTemplateServiceIdentity, svc)
|
|
|
|
}
|
|
|
|
|
2022-03-13 03:55:53 +00:00
|
|
|
func aclNodeIdentityRules(node string, _ *acl.EnterpriseMeta) string {
|
2021-09-16 14:17:02 +00:00
|
|
|
return fmt.Sprintf(aclPolicyTemplateNodeIdentity, node)
|
|
|
|
}
|
|
|
|
|
2019-10-24 18:38:09 +00:00
|
|
|
func (p *ACLPolicy) EnterprisePolicyMeta() *acl.EnterprisePolicyMeta {
|
|
|
|
return nil
|
|
|
|
}
|
2020-01-14 15:09:29 +00:00
|
|
|
|
2020-06-16 16:54:27 +00:00
|
|
|
func (t *ACLToken) NodeIdentityList() []*ACLNodeIdentity {
|
|
|
|
if len(t.NodeIdentities) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
out := make([]*ACLNodeIdentity, 0, len(t.NodeIdentities))
|
|
|
|
for _, n := range t.NodeIdentities {
|
|
|
|
out = append(out, n.Clone())
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
|
|
|
|
|
|
|
func (r *ACLRole) NodeIdentityList() []*ACLNodeIdentity {
|
|
|
|
if len(r.NodeIdentities) == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
out := make([]*ACLNodeIdentity, 0, len(r.NodeIdentities))
|
|
|
|
for _, n := range r.NodeIdentities {
|
|
|
|
out = append(out, n.Clone())
|
|
|
|
}
|
|
|
|
return out
|
|
|
|
}
|
2021-12-03 18:20:25 +00:00
|
|
|
|
2022-03-13 03:55:53 +00:00
|
|
|
func IsValidPartitionAndDatacenter(meta acl.EnterpriseMeta, datacenters []string, primaryDatacenter string) bool {
|
2021-12-03 18:20:25 +00:00
|
|
|
return true
|
|
|
|
}
|