2023-03-15 19:00:52 +03:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
2024-01-02 21:36:20 +03:00
|
|
|
// SPDX-License-Identifier: BUSL-1.1
|
2023-03-15 19:00:52 +03:00
|
|
|
|
2017-10-11 20:21:20 +03:00
|
|
|
package vault
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
|
|
|
memdb "github.com/hashicorp/go-memdb"
|
|
|
|
)
|
|
|
|
|
2017-11-02 23:05:48 +03:00
|
|
|
const (
|
|
|
|
entitiesTable = "entities"
|
|
|
|
entityAliasesTable = "entity_aliases"
|
|
|
|
groupsTable = "groups"
|
|
|
|
groupAliasesTable = "group_aliases"
|
2021-09-27 20:55:29 +03:00
|
|
|
oidcClientsTable = "oidc_clients"
|
2017-11-02 23:05:48 +03:00
|
|
|
)
|
|
|
|
|
2018-10-19 22:47:26 +03:00
|
|
|
func identityStoreSchema(lowerCaseName bool) *memdb.DBSchema {
|
2017-10-11 20:21:20 +03:00
|
|
|
iStoreSchema := &memdb.DBSchema{
|
|
|
|
Tables: make(map[string]*memdb.TableSchema),
|
|
|
|
}
|
|
|
|
|
2018-10-19 22:47:26 +03:00
|
|
|
schemas := []func(bool) *memdb.TableSchema{
|
2017-11-02 23:05:48 +03:00
|
|
|
entitiesTableSchema,
|
2017-10-11 20:21:20 +03:00
|
|
|
aliasesTableSchema,
|
2017-11-02 23:05:48 +03:00
|
|
|
groupsTableSchema,
|
|
|
|
groupAliasesTableSchema,
|
2021-09-27 20:55:29 +03:00
|
|
|
oidcClientsTableSchema,
|
2017-10-11 20:21:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for _, schemaFunc := range schemas {
|
2018-10-19 22:47:26 +03:00
|
|
|
schema := schemaFunc(lowerCaseName)
|
2017-10-11 20:21:20 +03:00
|
|
|
if _, ok := iStoreSchema.Tables[schema.Name]; ok {
|
|
|
|
panic(fmt.Sprintf("duplicate table name: %s", schema.Name))
|
|
|
|
}
|
|
|
|
iStoreSchema.Tables[schema.Name] = schema
|
|
|
|
}
|
|
|
|
|
|
|
|
return iStoreSchema
|
|
|
|
}
|
|
|
|
|
2018-10-19 22:47:26 +03:00
|
|
|
func aliasesTableSchema(lowerCaseName bool) *memdb.TableSchema {
|
2017-10-11 20:21:20 +03:00
|
|
|
return &memdb.TableSchema{
|
2017-11-02 23:05:48 +03:00
|
|
|
Name: entityAliasesTable,
|
2017-10-11 20:21:20 +03:00
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
2021-04-08 19:43:39 +03:00
|
|
|
"id": {
|
2017-10-11 20:21:20 +03:00
|
|
|
Name: "id",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "ID",
|
|
|
|
},
|
|
|
|
},
|
2021-04-08 19:43:39 +03:00
|
|
|
"factors": {
|
2017-10-11 20:21:20 +03:00
|
|
|
Name: "factors",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.CompoundIndex{
|
|
|
|
Indexes: []memdb.Indexer{
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "MountAccessor",
|
|
|
|
},
|
|
|
|
&memdb.StringFieldIndex{
|
2018-10-19 22:47:26 +03:00
|
|
|
Field: "Name",
|
|
|
|
Lowercase: lowerCaseName,
|
2017-10-11 20:21:20 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-04-08 19:43:39 +03:00
|
|
|
"namespace_id": {
|
2018-09-18 06:03:00 +03:00
|
|
|
Name: "namespace_id",
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "NamespaceID",
|
|
|
|
},
|
|
|
|
},
|
2021-10-15 22:20:00 +03:00
|
|
|
"local_bucket_key": {
|
2021-11-16 22:56:34 +03:00
|
|
|
Name: "local_bucket_key",
|
|
|
|
AllowMissing: true,
|
2021-10-15 22:20:00 +03:00
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "LocalBucketKey",
|
|
|
|
},
|
|
|
|
},
|
2017-10-11 20:21:20 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-19 22:47:26 +03:00
|
|
|
func entitiesTableSchema(lowerCaseName bool) *memdb.TableSchema {
|
2017-10-11 20:21:20 +03:00
|
|
|
return &memdb.TableSchema{
|
2017-11-02 23:05:48 +03:00
|
|
|
Name: entitiesTable,
|
2017-10-11 20:21:20 +03:00
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
2021-04-08 19:43:39 +03:00
|
|
|
"id": {
|
2017-10-11 20:21:20 +03:00
|
|
|
Name: "id",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "ID",
|
|
|
|
},
|
|
|
|
},
|
2021-04-08 19:43:39 +03:00
|
|
|
"name": {
|
2017-10-11 20:21:20 +03:00
|
|
|
Name: "name",
|
|
|
|
Unique: true,
|
2018-09-18 06:03:00 +03:00
|
|
|
Indexer: &memdb.CompoundIndex{
|
|
|
|
Indexes: []memdb.Indexer{
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "NamespaceID",
|
|
|
|
},
|
|
|
|
&memdb.StringFieldIndex{
|
2018-10-19 22:47:26 +03:00
|
|
|
Field: "Name",
|
|
|
|
Lowercase: lowerCaseName,
|
2018-09-18 06:03:00 +03:00
|
|
|
},
|
|
|
|
},
|
2017-10-11 20:21:20 +03:00
|
|
|
},
|
|
|
|
},
|
2021-04-08 19:43:39 +03:00
|
|
|
"merged_entity_ids": {
|
2017-10-11 20:21:20 +03:00
|
|
|
Name: "merged_entity_ids",
|
|
|
|
Unique: true,
|
|
|
|
AllowMissing: true,
|
|
|
|
Indexer: &memdb.StringSliceFieldIndex{
|
|
|
|
Field: "MergedEntityIDs",
|
|
|
|
},
|
|
|
|
},
|
2021-04-08 19:43:39 +03:00
|
|
|
"bucket_key": {
|
2019-05-07 22:29:51 +03:00
|
|
|
Name: "bucket_key",
|
2017-10-11 20:21:20 +03:00
|
|
|
Indexer: &memdb.StringFieldIndex{
|
2019-05-07 22:29:51 +03:00
|
|
|
Field: "BucketKey",
|
2017-10-11 20:21:20 +03:00
|
|
|
},
|
|
|
|
},
|
2021-04-08 19:43:39 +03:00
|
|
|
"namespace_id": {
|
2018-09-18 06:03:00 +03:00
|
|
|
Name: "namespace_id",
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "NamespaceID",
|
|
|
|
},
|
|
|
|
},
|
2017-10-11 20:21:20 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-19 22:47:26 +03:00
|
|
|
func groupsTableSchema(lowerCaseName bool) *memdb.TableSchema {
|
2017-10-11 20:21:20 +03:00
|
|
|
return &memdb.TableSchema{
|
2017-11-02 23:05:48 +03:00
|
|
|
Name: groupsTable,
|
2017-10-11 20:21:20 +03:00
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
|
|
|
"id": {
|
|
|
|
Name: "id",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "ID",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"name": {
|
|
|
|
Name: "name",
|
|
|
|
Unique: true,
|
2018-09-18 06:03:00 +03:00
|
|
|
Indexer: &memdb.CompoundIndex{
|
|
|
|
Indexes: []memdb.Indexer{
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "NamespaceID",
|
|
|
|
},
|
|
|
|
&memdb.StringFieldIndex{
|
2018-10-19 22:47:26 +03:00
|
|
|
Field: "Name",
|
|
|
|
Lowercase: lowerCaseName,
|
2018-09-18 06:03:00 +03:00
|
|
|
},
|
|
|
|
},
|
2017-10-11 20:21:20 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
"member_entity_ids": {
|
|
|
|
Name: "member_entity_ids",
|
|
|
|
AllowMissing: true,
|
|
|
|
Indexer: &memdb.StringSliceFieldIndex{
|
|
|
|
Field: "MemberEntityIDs",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"parent_group_ids": {
|
|
|
|
Name: "parent_group_ids",
|
|
|
|
AllowMissing: true,
|
|
|
|
Indexer: &memdb.StringSliceFieldIndex{
|
|
|
|
Field: "ParentGroupIDs",
|
|
|
|
},
|
|
|
|
},
|
2021-04-08 19:43:39 +03:00
|
|
|
"bucket_key": {
|
2019-05-07 22:29:51 +03:00
|
|
|
Name: "bucket_key",
|
2017-10-11 20:21:20 +03:00
|
|
|
Indexer: &memdb.StringFieldIndex{
|
2019-05-07 22:29:51 +03:00
|
|
|
Field: "BucketKey",
|
2017-10-11 20:21:20 +03:00
|
|
|
},
|
|
|
|
},
|
2021-04-08 19:43:39 +03:00
|
|
|
"namespace_id": {
|
2018-09-18 06:03:00 +03:00
|
|
|
Name: "namespace_id",
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "NamespaceID",
|
|
|
|
},
|
|
|
|
},
|
2017-10-11 20:21:20 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2017-11-02 23:05:48 +03:00
|
|
|
|
2018-10-19 22:47:26 +03:00
|
|
|
func groupAliasesTableSchema(lowerCaseName bool) *memdb.TableSchema {
|
2017-11-02 23:05:48 +03:00
|
|
|
return &memdb.TableSchema{
|
|
|
|
Name: groupAliasesTable,
|
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
2021-04-08 19:43:39 +03:00
|
|
|
"id": {
|
2017-11-02 23:05:48 +03:00
|
|
|
Name: "id",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "ID",
|
|
|
|
},
|
|
|
|
},
|
2021-04-08 19:43:39 +03:00
|
|
|
"factors": {
|
2017-11-02 23:05:48 +03:00
|
|
|
Name: "factors",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.CompoundIndex{
|
|
|
|
Indexes: []memdb.Indexer{
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "MountAccessor",
|
|
|
|
},
|
|
|
|
&memdb.StringFieldIndex{
|
2018-10-19 22:47:26 +03:00
|
|
|
Field: "Name",
|
|
|
|
Lowercase: lowerCaseName,
|
2017-11-02 23:05:48 +03:00
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
2021-04-08 19:43:39 +03:00
|
|
|
"namespace_id": {
|
2018-09-18 06:03:00 +03:00
|
|
|
Name: "namespace_id",
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "NamespaceID",
|
|
|
|
},
|
|
|
|
},
|
2017-11-02 23:05:48 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2021-09-27 20:55:29 +03:00
|
|
|
|
|
|
|
func oidcClientsTableSchema(_ bool) *memdb.TableSchema {
|
|
|
|
return &memdb.TableSchema{
|
|
|
|
Name: oidcClientsTable,
|
|
|
|
Indexes: map[string]*memdb.IndexSchema{
|
|
|
|
"id": {
|
|
|
|
Name: "id",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "ClientID",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"name": {
|
|
|
|
Name: "name",
|
|
|
|
Unique: true,
|
|
|
|
Indexer: &memdb.CompoundIndex{
|
|
|
|
Indexes: []memdb.Indexer{
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "NamespaceID",
|
|
|
|
},
|
|
|
|
&memdb.StringFieldIndex{
|
|
|
|
Field: "Name",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
"namespace_id": {
|
|
|
|
Name: "namespace_id",
|
|
|
|
Indexer: &memdb.StringFieldIndex{
|
|
|
|
Field: "NamespaceID",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|