Skip to content

Commit

Permalink
Merge branch 'main' into jmgoldsmith/update-consult-template
Browse files Browse the repository at this point in the history
  • Loading branch information
JMGoldsmith authored Jul 26, 2024
2 parents 53d4634 + a41c21b commit 49c51da
Show file tree
Hide file tree
Showing 167 changed files with 3,636 additions and 2,316 deletions.
2 changes: 1 addition & 1 deletion .github/actions/set-up-buf/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ runs:
fi
mkdir -p tmp
./.github/scripts/retry-command.sh gh release download "$VERSION" -p "buf-${OS}-${ARCH}.tar.gz" -O tmp/buf.tgz -R bufbuild/buf
./.github/scripts/retry-command.sh gh release download "$VERSION" --clobber -p "buf-${OS}-${ARCH}.tar.gz" -O tmp/buf.tgz -R bufbuild/buf
pushd tmp && tar -xvf buf.tgz && popd
mv tmp/buf/bin/buf "$DESTINATION"
rm -rf tmp
2 changes: 1 addition & 1 deletion .github/actions/set-up-gofumpt/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,6 @@ runs:
export OS="darwin"
fi
./.github/scripts/retry-command.sh gh release download "$VERSION" -p "gofumpt_*_${OS}_${ARCH}" -O gofumpt -R mvdan/gofumpt
./.github/scripts/retry-command.sh gh release download "$VERSION" --clobber -p "gofumpt_*_${OS}_${ARCH}" -O gofumpt -R mvdan/gofumpt
chmod +x gofumpt
mv gofumpt "$DESTINATION"
2 changes: 1 addition & 1 deletion .github/actions/set-up-gosimports/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ runs:
fi
mkdir -p tmp
./.github/scripts/retry-command.sh gh release download "$VERSION" -p "gosimports_*_${OS}_${ARCH}.tar.gz" -O tmp/gosimports.tgz -R rinchsan/gosimports
./.github/scripts/retry-command.sh gh release download "$VERSION" --clobber -p "gosimports_*_${OS}_${ARCH}.tar.gz" -O tmp/gosimports.tgz -R rinchsan/gosimports
pushd tmp && tar -xvf gosimports.tgz && popd
mv tmp/gosimports "$DESTINATION"
rm -rf tmp
2 changes: 1 addition & 1 deletion .github/actions/set-up-gotestsum/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ runs:
fi
mkdir -p tmp
./.github/scripts/retry-command.sh gh release download "$VERSION" -p "*${OS}_${ARCH}.tar.gz" -O tmp/gotestsum.tgz -R gotestyourself/gotestsum
./.github/scripts/retry-command.sh gh release download "$VERSION" --clobber -p "*${OS}_${ARCH}.tar.gz" -O tmp/gotestsum.tgz -R gotestyourself/gotestsum
pushd tmp && tar -xvf gotestsum.tgz && popd
mv tmp/gotestsum "$DESTINATION"
rm -rf tmp
2 changes: 1 addition & 1 deletion .github/actions/set-up-misspell/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ runs:
fi
mkdir -p tmp
./.github/scripts/retry-command.sh gh release download "$VERSION" -p "misspell_*_${OS}_${ARCH}.tar.gz" -O tmp/misspell.tgz -R golangci/misspell
./.github/scripts/retry-command.sh gh release download "$VERSION" --clobber -p "misspell_*_${OS}_${ARCH}.tar.gz" -O tmp/misspell.tgz -R golangci/misspell
pushd tmp && tar -xvf misspell.tgz && popd
mv tmp/misspell_"$(echo "$VERSION" | tr -d v)"_${OS}_${ARCH}/misspell "$DESTINATION"
rm -rf tmp
2 changes: 1 addition & 1 deletion .github/actions/set-up-staticcheck/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ runs:
fi
mkdir -p tmp
./.github/scripts/retry-command.sh gh release download "$VERSION" -p "staticcheck_${OS}_${ARCH}.tar.gz" -O tmp/staticcheck.tgz -R dominikh/go-tools
./.github/scripts/retry-command.sh gh release download "$VERSION" --clobber -p "staticcheck_${OS}_${ARCH}.tar.gz" -O tmp/staticcheck.tgz -R dominikh/go-tools
pushd tmp && tar -xvf staticcheck.tgz && popd
mv tmp/staticcheck/staticcheck "$DESTINATION"
rm -rf tmp
4 changes: 2 additions & 2 deletions .github/scripts/retry-command.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1
set -euo pipefail
set -uo pipefail

tries=5
count=0
Expand All @@ -14,5 +14,5 @@ do
fi
((count++))
echo "trying again, attempt $count"
sleep 2
sleep $count
done
1 change: 1 addition & 0 deletions api/sudo_paths.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ var sudoPaths = map[string]*regexp.Regexp{
"/sys/config/ui/headers": regexp.MustCompile(`^/sys/config/ui/headers/?$`),
"/sys/config/ui/headers/{header}": regexp.MustCompile(`^/sys/config/ui/headers/.+$`),
"/sys/internal/inspect/router/{tag}": regexp.MustCompile(`^/sys/internal/inspect/router/.+$`),
"/sys/internal/counters/activity/export": regexp.MustCompile(`^/sys/internal/counters/activity/export$`),
"/sys/leases": regexp.MustCompile(`^/sys/leases$`),
// This entry is a bit wrong... sys/leases/lookup does NOT require sudo. But sys/leases/lookup/ with a trailing
// slash DOES require sudo. But the part of the Vault CLI that uses this logic doesn't pass operation-appropriate
Expand Down
6 changes: 3 additions & 3 deletions audit/backend_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ func newFileBackend(conf *BackendConfig, headersConfig HeaderFormatter) (*FileBa
return nil, err
}

var opt []event.Option
sinkOpts := []event.Option{event.WithLogger(conf.Logger)}
if mode, ok := conf.Config[optionMode]; ok {
opt = append(opt, event.WithFileMode(mode))
sinkOpts = append(sinkOpts, event.WithFileMode(mode))
}

err = b.configureSinkNode(conf.MountPath, filePath, cfg.requiredFormat, opt...)
err = b.configureSinkNode(conf.MountPath, filePath, cfg.requiredFormat, sinkOpts...)
if err != nil {
return nil, err
}
Expand Down
1 change: 1 addition & 0 deletions audit/backend_socket.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ func newSocketBackend(conf *BackendConfig, headersConfig HeaderFormatter) (*Sock
sinkOpts := []event.Option{
event.WithSocketType(socketType),
event.WithMaxDuration(writeDeadline),
event.WithLogger(conf.Logger),
}

err = event.ValidateOptions(sinkOpts...)
Expand Down
1 change: 1 addition & 0 deletions audit/backend_syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ func newSyslogBackend(conf *BackendConfig, headersConfig HeaderFormatter) (*Sysl
sinkOpts := []event.Option{
event.WithFacility(facility),
event.WithTag(tag),
event.WithLogger(conf.Logger),
}

err = event.ValidateOptions(sinkOpts...)
Expand Down
61 changes: 30 additions & 31 deletions audit/broker.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import (
"github.com/armon/go-metrics"
"github.com/hashicorp/eventlogger"
"github.com/hashicorp/go-hclog"
"github.com/hashicorp/go-multierror"
"github.com/hashicorp/vault/helper/namespace"
"github.com/hashicorp/vault/internal/observability/event"
"github.com/hashicorp/vault/sdk/logical"
Expand Down Expand Up @@ -253,7 +252,7 @@ func (b *Broker) Deregister(ctx context.Context, name string) error {

// LogRequest is used to ensure all the audit backends have an opportunity to
// log the given request and that *at least one* succeeds.
func (b *Broker) LogRequest(ctx context.Context, in *logical.LogInput) (ret error) {
func (b *Broker) LogRequest(ctx context.Context, in *logical.LogInput) (retErr error) {
b.RLock()
defer b.RUnlock()

Expand All @@ -265,18 +264,15 @@ func (b *Broker) LogRequest(ctx context.Context, in *logical.LogInput) (ret erro
defer metrics.MeasureSince([]string{"audit", "log_request"}, time.Now())
defer func() {
metricVal := float32(0.0)
if ret != nil {
if retErr != nil {
metricVal = 1.0
}
metrics.IncrCounter([]string{"audit", "log_request_failure"}, metricVal)
}()

var retErr *multierror.Error

e, err := NewEvent(RequestType)
if err != nil {
retErr = multierror.Append(retErr, err)
return retErr.ErrorOrNil()
return err
}

e.Data = in
Expand All @@ -295,8 +291,7 @@ func (b *Broker) LogRequest(ctx context.Context, in *logical.LogInput) (ret erro
// cancelled context and refuse to process the nodes further.
ns, err := namespace.FromContext(ctx)
if err != nil {
retErr = multierror.Append(retErr, fmt.Errorf("namespace missing from context: %w", err))
return retErr.ErrorOrNil()
return fmt.Errorf("namespace missing from context: %w", err)
}

tempContext, auditCancel := context.WithTimeout(context.Background(), timeout)
Expand All @@ -308,34 +303,38 @@ func (b *Broker) LogRequest(ctx context.Context, in *logical.LogInput) (ret erro
if hasAuditPipelines(b.broker) {
status, err = b.broker.Send(auditContext, event.AuditType.AsEventType(), e)
if err != nil {
retErr = multierror.Append(retErr, multierror.Append(err, status.Warnings...))
return retErr.ErrorOrNil()
return fmt.Errorf("%w: %w", err, errors.Join(status.Warnings...))
}
}

// Audit event ended up in at least 1 sink.
if len(status.CompleteSinks()) > 0 {
return retErr.ErrorOrNil()
// We should log warnings to the operational logs regardless of whether
// we consider the overall auditing attempt to be successful.
if len(status.Warnings) > 0 {
b.logger.Error("log request underlying pipeline error(s)", "error", errors.Join(status.Warnings...))
}

return nil
}

// There were errors from inside the pipeline and we didn't write to a sink.
if len(status.Warnings) > 0 {
retErr = multierror.Append(retErr, multierror.Append(errors.New("error during audit pipeline processing"), status.Warnings...))
return retErr.ErrorOrNil()
return fmt.Errorf("error during audit pipeline processing: %w", errors.Join(status.Warnings...))
}

// Handle any additional audit that is required (Enterprise/CE dependant).
err = b.handleAdditionalAudit(auditContext, e)
if err != nil {
retErr = multierror.Append(retErr, err)
return err
}

return retErr.ErrorOrNil()
return nil
}

// LogResponse is used to ensure all the audit backends have an opportunity to
// log the given response and that *at least one* succeeds.
func (b *Broker) LogResponse(ctx context.Context, in *logical.LogInput) (ret error) {
func (b *Broker) LogResponse(ctx context.Context, in *logical.LogInput) (retErr error) {
b.RLock()
defer b.RUnlock()

Expand All @@ -347,18 +346,15 @@ func (b *Broker) LogResponse(ctx context.Context, in *logical.LogInput) (ret err
defer metrics.MeasureSince([]string{"audit", "log_response"}, time.Now())
defer func() {
metricVal := float32(0.0)
if ret != nil {
if retErr != nil {
metricVal = 1.0
}
metrics.IncrCounter([]string{"audit", "log_response_failure"}, metricVal)
}()

var retErr *multierror.Error

e, err := NewEvent(ResponseType)
if err != nil {
retErr = multierror.Append(retErr, err)
return retErr.ErrorOrNil()
return err
}

e.Data = in
Expand All @@ -377,8 +373,7 @@ func (b *Broker) LogResponse(ctx context.Context, in *logical.LogInput) (ret err
// cancelled context and refuse to process the nodes further.
ns, err := namespace.FromContext(ctx)
if err != nil {
retErr = multierror.Append(retErr, fmt.Errorf("namespace missing from context: %w", err))
return retErr.ErrorOrNil()
return fmt.Errorf("namespace missing from context: %w", err)
}

tempContext, auditCancel := context.WithTimeout(context.Background(), timeout)
Expand All @@ -390,29 +385,33 @@ func (b *Broker) LogResponse(ctx context.Context, in *logical.LogInput) (ret err
if hasAuditPipelines(b.broker) {
status, err = b.broker.Send(auditContext, event.AuditType.AsEventType(), e)
if err != nil {
retErr = multierror.Append(retErr, multierror.Append(err, status.Warnings...))
return retErr.ErrorOrNil()
return fmt.Errorf("%w: %w", err, errors.Join(status.Warnings...))
}
}

// Audit event ended up in at least 1 sink.
if len(status.CompleteSinks()) > 0 {
return retErr.ErrorOrNil()
// We should log warnings to the operational logs regardless of whether
// we consider the overall auditing attempt to be successful.
if len(status.Warnings) > 0 {
b.logger.Error("log response underlying pipeline error(s)", "error", errors.Join(status.Warnings...))
}

return nil
}

// There were errors from inside the pipeline and we didn't write to a sink.
if len(status.Warnings) > 0 {
retErr = multierror.Append(retErr, multierror.Append(errors.New("error during audit pipeline processing"), status.Warnings...))
return retErr.ErrorOrNil()
return fmt.Errorf("error during audit pipeline processing: %w", errors.Join(status.Warnings...))
}

// Handle any additional audit that is required (Enterprise/CE dependant).
err = b.handleAdditionalAudit(auditContext, e)
if err != nil {
retErr = multierror.Append(retErr, err)
return err
}

return retErr.ErrorOrNil()
return nil
}

func (b *Broker) Invalidate(ctx context.Context, _ string) {
Expand Down
12 changes: 6 additions & 6 deletions builtin/logical/database/backend_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ func TestBackend_BadConnectionString(t *testing.T) {
}
defer b.Cleanup(context.Background())

cleanup, _ := postgreshelper.PrepareTestContainer(t, "13.4-buster")
cleanup, _ := postgreshelper.PrepareTestContainer(t)
defer cleanup()

respCheck := func(req *logical.Request) {
Expand Down Expand Up @@ -410,7 +410,7 @@ func TestBackend_basic(t *testing.T) {
}
defer b.Cleanup(context.Background())

cleanup, connURL := postgreshelper.PrepareTestContainer(t, "13.4-buster")
cleanup, connURL := postgreshelper.PrepareTestContainer(t)
defer cleanup()

// Configure a connection
Expand Down Expand Up @@ -665,7 +665,7 @@ func TestBackend_connectionCrud(t *testing.T) {
dbFactory.sys = sys
client := cluster.Cores[0].Client.Logical()

cleanup, connURL := postgreshelper.PrepareTestContainer(t, "13.4-buster")
cleanup, connURL := postgreshelper.PrepareTestContainer(t)
defer cleanup()

// Mount the database plugin.
Expand Down Expand Up @@ -872,7 +872,7 @@ func TestBackend_roleCrud(t *testing.T) {
}
defer b.Cleanup(context.Background())

cleanup, connURL := postgreshelper.PrepareTestContainer(t, "13.4-buster")
cleanup, connURL := postgreshelper.PrepareTestContainer(t)
defer cleanup()

// Configure a connection
Expand Down Expand Up @@ -1121,7 +1121,7 @@ func TestBackend_allowedRoles(t *testing.T) {
}
defer b.Cleanup(context.Background())

cleanup, connURL := postgreshelper.PrepareTestContainer(t, "13.4-buster")
cleanup, connURL := postgreshelper.PrepareTestContainer(t)
defer cleanup()

// Configure a connection
Expand Down Expand Up @@ -1318,7 +1318,7 @@ func TestBackend_RotateRootCredentials(t *testing.T) {
}
defer b.Cleanup(context.Background())

cleanup, connURL := postgreshelper.PrepareTestContainer(t, "13.4-buster")
cleanup, connURL := postgreshelper.PrepareTestContainer(t)
defer cleanup()

connURL = strings.ReplaceAll(connURL, "postgres:secret", "{{username}}:{{password}}")
Expand Down
8 changes: 4 additions & 4 deletions builtin/logical/database/path_roles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ func TestBackend_StaticRole_Config(t *testing.T) {
}
defer b.Cleanup(context.Background())

cleanup, connURL := postgreshelper.PrepareTestContainer(t, "")
cleanup, connURL := postgreshelper.PrepareTestContainer(t)
defer cleanup()

// create the database user
Expand Down Expand Up @@ -487,7 +487,7 @@ func TestBackend_StaticRole_ReadCreds(t *testing.T) {
}
defer b.Cleanup(context.Background())

cleanup, connURL := postgreshelper.PrepareTestContainer(t, "")
cleanup, connURL := postgreshelper.PrepareTestContainer(t)
defer cleanup()

// create the database user
Expand Down Expand Up @@ -667,7 +667,7 @@ func TestBackend_StaticRole_Updates(t *testing.T) {
}
defer b.Cleanup(context.Background())

cleanup, connURL := postgreshelper.PrepareTestContainer(t, "")
cleanup, connURL := postgreshelper.PrepareTestContainer(t)
defer cleanup()

// create the database user
Expand Down Expand Up @@ -966,7 +966,7 @@ func TestBackend_StaticRole_Role_name_check(t *testing.T) {
}
defer b.Cleanup(context.Background())

cleanup, connURL := postgreshelper.PrepareTestContainer(t, "")
cleanup, connURL := postgreshelper.PrepareTestContainer(t)
defer cleanup()

// create the database user
Expand Down
6 changes: 3 additions & 3 deletions builtin/logical/database/rollback_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func TestBackend_RotateRootCredentials_WAL_rollback(t *testing.T) {
}
defer lb.Cleanup(context.Background())

cleanup, connURL := postgreshelper.PrepareTestContainer(t, "")
cleanup, connURL := postgreshelper.PrepareTestContainer(t)
defer cleanup()

connURL = strings.ReplaceAll(connURL, "postgres:secret", "{{username}}:{{password}}")
Expand Down Expand Up @@ -183,7 +183,7 @@ func TestBackend_RotateRootCredentials_WAL_no_rollback_1(t *testing.T) {
}
defer lb.Cleanup(context.Background())

cleanup, connURL := postgreshelper.PrepareTestContainer(t, "")
cleanup, connURL := postgreshelper.PrepareTestContainer(t)
defer cleanup()

connURL = strings.ReplaceAll(connURL, "postgres:secret", "{{username}}:{{password}}")
Expand Down Expand Up @@ -291,7 +291,7 @@ func TestBackend_RotateRootCredentials_WAL_no_rollback_2(t *testing.T) {
}
defer lb.Cleanup(context.Background())

cleanup, connURL := postgreshelper.PrepareTestContainer(t, "")
cleanup, connURL := postgreshelper.PrepareTestContainer(t)
defer cleanup()

connURL = strings.ReplaceAll(connURL, "postgres:secret", "{{username}}:{{password}}")
Expand Down
Loading

0 comments on commit 49c51da

Please sign in to comment.