Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/release/1.9.x' into backport/tsa…
Browse files Browse the repository at this point in the history
…arni/issue12855/similarly-rare-dove
  • Loading branch information
tvoran committed Jan 21, 2022
2 parents 5cbc6de + cf9a8e0 commit b68a204
Show file tree
Hide file tree
Showing 18 changed files with 517 additions and 143 deletions.
50 changes: 33 additions & 17 deletions builtin/credential/ldap/backend_test.go
Expand Up @@ -597,6 +597,26 @@ func TestBackend_basic_authbind_userfilter(t *testing.T) {

}

func TestBackend_basic_authbind_metadata_name(t *testing.T) {

b := factory(t)
cleanup, cfg := ldap.PrepareTestContainer(t, "latest")
defer cleanup()

cfg.UserAttr = "cn"
cfg.UPNDomain = "planetexpress.com"

addUPNAttributeToLDAPSchemaAndUser(t, cfg, "cn=Hubert J. Farnsworth,ou=people,dc=planetexpress,dc=com", "professor@planetexpress.com")

logicaltest.Test(t, logicaltest.TestCase{
CredentialBackend: b,
Steps: []logicaltest.TestStep{
testAccStepConfigUrlWithAuthBind(t, cfg),
testAccStepLoginAliasMetadataName(t, "professor", "professor"),
},
})
}

func addUPNAttributeToLDAPSchemaAndUser(t *testing.T, cfg *ldaputil.ConfigEntry, testUserDN string, testUserUPN string) {
// Setup connection
client := &ldaputil.Client{
Expand Down Expand Up @@ -644,23 +664,6 @@ func addUPNAttributeToLDAPSchemaAndUser(t *testing.T, cfg *ldaputil.ConfigEntry,

}

func TestBackend_basic_authbind_upndomain(t *testing.T) {
b := factory(t)
cleanup, cfg := ldap.PrepareTestContainer(t, "latest")
defer cleanup()
cfg.UPNDomain = "planetexpress.com"

addUPNAttributeToLDAPSchemaAndUser(t, cfg, "cn=Hubert J. Farnsworth,ou=people,dc=planetexpress,dc=com", "professor@planetexpress.com")

logicaltest.Test(t, logicaltest.TestCase{
CredentialBackend: b,
Steps: []logicaltest.TestStep{
testAccStepConfigUrlWithAuthBind(t, cfg),
testAccStepLoginNoAttachedPolicies(t, "professor", "professor"),
},
})
}

func TestBackend_basic_discover(t *testing.T) {
b := factory(t)
cleanup, cfg := ldap.PrepareTestContainer(t, "latest")
Expand Down Expand Up @@ -990,6 +993,19 @@ func testAccStepLoginNoAttachedPolicies(t *testing.T, user string, pass string)
}
}

func testAccStepLoginAliasMetadataName(t *testing.T, user string, pass string) logicaltest.TestStep {
return logicaltest.TestStep{
Operation: logical.UpdateOperation,
Path: "login/" + user,
Data: map[string]interface{}{
"password": pass,
},
Unauthenticated: true,

Check: logicaltest.TestCheckAuthEntityAliasMetadataName("name", user),
}
}

func testAccStepLoginFailure(t *testing.T, user string, pass string) logicaltest.TestStep {
return logicaltest.TestStep{
Operation: logical.UpdateOperation,
Expand Down
3 changes: 3 additions & 0 deletions builtin/credential/ldap/path_login.go
Expand Up @@ -97,6 +97,9 @@ func (b *backend) pathLogin(ctx context.Context, req *logical.Request, d *framew
DisplayName: username,
Alias: &logical.Alias{
Name: effectiveUsername,
Metadata: map[string]string{
"name": username,
},
},
}

Expand Down
3 changes: 3 additions & 0 deletions changelog/13669.txt
@@ -0,0 +1,3 @@
```release-note:improvement
auth/ldap: Add username to alias metadata
```
3 changes: 3 additions & 0 deletions changelog/13678.txt
@@ -0,0 +1,3 @@
```release-note:bug
core: add support for go-sockaddr templates in the top-level cluster_addr field
```
6 changes: 5 additions & 1 deletion command/server.go
Expand Up @@ -724,7 +724,6 @@ func (c *ServerCommand) runRecoveryMode() int {
c.logger.Info("goroutine trace", "stack", string(buf[:n]))
}
}

}

func logProxyEnvironmentVariables(logger hclog.Logger) {
Expand Down Expand Up @@ -2407,6 +2406,11 @@ CLUSTER_SYNTHESIS_COMPLETE:
}

if coreConfig.ClusterAddr != "" {
rendered, err := configutil.ParseSingleIPTemplate(coreConfig.ClusterAddr)
if err != nil {
return fmt.Errorf("Error parsing cluster address %s: %v", coreConfig.ClusterAddr, err)
}
coreConfig.ClusterAddr = rendered
// Force https as we'll always be TLS-secured
u, err := url.ParseRequestURI(coreConfig.ClusterAddr)
if err != nil {
Expand Down
34 changes: 29 additions & 5 deletions helper/testhelpers/logical/testing.go
Expand Up @@ -457,13 +457,37 @@ func TestCheckAuthEntityId(entity_id *string) TestCheckFunc {
return fmt.Errorf("no auth in response")
}

if *entity_id == "" {
// If we don't know what the entity_id should be, just save it
*entity_id = resp.Auth.EntityID
} else if resp.Auth.EntityID != *entity_id {
if *entity_id == "" {
// If we don't know what the entity_id should be, just save it
*entity_id = resp.Auth.EntityID
} else if resp.Auth.EntityID != *entity_id {
return fmt.Errorf("entity_id %s does not match the expected value of %s", resp.Auth.EntityID, *entity_id)
}
}

return nil
}
}

// TestCheckAuthEntityAliasMetadataName is a helper to check that a request generated an
// auth token with the expected alias metadata.
func TestCheckAuthEntityAliasMetadataName(key string, value string) TestCheckFunc {
return func(resp *logical.Response) error {
if resp == nil || resp.Auth == nil {
return fmt.Errorf("no auth in response")
}

if key == "" || value == "" {
return fmt.Errorf("alias metadata key and value required")
}

name, ok := resp.Auth.Alias.Metadata[key]
if !ok {
return fmt.Errorf("metadata key %s does not exist, it should", key)
}

if name != value {
return fmt.Errorf("expected map value %s, got %s", value, name)
}
return nil
}
}
Expand Down
3 changes: 3 additions & 0 deletions vault/core.go
Expand Up @@ -1368,6 +1368,9 @@ func (c *Core) getUnsealKey(ctx context.Context, seal Seal) ([]byte, error) {
if err != nil {
return nil, err
}
if config == nil {
return nil, fmt.Errorf("failed to obtain seal/recovery configuration")
}

// Check if we don't have enough keys to unlock, proceed through the rest of
// the call only if we have met the threshold
Expand Down
13 changes: 9 additions & 4 deletions website/content/api-docs/auth/kubernetes.mdx
Expand Up @@ -39,11 +39,17 @@ access the Kubernetes API.
JWTs. If a certificate is given, its public key will be
extracted. Not every installation of Kubernetes exposes these
keys.
- `issuer` `(string: "")` - Optional JWT issuer. If no issuer is specified, then this plugin will
use `kubernetes/serviceaccount` as the default issuer. See [these instructions](/docs/platform/k8s/csi#setting-issuer-for-kubernetes-authentication) for looking up the issuer for a given Kubernetes cluster.
- `disable_iss_validation` `(bool: false)` - Disable JWT issuer validation. Allows to skip ISS validation.
- `disable_local_ca_jwt` `(bool: false)` - Disable defaulting to the local CA cert and service account JWT when running in a Kubernetes pod.

### Deprecated Parameters

-> The following fields have been deprecated and will be removed in a future release:

- `disable_iss_validation` `(bool: true)` **Deprecated** Disable JWT issuer validation. Allows to skip ISS validation.

- `issuer` `(string: "")` **Deprecated** Optional JWT issuer. If no issuer is specified, then this plugin will use `kubernetes/serviceaccount` as the default issuer.
See [these instructions](/docs/auth/kubernetes#discovering-the-service-account-issuer) for looking up the issuer for a given Kubernetes cluster.

### Caveats

If Vault is running in a Kubernetes Pod, the `kubernetes_ca_cert` and
Expand Down Expand Up @@ -99,7 +105,6 @@ $ curl \
"kubernetes_host": "https://192.168.99.100:8443",
"kubernetes_ca_cert": "-----BEGIN CERTIFICATE-----.....-----END CERTIFICATE-----",
"pem_keys": ["-----BEGIN CERTIFICATE-----.....", .....],
"disable_iss_validation": false,
"disable_local_ca_jwt": false
}
}
Expand Down

0 comments on commit b68a204

Please sign in to comment.