Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Combined Database Backend: Static Accounts #6680

Closed
wants to merge 76 commits into from
Closed
Show file tree
Hide file tree
Changes from 29 commits
Commits
Show all changes
76 commits
Select commit Hold shift + click to select a range
561ce7b
Add priority queue to sdk
catsby Apr 30, 2019
4f6e85c
fix issue of storing pointers and now copy
catsby Apr 30, 2019
d61d162
update to use copy structure
catsby Apr 30, 2019
d7e72bc
Remove file, put Item struct def. into other file
catsby May 1, 2019
60f24bc
add link
catsby May 1, 2019
e684708
clean up docs
catsby May 1, 2019
dd454e5
Merge branch 'master' into cdcr-priority-queue
catsby May 1, 2019
97ac24c
refactor internal data structure to hide heap method implementations.…
catsby May 2, 2019
f6ed9b9
rename PushItem and PopItem to just Push/Pop, after encapsulating the…
catsby May 2, 2019
41ffc88
updates after feedback
catsby May 3, 2019
fbca439
refactoring/renaming
catsby May 3, 2019
5eb067c
guard against pushing a nil item
catsby May 3, 2019
47b4a4d
minor updates after feedback
catsby May 3, 2019
2c38dc6
Add SetCredentials, GenerateCredentials gRPC methods to combined data…
catsby May 1, 2019
50b221b
Initial Combined database backend implementation of static accounts a…
catsby May 1, 2019
0a3c56b
vendor updates
catsby May 1, 2019
5af0fdb
initial implementation of static accounts with Combined database back…
catsby May 1, 2019
4d47b9a
add lock and setup of rotation queue
catsby May 1, 2019
c1ae80d
vendor the queue
catsby May 1, 2019
42d01f8
rebase on new method signature of queue
catsby May 2, 2019
bebd2b5
remove mongo tests for now
catsby May 2, 2019
f94ffb8
update default role sql
catsby May 3, 2019
784585d
gofmt after rebase
catsby May 3, 2019
c006f1e
cleanup after rebasing to remove checks for ErrNotFound error
catsby May 3, 2019
2041814
rebase cdcr-priority-queue
catsby May 3, 2019
2ba681d
vendor dependencies with 'go mod vendor'
catsby May 3, 2019
7a9774b
website database docs for Static Role support
catsby May 6, 2019
3aa9b09
document the rotate-role API endpoint
catsby May 6, 2019
e4977bb
postgres specific static role docs
catsby May 6, 2019
b701a4a
use constants for paths
catsby May 9, 2019
236dc18
updates from review
catsby May 9, 2019
ce5fea3
remove dead code
catsby May 9, 2019
bf9358c
combine and clarify error message for older plugins
catsby May 10, 2019
d10a715
Update builtin/logical/database/backend.go
catsby May 13, 2019
c0907c0
cleanups from feedback
catsby May 13, 2019
d5df52c
code and comment cleanups
catsby May 14, 2019
447bd4d
move db.RLock higher to protect db.GenerateCredentials call
catsby May 14, 2019
8259534
Return output with WALID if we failed to delete the WAL
catsby May 14, 2019
616e4e0
Update builtin/logical/database/path_creds_create.go
catsby May 14, 2019
da1b8cc
Merge branch 'master' into cdcr-backend-grpc
catsby May 16, 2019
9c570c1
updates after running 'make fmt'
catsby May 16, 2019
cee43de
update after running 'make proto'
catsby May 16, 2019
f488a46
Update builtin/logical/database/path_roles.go
catsby May 16, 2019
9d86150
Update builtin/logical/database/path_roles.go
catsby May 16, 2019
21edf95
update comment and remove and rearrange some dead code
catsby May 16, 2019
e19e134
Update website/source/api/secret/databases/index.html.md
catsby May 16, 2019
a6affaf
cleanups after review
catsby May 16, 2019
134d8ec
Merge branch 'cdcr-backend-grpc' of github.com:hashicorp/vault into c…
catsby May 16, 2019
fb789a6
Update sdk/database/dbplugin/grpc_transport.go
catsby May 16, 2019
2ca4849
code cleanup after feedback
catsby May 17, 2019
5017de7
Merge branch 'cdcr-backend-grpc' of github.com:hashicorp/vault into c…
catsby May 17, 2019
06c4624
remove PasswordLastSet; it's not used
catsby May 17, 2019
01dab21
document GenerateCredentials and SetCredentials
catsby May 17, 2019
accd35e
Update builtin/logical/database/path_rotate_credentials.go
catsby May 17, 2019
c9246ad
wrap pop and popbykey in backend methods to protect against nil cred …
catsby May 17, 2019
b631b4f
Merge branch 'cdcr-backend-grpc' of github.com:hashicorp/vault into c…
catsby May 17, 2019
4081d27
use strings.HasPrefix instead of direct equality check for path
catsby May 17, 2019
7ee9e10
Forgot to commit this
catsby May 17, 2019
5eb9da1
updates after feedback
catsby May 20, 2019
96b3cbb
re-purpose an outdated test to now check that static and dynamic role…
catsby May 20, 2019
e1ffe33
check for unique name across dynamic and static roles
catsby May 20, 2019
547a8eb
refactor loadStaticWALs to return a map of name/setCredentialsWAL str…
catsby May 20, 2019
52c039b
remove commented out code
catsby May 20, 2019
8839757
refactor to have loadstaticwals filter out wals for roles that no lon…
catsby May 22, 2019
ba1b4a7
return error if nil input given
catsby May 22, 2019
29b0564
add nil check for input into setStaticAccount
catsby May 22, 2019
da66aca
Update builtin/logical/database/path_roles.go
catsby May 22, 2019
03b1ae9
add constant for queue tick time in seconds, used for comparrison in …
catsby May 22, 2019
e19307d
Update builtin/logical/database/path_roles.go
catsby May 22, 2019
c30b33f
code cleanup after review
catsby May 22, 2019
c00320f
remove misplaced code comment
catsby May 22, 2019
f6df0ff
Merge branch 'cdcr-backend-grpc' of github.com:hashicorp/vault into c…
catsby May 22, 2019
b1b8a62
remove commented out code
catsby May 22, 2019
35b66f2
create a queue in the Factory method, even if it's never used
catsby May 22, 2019
5b387f5
update path_roles to use a common set of fields, with specific overri…
catsby May 22, 2019
6babbfa
document new method
catsby May 23, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
545 changes: 534 additions & 11 deletions builtin/logical/database/backend.go

Large diffs are not rendered by default.

433 changes: 398 additions & 35 deletions builtin/logical/database/backend_test.go

Large diffs are not rendered by default.

90 changes: 78 additions & 12 deletions builtin/logical/database/path_creds_create.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,40 @@ import (
"github.com/hashicorp/vault/sdk/logical"
)

func pathCredsCreate(b *databaseBackend) *framework.Path {
return &framework.Path{
Pattern: "creds/" + framework.GenericNameRegex("name"),
Fields: map[string]*framework.FieldSchema{
"name": &framework.FieldSchema{
Type: framework.TypeString,
Description: "Name of the role.",
func pathCredsCreate(b *databaseBackend) []*framework.Path {
return []*framework.Path{
&framework.Path{
Pattern: "creds/" + framework.GenericNameRegex("name"),
Fields: map[string]*framework.FieldSchema{
"name": &framework.FieldSchema{
Type: framework.TypeString,
Description: "Name of the role.",
},
},

Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ReadOperation: b.pathCredsCreateRead(),
},
},

Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ReadOperation: b.pathCredsCreateRead(),
HelpSynopsis: pathCredsCreateReadHelpSyn,
HelpDescription: pathCredsCreateReadHelpDesc,
},
&framework.Path{
Pattern: "static-creds/" + framework.GenericNameRegex("name"),
Fields: map[string]*framework.FieldSchema{
"name": &framework.FieldSchema{
Type: framework.TypeString,
Description: "Name of the static role.",
},
},

HelpSynopsis: pathCredsCreateReadHelpSyn,
HelpDescription: pathCredsCreateReadHelpDesc,
Callbacks: map[logical.Operation]framework.OperationFunc{
logical.ReadOperation: b.pathStaticCredsRead(),
},

HelpSynopsis: pathStaticCredsReadHelpSyn,
HelpDescription: pathStaticCredsReadHelpDesc,
},
}
}

Expand Down Expand Up @@ -99,6 +117,43 @@ func (b *databaseBackend) pathCredsCreateRead() framework.OperationFunc {
}
}

func (b *databaseBackend) pathStaticCredsRead() framework.OperationFunc {
return func(ctx context.Context, req *logical.Request, data *framework.FieldData) (*logical.Response, error) {
name := data.Get("name").(string)

role, err := b.StaticRole(ctx, req.Storage, name)
if err != nil {
return nil, err
}
if role == nil {
return logical.ErrorResponse(fmt.Sprintf("unknown role: %s", name)), nil
catsby marked this conversation as resolved.
Show resolved Hide resolved
}

dbConfig, err := b.DatabaseConfig(ctx, req.Storage, role.DBName)
if err != nil {
return nil, err
}

// If role name isn't in the database's allowed roles, send back a
// permission denied.
if !strutil.StrListContains(dbConfig.AllowedRoles, "*") && !strutil.StrListContainsGlob(dbConfig.AllowedRoles, name) {
return nil, fmt.Errorf("%q is not an allowed role", name)
kalafut marked this conversation as resolved.
Show resolved Hide resolved
}

return &logical.Response{
Data: map[string]interface{}{
"username": role.StaticAccount.Username,
"password": role.StaticAccount.Password,
// "ttl": fmt.Sprintf("%v", role.StaticAccount.PasswordTTL()),
// "rotation_period": fmt.Sprintf("%v", role.StaticAccount.RotationPeriod),
"ttl": role.StaticAccount.PasswordTTL().Seconds(),
"rotation_period": role.StaticAccount.RotationPeriod.Seconds(),
"last_vault_rotation": role.StaticAccount.LastVaultRotation,
},
}, nil
}
}

const pathCredsCreateReadHelpSyn = `
Request database credentials for a certain role.
`
Expand All @@ -108,3 +163,14 @@ This path reads database credentials for a certain role. The
database credentials will be generated on demand and will be automatically
revoked when the lease is up.
`

const pathStaticCredsReadHelpSyn = `
Request database credentials for a certain static role. These credentials are
rotated periodically.
`

const pathStaticCredsReadHelpDesc = `
This path reads database credentials for a certain static role. The database
credentials are rotated periodically according to their configuration, and will
return the same password until they are rotated.
`
Loading