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

[v15] Fix loading of default license #39314

Merged
merged 1 commit into from
Mar 14, 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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions lib/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -942,13 +942,13 @@ func applyAuthConfig(fc *FileConfig, cfg *servicecfg.Config) error {
}

// read in and set the license file path (not used in open-source version)
licenseFile := fc.Auth.LicenseFile
if licenseFile != "" {
if filepath.IsAbs(licenseFile) {
cfg.Auth.LicenseFile = licenseFile
} else {
cfg.Auth.LicenseFile = filepath.Join(cfg.DataDir, licenseFile)
}
switch licenseFile := fc.Auth.LicenseFile; {
case licenseFile == "":
cfg.Auth.LicenseFile = filepath.Join(cfg.DataDir, defaults.LicenseFile)
case filepath.IsAbs(licenseFile):
cfg.Auth.LicenseFile = licenseFile
default:
cfg.Auth.LicenseFile = filepath.Join(cfg.DataDir, licenseFile)
}

cfg.Auth.LoadAllCAs = fc.Auth.LoadAllCAs
Expand Down
50 changes: 33 additions & 17 deletions lib/config/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1857,36 +1857,52 @@ func TestMergingCAPinConfig(t *testing.T) {

func TestLicenseFile(t *testing.T) {
testCases := []struct {
path string
result string
path string
datadir string
result string
}{
// 0 - no license
// 0 - no license, no data dir
{
path: "",
result: filepath.Join(defaults.DataDir, defaults.LicenseFile),
path: "",
datadir: "",
result: filepath.Join(defaults.DataDir, defaults.LicenseFile),
},
// 1 - relative path
// 1 - relative path, default data dir
{
path: "lic.pem",
result: filepath.Join(defaults.DataDir, "lic.pem"),
path: "lic.pem",
datadir: "",
result: filepath.Join(defaults.DataDir, "lic.pem"),
},
// 2 - absolute path
// 2 - relative path, custom data dir
{
path: "baz.pem",
datadir: filepath.Join("foo", "bar"),
result: filepath.Join("foo", "bar", "baz.pem"),
},
// 3 - absolute path
{
path: "/etc/teleport/license",
result: "/etc/teleport/license",
},
}

cfg := servicecfg.MakeDefaultConfig()
require.Equal(t, filepath.Join(defaults.DataDir, defaults.LicenseFile), cfg.Auth.LicenseFile)

for _, tc := range testCases {
fc := new(FileConfig)
require.NoError(t, fc.CheckAndSetDefaults())
fc.Auth.LicenseFile = tc.path
err := ApplyFileConfig(fc, cfg)
require.NoError(t, err)
require.Equal(t, tc.result, cfg.Auth.LicenseFile)
// 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)
require.NoError(t, fc.CheckAndSetDefaults())
fc.Auth.LicenseFile = tc.path
fc.DataDir = tc.datadir
err := ApplyFileConfig(fc, cfg)
require.NoError(t, err)
require.Equal(t, tc.result, cfg.Auth.LicenseFile)
})
}
}

Expand Down
1 change: 0 additions & 1 deletion lib/service/servicecfg/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -552,7 +552,6 @@ func ApplyDefaults(cfg *Config) {
cfg.Auth.SessionRecordingConfig = types.DefaultSessionRecordingConfig()
cfg.Auth.Preference = types.DefaultAuthPreference()
defaults.ConfigureLimiter(&cfg.Auth.Limiter)
cfg.Auth.LicenseFile = filepath.Join(cfg.DataDir, defaults.LicenseFile)

cfg.Proxy.WebAddr = *defaults.ProxyWebListenAddr()
// Proxy service defaults.
Expand Down