Skip to content

Commit

Permalink
A bunch of little fixes (#23)
Browse files Browse the repository at this point in the history
  • Loading branch information
pcman312 committed Feb 17, 2021
1 parent 65eba2f commit 6449f92
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion path_dynamic_creds.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func (b *backend) pathDynamicCredsRead(ctx context.Context, req *logical.Request
merr := multierror.Append(fmt.Errorf("failed to create user: %w", err))
_, err = b.executeLDIF(config.LDAP, dRole.RollbackLDIF, templateData, true)
if err != nil {
merr = multierror.Append(fmt.Errorf("failed to roll back user creation: %w", err))
merr = multierror.Append(merr, fmt.Errorf("failed to roll back user creation: %w", err))
}
return nil, merr
}
Expand Down
2 changes: 1 addition & 1 deletion path_dynamic_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ const (
secretCredsType = "creds"

dynamicRolePath = "role/"
dynamicCredPath = "cred/"
dynamicCredPath = "creds/"
)

func (b *backend) pathDynamicRoles() []*framework.Path {
Expand Down
3 changes: 1 addition & 2 deletions path_static_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package openldap
import (
"context"
"fmt"
"path"
"time"

"github.com/hashicorp/vault/sdk/framework"
Expand All @@ -19,7 +18,7 @@ const (
func (b *backend) pathListStaticRoles() []*framework.Path {
return []*framework.Path{
{
Pattern: path.Join(staticRolePath, framework.OptionalParamRegex("prefix")),
Pattern: staticRolePath + "?$",
Operations: map[logical.Operation]framework.OperationHandler{
logical.ListOperation: &framework.PathOperation{
Callback: b.pathStaticRoleList,
Expand Down
37 changes: 33 additions & 4 deletions scripts/acceptance-tests.bats
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ teardown() {
run vault read openldap/role/testrole
[ ${status} -ne 0 ]

run vault read openldap/cred/testrole
run vault read openldap/creds/testrole
[ ${status} -ne 0 ]
}

Expand Down Expand Up @@ -275,11 +275,11 @@ teardown() {
max_ttl=20

# Create role
run vault write openldap/role/testrole creation_ldif="${creation_ldif}" deletion_ldif="${deletion_ldif}" default_ttl="${default_ttl}s" max_ttl="${max_ttl}s"
run vault write openldap/role/testrole creation_ldif="${creation_ldif}" deletion_ldif="${deletion_ldif}" rollback_ldif="${deletion_ldif}" default_ttl="${default_ttl}s" max_ttl="${max_ttl}s"
[ ${status} -eq 0 ]

# Get credentials
run vault read -format=json openldap/cred/testrole
run vault read -format=json openldap/creds/testrole
[ ${status} -eq 0 ]


Expand Down Expand Up @@ -331,7 +331,7 @@ teardown() {

# Get credentials
log "Generating credentials..."
run vault read -format=json openldap/cred/testrole
run vault read -format=json openldap/creds/testrole
[ ${status} -eq 0 ]

lease_id=$(echo "${output}" | jq -r .lease_id)
Expand Down Expand Up @@ -404,3 +404,32 @@ teardown() {
run ldapsearch -b "${dn}" -D "${dn}" -w "${password}"
[ ${status} -ne 0 ]
}

@test "Dynamic Secrets - Useful error on creation failure" {
default_ttl=10
max_ttl=20

bad_creation_ldif='dn: cn={{.Username}},ou=thisgroupdoesnotexist,dc=learn,dc=example
objectClass: person
objectClass: top
cn: learn
sn: learn-{{.Username | utf16le | base64}}
memberOf: cn=dev,ou=groups,dc=learn,dc=example
userPassword: {{.Password}}'

# Create role
run vault write openldap/role/testrole creation_ldif="${bad_creation_ldif}" deletion_ldif="${deletion_ldif}" rollback_ldif="${deletion_ldif}" default_ttl="${default_ttl}s" max_ttl="${max_ttl}s"
[ ${status} -eq 0 ]

# Get credentials
run vault read -format=json openldap/creds/testrole
[ ${status} -ne 0 ]
[[ "${output}" == *"failed to create user" ]]

# Optional assertion that makes sure both errors are included but if this becomes flaky it isn't the important error and can be removed
[[ "${output}" == *"failed to roll back user" ]]

## Assert the credentials do *not* work in OpenLDAP
run ldapsearch -b "${dn}" -D "${dn}" -w "${password}"
[ ${status} -ne 0 ]
}

0 comments on commit 6449f92

Please sign in to comment.