Skip to content

Commit

Permalink
backport of commit 154a3a7
Browse files Browse the repository at this point in the history
  • Loading branch information
ccapurso committed Mar 23, 2022
1 parent 550d3aa commit 61cb98b
Show file tree
Hide file tree
Showing 223 changed files with 4,454 additions and 1,613 deletions.
2 changes: 1 addition & 1 deletion .circleci/config.yml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ steps:
name: Check branch name
command: |
case "$CIRCLE_BRANCH" in
main|ui/*|release/*|merge*) ;;
main|ui/*|backport/ui/*|release/*|merge*) ;;
*) # If the branch being tested doesn't match one of the above patterns,
# we don't need to run test-ui and can abort the job.
circleci-agent step halt
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ on:
push:
# Sequence of patterns matched against refs/heads
branches:
# Push events on main branch
- main
# Push events on release/1.10.x branch
- release/1.10.x

env:
PKG_NAME: "vault"
Expand Down Expand Up @@ -146,7 +146,7 @@ jobs:
path: out/${{ env.PKG_NAME }}_${{ needs.get-product-version.outputs.product-version }}_${{ matrix.goos }}_${{ matrix.goarch }}.zip

- name: Package
uses: hashicorp/actions-packaging-linux@v1.2
uses: hashicorp/actions-packaging-linux@v1
with:
name: ${{ github.event.repository.name }}
description: "Vault is a tool for secrets management, encryption as a service, and privileged access management."
Expand Down
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ _testmain.go
/pkg/

# Generated Web UI goes here
/http/web_ui/**
/http/web_ui/*.*
/http/web_ui/**/*.*

# Vault-specific
example.hcl
Expand Down
8 changes: 1 addition & 7 deletions .release/ci.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,7 @@ project "vault" {
github {
organization = "hashicorp"
repository = "vault"
release_branches = [
"main",
"release/1.6.x",
"release/1.7.x",
"release/1.8.x",
"release/1.9.x",
]
release_branches = ["release/1.10.x"]
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ StartLimitIntervalSec=60
StartLimitBurst=3

[Service]
Type=notify
EnvironmentFile=/etc/vault.d/vault.env
User=vault
Group=vault
Expand Down
6 changes: 6 additions & 0 deletions .release/release-metadata.hcl
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
url_docker_registry_dockerhub = "https://hub.docker.com/r/hashicorp/vault"
url_docker_registry_ecr = "https://gallery.ecr.aws/hashicorp/vault"
url_license = "https://github.com/hashicorp/vault/blob/main/LICENSE"
url_project_website = "https://www.vaultproject.io/"
url_source_repository = "https://github.com/hashicorp/vault"
url_release_notes = "https://www.vaultproject.io/docs/release-notes"
2 changes: 1 addition & 1 deletion .release/security-scan.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ binary {
go_modules = false
osv = true
oss_index = true
nvd = true
nvd = false
}
2 changes: 1 addition & 1 deletion api/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ require (
github.com/hashicorp/go-multierror v1.1.1
github.com/hashicorp/go-retryablehttp v0.6.6
github.com/hashicorp/go-rootcerts v1.0.2
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.1
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.4
github.com/hashicorp/hcl v1.0.0
github.com/hashicorp/vault/sdk v0.4.1
github.com/mitchellh/mapstructure v1.4.2
Expand Down
3 changes: 2 additions & 1 deletion api/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,9 @@ github.com/hashicorp/go-rootcerts v1.0.2/go.mod h1:pqUvnprVnM5bf7AOirdbb01K4ccR3
github.com/hashicorp/go-secure-stdlib/base62 v0.1.1/go.mod h1:EdWO6czbmthiwZ3/PUsDV+UD1D5IRU4ActiaWGwt0Yw=
github.com/hashicorp/go-secure-stdlib/mlock v0.1.1 h1:cCRo8gK7oq6A2L6LICkUZ+/a5rLiRXFMf1Qd4xSwxTc=
github.com/hashicorp/go-secure-stdlib/mlock v0.1.1/go.mod h1:zq93CJChV6L9QTfGKtfBxKqD7BqqXx5O04A/ns2p5+I=
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.1 h1:78ki3QBevHwYrVxnyVeaEz+7WtifHhauYF23es/0KlI=
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.1/go.mod h1:QmrqtbKuxxSWTN3ETMPuB+VtEiBJ/A9XhoYGv8E1uD8=
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.4 h1:hrIH/qrOTHfG9a1Jz6Z2jQf7Xe77AaD464W1fCFLwPQ=
github.com/hashicorp/go-secure-stdlib/parseutil v0.1.4/go.mod h1:QmrqtbKuxxSWTN3ETMPuB+VtEiBJ/A9XhoYGv8E1uD8=
github.com/hashicorp/go-secure-stdlib/password v0.1.1/go.mod h1:9hH302QllNwu1o2TGYtSk8I8kTAN0ca1EHpwhm5Mmzo=
github.com/hashicorp/go-secure-stdlib/strutil v0.1.1 h1:nd0HIW15E6FG1MsnArYaHfuw9C2zgzM8LxkG5Ty/788=
github.com/hashicorp/go-secure-stdlib/strutil v0.1.1/go.mod h1:gKOamz3EwoIoJq7mlMIRBpVTAUn8qPCrEclOKKWhD3U=
Expand Down
11 changes: 3 additions & 8 deletions api/renewer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,8 @@ func TestLifetimeWatcher(t *testing.T) {
t.Fatal(err)
}

doneCh := make(chan error, 1)
go func() {
doneCh <- v.doRenewWithOptions(false, false,
tc.leaseDurationSeconds, "myleaseID", tc.renew, time.Second)
v.doneCh <- v.doRenewWithOptions(false, false, tc.leaseDurationSeconds, "myleaseID", tc.renew, time.Second)
}()
defer v.Stop()

Expand All @@ -191,15 +189,12 @@ func TestLifetimeWatcher(t *testing.T) {
if r.Secret != renewedSecret {
t.Fatalf("expected secret %v, got %v", renewedSecret, r.Secret)
}
case err := <-doneCh:
case err := <-v.DoneCh():
if tc.expectError != nil && !errors.Is(err, tc.expectError) {
t.Fatalf("expected error %q, got: %v", tc.expectError, err)
}
if tc.expectError == nil && err != nil {
t.Fatalf("expected no error, got: %v", err)
}
if tc.expectRenewal {
t.Fatalf("expected at least one renewal, got donech result: %v", err)
t.Fatal("expected at least one renewal")
}
}
})
Expand Down
21 changes: 21 additions & 0 deletions builtin/credential/approle/path_login_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package approle

import (
"context"
"strings"
"testing"
"time"

Expand Down Expand Up @@ -264,6 +265,26 @@ func TestAppRole_RoleLogin(t *testing.T) {
if resp.Auth.Period != period {
t.Fatalf("expected period value of %d in the response, got: %s", period, resp.Auth.Period)
}

// Test input validation with secret_id that exceeds max length
loginData["secret_id"] = strings.Repeat("a", maxHmacInputLength+1)

loginReq = &logical.Request{
Operation: logical.UpdateOperation,
Path: "login",
Storage: storage,
Data: loginData,
Connection: &logical.Connection{
RemoteAddr: "127.0.0.1",
},
}

loginResp, err = b.HandleRequest(context.Background(), loginReq)

expectedErr := "failed to create HMAC of secret_id"
if loginResp != nil || err == nil || !strings.Contains(err.Error(), expectedErr) {
t.Fatalf("expected login test to fail with error %q, resp: %#v, err: %v", expectedErr, loginResp, err)
}
}

func generateRenewRequest(s logical.Storage, auth *logical.Auth) *logical.Request {
Expand Down
7 changes: 7 additions & 0 deletions builtin/credential/approle/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,19 @@ func verifyCIDRRoleSecretIDSubset(secretIDCIDRs []string, roleBoundCIDRList []st
return nil
}

const maxHmacInputLength = 1024

// Creates a SHA256 HMAC of the given 'value' using the given 'key' and returns
// a hex encoded string.
func createHMAC(key, value string) (string, error) {
if key == "" {
return "", fmt.Errorf("invalid HMAC key")
}

if len(value) > maxHmacInputLength {
return "", fmt.Errorf("value is longer than maximum of %d bytes", maxHmacInputLength)
}

hm := hmac.New(sha256.New, []byte(key))
hm.Write([]byte(value))
return hex.EncodeToString(hm.Sum(nil)), nil
Expand Down
1 change: 1 addition & 0 deletions builtin/credential/ldap/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1205,6 +1205,7 @@ func TestLdapAuthBackend_ConfigUpgrade(t *testing.T) {
CaseSensitiveNames: falseBool,
UsePre111GroupCNBehavior: new(bool),
RequestTimeout: cfg.RequestTimeout,
UsernameAsAlias: false,
},
}

Expand Down
4 changes: 4 additions & 0 deletions builtin/credential/ldap/path_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,10 @@ func (b *backend) pathLogin(ctx context.Context, req *logical.Request, d *framew
},
}

if cfg.UsernameAsAlias {
auth.Alias.Name = username
}

cfg.PopulateTokenAuth(auth)

// Add in configured policies from mappings
Expand Down
117 changes: 115 additions & 2 deletions builtin/logical/database/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package database
import (
"context"
"database/sql"
"fmt"
"log"
"net/url"
"os"
"reflect"
"strings"
Expand All @@ -12,6 +14,9 @@ import (

"github.com/go-test/deep"
mongodbatlas "github.com/hashicorp/vault-plugin-database-mongodbatlas"
"github.com/lib/pq"
"github.com/mitchellh/mapstructure"

"github.com/hashicorp/vault/helper/namespace"
postgreshelper "github.com/hashicorp/vault/helper/testhelpers/postgresql"
vaulthttp "github.com/hashicorp/vault/http"
Expand All @@ -25,8 +30,6 @@ import (
"github.com/hashicorp/vault/sdk/helper/pluginutil"
"github.com/hashicorp/vault/sdk/logical"
"github.com/hashicorp/vault/vault"
"github.com/lib/pq"
"github.com/mitchellh/mapstructure"
)

func getCluster(t *testing.T) (*vault.TestCluster, logical.SystemView) {
Expand Down Expand Up @@ -1322,6 +1325,116 @@ func TestBackend_RotateRootCredentials(t *testing.T) {
}
}

func TestBackend_ConnectionURL_redacted(t *testing.T) {
cluster, sys := getCluster(t)
t.Cleanup(cluster.Cleanup)

config := logical.TestBackendConfig()
config.StorageView = &logical.InmemStorage{}
config.System = sys

b, err := Factory(context.Background(), config)
if err != nil {
t.Fatal(err)
}
defer b.Cleanup(context.Background())

tests := []struct {
name string
password string
}{
{
name: "basic",
password: "secret",
},
{
name: "encoded",
password: "yourStrong(!)Password",
},
}

respCheck := func(req *logical.Request) *logical.Response {
t.Helper()
resp, err := b.HandleRequest(namespace.RootContext(nil), req)
if err != nil {
t.Fatalf("err: %v", err)
}
if resp == nil {
t.Fatalf("expected a response, resp: %#v", resp)
}

if resp.Error() != nil {
t.Fatalf("unexpected error in response, err: %#v", resp.Error())
}

return resp
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
cleanup, u := postgreshelper.PrepareTestContainerWithPassword(t, "13.4-buster", tt.password)
t.Cleanup(cleanup)

p, err := url.Parse(u)
if err != nil {
t.Fatal(err)
}

actualPassword, _ := p.User.Password()
if tt.password != actualPassword {
t.Fatalf("expected computed URL password %#v, actual %#v", tt.password, actualPassword)
}

// Configure a connection
data := map[string]interface{}{
"connection_url": u,
"plugin_name": "postgresql-database-plugin",
"allowed_roles": []string{"plugin-role-test"},
}
req := &logical.Request{
Operation: logical.UpdateOperation,
Path: fmt.Sprintf("config/%s", tt.name),
Storage: config.StorageView,
Data: data,
}
respCheck(req)

// read config
readReq := &logical.Request{
Operation: logical.ReadOperation,
Path: req.Path,
Storage: config.StorageView,
}
resp := respCheck(readReq)

var connDetails map[string]interface{}
if v, ok := resp.Data["connection_details"]; ok {
connDetails = v.(map[string]interface{})
}

if connDetails == nil {
t.Fatalf("response data missing connection_details, resp: %#v", resp)
}

actual := connDetails["connection_url"].(string)
expected := p.Redacted()
if expected != actual {
t.Fatalf("expected redacted URL %q, actual %q", expected, actual)
}

if tt.password != "" {
// extra test to ensure that URL.Redacted() is working as expected.
p, err = url.Parse(actual)
if err != nil {
t.Fatal(err)
}
if pp, _ := p.User.Password(); pp == tt.password {
t.Fatalf("password was not redacted by URL.Redacted()")
}
}
})
}
}

func testCredsExist(t *testing.T, resp *logical.Response, connURL string) bool {
t.Helper()
var d struct {
Expand Down
13 changes: 5 additions & 8 deletions builtin/logical/database/path_config_connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (
"errors"
"fmt"
"net/url"
"strings"

"github.com/fatih/structs"
uuid "github.com/hashicorp/go-uuid"
"github.com/hashicorp/go-uuid"

v5 "github.com/hashicorp/vault/sdk/database/dbplugin/v5"
"github.com/hashicorp/vault/sdk/framework"
"github.com/hashicorp/vault/sdk/logical"
Expand Down Expand Up @@ -195,13 +195,10 @@ func (b *databaseBackend) connectionReadHandler() framework.OperationFunc {
return nil, err
}

// Mask the password if it is in the url
// Ensure that we only ever include a redacted valid URL in the response.
if connURLRaw, ok := config.ConnectionDetails["connection_url"]; ok {
connURL := connURLRaw.(string)
if conn, err := url.Parse(connURL); err == nil {
if password, ok := conn.User.Password(); ok {
config.ConnectionDetails["connection_url"] = strings.Replace(connURL, password, "*****", -1)
}
if p, err := url.Parse(connURLRaw.(string)); err == nil {
config.ConnectionDetails["connection_url"] = p.Redacted()
}
}

Expand Down

0 comments on commit 61cb98b

Please sign in to comment.