Skip to content

Commit

Permalink
Support configuration teleport.join_params.join_method "token" (#13559
Browse files Browse the repository at this point in the history
)

* Support configuration `teleport.join_params.join_method` "token"

* support loading token name from file

* update tests

* update documentation for AuthToken to hint towards deprecation
  • Loading branch information
strideynet authored Jun 16, 2022
1 parent 78c1450 commit 796e37b
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 14 deletions.
9 changes: 6 additions & 3 deletions lib/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -2124,12 +2124,15 @@ func applyTokenConfig(fc *FileConfig, cfg *service.Config) error {
if cfg.Token != "" {
return trace.BadParameter("only one of auth_token or join_params should be set")
}
cfg.Token = fc.JoinParams.TokenName
_, err := cfg.ApplyToken(fc.JoinParams.TokenName)
if err != nil {
return trace.Wrap(err)
}
switch fc.JoinParams.Method {
case types.JoinMethodEC2, types.JoinMethodIAM:
case types.JoinMethodEC2, types.JoinMethodIAM, types.JoinMethodToken:
cfg.JoinMethod = fc.JoinParams.Method
default:
return trace.BadParameter(`unknown value for join_params.method: %q, expected one of %v`, fc.JoinParams.Method, []types.JoinMethod{types.JoinMethodEC2, types.JoinMethodIAM})
return trace.BadParameter(`unknown value for join_params.method: %q, expected one of %v`, fc.JoinParams.Method, []types.JoinMethod{types.JoinMethodEC2, types.JoinMethodIAM, types.JoinMethodToken})
}
}
return nil
Expand Down
16 changes: 12 additions & 4 deletions lib/config/fileconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,13 @@ func MakeSampleFileConfig(flags SampleFlags) (fc *FileConfig, err error) {
g.DataDir = defaults.DataDir
}

joinMethod := flags.JoinMethod
if joinMethod == "" && flags.AuthToken != "" {
joinMethod = string(types.JoinMethodToken)
}
g.JoinParams = JoinParams{
TokenName: flags.AuthToken,
Method: types.JoinMethod(flags.JoinMethod),
Method: types.JoinMethod(joinMethod),
}

if flags.AuthServer != "" {
Expand Down Expand Up @@ -510,9 +514,13 @@ func (l *Log) UnmarshalYAML(unmarshal func(interface{}) error) error {

// Global is 'teleport' (global) section of the config file
type Global struct {
NodeName string `yaml:"nodename,omitempty"`
DataDir string `yaml:"data_dir,omitempty"`
PIDFile string `yaml:"pid_file,omitempty"`
NodeName string `yaml:"nodename,omitempty"`
DataDir string `yaml:"data_dir,omitempty"`
PIDFile string `yaml:"pid_file,omitempty"`

// AuthToken is the old way of configuring the token to be used by the
// node to join the Teleport cluster. `JoinParams.TokenName` should be
// used instead with `JoinParams.JoinMethod = types.JoinMethodToken`.
AuthToken string `yaml:"auth_token,omitempty"`
JoinParams JoinParams `yaml:"join_params,omitempty"`
AuthServers []string `yaml:"auth_servers,omitempty"`
Expand Down
24 changes: 17 additions & 7 deletions lib/config/fileconf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,15 +126,13 @@ func TestAuthSection(t *testing.T) {
desc: "Web idle timeout",
mutate: func(cfg cfgMap) {
cfg["auth_service"].(cfgMap)["web_idle_timeout"] = "10m"

},
expectError: require.NoError,
expectWebIdleTimeout: requireEqual(types.Duration(10 * time.Minute)),
}, {
desc: "Web idle timeout (invalid)",
mutate: func(cfg cfgMap) {
cfg["auth_service"].(cfgMap)["web_idle_timeout"] = "potato"

},
expectError: require.Error,
},
Expand Down Expand Up @@ -465,7 +463,6 @@ func TestSSHSection(t *testing.T) {
}
})
}

}

func TestX11Config(t *testing.T) {
Expand All @@ -490,7 +487,8 @@ func TestX11Config(t *testing.T) {
}
},
expectX11Config: &x11.ServerConfig{},
}, {
},
{
desc: "x11 enabled",
mutate: func(cfg cfgMap) {
cfg["ssh_service"].(cfgMap)["x11"] = cfgMap{
Expand All @@ -517,7 +515,8 @@ func TestX11Config(t *testing.T) {
DisplayOffset: 100,
MaxDisplay: 100 + x11.DefaultMaxDisplays,
},
}, {
},
{
desc: "display offset value capped",
mutate: func(cfg cfgMap) {
cfg["ssh_service"].(cfgMap)["x11"] = cfgMap{
Expand Down Expand Up @@ -545,7 +544,8 @@ func TestX11Config(t *testing.T) {
DisplayOffset: x11.DefaultDisplayOffset,
MaxDisplay: 100,
},
}, {
},
{
desc: "max display value capped",
mutate: func(cfg cfgMap) {
cfg["ssh_service"].(cfgMap)["x11"] = cfgMap{
Expand All @@ -558,7 +558,8 @@ func TestX11Config(t *testing.T) {
DisplayOffset: x11.DefaultDisplayOffset,
MaxDisplay: x11.MaxDisplayNumber,
},
}, {
},
{
desc: "max display smaller than display offset",
mutate: func(cfg cfgMap) {
cfg["ssh_service"].(cfgMap)["x11"] = cfgMap{
Expand Down Expand Up @@ -726,6 +727,15 @@ func TestMakeSampleFileConfig(t *testing.T) {
require.Equal(t, types.JoinMethodToken, fc.JoinParams.Method)
})

t.Run("Token, method not specified", func(t *testing.T) {
fc, err := MakeSampleFileConfig(SampleFlags{
AuthToken: "auth-token",
})
require.NoError(t, err)
require.Equal(t, "auth-token", fc.JoinParams.TokenName)
require.Equal(t, types.JoinMethodToken, fc.JoinParams.Method)
})

t.Run("App name and URI", func(t *testing.T) {
fc, err := MakeSampleFileConfig(SampleFlags{
AppName: "app-name",
Expand Down

0 comments on commit 796e37b

Please sign in to comment.