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
|
|
|
|
2015-09-09 22:24:45 +03:00
|
|
|
package vault
|
|
|
|
|
|
|
|
import (
|
2018-01-19 09:44:44 +03:00
|
|
|
"context"
|
2018-09-18 06:03:00 +03:00
|
|
|
"errors"
|
2015-09-09 22:24:45 +03:00
|
|
|
"fmt"
|
2016-05-03 21:24:04 +03:00
|
|
|
"strings"
|
2015-09-21 16:39:37 +03:00
|
|
|
"time"
|
2018-09-18 06:03:00 +03:00
|
|
|
|
2022-02-18 00:08:51 +03:00
|
|
|
"github.com/hashicorp/go-memdb"
|
2018-09-18 06:03:00 +03:00
|
|
|
"github.com/hashicorp/vault/helper/namespace"
|
2019-04-13 00:54:35 +03:00
|
|
|
"github.com/hashicorp/vault/sdk/framework"
|
2019-04-13 10:44:06 +03:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2018-09-18 06:03:00 +03:00
|
|
|
)
|
|
|
|
|
2023-05-17 21:56:45 +03:00
|
|
|
type enterprisePathStub struct {
|
|
|
|
parameters []string
|
|
|
|
operations []logical.Operation
|
|
|
|
}
|
|
|
|
|
2018-09-18 06:03:00 +03:00
|
|
|
var (
|
2022-02-18 00:08:51 +03:00
|
|
|
invalidateMFAConfig = func(context.Context, *SystemBackend, string) {}
|
|
|
|
invalidateLoginMFAConfig = func(context.Context, *SystemBackend, string) {}
|
|
|
|
invalidateLoginMFALoginEnforcementConfig = func(context.Context, *SystemBackend, string) {}
|
2018-09-18 06:03:00 +03:00
|
|
|
|
|
|
|
sysInvalidate = func(b *SystemBackend) func(context.Context, string) {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
getSystemSchemas = func() []func() *memdb.TableSchema { return nil }
|
|
|
|
|
|
|
|
getEGPListResponseKeyInfo = func(*SystemBackend, *namespace.Namespace) map[string]interface{} { return nil }
|
|
|
|
addSentinelPolicyData = func(map[string]interface{}, *Policy) {}
|
|
|
|
inputSentinelPolicyData = func(*framework.FieldData, *Policy) *logical.Response { return nil }
|
|
|
|
|
|
|
|
controlGroupUnwrap = func(context.Context, *SystemBackend, string, bool) (string, error) {
|
|
|
|
return "", errors.New("control groups unavailable")
|
|
|
|
}
|
|
|
|
|
|
|
|
pathInternalUINamespacesRead = func(b *SystemBackend) framework.OperationFunc {
|
|
|
|
return func(ctx context.Context, req *logical.Request, _ *framework.FieldData) (*logical.Response, error) {
|
|
|
|
// Short-circuit here if there's no client token provided
|
|
|
|
if req.ClientToken == "" {
|
|
|
|
return nil, fmt.Errorf("client token empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Load the ACL policies so we can check for access and filter namespaces
|
|
|
|
_, te, entity, _, err := b.Core.fetchACLTokenEntryAndEntity(ctx, req)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
if entity != nil && entity.Disabled {
|
|
|
|
b.logger.Warn("permission denied as the entity on the token is disabled")
|
|
|
|
return nil, logical.ErrPermissionDenied
|
|
|
|
}
|
|
|
|
if te != nil && te.EntityID != "" && entity == nil {
|
|
|
|
b.logger.Warn("permission denied as the entity on the token is invalid")
|
|
|
|
return nil, logical.ErrPermissionDenied
|
|
|
|
}
|
|
|
|
|
|
|
|
return logical.ListResponse([]string{""}), nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-21 23:14:40 +03:00
|
|
|
entPaths = entStubPaths
|
|
|
|
entStubPaths = func(b *SystemBackend) []*framework.Path {
|
2023-05-17 21:56:45 +03:00
|
|
|
buildEnterpriseOnlyPaths := func(paths map[string]enterprisePathStub) []*framework.Path {
|
2023-04-21 23:14:40 +03:00
|
|
|
var results []*framework.Path
|
2023-05-17 21:56:45 +03:00
|
|
|
for pattern, pathSpec := range paths {
|
|
|
|
path := &framework.Path{
|
|
|
|
Pattern: pattern,
|
|
|
|
Operations: make(map[logical.Operation]framework.OperationHandler),
|
|
|
|
Fields: make(map[string]*framework.FieldSchema),
|
|
|
|
}
|
2023-04-21 23:14:40 +03:00
|
|
|
|
2023-05-17 21:56:45 +03:00
|
|
|
for _, parameter := range pathSpec.parameters {
|
|
|
|
path.Fields[parameter] = &framework.FieldSchema{
|
|
|
|
Type: framework.TypeString,
|
|
|
|
Required: true,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for _, operation := range pathSpec.operations {
|
|
|
|
path.Operations[operation] = &framework.PathOperation{
|
2023-04-21 23:14:40 +03:00
|
|
|
Callback: func(context.Context, *logical.Request, *framework.FieldData) (*logical.Response, error) {
|
|
|
|
return logical.ErrorResponse("enterprise-only feature"), logical.ErrUnsupportedPath
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-17 21:56:45 +03:00
|
|
|
results = append(results, path)
|
2023-04-21 23:14:40 +03:00
|
|
|
}
|
2023-04-13 18:32:57 +03:00
|
|
|
|
2023-04-21 23:14:40 +03:00
|
|
|
return results
|
|
|
|
}
|
|
|
|
|
|
|
|
var paths []*framework.Path
|
|
|
|
|
|
|
|
// license paths
|
2023-05-17 21:56:45 +03:00
|
|
|
paths = append(paths, buildEnterpriseOnlyPaths(map[string]enterprisePathStub{
|
|
|
|
"license/status$": {operations: []logical.Operation{logical.ReadOperation}},
|
2023-04-21 23:14:40 +03:00
|
|
|
})...)
|
|
|
|
|
|
|
|
// group-policy-application paths
|
2023-05-17 21:56:45 +03:00
|
|
|
paths = append(paths, buildEnterpriseOnlyPaths(map[string]enterprisePathStub{
|
|
|
|
"config/group-policy-application$": {operations: []logical.Operation{logical.ReadOperation, logical.UpdateOperation}},
|
2023-04-21 23:14:40 +03:00
|
|
|
})...)
|
|
|
|
|
|
|
|
// namespaces paths
|
2023-05-17 21:56:45 +03:00
|
|
|
paths = append(paths, buildEnterpriseOnlyPaths(map[string]enterprisePathStub{
|
|
|
|
"namespaces/?$": {operations: []logical.Operation{logical.ListOperation}},
|
|
|
|
"namespaces/api-lock/lock" + framework.OptionalParamRegex("path"): {parameters: []string{"path"}, operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"namespaces/api-lock/unlock" + framework.OptionalParamRegex("path"): {parameters: []string{"path"}, operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"namespaces/(?P<path>.+?)": {parameters: []string{"path"}, operations: []logical.Operation{logical.DeleteOperation, logical.PatchOperation, logical.ReadOperation, logical.UpdateOperation}},
|
2023-04-21 23:14:40 +03:00
|
|
|
})...)
|
|
|
|
|
|
|
|
// replication paths
|
2023-05-17 21:56:45 +03:00
|
|
|
paths = append(paths, buildEnterpriseOnlyPaths(map[string]enterprisePathStub{
|
|
|
|
"replication/performance/primary/enable": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/dr/primary/enable": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/performance/primary/demote": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/dr/primary/demote": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/performance/primary/disable": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/dr/primary/disable": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/performance/primary/secondary-token": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/dr/primary/secondary-token": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/performance/primary/revoke-secondary": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/dr/primary/revoke-secondary": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/performance/secondary/generate-public-key": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/dr/secondary/generate-public-key": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/performance/secondary/enable": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/dr/secondary/enable": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/performance/secondary/promote": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/dr/secondary/promote": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/performance/secondary/disable": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/dr/secondary/disable": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/dr/secondary/operation-token/delete": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/performance/secondary/update-primary": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/dr/secondary/update-primary": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/dr/secondary/license/status": {operations: []logical.Operation{logical.ReadOperation}},
|
|
|
|
"replication/dr/secondary/config/reload/(?P<subsystem>.+)": {parameters: []string{"subsystem"}, operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/recover": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/dr/secondary/recover": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/dr/secondary/reindex": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/reindex": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/dr/status": {operations: []logical.Operation{logical.ReadOperation}},
|
|
|
|
"replication/performance/status": {operations: []logical.Operation{logical.ReadOperation}},
|
|
|
|
"replication/primary/enable": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/primary/demote": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/primary/disable": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/primary/secondary-token": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/performance/primary/paths-filter/" + framework.GenericNameRegex("id"): {parameters: []string{"id"}, operations: []logical.Operation{logical.DeleteOperation, logical.ReadOperation, logical.UpdateOperation}},
|
|
|
|
"replication/performance/primary/dynamic-filter/" + framework.GenericNameRegex("id"): {parameters: []string{"id"}, operations: []logical.Operation{logical.ReadOperation}},
|
|
|
|
"replication/primary/revoke-secondary": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/secondary/enable": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/secondary/promote": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/secondary/disable": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/secondary/update-primary": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"replication/performance/secondary/dynamic-filter/" + framework.GenericNameRegex("id"): {parameters: []string{"id"}, operations: []logical.Operation{logical.ReadOperation}},
|
2023-04-21 23:14:40 +03:00
|
|
|
})...)
|
|
|
|
// This path, though an enterprise path, has always been handled in OSS.
|
|
|
|
paths = append(paths, &framework.Path{
|
|
|
|
Pattern: "replication/status",
|
|
|
|
Callbacks: map[logical.Operation]framework.OperationFunc{
|
|
|
|
logical.ReadOperation: func(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
|
|
|
|
resp := &logical.Response{
|
|
|
|
Data: map[string]interface{}{
|
|
|
|
"mode": "disabled",
|
|
|
|
},
|
|
|
|
}
|
|
|
|
return resp, nil
|
2018-09-18 06:03:00 +03:00
|
|
|
},
|
|
|
|
},
|
2023-04-21 23:14:40 +03:00
|
|
|
})
|
|
|
|
|
|
|
|
// seal paths
|
2023-05-17 21:56:45 +03:00
|
|
|
paths = append(paths, buildEnterpriseOnlyPaths(map[string]enterprisePathStub{
|
|
|
|
"sealwrap/rewrap": {operations: []logical.Operation{logical.ReadOperation, logical.UpdateOperation}},
|
2023-04-21 23:14:40 +03:00
|
|
|
})...)
|
|
|
|
|
|
|
|
// mfa paths
|
2023-05-17 21:56:45 +03:00
|
|
|
paths = append(paths, buildEnterpriseOnlyPaths(map[string]enterprisePathStub{
|
|
|
|
"mfa/method/?": {operations: []logical.Operation{logical.ListOperation}},
|
|
|
|
"mfa/method/totp/" + framework.GenericNameRegex("name") + "/generate$": {parameters: []string{"name"}, operations: []logical.Operation{logical.ReadOperation}},
|
|
|
|
"mfa/method/totp/" + framework.GenericNameRegex("name") + "/admin-generate$": {parameters: []string{"name"}, operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"mfa/method/totp/" + framework.GenericNameRegex("name") + "/admin-destroy$": {parameters: []string{"name"}, operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"mfa/method/totp/" + framework.GenericNameRegex("name"): {parameters: []string{"name"}, operations: []logical.Operation{logical.DeleteOperation, logical.ReadOperation, logical.UpdateOperation}},
|
2023-04-21 23:14:40 +03:00
|
|
|
})...)
|
|
|
|
|
|
|
|
// control-group paths
|
2023-05-17 21:56:45 +03:00
|
|
|
paths = append(paths, buildEnterpriseOnlyPaths(map[string]enterprisePathStub{
|
|
|
|
"control-group/authorize": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"control-group/request": {operations: []logical.Operation{logical.UpdateOperation}},
|
|
|
|
"config/control-group": {operations: []logical.Operation{logical.DeleteOperation, logical.ReadOperation, logical.UpdateOperation}},
|
2023-04-21 23:14:40 +03:00
|
|
|
})...)
|
|
|
|
|
|
|
|
// sentinel paths
|
2023-05-17 21:56:45 +03:00
|
|
|
paths = append(paths, buildEnterpriseOnlyPaths(map[string]enterprisePathStub{
|
|
|
|
"policies/rgp/?$": {operations: []logical.Operation{logical.ListOperation}},
|
|
|
|
"policies/rgp/(?P<name>.+)": {parameters: []string{"name"}, operations: []logical.Operation{logical.DeleteOperation, logical.ReadOperation, logical.UpdateOperation}},
|
|
|
|
"policies/egp/?$": {operations: []logical.Operation{logical.ListOperation}},
|
|
|
|
"policies/egp/(?P<name>.+)": {parameters: []string{"name"}, operations: []logical.Operation{logical.DeleteOperation, logical.ReadOperation, logical.UpdateOperation}},
|
2023-04-21 23:14:40 +03:00
|
|
|
})...)
|
|
|
|
|
|
|
|
// plugins reload status paths
|
2023-05-17 21:56:45 +03:00
|
|
|
paths = append(paths, buildEnterpriseOnlyPaths(map[string]enterprisePathStub{
|
|
|
|
"plugins/reload/backend/status$": {operations: []logical.Operation{logical.ReadOperation}},
|
2023-04-21 23:14:40 +03:00
|
|
|
})...)
|
|
|
|
|
|
|
|
// quotas paths
|
2023-05-17 21:56:45 +03:00
|
|
|
paths = append(paths, buildEnterpriseOnlyPaths(map[string]enterprisePathStub{
|
|
|
|
"quotas/lease-count/?$": {operations: []logical.Operation{logical.ListOperation}},
|
|
|
|
"quotas/lease-count/" + framework.GenericNameRegex("name"): {parameters: []string{"name"}, operations: []logical.Operation{logical.DeleteOperation, logical.ReadOperation, logical.UpdateOperation}},
|
2023-04-21 23:14:40 +03:00
|
|
|
})...)
|
|
|
|
|
|
|
|
// raft auto-snapshot paths
|
2023-05-17 21:56:45 +03:00
|
|
|
paths = append(paths, buildEnterpriseOnlyPaths(map[string]enterprisePathStub{
|
|
|
|
"storage/raft/snapshot-auto/config/": {operations: []logical.Operation{logical.ListOperation}},
|
|
|
|
"storage/raft/snapshot-auto/config/" + framework.GenericNameRegex("name"): {parameters: []string{"name"}, operations: []logical.Operation{logical.DeleteOperation, logical.ReadOperation, logical.UpdateOperation}},
|
|
|
|
"storage/raft/snapshot-auto/status/" + framework.GenericNameRegex("name"): {parameters: []string{"name"}, operations: []logical.Operation{logical.ReadOperation}},
|
2023-04-21 23:14:40 +03:00
|
|
|
})...)
|
|
|
|
|
2023-05-17 21:56:45 +03:00
|
|
|
paths = append(paths, buildEnterpriseOnlyPaths(map[string]enterprisePathStub{
|
|
|
|
"managed-keys/" + framework.GenericNameRegex("type") + "/?": {parameters: []string{"type"}, operations: []logical.Operation{logical.ListOperation}},
|
|
|
|
"managed-keys/" + framework.GenericNameRegex("type") + "/" + framework.GenericNameRegex("name"): {parameters: []string{"type", "name"}, operations: []logical.Operation{logical.CreateOperation, logical.DeleteOperation, logical.ReadOperation, logical.UpdateOperation}},
|
|
|
|
"managed-keys/" + framework.GenericNameRegex("type") + "/" + framework.GenericNameRegex("name") + "/test/sign": {parameters: []string{"type", "name"}, operations: []logical.Operation{logical.CreateOperation, logical.UpdateOperation}},
|
2023-04-21 23:14:40 +03:00
|
|
|
})...)
|
|
|
|
|
|
|
|
return paths
|
2018-09-18 06:03:00 +03:00
|
|
|
}
|
2020-06-30 18:26:52 +03:00
|
|
|
handleGlobalPluginReload = func(context.Context, *Core, string, string, []string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
handleSetupPluginReload = func(*Core) error {
|
|
|
|
return nil
|
|
|
|
}
|
2021-06-03 20:30:30 +03:00
|
|
|
handleLicenseReload = func(b *SystemBackend) framework.OperationFunc {
|
|
|
|
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
2019-03-15 16:25:05 +03:00
|
|
|
checkRaw = func(b *SystemBackend, path string) error { return nil }
|
2015-09-09 22:24:45 +03:00
|
|
|
)
|
|
|
|
|
|
|
|
// tuneMount is used to set config on a mount point
|
2018-01-19 09:44:44 +03:00
|
|
|
func (b *SystemBackend) tuneMountTTLs(ctx context.Context, path string, me *MountEntry, newDefault, newMax time.Duration) error {
|
2017-09-05 17:57:25 +03:00
|
|
|
zero := time.Duration(0)
|
2017-03-02 22:37:59 +03:00
|
|
|
|
2017-09-05 17:57:25 +03:00
|
|
|
switch {
|
|
|
|
case newDefault == zero && newMax == zero:
|
|
|
|
// No checks needed
|
2015-09-09 22:24:45 +03:00
|
|
|
|
2017-09-05 17:57:25 +03:00
|
|
|
case newDefault == zero && newMax != zero:
|
|
|
|
// No default/max conflict, no checks needed
|
2015-09-09 22:24:45 +03:00
|
|
|
|
2017-09-05 17:57:25 +03:00
|
|
|
case newDefault != zero && newMax == zero:
|
|
|
|
// No default/max conflict, no checks needed
|
2015-09-21 16:39:37 +03:00
|
|
|
|
2017-09-05 17:57:25 +03:00
|
|
|
case newDefault != zero && newMax != zero:
|
|
|
|
if newMax < newDefault {
|
2018-04-05 18:49:21 +03:00
|
|
|
return fmt.Errorf("backend max lease TTL of %d would be less than backend default lease TTL of %d", int(newMax.Seconds()), int(newDefault.Seconds()))
|
2015-09-09 22:24:45 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-05 17:57:25 +03:00
|
|
|
origMax := me.Config.MaxLeaseTTL
|
|
|
|
origDefault := me.Config.DefaultLeaseTTL
|
2016-05-03 21:24:04 +03:00
|
|
|
|
2017-09-05 17:57:25 +03:00
|
|
|
me.Config.MaxLeaseTTL = newMax
|
|
|
|
me.Config.DefaultLeaseTTL = newDefault
|
2015-09-09 22:24:45 +03:00
|
|
|
|
|
|
|
// Update the mount table
|
2016-05-03 21:24:04 +03:00
|
|
|
var err error
|
|
|
|
switch {
|
2017-10-23 22:35:28 +03:00
|
|
|
case strings.HasPrefix(path, credentialRoutePrefix):
|
2018-04-11 21:32:55 +03:00
|
|
|
err = b.Core.persistAuth(ctx, b.Core.auth, &me.Local)
|
2016-05-03 21:24:04 +03:00
|
|
|
default:
|
2018-04-11 21:32:55 +03:00
|
|
|
err = b.Core.persistMounts(ctx, b.Core.mounts, &me.Local)
|
2016-05-03 21:24:04 +03:00
|
|
|
}
|
|
|
|
if err != nil {
|
2017-09-05 17:57:25 +03:00
|
|
|
me.Config.MaxLeaseTTL = origMax
|
|
|
|
me.Config.DefaultLeaseTTL = origDefault
|
2016-05-03 21:24:04 +03:00
|
|
|
return fmt.Errorf("failed to update mount table, rolling back TTL changes")
|
2015-09-09 22:24:45 +03:00
|
|
|
}
|
2016-08-19 23:45:17 +03:00
|
|
|
if b.Core.logger.IsInfo() {
|
2018-04-03 03:46:59 +03:00
|
|
|
b.Core.logger.Info("mount tuning of leases successful", "path", path)
|
2016-08-19 23:45:17 +03:00
|
|
|
}
|
2015-09-09 22:24:45 +03:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|