Skip to content

Commit

Permalink
Don't default the backend path
Browse files Browse the repository at this point in the history
  • Loading branch information
zmb3 committed Nov 1, 2024
1 parent 42c91a5 commit 8c03c14
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 19 deletions.
6 changes: 1 addition & 5 deletions lib/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6136,11 +6136,7 @@ func warnOnErr(ctx context.Context, err error, log *slog.Logger) {
func (process *TeleportProcess) initAuthStorage() (backend.Backend, error) {
ctx := context.TODO()
bc := process.Config.Auth.StorageConfig
process.logger.DebugContext(process.ExitContext(), "Initializing auth backend.",
"backend", process.Config.Auth.StorageConfig.Type,
"type", bc.Type,
"params", bc.Params,
)
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
1 change: 0 additions & 1 deletion lib/service/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,6 @@ func TestDynamicClientReuse(t *testing.T) {
cfg.DiagnosticAddr = utils.NetAddr{AddrNetwork: "tcp", Addr: "127.0.0.1:0"}
cfg.SetAuthServerAddress(utils.NetAddr{AddrNetwork: "tcp", Addr: "127.0.0.1:0"})
cfg.Auth.Enabled = true
// cfg.Auth.StorageConfig.Params[defaults.BackendPath] = filepath.Join(cfg.DataDir, "backend")
cfg.Auth.ListenAddr = utils.NetAddr{AddrNetwork: "tcp", Addr: "127.0.0.1:0"}
cfg.Auth.SessionRecordingConfig.SetMode(types.RecordOff)
cfg.Proxy.Enabled = true
Expand Down
21 changes: 10 additions & 11 deletions 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 All @@ -671,16 +680,6 @@ func ValidateConfig(cfg *Config) error {

cfg.SSH.Namespace = types.ProcessNamespace(cfg.SSH.Namespace)

// If we've overridden the process's data dir, but left auth's backend
// pointing at the default data dir this is probably a test that forgot
// to customize the auth storage config. Fix it.
if cfg.Auth.Enabled && cfg.Auth.StorageConfig.Type == lite.GetName() {
storagePath := cfg.Auth.StorageConfig.Params.GetString(defaults.BackendPath)
if storagePath == filepath.Join(defaults.DataDir, defaults.BackendDir) && cfg.DataDir != defaults.DataDir {
cfg.Auth.StorageConfig.Params[defaults.BackendPath] = filepath.Join(cfg.DataDir, defaults.BackendDir)
}
}

return nil
}

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 8c03c14

Please sign in to comment.