2015-09-09 19:24:45 +00:00
|
|
|
package vault
|
|
|
|
|
|
|
|
import (
|
2018-01-19 06:44:44 +00:00
|
|
|
"context"
|
2018-09-18 03:03:00 +00:00
|
|
|
"errors"
|
2015-09-09 19:24:45 +00:00
|
|
|
"fmt"
|
2016-05-03 18:24:04 +00:00
|
|
|
"strings"
|
2015-09-21 13:39:37 +00:00
|
|
|
"time"
|
2018-09-18 03:03:00 +00:00
|
|
|
|
|
|
|
memdb "github.com/hashicorp/go-memdb"
|
|
|
|
"github.com/hashicorp/vault/helper/namespace"
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/framework"
|
2019-04-13 07:44:06 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2018-09-18 03:03:00 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
var (
|
|
|
|
invalidateMFAConfig = func(context.Context, *SystemBackend, string) {}
|
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pathLicenseRead = func(b *SystemBackend) framework.OperationFunc {
|
|
|
|
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pathLicenseUpdate = func(b *SystemBackend) framework.OperationFunc {
|
|
|
|
return func(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
|
|
|
|
return nil, nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
entPaths = func(b *SystemBackend) []*framework.Path {
|
|
|
|
return []*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
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
2020-06-30 15:26:52 +00:00
|
|
|
handleGlobalPluginReload = func(context.Context, *Core, string, string, []string) error {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
handleSetupPluginReload = func(*Core) error {
|
|
|
|
return nil
|
|
|
|
}
|
2019-03-15 13:25:05 +00:00
|
|
|
|
|
|
|
checkRaw = func(b *SystemBackend, path string) error { return nil }
|
2020-10-01 19:15:20 +00:00
|
|
|
|
|
|
|
wrapHandleRaftRemovePeer = func(b *SystemBackend) framework.OperationFunc {
|
|
|
|
return b.handleRaftRemovePeerUpdate()
|
|
|
|
}
|
2015-09-09 19:24:45 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// tuneMount is used to set config on a mount point
|
2018-01-19 06:44:44 +00:00
|
|
|
func (b *SystemBackend) tuneMountTTLs(ctx context.Context, path string, me *MountEntry, newDefault, newMax time.Duration) error {
|
2017-09-05 14:57:25 +00:00
|
|
|
zero := time.Duration(0)
|
2017-03-02 19:37:59 +00:00
|
|
|
|
2017-09-05 14:57:25 +00:00
|
|
|
switch {
|
|
|
|
case newDefault == zero && newMax == zero:
|
|
|
|
// No checks needed
|
2015-09-09 19:24:45 +00:00
|
|
|
|
2017-09-05 14:57:25 +00:00
|
|
|
case newDefault == zero && newMax != zero:
|
|
|
|
// No default/max conflict, no checks needed
|
2015-09-09 19:24:45 +00:00
|
|
|
|
2017-09-05 14:57:25 +00:00
|
|
|
case newDefault != zero && newMax == zero:
|
|
|
|
// No default/max conflict, no checks needed
|
2015-09-21 13:39:37 +00:00
|
|
|
|
2017-09-05 14:57:25 +00:00
|
|
|
case newDefault != zero && newMax != zero:
|
|
|
|
if newMax < newDefault {
|
2018-04-05 15:49:21 +00: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 19:24:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-09-05 14:57:25 +00:00
|
|
|
origMax := me.Config.MaxLeaseTTL
|
|
|
|
origDefault := me.Config.DefaultLeaseTTL
|
2016-05-03 18:24:04 +00:00
|
|
|
|
2017-09-05 14:57:25 +00:00
|
|
|
me.Config.MaxLeaseTTL = newMax
|
|
|
|
me.Config.DefaultLeaseTTL = newDefault
|
2015-09-09 19:24:45 +00:00
|
|
|
|
|
|
|
// Update the mount table
|
2016-05-03 18:24:04 +00:00
|
|
|
var err error
|
|
|
|
switch {
|
2017-10-23 19:35:28 +00:00
|
|
|
case strings.HasPrefix(path, credentialRoutePrefix):
|
2018-04-11 18:32:55 +00:00
|
|
|
err = b.Core.persistAuth(ctx, b.Core.auth, &me.Local)
|
2016-05-03 18:24:04 +00:00
|
|
|
default:
|
2018-04-11 18:32:55 +00:00
|
|
|
err = b.Core.persistMounts(ctx, b.Core.mounts, &me.Local)
|
2016-05-03 18:24:04 +00:00
|
|
|
}
|
|
|
|
if err != nil {
|
2017-09-05 14:57:25 +00:00
|
|
|
me.Config.MaxLeaseTTL = origMax
|
|
|
|
me.Config.DefaultLeaseTTL = origDefault
|
2016-05-03 18:24:04 +00:00
|
|
|
return fmt.Errorf("failed to update mount table, rolling back TTL changes")
|
2015-09-09 19:24:45 +00:00
|
|
|
}
|
2016-08-19 20:45:17 +00:00
|
|
|
if b.Core.logger.IsInfo() {
|
2018-04-03 00:46:59 +00:00
|
|
|
b.Core.logger.Info("mount tuning of leases successful", "path", path)
|
2016-08-19 20:45:17 +00:00
|
|
|
}
|
2015-09-09 19:24:45 +00:00
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|