open-vault/builtin/logical/aws/path_config_root.go

87 lines
2.4 KiB
Go
Raw Normal View History

2015-03-20 16:59:48 +00:00
package aws
import (
"github.com/hashicorp/vault/logical"
"github.com/hashicorp/vault/logical/framework"
)
2015-04-19 05:22:35 +00:00
func pathConfigRoot() *framework.Path {
2015-03-20 16:59:48 +00:00
return &framework.Path{
Pattern: "config/root",
2015-03-20 16:59:48 +00:00
Fields: map[string]*framework.FieldSchema{
"access_key": &framework.FieldSchema{
Type: framework.TypeString,
Description: "Access key with permission to create new keys.",
},
"secret_key": &framework.FieldSchema{
Type: framework.TypeString,
Description: "Secret key with permission to create new keys.",
},
"region": &framework.FieldSchema{
Type: framework.TypeString,
Description: "Region for API calls.",
},
2017-11-06 18:31:38 +00:00
"iam_endpoint": &framework.FieldSchema{
Type: framework.TypeString,
Description: "Endpoint to custom IAM server URL",
},
"sts_endpoint": &framework.FieldSchema{
Type: framework.TypeString,
Description: "Endpoint to custom STS server URL",
},
2015-03-20 16:59:48 +00:00
},
Callbacks: map[logical.Operation]framework.OperationFunc{
2016-01-07 15:30:47 +00:00
logical.UpdateOperation: pathConfigRootWrite,
2015-03-20 16:59:48 +00:00
},
2015-04-04 04:10:54 +00:00
2015-04-19 05:22:35 +00:00
HelpSynopsis: pathConfigRootHelpSyn,
HelpDescription: pathConfigRootHelpDesc,
2015-03-20 16:59:48 +00:00
}
}
2015-04-19 05:22:35 +00:00
func pathConfigRootWrite(
2015-03-20 16:59:48 +00:00
req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
region := data.Get("region").(string)
2017-11-06 18:31:38 +00:00
iamendpoint := data.Get("iam_endpoint").(string)
stsendpoint := data.Get("sts_endpoint").(string)
entry, err := logical.StorageEntryJSON("config/root", rootConfig{
2017-11-06 18:31:38 +00:00
AccessKey: data.Get("access_key").(string),
SecretKey: data.Get("secret_key").(string),
IAMEndpoint: iamendpoint,
STSEndpoint: stsendpoint,
Region: region,
2015-03-20 16:59:48 +00:00
})
if err != nil {
return nil, err
}
if err := req.Storage.Put(entry); err != nil {
return nil, err
}
return nil, nil
}
type rootConfig struct {
2017-11-06 18:31:38 +00:00
AccessKey string `json:"access_key"`
SecretKey string `json:"secret_key"`
IAMEndpoint string `json:"iam_endpoint"`
STSEndpoint string `json:"sts_endpoint"`
Region string `json:"region"`
2015-03-20 16:59:48 +00:00
}
2015-04-04 04:10:54 +00:00
2015-04-19 05:22:35 +00:00
const pathConfigRootHelpSyn = `
2015-04-04 04:10:54 +00:00
Configure the root credentials that are used to manage IAM.
`
2015-04-19 05:22:35 +00:00
const pathConfigRootHelpDesc = `
2015-04-04 04:10:54 +00:00
Before doing anything, the AWS backend needs credentials that are able
to manage IAM policies, users, access keys, etc. This endpoint is used
to configure those credentials. They don't necessarilly need to be root
keys as long as they have permission to manage IAM.
`