2016-04-06 00:42:26 +00:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
2016-04-07 18:13:19 +00:00
|
|
|
"sync"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/service/ec2"
|
2016-04-06 00:42:26 +00:00
|
|
|
"github.com/hashicorp/vault/helper/salt"
|
|
|
|
"github.com/hashicorp/vault/logical"
|
|
|
|
"github.com/hashicorp/vault/logical/framework"
|
|
|
|
)
|
|
|
|
|
|
|
|
func Factory(conf *logical.BackendConfig) (logical.Backend, error) {
|
|
|
|
b, err := Backend(conf)
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
return b.Setup(conf)
|
|
|
|
}
|
|
|
|
|
|
|
|
func Backend(conf *logical.BackendConfig) (*framework.Backend, error) {
|
|
|
|
salt, err := salt.NewSalt(conf.StorageView, &salt.Config{
|
|
|
|
HashFunc: salt.SHA256Hash,
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
|
|
|
var b backend
|
|
|
|
b.Salt = salt
|
|
|
|
b.Backend = &framework.Backend{
|
|
|
|
Help: backendHelp,
|
|
|
|
|
|
|
|
PathsSpecial: &logical.Paths{
|
|
|
|
Unauthenticated: []string{
|
|
|
|
"login",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
|
|
|
Paths: append([]*framework.Path{
|
|
|
|
pathLogin(&b),
|
|
|
|
pathImage(&b),
|
|
|
|
pathListImages(&b),
|
|
|
|
pathImageTag(&b),
|
|
|
|
pathConfigClient(&b),
|
|
|
|
pathConfigCertificate(&b),
|
2016-04-13 23:01:06 +00:00
|
|
|
pathListCertificates(&b),
|
2016-04-06 00:42:26 +00:00
|
|
|
pathBlacklistRoleTag(&b),
|
|
|
|
pathListBlacklistRoleTags(&b),
|
|
|
|
pathBlacklistRoleTagTidy(&b),
|
|
|
|
pathWhitelistIdentity(&b),
|
|
|
|
pathWhitelistIdentityTidy(&b),
|
|
|
|
pathListWhitelistIdentities(&b),
|
|
|
|
}),
|
|
|
|
|
|
|
|
AuthRenew: b.pathLoginRenew,
|
|
|
|
}
|
|
|
|
|
2016-04-14 04:11:17 +00:00
|
|
|
b.EC2ClientsMap = make(map[string]*ec2.EC2)
|
|
|
|
|
2016-04-06 00:42:26 +00:00
|
|
|
return b.Backend, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
type backend struct {
|
|
|
|
*framework.Backend
|
|
|
|
Salt *salt.Salt
|
2016-04-07 18:13:19 +00:00
|
|
|
|
|
|
|
configMutex sync.RWMutex
|
|
|
|
|
2016-04-14 04:11:17 +00:00
|
|
|
EC2ClientsMap map[string]*ec2.EC2
|
2016-04-06 00:42:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const backendHelp = `
|
|
|
|
AWS auth backend takes in a AWS EC2 instance identity document, its PKCS#7 signature
|
|
|
|
and a client created nonce to authenticates the instance with Vault.
|
|
|
|
|
|
|
|
Authentication is backed by a preconfigured association of AMIs to Vault's policies
|
2016-04-08 06:05:57 +00:00
|
|
|
through 'image/<ami_id>' endpoint. For instances that share an AMI, an instance tag can
|
|
|
|
be created through 'image/<ami_id>/tag'. This tag should be attached to the EC2 instance
|
2016-04-06 00:42:26 +00:00
|
|
|
before the instance attempts to login to Vault.
|
|
|
|
`
|