2021-01-29 01:05:09 +00:00
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
2021-03-29 18:07:36 +00:00
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
|
2021-01-29 01:05:09 +00:00
|
|
|
"github.com/hashicorp/go-memdb"
|
|
|
|
|
2022-04-05 21:10:06 +00:00
|
|
|
"github.com/hashicorp/consul/acl"
|
2021-01-29 01:05:09 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
|
|
|
tableACLTokens = "acl-tokens"
|
|
|
|
tableACLPolicies = "acl-policies"
|
|
|
|
tableACLRoles = "acl-roles"
|
|
|
|
tableACLBindingRules = "acl-binding-rules"
|
|
|
|
tableACLAuthMethods = "acl-auth-methods"
|
|
|
|
|
2021-09-13 18:37:16 +00:00
|
|
|
indexAccessor = "accessor"
|
|
|
|
indexPolicies = "policies"
|
|
|
|
indexRoles = "roles"
|
|
|
|
indexAuthMethod = "authmethod"
|
|
|
|
indexLocality = "locality"
|
|
|
|
indexName = "name"
|
|
|
|
indexExpiresGlobal = "expires-global"
|
|
|
|
indexExpiresLocal = "expires-local"
|
2021-01-29 01:05:09 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
func tokensTableSchema() *memdb.TableSchema {
|
|
|
|
return &memdb.TableSchema{
|
|
|
|
Name: tableACLTokens,
|
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
2021-09-09 20:28:04 +00:00
|
|
|
indexAccessor: {
|
|
|
|
Name: indexAccessor,
|
2021-01-29 01:05:09 +00:00
|
|
|
// DEPRECATED (ACL-Legacy-Compat) - we should not AllowMissing here once legacy compat is removed
|
|
|
|
AllowMissing: true,
|
|
|
|
Unique: true,
|
2021-09-09 20:28:04 +00:00
|
|
|
Indexer: indexerSingle{
|
|
|
|
readIndex: readIndex(indexFromUUIDString),
|
|
|
|
writeIndex: writeIndex(indexAccessorIDFromACLToken),
|
2021-01-29 01:05:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
indexID: {
|
|
|
|
Name: indexID,
|
|
|
|
AllowMissing: false,
|
|
|
|
Unique: true,
|
2021-09-10 13:10:11 +00:00
|
|
|
Indexer: indexerSingle{
|
|
|
|
readIndex: readIndex(indexFromStringCaseSensitive),
|
|
|
|
writeIndex: writeIndex(indexSecretIDFromACLToken),
|
2021-01-29 01:05:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
indexPolicies: {
|
|
|
|
Name: indexPolicies,
|
|
|
|
// Need to allow missing for the anonymous token
|
|
|
|
AllowMissing: true,
|
|
|
|
Unique: false,
|
2021-09-10 18:57:37 +00:00
|
|
|
Indexer: indexerMulti{
|
|
|
|
readIndex: readIndex(indexFromUUIDQuery),
|
|
|
|
writeIndexMulti: writeIndexMulti(indexPoliciesFromACLToken),
|
|
|
|
},
|
2021-01-29 01:05:09 +00:00
|
|
|
},
|
|
|
|
indexRoles: {
|
|
|
|
Name: indexRoles,
|
|
|
|
AllowMissing: true,
|
|
|
|
Unique: false,
|
2021-09-10 20:04:33 +00:00
|
|
|
Indexer: indexerMulti{
|
|
|
|
readIndex: readIndex(indexFromUUIDQuery),
|
|
|
|
writeIndexMulti: writeIndexMulti(indexRolesFromACLToken),
|
|
|
|
},
|
2021-01-29 01:05:09 +00:00
|
|
|
},
|
|
|
|
indexAuthMethod: {
|
|
|
|
Name: indexAuthMethod,
|
|
|
|
AllowMissing: true,
|
|
|
|
Unique: false,
|
2021-09-10 20:56:56 +00:00
|
|
|
Indexer: indexerSingle{
|
|
|
|
readIndex: readIndex(indexFromAuthMethodQuery),
|
|
|
|
writeIndex: writeIndex(indexAuthMethodFromACLToken),
|
2021-01-29 01:05:09 +00:00
|
|
|
},
|
|
|
|
},
|
2021-09-13 15:53:00 +00:00
|
|
|
indexLocality: {
|
|
|
|
Name: indexLocality,
|
2021-01-29 01:05:09 +00:00
|
|
|
AllowMissing: false,
|
|
|
|
Unique: false,
|
2021-09-13 15:53:00 +00:00
|
|
|
Indexer: indexerSingle{
|
|
|
|
readIndex: readIndex(indexFromBoolQuery),
|
|
|
|
writeIndex: writeIndex(indexLocalFromACLToken),
|
2021-01-29 01:05:09 +00:00
|
|
|
},
|
|
|
|
},
|
2021-09-13 18:37:16 +00:00
|
|
|
indexExpiresGlobal: {
|
|
|
|
Name: indexExpiresGlobal,
|
2021-01-29 01:05:09 +00:00
|
|
|
AllowMissing: true,
|
|
|
|
Unique: false,
|
2021-09-13 18:37:16 +00:00
|
|
|
Indexer: indexerSingle{
|
|
|
|
readIndex: readIndex(indexFromTimeQuery),
|
|
|
|
writeIndex: writeIndex(indexExpiresGlobalFromACLToken),
|
|
|
|
},
|
2021-01-29 01:05:09 +00:00
|
|
|
},
|
2021-09-13 18:37:16 +00:00
|
|
|
indexExpiresLocal: {
|
|
|
|
Name: indexExpiresLocal,
|
2021-01-29 01:05:09 +00:00
|
|
|
AllowMissing: true,
|
|
|
|
Unique: false,
|
2021-09-13 18:37:16 +00:00
|
|
|
Indexer: indexerSingle{
|
|
|
|
readIndex: readIndex(indexFromTimeQuery),
|
|
|
|
writeIndex: writeIndex(indexExpiresLocalFromACLToken),
|
|
|
|
},
|
2021-01-29 01:05:09 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
//DEPRECATED (ACL-Legacy-Compat) - This index is only needed while we support upgrading v1 to v2 acls
|
|
|
|
// This table indexes all the ACL tokens that do not have an AccessorID
|
2021-09-29 20:14:36 +00:00
|
|
|
// TODO(ACL-Legacy-Compat): remove in phase 2
|
2021-01-29 01:05:09 +00:00
|
|
|
"needs-upgrade": {
|
|
|
|
Name: "needs-upgrade",
|
|
|
|
AllowMissing: false,
|
|
|
|
Unique: false,
|
|
|
|
Indexer: &memdb.ConditionalIndex{
|
|
|
|
Conditional: func(obj interface{}) (bool, error) {
|
|
|
|
if token, ok := obj.(*structs.ACLToken); ok {
|
|
|
|
return token.AccessorID == "", nil
|
|
|
|
}
|
|
|
|
return false, nil
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func policiesTableSchema() *memdb.TableSchema {
|
|
|
|
return &memdb.TableSchema{
|
|
|
|
Name: tableACLPolicies,
|
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
|
|
|
indexID: {
|
|
|
|
Name: indexID,
|
|
|
|
AllowMissing: false,
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.UUIDFieldIndex{
|
|
|
|
Field: "ID",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
indexName: {
|
|
|
|
Name: indexName,
|
|
|
|
AllowMissing: false,
|
|
|
|
Unique: true,
|
2021-03-16 19:29:30 +00:00
|
|
|
Indexer: indexerSingleWithPrefix{
|
2021-03-29 18:07:36 +00:00
|
|
|
readIndex: indexFromQuery,
|
|
|
|
writeIndex: indexNameFromACLPolicy,
|
|
|
|
prefixIndex: prefixIndexFromQuery,
|
2021-01-29 01:05:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-29 18:07:36 +00:00
|
|
|
func indexNameFromACLPolicy(raw interface{}) ([]byte, error) {
|
|
|
|
p, ok := raw.(*structs.ACLPolicy)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for structs.ACLPolicy index", raw)
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.Name == "" {
|
|
|
|
return nil, errMissingValueForIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
var b indexBuilder
|
|
|
|
b.String(strings.ToLower(p.Name))
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
2021-01-29 01:05:09 +00:00
|
|
|
func rolesTableSchema() *memdb.TableSchema {
|
|
|
|
return &memdb.TableSchema{
|
|
|
|
Name: tableACLRoles,
|
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
|
|
|
indexID: {
|
|
|
|
Name: indexID,
|
|
|
|
AllowMissing: false,
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.UUIDFieldIndex{
|
|
|
|
Field: "ID",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
indexName: {
|
|
|
|
Name: indexName,
|
|
|
|
AllowMissing: false,
|
|
|
|
Unique: true,
|
2021-03-17 17:57:40 +00:00
|
|
|
Indexer: indexerSingleWithPrefix{
|
2021-03-29 18:07:36 +00:00
|
|
|
readIndex: indexFromQuery,
|
|
|
|
writeIndex: indexNameFromACLRole,
|
|
|
|
prefixIndex: prefixIndexFromQuery,
|
2021-01-29 01:05:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
indexPolicies: {
|
|
|
|
Name: indexPolicies,
|
|
|
|
// Need to allow missing for the anonymous token
|
|
|
|
AllowMissing: true,
|
|
|
|
Unique: false,
|
2021-03-19 20:07:55 +00:00
|
|
|
Indexer: indexerMulti{
|
2021-03-29 18:07:36 +00:00
|
|
|
readIndex: indexFromUUIDQuery,
|
|
|
|
writeIndexMulti: multiIndexPolicyFromACLRole,
|
2021-03-19 20:07:55 +00:00
|
|
|
},
|
2021-01-29 01:05:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-29 18:07:36 +00:00
|
|
|
func indexNameFromACLRole(raw interface{}) ([]byte, error) {
|
|
|
|
p, ok := raw.(*structs.ACLRole)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for structs.ACLRole index", raw)
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.Name == "" {
|
|
|
|
return nil, errMissingValueForIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
var b indexBuilder
|
|
|
|
b.String(strings.ToLower(p.Name))
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func indexFromUUIDQuery(raw interface{}) ([]byte, error) {
|
|
|
|
q, ok := raw.(Query)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for UUIDQuery index", raw)
|
|
|
|
}
|
|
|
|
return uuidStringToBytes(q.Value)
|
|
|
|
}
|
|
|
|
|
2021-08-19 21:17:59 +00:00
|
|
|
func prefixIndexFromUUIDQuery(arg interface{}) ([]byte, error) {
|
|
|
|
switch v := arg.(type) {
|
2022-04-05 21:10:06 +00:00
|
|
|
case *acl.EnterpriseMeta:
|
2021-08-19 21:17:59 +00:00
|
|
|
return nil, nil
|
2022-04-05 21:10:06 +00:00
|
|
|
case acl.EnterpriseMeta:
|
2021-08-19 21:17:59 +00:00
|
|
|
return nil, nil
|
|
|
|
case Query:
|
|
|
|
return variableLengthUUIDStringToBytes(v.Value)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for Query prefix index", arg)
|
|
|
|
}
|
|
|
|
|
peering: initial sync (#12842)
- Add endpoints related to peering: read, list, generate token, initiate peering
- Update node/service/check table indexing to account for peers
- Foundational changes for pushing service updates to a peer
- Plumb peer name through Health.ServiceNodes path
see: ENT-1765, ENT-1280, ENT-1283, ENT-1283, ENT-1756, ENT-1739, ENT-1750, ENT-1679,
ENT-1709, ENT-1704, ENT-1690, ENT-1689, ENT-1702, ENT-1701, ENT-1683, ENT-1663,
ENT-1650, ENT-1678, ENT-1628, ENT-1658, ENT-1640, ENT-1637, ENT-1597, ENT-1634,
ENT-1613, ENT-1616, ENT-1617, ENT-1591, ENT-1588, ENT-1596, ENT-1572, ENT-1555
Co-authored-by: R.B. Boyer <rb@hashicorp.com>
Co-authored-by: freddygv <freddy@hashicorp.com>
Co-authored-by: Chris S. Kim <ckim@hashicorp.com>
Co-authored-by: Evan Culver <eculver@hashicorp.com>
Co-authored-by: Nitya Dhanushkodi <nitya@hashicorp.com>
2022-04-21 22:34:40 +00:00
|
|
|
func prefixIndexFromUUIDWithPeerQuery(arg interface{}) ([]byte, error) {
|
|
|
|
switch v := arg.(type) {
|
|
|
|
case Query:
|
|
|
|
var b indexBuilder
|
|
|
|
peername := v.PeerOrEmpty()
|
|
|
|
if peername == "" {
|
|
|
|
b.String(structs.LocalPeerKeyword)
|
|
|
|
} else {
|
|
|
|
b.String(strings.ToLower(peername))
|
|
|
|
}
|
|
|
|
uuidBytes, err := variableLengthUUIDStringToBytes(v.Value)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return append(b.Bytes(), uuidBytes...), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for Query prefix index", arg)
|
|
|
|
}
|
|
|
|
|
2021-03-29 18:07:36 +00:00
|
|
|
func multiIndexPolicyFromACLRole(raw interface{}) ([][]byte, error) {
|
|
|
|
role, ok := raw.(*structs.ACLRole)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for structs.ACLRole index", raw)
|
|
|
|
}
|
|
|
|
|
|
|
|
count := len(role.Policies)
|
|
|
|
if count == 0 {
|
|
|
|
return nil, errMissingValueForIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
vals := make([][]byte, 0, count)
|
|
|
|
for _, link := range role.Policies {
|
|
|
|
v, err := uuidStringToBytes(link.ID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
vals = append(vals, v)
|
|
|
|
}
|
|
|
|
|
|
|
|
return vals, nil
|
|
|
|
}
|
|
|
|
|
2021-01-29 01:05:09 +00:00
|
|
|
func bindingRulesTableSchema() *memdb.TableSchema {
|
|
|
|
return &memdb.TableSchema{
|
|
|
|
Name: tableACLBindingRules,
|
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
|
|
|
indexID: {
|
|
|
|
Name: indexID,
|
|
|
|
AllowMissing: false,
|
|
|
|
Unique: true,
|
2021-09-15 20:26:08 +00:00
|
|
|
Indexer: indexerSingle{
|
|
|
|
readIndex: readIndex(indexFromUUIDString),
|
|
|
|
writeIndex: writeIndex(indexIDFromACLBindingRule),
|
2021-01-29 01:05:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
indexAuthMethod: {
|
|
|
|
Name: indexAuthMethod,
|
|
|
|
AllowMissing: false,
|
|
|
|
Unique: false,
|
2021-09-15 13:34:19 +00:00
|
|
|
Indexer: indexerSingle{
|
|
|
|
readIndex: indexFromQuery,
|
|
|
|
writeIndex: indexAuthMethodFromACLBindingRule,
|
2021-01-29 01:05:09 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-15 20:26:08 +00:00
|
|
|
func indexIDFromACLBindingRule(raw interface{}) ([]byte, error) {
|
|
|
|
p, ok := raw.(*structs.ACLBindingRule)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for structs.ACLBindingRule index", raw)
|
|
|
|
}
|
|
|
|
vv, err := uuidStringToBytes(p.ID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
return vv, err
|
|
|
|
}
|
|
|
|
|
2021-09-15 13:34:19 +00:00
|
|
|
func indexAuthMethodFromACLBindingRule(raw interface{}) ([]byte, error) {
|
|
|
|
p, ok := raw.(*structs.ACLBindingRule)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for structs.ACLBindingRule index", raw)
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.AuthMethod == "" {
|
|
|
|
return nil, errMissingValueForIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
var b indexBuilder
|
|
|
|
b.String(strings.ToLower(p.AuthMethod))
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
2021-09-09 20:28:04 +00:00
|
|
|
func indexFromUUIDString(raw interface{}) ([]byte, error) {
|
|
|
|
index, ok := raw.(string)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for UUID string index", raw)
|
|
|
|
}
|
|
|
|
uuid, err := uuidStringToBytes(index)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var b indexBuilder
|
|
|
|
b.Raw(uuid)
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func indexAccessorIDFromACLToken(raw interface{}) ([]byte, error) {
|
|
|
|
p, ok := raw.(*structs.ACLToken)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for structs.ACLToken index", raw)
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.AccessorID == "" {
|
|
|
|
return nil, errMissingValueForIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
uuid, err := uuidStringToBytes(p.AccessorID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
var b indexBuilder
|
|
|
|
b.Raw(uuid)
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
2021-09-10 13:10:11 +00:00
|
|
|
|
|
|
|
func indexSecretIDFromACLToken(raw interface{}) ([]byte, error) {
|
|
|
|
p, ok := raw.(*structs.ACLToken)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for structs.ACLToken index", raw)
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.SecretID == "" {
|
|
|
|
return nil, errMissingValueForIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
var b indexBuilder
|
|
|
|
b.String(p.SecretID)
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func indexFromStringCaseSensitive(raw interface{}) ([]byte, error) {
|
|
|
|
q, ok := raw.(string)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for string prefix query", raw)
|
|
|
|
}
|
|
|
|
|
|
|
|
var b indexBuilder
|
|
|
|
b.String(q)
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
2021-09-10 18:57:37 +00:00
|
|
|
|
|
|
|
func indexPoliciesFromACLToken(raw interface{}) ([][]byte, error) {
|
|
|
|
token, ok := raw.(*structs.ACLToken)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for structs.ACLToken index", raw)
|
|
|
|
}
|
|
|
|
links := token.Policies
|
|
|
|
|
|
|
|
numLinks := len(links)
|
|
|
|
if numLinks == 0 {
|
|
|
|
return nil, errMissingValueForIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
vals := make([][]byte, numLinks)
|
|
|
|
|
|
|
|
for i, link := range links {
|
|
|
|
id, err := uuidStringToBytes(link.ID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
vals[i] = id
|
|
|
|
}
|
|
|
|
|
|
|
|
return vals, nil
|
|
|
|
}
|
2021-09-10 20:04:33 +00:00
|
|
|
|
|
|
|
func indexRolesFromACLToken(raw interface{}) ([][]byte, error) {
|
|
|
|
token, ok := raw.(*structs.ACLToken)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for structs.ACLToken index", raw)
|
|
|
|
}
|
|
|
|
links := token.Roles
|
|
|
|
|
|
|
|
numLinks := len(links)
|
|
|
|
if numLinks == 0 {
|
|
|
|
return nil, errMissingValueForIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
vals := make([][]byte, numLinks)
|
|
|
|
|
|
|
|
for i, link := range links {
|
|
|
|
id, err := uuidStringToBytes(link.ID)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
vals[i] = id
|
|
|
|
}
|
|
|
|
|
|
|
|
return vals, nil
|
|
|
|
}
|
2021-09-13 15:53:00 +00:00
|
|
|
|
|
|
|
func indexFromBoolQuery(raw interface{}) ([]byte, error) {
|
|
|
|
q, ok := raw.(BoolQuery)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for BoolQuery index", raw)
|
|
|
|
}
|
|
|
|
var b indexBuilder
|
|
|
|
b.Bool(q.Value)
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func indexLocalFromACLToken(raw interface{}) ([]byte, error) {
|
|
|
|
p, ok := raw.(*structs.ACLToken)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for structs.ACLPolicy index", raw)
|
|
|
|
}
|
|
|
|
|
|
|
|
var b indexBuilder
|
|
|
|
b.Bool(p.Local)
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
2021-09-13 18:37:16 +00:00
|
|
|
|
|
|
|
func indexFromTimeQuery(arg interface{}) ([]byte, error) {
|
|
|
|
p, ok := arg.(*TimeQuery)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for TimeQuery index", arg)
|
|
|
|
}
|
|
|
|
|
|
|
|
var b indexBuilder
|
|
|
|
b.Time(p.Value)
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func indexExpiresLocalFromACLToken(raw interface{}) ([]byte, error) {
|
|
|
|
return indexExpiresFromACLToken(raw, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
func indexExpiresGlobalFromACLToken(raw interface{}) ([]byte, error) {
|
|
|
|
return indexExpiresFromACLToken(raw, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
func indexExpiresFromACLToken(raw interface{}, local bool) ([]byte, error) {
|
|
|
|
p, ok := raw.(*structs.ACLToken)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for structs.ACLToken index", raw)
|
|
|
|
}
|
|
|
|
if p.Local != local {
|
|
|
|
return nil, errMissingValueForIndex
|
|
|
|
}
|
|
|
|
if !p.HasExpirationTime() {
|
|
|
|
return nil, errMissingValueForIndex
|
|
|
|
}
|
|
|
|
if p.ExpirationTime.Unix() < 0 {
|
|
|
|
return nil, fmt.Errorf("token expiration time cannot be before the unix epoch: %s", p.ExpirationTime)
|
|
|
|
}
|
|
|
|
|
|
|
|
var b indexBuilder
|
|
|
|
b.Time(*p.ExpirationTime)
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|
2021-09-22 20:19:20 +00:00
|
|
|
|
|
|
|
func authMethodsTableSchema() *memdb.TableSchema {
|
|
|
|
return &memdb.TableSchema{
|
|
|
|
Name: tableACLAuthMethods,
|
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
|
|
|
indexID: {
|
|
|
|
Name: indexID,
|
|
|
|
AllowMissing: false,
|
|
|
|
Unique: true,
|
|
|
|
Indexer: indexerSingle{
|
|
|
|
readIndex: indexFromQuery,
|
|
|
|
writeIndex: indexNameFromACLAuthMethod,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func indexNameFromACLAuthMethod(raw interface{}) ([]byte, error) {
|
|
|
|
p, ok := raw.(*structs.ACLAuthMethod)
|
|
|
|
if !ok {
|
|
|
|
return nil, fmt.Errorf("unexpected type %T for structs.ACLAuthMethod index", raw)
|
|
|
|
}
|
|
|
|
|
|
|
|
if p.Name == "" {
|
|
|
|
return nil, errMissingValueForIndex
|
|
|
|
}
|
|
|
|
|
|
|
|
var b indexBuilder
|
|
|
|
b.String(strings.ToLower(p.Name))
|
|
|
|
return b.Bytes(), nil
|
|
|
|
}
|