2023-03-15 16:00:52 +00:00
|
|
|
// Copyright (c) HashiCorp, Inc.
|
|
|
|
// SPDX-License-Identifier: MPL-2.0
|
|
|
|
|
2017-04-24 19:15:50 +00:00
|
|
|
package awsauth
|
2016-04-06 00:42:26 +00:00
|
|
|
|
|
|
|
import (
|
2018-01-19 06:44:44 +00:00
|
|
|
"context"
|
2017-06-07 14:27:11 +00:00
|
|
|
"fmt"
|
2019-06-20 14:31:31 +00:00
|
|
|
"strings"
|
2016-04-07 18:13:19 +00:00
|
|
|
"sync"
|
2016-04-19 18:21:27 +00:00
|
|
|
"time"
|
2016-04-07 18:13:19 +00:00
|
|
|
|
2017-06-07 14:27:11 +00:00
|
|
|
"github.com/aws/aws-sdk-go/aws/endpoints"
|
2016-04-07 18:13:19 +00:00
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
2016-09-23 16:47:35 +00:00
|
|
|
"github.com/aws/aws-sdk-go/service/iam"
|
2021-07-21 00:42:00 +00:00
|
|
|
"github.com/hashicorp/go-secure-stdlib/awsutil"
|
2019-04-13 07:44:06 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/framework"
|
2019-04-12 21:54:35 +00:00
|
|
|
"github.com/hashicorp/vault/sdk/helper/consts"
|
|
|
|
"github.com/hashicorp/vault/sdk/logical"
|
2019-01-09 00:48:57 +00:00
|
|
|
cache "github.com/patrickmn/go-cache"
|
2016-04-06 00:42:26 +00:00
|
|
|
)
|
|
|
|
|
2023-04-06 15:08:30 +00:00
|
|
|
const (
|
|
|
|
amzHeaderPrefix = "X-Amz-"
|
|
|
|
operationPrefixAWS = "aws"
|
|
|
|
)
|
2020-09-15 14:01:26 +00:00
|
|
|
|
2020-08-25 22:37:59 +00:00
|
|
|
var defaultAllowedSTSRequestHeaders = []string{
|
2020-09-22 17:02:37 +00:00
|
|
|
"X-Amz-Algorithm",
|
|
|
|
"X-Amz-Content-Sha256",
|
2020-08-25 22:37:59 +00:00
|
|
|
"X-Amz-Credential",
|
2020-09-22 17:02:37 +00:00
|
|
|
"X-Amz-Date",
|
2020-08-25 22:37:59 +00:00
|
|
|
"X-Amz-Security-Token",
|
|
|
|
"X-Amz-Signature",
|
2021-04-08 16:43:39 +00:00
|
|
|
"X-Amz-SignedHeaders",
|
|
|
|
}
|
2020-08-25 22:37:59 +00:00
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
func Factory(ctx context.Context, conf *logical.BackendConfig) (logical.Backend, error) {
|
2016-04-06 00:42:26 +00:00
|
|
|
b, err := Backend(conf)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
2018-01-19 06:44:44 +00:00
|
|
|
if err := b.Setup(ctx, conf); err != nil {
|
Backend plugin system (#2874)
* Add backend plugin changes
* Fix totp backend plugin tests
* Fix logical/plugin InvalidateKey test
* Fix plugin catalog CRUD test, fix NoopBackend
* Clean up commented code block
* Fix system backend mount test
* Set plugin_name to omitempty, fix handleMountTable config parsing
* Clean up comments, keep shim connections alive until cleanup
* Include pluginClient, disallow LookupPlugin call from within a plugin
* Add wrapper around backendPluginClient for proper cleanup
* Add logger shim tests
* Add logger, storage, and system shim tests
* Use pointer receivers for system view shim
* Use plugin name if no path is provided on mount
* Enable plugins for auth backends
* Add backend type attribute, move builtin/plugin/package
* Fix merge conflict
* Fix missing plugin name in mount config
* Add integration tests on enabling auth backend plugins
* Remove dependency cycle on mock-plugin
* Add passthrough backend plugin, use logical.BackendType to determine lease generation
* Remove vault package dependency on passthrough package
* Add basic impl test for passthrough plugin
* Incorporate feedback; set b.backend after shims creation on backendPluginServer
* Fix totp plugin test
* Add plugin backends docs
* Fix tests
* Fix builtin/plugin tests
* Remove flatten from PluginRunner fields
* Move mock plugin to logical/plugin, remove totp and passthrough plugins
* Move pluginMap into newPluginClient
* Do not create storage RPC connection on HandleRequest and HandleExistenceCheck
* Change shim logger's Fatal to no-op
* Change BackendType to uint32, match UX backend types
* Change framework.Backend Setup signature
* Add Setup func to logical.Backend interface
* Move OptionallyEnableMlock call into plugin.Serve, update docs and comments
* Remove commented var in plugin package
* RegisterLicense on logical.Backend interface (#3017)
* Add RegisterLicense to logical.Backend interface
* Update RegisterLicense to use callback func on framework.Backend
* Refactor framework.Backend.RegisterLicense
* plugin: Prevent plugin.SystemViewClient.ResponseWrapData from getting JWTs
* plugin: Revert BackendType to remove TypePassthrough and related references
* Fix typo in plugin backends docs
2017-07-20 17:28:40 +00:00
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return b, nil
|
2016-04-06 00:42:26 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 16:14:07 +00:00
|
|
|
type backend struct {
|
|
|
|
*framework.Backend
|
|
|
|
|
|
|
|
// Lock to make changes to any of the backend's configuration endpoints.
|
|
|
|
configMutex sync.RWMutex
|
|
|
|
|
2016-05-05 18:51:09 +00:00
|
|
|
// Lock to make changes to role entries
|
2019-07-05 23:55:40 +00:00
|
|
|
roleMutex sync.Mutex
|
2016-05-05 18:51:09 +00:00
|
|
|
|
2021-02-26 07:23:34 +00:00
|
|
|
// Lock to make changes to the deny list entries
|
|
|
|
denyListMutex sync.RWMutex
|
2016-05-05 18:12:22 +00:00
|
|
|
|
2021-02-26 07:23:34 +00:00
|
|
|
// Guards the deny list/access list tidy functions
|
|
|
|
tidyDenyListCASGuard *uint32
|
|
|
|
tidyAccessListCASGuard *uint32
|
2016-05-05 18:28:46 +00:00
|
|
|
|
2016-05-03 16:14:07 +00:00
|
|
|
// Duration after which the periodic function of the backend needs to
|
2021-02-26 07:23:34 +00:00
|
|
|
// tidy the deny list and access list entries.
|
2016-05-03 16:14:07 +00:00
|
|
|
tidyCooldownPeriod time.Duration
|
|
|
|
|
2018-03-20 18:54:10 +00:00
|
|
|
// nextTidyTime holds the time at which the periodic func should initiate
|
2016-05-03 16:14:07 +00:00
|
|
|
// the tidy operations. This is set by the periodicFunc based on the value
|
|
|
|
// of tidyCooldownPeriod.
|
|
|
|
nextTidyTime time.Time
|
|
|
|
|
2017-02-01 19:16:03 +00:00
|
|
|
// Map to hold the EC2 client objects indexed by region and STS role.
|
|
|
|
// This avoids the overhead of creating a client object for every login request.
|
|
|
|
// When the credentials are modified or deleted, all the cached client objects
|
|
|
|
// will be flushed. The empty STS role signifies the master account
|
|
|
|
EC2ClientsMap map[string]map[string]*ec2.EC2
|
|
|
|
|
|
|
|
// Map to hold the IAM client objects indexed by region and STS role.
|
|
|
|
// This avoids the overhead of creating a client object for every login request.
|
|
|
|
// When the credentials are modified or deleted, all the cached client objects
|
|
|
|
// will be flushed. The empty STS role signifies the master account
|
|
|
|
IAMClientsMap map[string]map[string]*iam.IAM
|
2017-06-07 14:27:11 +00:00
|
|
|
|
2020-02-14 06:21:58 +00:00
|
|
|
// Map to associate a partition to a random region in that partition. Users of
|
|
|
|
// this don't care what region in the partition they use, but there is some client
|
|
|
|
// cache efficiency gain if we keep the mapping stable, hence caching a single copy.
|
|
|
|
partitionToRegionMap map[string]*endpoints.Region
|
|
|
|
|
2017-08-30 21:51:48 +00:00
|
|
|
// Map of AWS unique IDs to the full ARN corresponding to that unique ID
|
|
|
|
// This avoids the overhead of an AWS API hit for every login request
|
|
|
|
// using the IAM auth method when bound_iam_principal_arn contains a wildcard
|
|
|
|
iamUserIdToArnCache *cache.Cache
|
|
|
|
|
2017-06-07 14:27:11 +00:00
|
|
|
// AWS Account ID of the "default" AWS credentials
|
|
|
|
// This cache avoids the need to call GetCallerIdentity repeatedly to learn it
|
|
|
|
// We can't store this because, in certain pathological cases, it could change
|
|
|
|
// out from under us, such as a standby and active Vault server in different AWS
|
|
|
|
// accounts using their IAM instance profile to get their credentials.
|
|
|
|
defaultAWSAccountID string
|
|
|
|
|
2019-06-20 14:31:31 +00:00
|
|
|
// roleCache caches role entries to avoid locking headaches
|
|
|
|
roleCache *cache.Cache
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
resolveArnToUniqueIDFunc func(context.Context, logical.Storage, string) (string, error)
|
2019-07-05 23:55:40 +00:00
|
|
|
|
|
|
|
// upgradeCancelFunc is used to cancel the context used in the upgrade
|
|
|
|
// function
|
|
|
|
upgradeCancelFunc context.CancelFunc
|
2021-02-26 07:23:34 +00:00
|
|
|
|
|
|
|
// deprecatedTerms is used to downgrade preferred terminology (e.g. accesslist)
|
|
|
|
// to the legacy term. This allows for consolidated aliasing of the affected
|
|
|
|
// endpoints until the legacy terms are removed.
|
|
|
|
deprecatedTerms *strings.Replacer
|
2016-05-03 16:14:07 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 23:11:35 +00:00
|
|
|
func Backend(_ *logical.BackendConfig) (*backend, error) {
|
2016-04-19 18:21:27 +00:00
|
|
|
b := &backend{
|
2016-04-28 00:01:39 +00:00
|
|
|
// Setting the periodic func to be run once in an hour.
|
|
|
|
// If there is a real need, this can be made configurable.
|
2021-02-26 07:23:34 +00:00
|
|
|
tidyCooldownPeriod: time.Hour,
|
|
|
|
EC2ClientsMap: make(map[string]map[string]*ec2.EC2),
|
|
|
|
IAMClientsMap: make(map[string]map[string]*iam.IAM),
|
|
|
|
iamUserIdToArnCache: cache.New(7*24*time.Hour, 24*time.Hour),
|
|
|
|
tidyDenyListCASGuard: new(uint32),
|
|
|
|
tidyAccessListCASGuard: new(uint32),
|
|
|
|
roleCache: cache.New(cache.NoExpiration, cache.NoExpiration),
|
|
|
|
|
|
|
|
deprecatedTerms: strings.NewReplacer(
|
|
|
|
"accesslist", "whitelist",
|
2023-04-06 15:08:30 +00:00
|
|
|
"access-list", "whitelist",
|
2021-02-26 07:23:34 +00:00
|
|
|
"denylist", "blacklist",
|
2023-04-06 15:08:30 +00:00
|
|
|
"deny-list", "blacklist",
|
2021-02-26 07:23:34 +00:00
|
|
|
),
|
2016-04-19 18:21:27 +00:00
|
|
|
}
|
2016-04-06 00:42:26 +00:00
|
|
|
|
2017-06-07 14:27:11 +00:00
|
|
|
b.resolveArnToUniqueIDFunc = b.resolveArnToRealUniqueId
|
|
|
|
|
2016-04-19 18:21:27 +00:00
|
|
|
b.Backend = &framework.Backend{
|
|
|
|
PeriodicFunc: b.periodicFunc,
|
|
|
|
AuthRenew: b.pathLoginRenew,
|
|
|
|
Help: backendHelp,
|
2016-04-06 00:42:26 +00:00
|
|
|
PathsSpecial: &logical.Paths{
|
|
|
|
Unauthenticated: []string{
|
|
|
|
"login",
|
|
|
|
},
|
2017-02-16 21:29:30 +00:00
|
|
|
LocalStorage: []string{
|
2021-02-26 07:23:34 +00:00
|
|
|
identityAccessListStorage,
|
2017-02-16 21:29:30 +00:00
|
|
|
},
|
2017-11-03 15:43:31 +00:00
|
|
|
SealWrapStorage: []string{
|
|
|
|
"config/client",
|
|
|
|
},
|
2016-04-06 00:42:26 +00:00
|
|
|
},
|
2016-04-30 07:20:21 +00:00
|
|
|
Paths: []*framework.Path{
|
2019-07-31 23:11:35 +00:00
|
|
|
b.pathLogin(),
|
|
|
|
b.pathListRole(),
|
|
|
|
b.pathListRoles(),
|
|
|
|
b.pathRole(),
|
|
|
|
b.pathRoleTag(),
|
|
|
|
b.pathConfigClient(),
|
|
|
|
b.pathConfigCertificate(),
|
|
|
|
b.pathConfigIdentity(),
|
2020-09-15 22:26:56 +00:00
|
|
|
b.pathConfigRotateRoot(),
|
2019-07-31 23:11:35 +00:00
|
|
|
b.pathConfigSts(),
|
|
|
|
b.pathListSts(),
|
|
|
|
b.pathListCertificates(),
|
2021-02-26 07:23:34 +00:00
|
|
|
|
|
|
|
// The following pairs of functions are path aliases. The first is the
|
|
|
|
// primary endpoint, and the second is version using deprecated language,
|
|
|
|
// for backwards compatibility. The functionality is identical between the two.
|
|
|
|
b.pathConfigTidyRoletagDenyList(),
|
|
|
|
b.genDeprecatedPath(b.pathConfigTidyRoletagDenyList()),
|
|
|
|
|
|
|
|
b.pathConfigTidyIdentityAccessList(),
|
|
|
|
b.genDeprecatedPath(b.pathConfigTidyIdentityAccessList()),
|
|
|
|
|
|
|
|
b.pathListRoletagDenyList(),
|
|
|
|
b.genDeprecatedPath(b.pathListRoletagDenyList()),
|
|
|
|
|
|
|
|
b.pathRoletagDenyList(),
|
|
|
|
b.genDeprecatedPath(b.pathRoletagDenyList()),
|
|
|
|
|
|
|
|
b.pathTidyRoletagDenyList(),
|
|
|
|
b.genDeprecatedPath(b.pathTidyRoletagDenyList()),
|
|
|
|
|
|
|
|
b.pathListIdentityAccessList(),
|
|
|
|
b.genDeprecatedPath(b.pathListIdentityAccessList()),
|
|
|
|
|
|
|
|
b.pathIdentityAccessList(),
|
|
|
|
b.genDeprecatedPath(b.pathIdentityAccessList()),
|
|
|
|
|
|
|
|
b.pathTidyIdentityAccessList(),
|
|
|
|
b.genDeprecatedPath(b.pathTidyIdentityAccessList()),
|
2016-04-30 07:20:21 +00:00
|
|
|
},
|
2019-07-05 23:55:40 +00:00
|
|
|
Invalidate: b.invalidate,
|
|
|
|
InitializeFunc: b.initialize,
|
|
|
|
BackendType: logical.TypeCredential,
|
|
|
|
Clean: b.cleanup,
|
2016-04-06 00:42:26 +00:00
|
|
|
}
|
|
|
|
|
2020-02-14 06:21:58 +00:00
|
|
|
b.partitionToRegionMap = generatePartitionToRegionMap()
|
|
|
|
|
2016-06-01 16:17:47 +00:00
|
|
|
return b, nil
|
2016-04-06 00:42:26 +00:00
|
|
|
}
|
|
|
|
|
2016-04-19 18:21:27 +00:00
|
|
|
// periodicFunc performs the tasks that the backend wishes to do periodically.
|
|
|
|
// Currently this will be triggered once in a minute by the RollbackManager.
|
2016-04-28 00:01:39 +00:00
|
|
|
//
|
2016-05-03 16:14:07 +00:00
|
|
|
// The tasks being done currently by this function are to cleanup the expired
|
2021-02-26 07:23:34 +00:00
|
|
|
// entries of both deny list role tags and access list identities. Tidying is done
|
2016-05-03 16:14:07 +00:00
|
|
|
// not once in a minute, but once in an hour, controlled by 'tidyCooldownPeriod'.
|
2021-02-26 07:23:34 +00:00
|
|
|
// Tidying of deny list and access list are by default enabled. This can be
|
2016-04-28 00:01:39 +00:00
|
|
|
// changed using `config/tidy/roletags` and `config/tidy/identities` endpoints.
|
2018-01-19 06:44:44 +00:00
|
|
|
func (b *backend) periodicFunc(ctx context.Context, req *logical.Request) error {
|
2016-05-03 16:14:07 +00:00
|
|
|
// Run the tidy operations for the first time. Then run it when current
|
|
|
|
// time matches the nextTidyTime.
|
2016-07-07 21:44:14 +00:00
|
|
|
if b.nextTidyTime.IsZero() || !time.Now().Before(b.nextTidyTime) {
|
2019-02-01 21:56:57 +00:00
|
|
|
if b.System().LocalMount() || !b.System().ReplicationState().HasState(consts.ReplicationPerformanceSecondary|consts.ReplicationPerformanceStandby) {
|
2021-02-26 07:23:34 +00:00
|
|
|
// safetyBuffer defaults to 180 days for roletag deny list
|
2019-07-31 23:11:35 +00:00
|
|
|
safetyBuffer := 15552000
|
2018-02-03 01:28:25 +00:00
|
|
|
tidyBlacklistConfigEntry, err := b.lockedConfigTidyRoleTags(ctx, req.Storage)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
skipBlacklistTidy := false
|
|
|
|
// check if tidying of role tags was configured
|
|
|
|
if tidyBlacklistConfigEntry != nil {
|
|
|
|
// check if periodic tidying of role tags was disabled
|
|
|
|
if tidyBlacklistConfigEntry.DisablePeriodicTidy {
|
|
|
|
skipBlacklistTidy = true
|
|
|
|
}
|
2019-07-31 23:11:35 +00:00
|
|
|
// overwrite the default safetyBuffer with the configured value
|
|
|
|
safetyBuffer = tidyBlacklistConfigEntry.SafetyBuffer
|
2018-02-03 01:28:25 +00:00
|
|
|
}
|
|
|
|
// tidy role tags if explicitly not disabled
|
|
|
|
if !skipBlacklistTidy {
|
2021-02-26 07:23:34 +00:00
|
|
|
b.tidyDenyListRoleTag(ctx, req, safetyBuffer)
|
2016-04-19 18:21:27 +00:00
|
|
|
}
|
2016-04-19 01:06:26 +00:00
|
|
|
}
|
|
|
|
|
2021-02-26 07:23:34 +00:00
|
|
|
// We don't check for replication state for access list identities as
|
2018-02-03 01:28:25 +00:00
|
|
|
// these are locally stored
|
|
|
|
|
|
|
|
safety_buffer := 259200
|
2018-01-19 06:44:44 +00:00
|
|
|
tidyWhitelistConfigEntry, err := b.lockedConfigTidyIdentities(ctx, req.Storage)
|
2016-04-19 18:21:27 +00:00
|
|
|
if err != nil {
|
|
|
|
return err
|
2016-04-19 01:06:26 +00:00
|
|
|
}
|
2016-04-19 18:21:27 +00:00
|
|
|
skipWhitelistTidy := false
|
2016-04-28 00:01:39 +00:00
|
|
|
// check if tidying of identities was configured
|
2016-04-19 18:21:27 +00:00
|
|
|
if tidyWhitelistConfigEntry != nil {
|
2016-04-28 00:01:39 +00:00
|
|
|
// check if periodic tidying of identities was disabled
|
2016-04-19 18:21:27 +00:00
|
|
|
if tidyWhitelistConfigEntry.DisablePeriodicTidy {
|
|
|
|
skipWhitelistTidy = true
|
|
|
|
}
|
2016-04-28 00:01:39 +00:00
|
|
|
// overwrite the default safety_buffer with the configured value
|
2016-04-19 18:21:27 +00:00
|
|
|
safety_buffer = tidyWhitelistConfigEntry.SafetyBuffer
|
|
|
|
}
|
2016-04-28 00:01:39 +00:00
|
|
|
// tidy identities if explicitly not disabled
|
2016-04-19 18:21:27 +00:00
|
|
|
if !skipWhitelistTidy {
|
2021-02-26 07:23:34 +00:00
|
|
|
b.tidyAccessListIdentity(ctx, req, safety_buffer)
|
2016-04-19 18:21:27 +00:00
|
|
|
}
|
|
|
|
|
2016-05-03 16:14:07 +00:00
|
|
|
// Update the time at which to run the tidy functions again.
|
2016-07-07 21:44:14 +00:00
|
|
|
b.nextTidyTime = time.Now().Add(b.tidyCooldownPeriod)
|
2016-04-19 01:06:26 +00:00
|
|
|
}
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2019-07-05 23:55:40 +00:00
|
|
|
func (b *backend) cleanup(ctx context.Context) {
|
|
|
|
if b.upgradeCancelFunc != nil {
|
|
|
|
b.upgradeCancelFunc()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-01-19 06:44:44 +00:00
|
|
|
func (b *backend) invalidate(ctx context.Context, key string) {
|
2019-06-20 14:31:31 +00:00
|
|
|
switch {
|
|
|
|
case key == "config/client":
|
2017-02-16 21:29:30 +00:00
|
|
|
b.configMutex.Lock()
|
|
|
|
defer b.configMutex.Unlock()
|
|
|
|
b.flushCachedEC2Clients()
|
|
|
|
b.flushCachedIAMClients()
|
2017-06-07 14:27:11 +00:00
|
|
|
b.defaultAWSAccountID = ""
|
2019-06-20 14:31:31 +00:00
|
|
|
case strings.HasPrefix(key, "role"):
|
|
|
|
// TODO: We could make this better
|
|
|
|
b.roleCache.Flush()
|
2017-06-07 14:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Putting this here so we can inject a fake resolver into the backend for unit testing
|
|
|
|
// purposes
|
2018-01-19 06:44:44 +00:00
|
|
|
func (b *backend) resolveArnToRealUniqueId(ctx context.Context, s logical.Storage, arn string) (string, error) {
|
2017-06-07 14:27:11 +00:00
|
|
|
entity, err := parseIamArn(arn)
|
|
|
|
if err != nil {
|
|
|
|
return "", err
|
|
|
|
}
|
|
|
|
// This odd-looking code is here because IAM is an inherently global service. IAM and STS ARNs
|
|
|
|
// don't have regions in them, and there is only a single global endpoint for IAM; see
|
|
|
|
// http://docs.aws.amazon.com/general/latest/gr/rande.html#iam_region
|
|
|
|
// However, the ARNs do have a partition in them, because the GovCloud and China partitions DO
|
|
|
|
// have their own separate endpoints, and the partition is encoded in the ARN. If Amazon's Go SDK
|
|
|
|
// would allow us to pass a partition back to the IAM client, it would be much simpler. But it
|
|
|
|
// doesn't appear that's possible, so in order to properly support GovCloud and China, we do a
|
|
|
|
// circular dance of extracting the partition from the ARN, finding any arbitrary region in the
|
|
|
|
// partition, and passing that region back back to the SDK, so that the SDK can figure out the
|
|
|
|
// proper partition from the arbitrary region we passed in to look up the endpoint.
|
|
|
|
// Sigh
|
2020-02-14 06:21:58 +00:00
|
|
|
region := b.partitionToRegionMap[entity.Partition]
|
2017-06-07 14:27:11 +00:00
|
|
|
if region == nil {
|
2018-04-05 15:49:21 +00:00
|
|
|
return "", fmt.Errorf("unable to resolve partition %q to a region", entity.Partition)
|
2017-06-07 14:27:11 +00:00
|
|
|
}
|
2018-01-19 06:44:44 +00:00
|
|
|
iamClient, err := b.clientIAM(ctx, s, region.ID(), entity.AccountNumber)
|
2017-06-07 14:27:11 +00:00
|
|
|
if err != nil {
|
2020-01-11 01:39:52 +00:00
|
|
|
return "", awsutil.AppendAWSError(err)
|
2017-06-07 14:27:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
switch entity.Type {
|
|
|
|
case "user":
|
2023-03-23 17:02:24 +00:00
|
|
|
userInfo, err := iamClient.GetUserWithContext(ctx, &iam.GetUserInput{UserName: &entity.FriendlyName})
|
2017-06-07 14:27:11 +00:00
|
|
|
if err != nil {
|
2020-01-11 01:39:52 +00:00
|
|
|
return "", awsutil.AppendAWSError(err)
|
2017-06-07 14:27:11 +00:00
|
|
|
}
|
|
|
|
if userInfo == nil {
|
|
|
|
return "", fmt.Errorf("got nil result from GetUser")
|
|
|
|
}
|
|
|
|
return *userInfo.User.UserId, nil
|
|
|
|
case "role":
|
2023-03-23 17:02:24 +00:00
|
|
|
roleInfo, err := iamClient.GetRoleWithContext(ctx, &iam.GetRoleInput{RoleName: &entity.FriendlyName})
|
2017-06-07 14:27:11 +00:00
|
|
|
if err != nil {
|
2020-01-11 01:39:52 +00:00
|
|
|
return "", awsutil.AppendAWSError(err)
|
2017-06-07 14:27:11 +00:00
|
|
|
}
|
|
|
|
if roleInfo == nil {
|
|
|
|
return "", fmt.Errorf("got nil result from GetRole")
|
|
|
|
}
|
|
|
|
return *roleInfo.Role.RoleId, nil
|
|
|
|
case "instance-profile":
|
2023-03-23 17:02:24 +00:00
|
|
|
profileInfo, err := iamClient.GetInstanceProfileWithContext(ctx, &iam.GetInstanceProfileInput{InstanceProfileName: &entity.FriendlyName})
|
2017-06-07 14:27:11 +00:00
|
|
|
if err != nil {
|
2020-01-11 01:39:52 +00:00
|
|
|
return "", awsutil.AppendAWSError(err)
|
2017-06-07 14:27:11 +00:00
|
|
|
}
|
|
|
|
if profileInfo == nil {
|
|
|
|
return "", fmt.Errorf("got nil result from GetInstanceProfile")
|
|
|
|
}
|
|
|
|
return *profileInfo.InstanceProfile.InstanceProfileId, nil
|
|
|
|
default:
|
|
|
|
return "", fmt.Errorf("unrecognized error type %#v", entity.Type)
|
2017-02-16 21:29:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-04-06 15:08:30 +00:00
|
|
|
// genDeprecatedPath will return a deprecated version of a framework.Path. The
|
|
|
|
// path pattern and display attributes (if any) will contain deprecated terms,
|
|
|
|
// and the path will be marked as deprecated.
|
2021-02-26 07:23:34 +00:00
|
|
|
func (b *backend) genDeprecatedPath(path *framework.Path) *framework.Path {
|
|
|
|
pathDeprecated := *path
|
|
|
|
pathDeprecated.Pattern = b.deprecatedTerms.Replace(path.Pattern)
|
|
|
|
pathDeprecated.Deprecated = true
|
|
|
|
|
2023-04-06 15:08:30 +00:00
|
|
|
if path.DisplayAttrs != nil {
|
|
|
|
deprecatedDisplayAttrs := *path.DisplayAttrs
|
|
|
|
deprecatedDisplayAttrs.OperationPrefix = b.deprecatedTerms.Replace(path.DisplayAttrs.OperationPrefix)
|
|
|
|
deprecatedDisplayAttrs.OperationVerb = b.deprecatedTerms.Replace(path.DisplayAttrs.OperationVerb)
|
|
|
|
deprecatedDisplayAttrs.OperationSuffix = b.deprecatedTerms.Replace(path.DisplayAttrs.OperationSuffix)
|
|
|
|
pathDeprecated.DisplayAttrs = &deprecatedDisplayAttrs
|
|
|
|
}
|
|
|
|
|
|
|
|
for i, op := range path.Operations {
|
|
|
|
if op.Properties().DisplayAttrs != nil {
|
|
|
|
deprecatedDisplayAttrs := *op.Properties().DisplayAttrs
|
|
|
|
deprecatedDisplayAttrs.OperationPrefix = b.deprecatedTerms.Replace(op.Properties().DisplayAttrs.OperationPrefix)
|
|
|
|
deprecatedDisplayAttrs.OperationVerb = b.deprecatedTerms.Replace(op.Properties().DisplayAttrs.OperationVerb)
|
|
|
|
deprecatedDisplayAttrs.OperationSuffix = b.deprecatedTerms.Replace(op.Properties().DisplayAttrs.OperationSuffix)
|
|
|
|
deprecatedProperties := pathDeprecated.Operations[i].(*framework.PathOperation)
|
|
|
|
deprecatedProperties.DisplayAttrs = &deprecatedDisplayAttrs
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-26 07:23:34 +00:00
|
|
|
return &pathDeprecated
|
|
|
|
}
|
|
|
|
|
2017-06-07 14:27:11 +00:00
|
|
|
// Adapted from https://docs.aws.amazon.com/sdk-for-go/api/aws/endpoints/
|
|
|
|
// the "Enumerating Regions and Endpoint Metadata" section
|
2020-02-14 06:21:58 +00:00
|
|
|
func generatePartitionToRegionMap() map[string]*endpoints.Region {
|
|
|
|
partitionToRegion := make(map[string]*endpoints.Region)
|
|
|
|
|
2017-06-07 14:27:11 +00:00
|
|
|
resolver := endpoints.DefaultResolver()
|
|
|
|
partitions := resolver.(endpoints.EnumPartitions).Partitions()
|
|
|
|
|
|
|
|
for _, p := range partitions {
|
2020-04-03 22:08:56 +00:00
|
|
|
// For most partitions, it's fine to choose a single region randomly.
|
2020-09-26 00:13:26 +00:00
|
|
|
// However, there are a few exceptions:
|
|
|
|
//
|
|
|
|
// For "aws", choose "us-east-1" because it is always enabled (and
|
|
|
|
// enabled for STS) by default.
|
|
|
|
//
|
|
|
|
// For "aws-us-gov", choose "us-gov-west-1" because it is the only
|
|
|
|
// valid region for IAM operations.
|
|
|
|
// ref: https://github.com/aws/aws-sdk-go/blob/v1.34.25/aws/endpoints/defaults.go#L8176-L8194
|
2020-02-14 06:21:58 +00:00
|
|
|
for _, r := range p.Regions() {
|
2020-04-03 22:08:56 +00:00
|
|
|
if p.ID() == "aws" && r.ID() != "us-east-1" {
|
|
|
|
continue
|
|
|
|
}
|
2020-09-26 00:13:26 +00:00
|
|
|
if p.ID() == "aws-us-gov" && r.ID() != "us-gov-west-1" {
|
|
|
|
continue
|
|
|
|
}
|
2020-02-14 06:21:58 +00:00
|
|
|
partitionToRegion[p.ID()] = &r
|
|
|
|
break
|
2017-06-07 14:27:11 +00:00
|
|
|
}
|
|
|
|
}
|
2020-02-14 06:21:58 +00:00
|
|
|
|
|
|
|
return partitionToRegion
|
2017-06-07 14:27:11 +00:00
|
|
|
}
|
|
|
|
|
2016-04-06 00:42:26 +00:00
|
|
|
const backendHelp = `
|
2018-09-04 17:55:02 +00:00
|
|
|
The aws auth method uses either AWS IAM credentials or AWS-signed EC2 metadata
|
|
|
|
to authenticate clients, which are IAM principals or EC2 instances.
|
2016-04-06 00:42:26 +00:00
|
|
|
|
2016-05-03 16:14:07 +00:00
|
|
|
Authentication is backed by a preconfigured role in the backend. The role
|
|
|
|
represents the authorization of resources by containing Vault's policies.
|
2016-05-13 18:31:13 +00:00
|
|
|
Role can be created using 'role/<role>' endpoint.
|
2016-04-28 00:01:39 +00:00
|
|
|
|
2018-09-04 17:55:02 +00:00
|
|
|
Authentication of IAM principals, either IAM users or roles, is done using a
|
|
|
|
specifically signed AWS API request using clients' AWS IAM credentials. IAM
|
|
|
|
principals can then be assigned to roles within Vault. This is known as the
|
|
|
|
"iam" auth method.
|
|
|
|
|
|
|
|
Authentication of EC2 instances is done using either a signed PKCS#7 document
|
|
|
|
or a detached RSA signature of an AWS EC2 instance's identity document along
|
|
|
|
with a client-created nonce. This is known as the "ec2" auth method.
|
|
|
|
|
2016-05-12 11:19:29 +00:00
|
|
|
If there is need to further restrict the capabilities of the role on the instance
|
|
|
|
that is using the role, 'role_tag' option can be enabled on the role, and a tag
|
2016-05-13 18:31:13 +00:00
|
|
|
can be generated using 'role/<role>/tag' endpoint. This tag represents the
|
2016-05-12 11:19:29 +00:00
|
|
|
subset of capabilities set on the role. When the 'role_tag' option is enabled on
|
|
|
|
the role, the login operation requires that a respective role tag is attached to
|
|
|
|
the EC2 instance which performs the login.
|
2016-04-06 00:42:26 +00:00
|
|
|
`
|