Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly default auth's storage config #48247

Merged
merged 1 commit into from
Nov 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading