2019-10-24 18:38:09 +00:00
|
|
|
// +build !consulent
|
|
|
|
|
|
|
|
package state
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
memdb "github.com/hashicorp/go-memdb"
|
|
|
|
|
2021-01-29 01:05:09 +00:00
|
|
|
"github.com/hashicorp/consul/agent/structs"
|
|
|
|
)
|
2019-10-24 18:38:09 +00:00
|
|
|
|
2021-03-08 22:41:10 +00:00
|
|
|
func aclPolicyInsert(tx WriteTxn, policy *structs.ACLPolicy) error {
|
2021-03-16 18:53:56 +00:00
|
|
|
if err := tx.Insert(tableACLPolicies, policy); err != nil {
|
2019-10-24 18:38:09 +00:00
|
|
|
return fmt.Errorf("failed inserting acl policy: %v", err)
|
|
|
|
}
|
|
|
|
|
2021-03-16 18:53:56 +00:00
|
|
|
if err := indexUpdateMaxTxn(tx, policy.ModifyIndex, tableACLPolicies); err != nil {
|
2019-12-06 19:01:34 +00:00
|
|
|
return fmt.Errorf("failed updating acl policies index: %v", err)
|
2019-10-24 18:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2021-03-16 19:29:30 +00:00
|
|
|
func aclPolicyGetByID(tx ReadTxn, id string, _ *structs.EnterpriseMeta) (<-chan struct{}, interface{}, error) {
|
|
|
|
return tx.FirstWatch(tableACLPolicies, indexID, id)
|
2019-10-24 18:38:09 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 22:41:10 +00:00
|
|
|
func aclPolicyDeleteWithPolicy(tx WriteTxn, policy *structs.ACLPolicy, idx uint64) error {
|
2019-10-24 18:38:09 +00:00
|
|
|
// remove the policy
|
2021-03-16 18:53:56 +00:00
|
|
|
if err := tx.Delete(tableACLPolicies, policy); err != nil {
|
2019-10-24 18:38:09 +00:00
|
|
|
return fmt.Errorf("failed deleting acl policy: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the overall acl-policies index
|
2021-03-16 18:53:56 +00:00
|
|
|
if err := indexUpdateMaxTxn(tx, idx, tableACLPolicies); err != nil {
|
2019-10-24 18:38:09 +00:00
|
|
|
return fmt.Errorf("failed updating acl policies index: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:38:03 +00:00
|
|
|
func aclPolicyMaxIndex(tx ReadTxn, _ *structs.ACLPolicy, _ *structs.EnterpriseMeta) uint64 {
|
2021-03-16 18:53:56 +00:00
|
|
|
return maxIndexTxn(tx, tableACLPolicies)
|
2019-10-24 18:38:09 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 22:41:10 +00:00
|
|
|
func aclPolicyUpsertValidateEnterprise(ReadTxn, *structs.ACLPolicy, *structs.ACLPolicy) error {
|
2019-10-24 18:38:09 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Store) ACLPolicyUpsertValidateEnterprise(*structs.ACLPolicy, *structs.ACLPolicy) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
///// ACL Token Functions /////
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-03-08 22:41:10 +00:00
|
|
|
func aclTokenInsert(tx WriteTxn, token *structs.ACLToken) error {
|
2019-10-24 18:38:09 +00:00
|
|
|
// insert the token into memdb
|
|
|
|
if err := tx.Insert("acl-tokens", token); err != nil {
|
|
|
|
return fmt.Errorf("failed inserting acl token: %v", err)
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:01:34 +00:00
|
|
|
// update the overall acl-tokens index
|
|
|
|
if err := indexUpdateMaxTxn(tx, token.ModifyIndex, "acl-tokens"); err != nil {
|
|
|
|
return fmt.Errorf("failed updating acl tokens index: %v", err)
|
2019-10-24 18:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:38:03 +00:00
|
|
|
func aclTokenGetFromIndex(tx ReadTxn, id string, index string, entMeta *structs.EnterpriseMeta) (<-chan struct{}, interface{}, error) {
|
2019-10-24 18:38:09 +00:00
|
|
|
return tx.FirstWatch("acl-tokens", index, id)
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:38:03 +00:00
|
|
|
func aclTokenListAll(tx ReadTxn, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
2019-10-24 18:38:09 +00:00
|
|
|
return tx.Get("acl-tokens", "id")
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:38:03 +00:00
|
|
|
func aclTokenListLocal(tx ReadTxn, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
2019-10-24 18:38:09 +00:00
|
|
|
return tx.Get("acl-tokens", "local", true)
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:38:03 +00:00
|
|
|
func aclTokenListGlobal(tx ReadTxn, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
2019-10-24 18:38:09 +00:00
|
|
|
return tx.Get("acl-tokens", "local", false)
|
|
|
|
}
|
|
|
|
|
2020-07-06 22:44:51 +00:00
|
|
|
func aclTokenListByPolicy(tx ReadTxn, policy string, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
2019-10-24 18:38:09 +00:00
|
|
|
return tx.Get("acl-tokens", "policies", policy)
|
|
|
|
}
|
|
|
|
|
2020-07-06 22:44:51 +00:00
|
|
|
func aclTokenListByRole(tx ReadTxn, role string, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
2019-10-24 18:38:09 +00:00
|
|
|
return tx.Get("acl-tokens", "roles", role)
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:38:03 +00:00
|
|
|
func aclTokenListByAuthMethod(tx ReadTxn, authMethod string, _, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
2019-10-24 18:38:09 +00:00
|
|
|
return tx.Get("acl-tokens", "authmethod", authMethod)
|
|
|
|
}
|
|
|
|
|
2021-03-08 22:41:10 +00:00
|
|
|
func aclTokenDeleteWithToken(tx WriteTxn, token *structs.ACLToken, idx uint64) error {
|
2019-10-24 18:38:09 +00:00
|
|
|
// remove the token
|
|
|
|
if err := tx.Delete("acl-tokens", token); err != nil {
|
|
|
|
return fmt.Errorf("failed deleting acl token: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the overall acl-tokens index
|
2019-12-06 19:01:34 +00:00
|
|
|
if err := indexUpdateMaxTxn(tx, idx, "acl-tokens"); err != nil {
|
2019-10-24 18:38:09 +00:00
|
|
|
return fmt.Errorf("failed updating acl tokens index: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:38:03 +00:00
|
|
|
func aclTokenMaxIndex(tx ReadTxn, _ *structs.ACLToken, entMeta *structs.EnterpriseMeta) uint64 {
|
2019-10-24 18:38:09 +00:00
|
|
|
return maxIndexTxn(tx, "acl-tokens")
|
|
|
|
}
|
|
|
|
|
2021-03-08 22:41:10 +00:00
|
|
|
func aclTokenUpsertValidateEnterprise(tx WriteTxn, token *structs.ACLToken, existing *structs.ACLToken) error {
|
2019-10-24 18:38:09 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Store) ACLTokenUpsertValidateEnterprise(token *structs.ACLToken, existing *structs.ACLToken) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
///// ACL Role Functions /////
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-03-08 22:41:10 +00:00
|
|
|
func aclRoleInsert(tx WriteTxn, role *structs.ACLRole) error {
|
2019-10-24 18:38:09 +00:00
|
|
|
// insert the role into memdb
|
2021-03-16 20:39:22 +00:00
|
|
|
if err := tx.Insert(tableACLRoles, role); err != nil {
|
2019-10-24 18:38:09 +00:00
|
|
|
return fmt.Errorf("failed inserting acl role: %v", err)
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:01:34 +00:00
|
|
|
// update the overall acl-roles index
|
2021-03-16 20:39:22 +00:00
|
|
|
if err := indexUpdateMaxTxn(tx, role.ModifyIndex, tableACLRoles); err != nil {
|
2019-12-06 19:01:34 +00:00
|
|
|
return fmt.Errorf("failed updating acl roles index: %v", err)
|
2019-10-24 18:38:09 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-08-11 20:31:23 +00:00
|
|
|
func aclRoleGetByID(tx ReadTxn, id string, _ *structs.EnterpriseMeta) (<-chan struct{}, interface{}, error) {
|
2021-03-16 20:39:22 +00:00
|
|
|
return tx.FirstWatch(tableACLRoles, indexID, id)
|
2019-10-24 18:38:09 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 22:41:10 +00:00
|
|
|
func aclRoleDeleteWithRole(tx WriteTxn, role *structs.ACLRole, idx uint64) error {
|
2019-10-24 18:38:09 +00:00
|
|
|
// remove the role
|
2021-03-16 20:39:22 +00:00
|
|
|
if err := tx.Delete(tableACLRoles, role); err != nil {
|
2019-10-24 18:38:09 +00:00
|
|
|
return fmt.Errorf("failed deleting acl role: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the overall acl-roles index
|
2021-03-16 20:39:22 +00:00
|
|
|
if err := indexUpdateMaxTxn(tx, idx, tableACLRoles); err != nil {
|
2019-10-24 18:38:09 +00:00
|
|
|
return fmt.Errorf("failed updating acl policies index: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:38:03 +00:00
|
|
|
func aclRoleMaxIndex(tx ReadTxn, _ *structs.ACLRole, _ *structs.EnterpriseMeta) uint64 {
|
2021-03-16 20:39:22 +00:00
|
|
|
return maxIndexTxn(tx, tableACLRoles)
|
2019-10-24 18:38:09 +00:00
|
|
|
}
|
|
|
|
|
2021-03-08 22:41:10 +00:00
|
|
|
func aclRoleUpsertValidateEnterprise(tx WriteTxn, role *structs.ACLRole, existing *structs.ACLRole) error {
|
2019-10-24 18:38:09 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Store) ACLRoleUpsertValidateEnterprise(role *structs.ACLRole, existing *structs.ACLRole) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
///// ACL Binding Rule Functions /////
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-03-08 22:41:10 +00:00
|
|
|
func aclBindingRuleInsert(tx WriteTxn, rule *structs.ACLBindingRule) error {
|
2019-10-24 18:38:09 +00:00
|
|
|
// insert the role into memdb
|
|
|
|
if err := tx.Insert("acl-binding-rules", rule); err != nil {
|
|
|
|
return fmt.Errorf("failed inserting acl role: %v", err)
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:01:34 +00:00
|
|
|
// update the overall acl-binding-rules index
|
|
|
|
if err := indexUpdateMaxTxn(tx, rule.ModifyIndex, "acl-binding-rules"); err != nil {
|
|
|
|
return fmt.Errorf("failed updating acl binding-rules index: %v", err)
|
2019-10-24 18:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:38:03 +00:00
|
|
|
func aclBindingRuleGetByID(tx ReadTxn, id string, _ *structs.EnterpriseMeta) (<-chan struct{}, interface{}, error) {
|
2019-10-24 18:38:09 +00:00
|
|
|
return tx.FirstWatch("acl-binding-rules", "id", id)
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:38:03 +00:00
|
|
|
func aclBindingRuleList(tx ReadTxn, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
2019-10-24 18:38:09 +00:00
|
|
|
return tx.Get("acl-binding-rules", "id")
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:38:03 +00:00
|
|
|
func aclBindingRuleListByAuthMethod(tx ReadTxn, method string, _ *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
2019-10-24 18:38:09 +00:00
|
|
|
return tx.Get("acl-binding-rules", "authmethod", method)
|
|
|
|
}
|
|
|
|
|
2021-03-08 22:41:10 +00:00
|
|
|
func aclBindingRuleDeleteWithRule(tx WriteTxn, rule *structs.ACLBindingRule, idx uint64) error {
|
2019-10-24 18:38:09 +00:00
|
|
|
// remove the rule
|
|
|
|
if err := tx.Delete("acl-binding-rules", rule); err != nil {
|
|
|
|
return fmt.Errorf("failed deleting acl binding rule: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the overall acl-binding-rules index
|
2019-12-06 19:01:34 +00:00
|
|
|
if err := indexUpdateMaxTxn(tx, idx, "acl-binding-rules"); err != nil {
|
2019-10-24 18:38:09 +00:00
|
|
|
return fmt.Errorf("failed updating acl binding rules index: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:38:03 +00:00
|
|
|
func aclBindingRuleMaxIndex(tx ReadTxn, _ *structs.ACLBindingRule, entMeta *structs.EnterpriseMeta) uint64 {
|
2019-10-24 18:38:09 +00:00
|
|
|
return maxIndexTxn(tx, "acl-binding-rules")
|
|
|
|
}
|
|
|
|
|
2021-03-08 22:41:10 +00:00
|
|
|
func aclBindingRuleUpsertValidateEnterprise(tx ReadTxn, rule *structs.ACLBindingRule, existing *structs.ACLBindingRule) error {
|
2019-10-24 18:38:09 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Store) ACLBindingRuleUpsertValidateEnterprise(rule *structs.ACLBindingRule, existing *structs.ACLBindingRule) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
///// ACL Auth Method Functions /////
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2021-03-08 22:41:10 +00:00
|
|
|
func aclAuthMethodInsert(tx WriteTxn, method *structs.ACLAuthMethod) error {
|
2019-10-24 18:38:09 +00:00
|
|
|
// insert the role into memdb
|
|
|
|
if err := tx.Insert("acl-auth-methods", method); err != nil {
|
|
|
|
return fmt.Errorf("failed inserting acl role: %v", err)
|
|
|
|
}
|
|
|
|
|
2019-12-06 19:01:34 +00:00
|
|
|
// update the overall acl-auth-methods index
|
|
|
|
if err := indexUpdateMaxTxn(tx, method.ModifyIndex, "acl-auth-methods"); err != nil {
|
|
|
|
return fmt.Errorf("failed updating acl auth methods index: %v", err)
|
2019-10-24 18:38:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:38:03 +00:00
|
|
|
func aclAuthMethodGetByName(tx ReadTxn, method string, _ *structs.EnterpriseMeta) (<-chan struct{}, interface{}, error) {
|
2019-10-24 18:38:09 +00:00
|
|
|
return tx.FirstWatch("acl-auth-methods", "id", method)
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:38:03 +00:00
|
|
|
func aclAuthMethodList(tx ReadTxn, entMeta *structs.EnterpriseMeta) (memdb.ResultIterator, error) {
|
2019-10-24 18:38:09 +00:00
|
|
|
return tx.Get("acl-auth-methods", "id")
|
|
|
|
}
|
|
|
|
|
2021-03-08 22:41:10 +00:00
|
|
|
func aclAuthMethodDeleteWithMethod(tx WriteTxn, method *structs.ACLAuthMethod, idx uint64) error {
|
2019-10-24 18:38:09 +00:00
|
|
|
// remove the method
|
|
|
|
if err := tx.Delete("acl-auth-methods", method); err != nil {
|
|
|
|
return fmt.Errorf("failed deleting acl auth method: %v", err)
|
|
|
|
}
|
|
|
|
|
|
|
|
// update the overall acl-auth-methods index
|
2019-12-06 19:01:34 +00:00
|
|
|
if err := indexUpdateMaxTxn(tx, idx, "acl-auth-methods"); err != nil {
|
2019-10-24 18:38:09 +00:00
|
|
|
return fmt.Errorf("failed updating acl auth methods index: %v", err)
|
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-09-03 23:38:03 +00:00
|
|
|
func aclAuthMethodMaxIndex(tx ReadTxn, _ *structs.ACLAuthMethod, entMeta *structs.EnterpriseMeta) uint64 {
|
2019-10-24 18:38:09 +00:00
|
|
|
return maxIndexTxn(tx, "acl-auth-methods")
|
|
|
|
}
|
|
|
|
|
2021-03-08 22:41:10 +00:00
|
|
|
func aclAuthMethodUpsertValidateEnterprise(_ ReadTxn, method *structs.ACLAuthMethod, existing *structs.ACLAuthMethod) error {
|
2019-10-24 18:38:09 +00:00
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (s *Store) ACLAuthMethodUpsertValidateEnterprise(method *structs.ACLAuthMethod, existing *structs.ACLAuthMethod) error {
|
|
|
|
return nil
|
|
|
|
}
|