diff --git a/command/server.go b/command/server.go index 661264dce0e2..35ced21ffd8c 100644 --- a/command/server.go +++ b/command/server.go @@ -1711,7 +1711,7 @@ func (c *ServerCommand) Run(args []string) int { sr.NotifyConfigurationReload(srConfig) } - if err := core.ReloadCensus(); err != nil { + if err := core.ReloadCensusManager(); err != nil { c.UI.Error(err.Error()) } diff --git a/vault/activity_log.go b/vault/activity_log.go index 9aab39684be0..28a56d44e92d 100644 --- a/vault/activity_log.go +++ b/vault/activity_log.go @@ -1016,7 +1016,8 @@ func (a *ActivityLog) SetConfigInit(config activityConfig) { a.defaultReportMonths = config.DefaultReportMonths a.retentionMonths = config.RetentionMonths - if a.retentionMonths < a.configOverrides.MinimumRetentionMonths { + // Let tests override the minimum if they want to. + if a.configOverrides.MinimumRetentionMonths > 0 { a.retentionMonths = a.configOverrides.MinimumRetentionMonths } diff --git a/vault/census.go b/vault/census.go index e492ac2c88c3..fc1cf2b10851 100644 --- a/vault/census.go +++ b/vault/census.go @@ -14,7 +14,6 @@ func (c *Core) setupCensusManager() error { return nil } func (c *Core) BillingStart() time.Time { return time.Time{} } func (c *Core) AutomatedLicenseReportingEnabled() bool { return false } func (c *Core) CensusAgent() CensusReporter { return nil } -func (c *Core) ReloadCensus() error { return nil } func (c *Core) teardownCensusManager() error { return nil } func (c *Core) StartManualCensusSnapshots() {} func (c *Core) ManualLicenseReportingEnabled() bool { return false } diff --git a/vault/census_stubs_oss.go b/vault/census_stubs_oss.go index 3cf43c495bf7..0b5b1c11f0e6 100644 --- a/vault/census_stubs_oss.go +++ b/vault/census_stubs_oss.go @@ -10,4 +10,5 @@ import "context" //go:generate go run github.com/hashicorp/vault/tools/stubmaker func (c *Core) StartCensusReports(ctx context.Context) {} -func (c *Core) ReloadCensusActivityLog() error { return nil } +func (c *Core) SetRetentionMonths(months int) error { return nil } +func (c *Core) ReloadCensusManager() error { return nil } diff --git a/vault/core.go b/vault/core.go index 18b1a872478d..30b3c284e964 100644 --- a/vault/core.go +++ b/vault/core.go @@ -2445,16 +2445,13 @@ func (s standardUnsealStrategy) unseal(ctx context.Context, logger log.Logger, c return err } - if !c.perfStandby { - if err := c.setupCensusManager(); err != nil { - logger.Error("failed to instantiate the license reporting agent", "error", err) - } - - c.StartCensusReports(ctx) - - c.StartManualCensusSnapshots() + if err := c.setupCensusManager(); err != nil { + logger.Error("failed to instantiate the license reporting agent", "error", err) } + c.StartCensusReports(ctx) + c.StartManualCensusSnapshots() + } else { broker, err := audit.NewBroker(logger) if err != nil { @@ -2847,7 +2844,6 @@ func (c *Core) preSeal() error { if err := c.teardownCensusManager(); err != nil { result = multierror.Append(result, fmt.Errorf("error tearing down reporting agent: %w", err)) } - if err := c.teardownCredentials(context.Background()); err != nil { result = multierror.Append(result, fmt.Errorf("error tearing down credentials: %w", err)) } diff --git a/vault/logical_system_activity.go b/vault/logical_system_activity.go index 38674be00042..92feaf3ca59c 100644 --- a/vault/logical_system_activity.go +++ b/vault/logical_system_activity.go @@ -422,9 +422,6 @@ func (b *SystemBackend) handleActivityConfigUpdate(ctx context.Context, req *log } } - a.core.activityLogLock.RLock() - minimumRetentionMonths := a.configOverrides.MinimumRetentionMonths - a.core.activityLogLock.RUnlock() enabled := config.Enabled == "enable" if !enabled && config.Enabled == "default" { enabled = activityLogEnabledDefault @@ -435,8 +432,8 @@ func (b *SystemBackend) handleActivityConfigUpdate(ctx context.Context, req *log } // if manual license reporting is enabled, retention months must at least be 48 months - if a.core.ManualLicenseReportingEnabled() && config.RetentionMonths < minimumRetentionMonths { - return logical.ErrorResponse("retention_months must be at least %d while Reporting is enabled", minimumRetentionMonths), logical.ErrInvalidRequest + if a.core.ManualLicenseReportingEnabled() && config.RetentionMonths < ActivityLogMinimumRetentionMonths { + return logical.ErrorResponse("retention_months must be at least %d while Reporting is enabled", ActivityLogMinimumRetentionMonths), logical.ErrInvalidRequest } // Store the config @@ -451,9 +448,9 @@ func (b *SystemBackend) handleActivityConfigUpdate(ctx context.Context, req *log // Set the new config on the activity log a.SetConfig(ctx, config) - // reload census agent if retention months change during update when reporting is enabled + // Update Census agent's metadata if retention months change if prevRetentionMonths != config.RetentionMonths { - if err := a.core.ReloadCensusActivityLog(); err != nil { + if err := b.Core.SetRetentionMonths(config.RetentionMonths); err != nil { return nil, err } }