Skip to content

Commit

Permalink
Look for a license in the default location if no config is provided
Browse files Browse the repository at this point in the history
Prior to this change, the code that determines where to look for a
license file would only run when a config file is provided. When running
teleport start without a config file, the license file path would
be an empty string and loading would fail.

Closes #47764
  • Loading branch information
zmb3 authored and github-actions committed Nov 18, 2024
1 parent 90fce4f commit 285ee63
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
3 changes: 1 addition & 2 deletions docs/pages/includes/config-reference/auth-service.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ auth_service:
routing_strategy: unambiguous_match

# License file to start auth server with. Note that this setting is ignored
# in the Teleport Community Edition and is required only for Teleport Pro, Business
# and Enterprise subscription plans.
# in the Teleport Community Edition and is required only for Teleport Enterprise.
#
# The path can be either absolute or relative to the configured `data_dir`
# and should point to the license file obtained from Teleport Download
Expand Down
11 changes: 6 additions & 5 deletions lib/config/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1976,11 +1976,6 @@ func TestLicenseFile(t *testing.T) {

cfg := servicecfg.MakeDefaultConfig()

// the license file should be empty by default, as we can only fill
// in the default (<datadir>/license.pem) after we know what the
// data dir is supposed to be
require.Empty(t, cfg.Auth.LicenseFile)

for i, tc := range testCases {
t.Run(fmt.Sprintf("test%d", i), func(t *testing.T) {
fc := new(FileConfig)
Expand All @@ -1994,6 +1989,12 @@ func TestLicenseFile(t *testing.T) {
}
}

func TestLicenseFileNoConfig(t *testing.T) {
cfg := servicecfg.MakeDefaultConfig()
require.NoError(t, Configure(new(CommandLineFlags), cfg, false /* legacy app flags */))
require.Equal(t, filepath.Join(defaults.DataDir, defaults.LicenseFile), cfg.Auth.LicenseFile)
}

// TestFIPS makes sure configuration is correctly updated/enforced when in
// FedRAMP/FIPS 140-2 mode.
func TestFIPS(t *testing.T) {
Expand Down
1 change: 1 addition & 0 deletions lib/service/servicecfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -561,6 +561,7 @@ func ApplyDefaults(cfg *Config) {
cfg.Auth.NetworkingConfig = types.DefaultClusterNetworkingConfig()
cfg.Auth.SessionRecordingConfig = types.DefaultSessionRecordingConfig()
cfg.Auth.Preference = types.DefaultAuthPreference()
cfg.Auth.LicenseFile = filepath.Join(cfg.DataDir, defaults.LicenseFile)
defaults.ConfigureLimiter(&cfg.Auth.Limiter)

cfg.Proxy.WebAddr = *defaults.ProxyWebListenAddr()
Expand Down
2 changes: 2 additions & 0 deletions lib/service/servicecfg/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
"fmt"
"io"
"log/slog"
"path/filepath"
"regexp"
"strings"
"testing"
Expand Down Expand Up @@ -88,6 +89,7 @@ func TestDefaultConfig(t *testing.T) {
require.Equal(t, int64(defaults.LimiterMaxConnections), auth.Limiter.MaxConnections)
require.Equal(t, lite.GetName(), config.Auth.StorageConfig.Type)
require.Empty(t, auth.StorageConfig.Params[defaults.BackendPath])
require.Equal(t, filepath.Join(defaults.DataDir, defaults.LicenseFile), config.Auth.LicenseFile)

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

0 comments on commit 285ee63

Please sign in to comment.