Skip to content

Commit

Permalink
Properly default auth's storage config
Browse files Browse the repository at this point in the history
Most of our tests override cfg.DataDir, but auth's storage config
still uses a hard-coded /var/lib/teleport for backend state.

Instead of fixing this in a bunch of tests, we stop defaulting to
/var/lib/teleport and set the storage dir only after we know what
the configured data dir is.
  • Loading branch information
zmb3 committed Nov 1, 2024
1 parent 6d756d2 commit aaad226
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 4 deletions.
2 changes: 1 addition & 1 deletion lib/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6135,8 +6135,8 @@ func warnOnErr(ctx context.Context, err error, log *slog.Logger) {
// initAuthStorage initializes the storage backend for the auth service.
func (process *TeleportProcess) initAuthStorage() (backend.Backend, error) {
ctx := context.TODO()
process.logger.DebugContext(process.ExitContext(), "Initializing auth backend.", "backend", process.Config.Auth.StorageConfig.Type)
bc := process.Config.Auth.StorageConfig
process.logger.DebugContext(process.ExitContext(), "Initializing auth backend.", "type", bc.Type)
bk, err := backend.New(ctx, bc.Type, bc.Params)
if err != nil {
return nil, trace.Wrap(err)
Expand Down
11 changes: 10 additions & 1 deletion lib/service/servicecfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ func ApplyDefaults(cfg *Config) {
cfg.Auth.Enabled = true
cfg.Auth.ListenAddr = *defaults.AuthListenAddr()
cfg.Auth.StorageConfig.Type = lite.GetName()
cfg.Auth.StorageConfig.Params = backend.Params{defaults.BackendPath: filepath.Join(cfg.DataDir, defaults.BackendDir)}
cfg.Auth.StorageConfig.Params = make(backend.Params)
cfg.Auth.StaticTokens = types.DefaultStaticTokens()
cfg.Auth.AuditConfig = types.DefaultClusterAuditConfig()
cfg.Auth.NetworkingConfig = types.DefaultClusterNetworkingConfig()
Expand Down Expand Up @@ -657,6 +657,15 @@ func ValidateConfig(cfg *Config) error {
return trace.BadParameter("config: please supply data directory")
}

if cfg.Auth.Enabled {
if cfg.Auth.StorageConfig.Params.GetString(defaults.BackendPath) == "" {
if cfg.Auth.StorageConfig.Params == nil {
cfg.Auth.StorageConfig.Params = make(backend.Params)
}
cfg.Auth.StorageConfig.Params[defaults.BackendPath] = filepath.Join(cfg.DataDir, defaults.BackendDir)
}
}

for i := range cfg.Auth.Authorities {
if err := services.ValidateCertAuthority(cfg.Auth.Authorities[i]); err != nil {
return trace.Wrap(err)
Expand Down
3 changes: 1 addition & 2 deletions lib/service/servicecfg/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import (
"fmt"
"io"
"log/slog"
"path/filepath"
"regexp"
"strings"
"testing"
Expand Down Expand Up @@ -88,7 +87,7 @@ func TestDefaultConfig(t *testing.T) {
require.Equal(t, localAuthAddr, auth.ListenAddr)
require.Equal(t, int64(defaults.LimiterMaxConnections), auth.Limiter.MaxConnections)
require.Equal(t, lite.GetName(), config.Auth.StorageConfig.Type)
require.Equal(t, filepath.Join(config.DataDir, defaults.BackendDir), auth.StorageConfig.Params[defaults.BackendPath])
require.Empty(t, auth.StorageConfig.Params[defaults.BackendPath])

// SSH section
ssh := config.SSH
Expand Down

0 comments on commit aaad226

Please sign in to comment.