-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
disable identity for local mounts (#4407)
- Loading branch information
1 parent
037d51a
commit 6c464cf
Showing
7 changed files
with
143 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package vault_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/vault/api" | ||
vaulthttp "github.com/hashicorp/vault/http" | ||
"github.com/hashicorp/vault/logical" | ||
"github.com/hashicorp/vault/vault" | ||
|
||
credLdap "github.com/hashicorp/vault/builtin/credential/ldap" | ||
) | ||
|
||
func TestIdentityStore_EntityAliasLocalMount(t *testing.T) { | ||
coreConfig := &vault.CoreConfig{ | ||
CredentialBackends: map[string]logical.Factory{ | ||
"ldap": credLdap.Factory, | ||
}, | ||
} | ||
cluster := vault.NewTestCluster(t, coreConfig, &vault.TestClusterOptions{ | ||
HandlerFunc: vaulthttp.Handler, | ||
}) | ||
cluster.Start() | ||
defer cluster.Cleanup() | ||
|
||
core := cluster.Cores[0].Core | ||
vault.TestWaitActive(t, core) | ||
client := cluster.Cores[0].Client | ||
|
||
// Create a local auth mount | ||
err := client.Sys().EnableAuthWithOptions("ldap", &api.EnableAuthOptions{ | ||
Type: "ldap", | ||
Local: true, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Extract out the mount accessor for LDAP auth | ||
auths, err := client.Sys().ListAuth() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
ldapMountAccessor := auths["ldap/"].Accessor | ||
|
||
// Create an entity | ||
secret, err := client.Logical().Write("identity/entity", nil) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
entityID := secret.Data["id"].(string) | ||
|
||
// Attempt to create an entity alias against a local mount should fail | ||
secret, err = client.Logical().Write("identity/entity-alias", map[string]interface{}{ | ||
"name": "testuser", | ||
"mount_accessor": ldapMountAccessor, | ||
"canonical_id": entityID, | ||
}) | ||
if err == nil { | ||
t.Fatalf("expected error since mount is local") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
package vault_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/vault/api" | ||
vaulthttp "github.com/hashicorp/vault/http" | ||
"github.com/hashicorp/vault/logical" | ||
"github.com/hashicorp/vault/vault" | ||
|
||
credLdap "github.com/hashicorp/vault/builtin/credential/ldap" | ||
) | ||
|
||
func TestIdentityStore_GroupAliasLocalMount(t *testing.T) { | ||
coreConfig := &vault.CoreConfig{ | ||
CredentialBackends: map[string]logical.Factory{ | ||
"ldap": credLdap.Factory, | ||
}, | ||
} | ||
cluster := vault.NewTestCluster(t, coreConfig, &vault.TestClusterOptions{ | ||
HandlerFunc: vaulthttp.Handler, | ||
}) | ||
cluster.Start() | ||
defer cluster.Cleanup() | ||
|
||
core := cluster.Cores[0].Core | ||
vault.TestWaitActive(t, core) | ||
client := cluster.Cores[0].Client | ||
|
||
// Create a local auth mount | ||
err := client.Sys().EnableAuthWithOptions("ldap", &api.EnableAuthOptions{ | ||
Type: "ldap", | ||
Local: true, | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
|
||
// Extract out the mount accessor for LDAP auth | ||
auths, err := client.Sys().ListAuth() | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
ldapMountAccessor := auths["ldap/"].Accessor | ||
|
||
// Create an external group | ||
secret, err := client.Logical().Write("identity/group", map[string]interface{}{ | ||
"type": "external", | ||
}) | ||
if err != nil { | ||
t.Fatal(err) | ||
} | ||
groupID := secret.Data["id"].(string) | ||
|
||
// Attempt to create a group alias against a local mount should fail | ||
secret, err = client.Logical().Write("identity/group-alias", map[string]interface{}{ | ||
"name": "testuser", | ||
"mount_accessor": ldapMountAccessor, | ||
"canonical_id": groupID, | ||
}) | ||
if err == nil { | ||
t.Fatalf("expected error since mount is local") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters