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

[v14] fix: Move module-based device trust check to the teleport binary #44136

Merged
merged 1 commit into from
Jul 15, 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
6 changes: 2 additions & 4 deletions lib/config/configuration.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ import (
"github.com/gravitational/teleport/lib/backend/memory"
"github.com/gravitational/teleport/lib/client"
"github.com/gravitational/teleport/lib/defaults"
dtconfig "github.com/gravitational/teleport/lib/devicetrust/config"
"github.com/gravitational/teleport/lib/integrations/externalauditstorage/easconfig"
"github.com/gravitational/teleport/lib/limiter"
"github.com/gravitational/teleport/lib/multiplexer"
Expand Down Expand Up @@ -345,6 +344,8 @@ func ReadResources(filePath string) ([]types.Resource, error) {

// ApplyFileConfig applies configuration from a YAML file to Teleport
// runtime config
//
// ApplyFileConfig is used by both teleport and tctl binaries.
func ApplyFileConfig(fc *FileConfig, cfg *servicecfg.Config) error {
var err error

Expand Down Expand Up @@ -803,9 +804,6 @@ func applyAuthConfig(fc *FileConfig, cfg *servicecfg.Config) error {
if err != nil {
return trace.Wrap(err)
}
if err := dtconfig.ValidateConfigAgainstModules(cfg.Auth.Preference.GetDeviceTrust()); err != nil {
return trace.Wrap(err)
}
}

if fc.Auth.MessageOfTheDay != "" {
Expand Down
57 changes: 0 additions & 57 deletions lib/config/configuration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ import (
"github.com/gravitational/teleport/lib/defaults"
"github.com/gravitational/teleport/lib/fixtures"
"github.com/gravitational/teleport/lib/limiter"
"github.com/gravitational/teleport/lib/modules"
"github.com/gravitational/teleport/lib/service/servicecfg"
"github.com/gravitational/teleport/lib/services"
"github.com/gravitational/teleport/lib/utils"
Expand Down Expand Up @@ -3429,62 +3428,6 @@ teleport:
}
}

func TestApplyFileConfig_deviceTrustMode_errors(t *testing.T) {
tests := []struct {
name string
buildType string
deviceTrust *DeviceTrust
wantErr bool
}{
{
name: "ok: OSS Mode=off",
buildType: modules.BuildOSS,
deviceTrust: &DeviceTrust{
Mode: constants.DeviceTrustModeOff,
},
},
{
name: "nok: OSS Mode=required",
buildType: modules.BuildOSS,
deviceTrust: &DeviceTrust{
Mode: constants.DeviceTrustModeRequired,
},
wantErr: true,
},
{
name: "ok: Enterprise Mode=required",
buildType: modules.BuildEnterprise,
deviceTrust: &DeviceTrust{
Mode: constants.DeviceTrustModeRequired,
},
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
modules.SetTestModules(t, &modules.TestModules{
TestBuildType: test.buildType,
})

defaultCfg := servicecfg.MakeDefaultConfig()
err := ApplyFileConfig(&FileConfig{
Auth: Auth{
Service: Service{
EnabledFlag: "yes",
},
Authentication: &AuthenticationConfig{
DeviceTrust: test.deviceTrust,
},
},
}, defaultCfg)
if test.wantErr {
assert.Error(t, err, "ApplyFileConfig mismatch")
} else {
assert.NoError(t, err, "ApplyFileConfig mismatch")
}
})
}
}

func TestApplyConfig_JamfService(t *testing.T) {
tempDir := t.TempDir()

Expand Down
10 changes: 10 additions & 0 deletions tool/teleport/common/teleport.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ import (
"github.com/gravitational/teleport/lib/configurators"
awsconfigurators "github.com/gravitational/teleport/lib/configurators/aws"
"github.com/gravitational/teleport/lib/defaults"
dtconfig "github.com/gravitational/teleport/lib/devicetrust/config"
"github.com/gravitational/teleport/lib/integrations/awsoidc"
"github.com/gravitational/teleport/lib/integrations/externalauditstorage"
"github.com/gravitational/teleport/lib/integrations/externalauditstorage/easconfig"
Expand Down Expand Up @@ -539,6 +540,15 @@ func Run(options Options) (app *kingpin.Application, executedCommand string, con
if err = config.Configure(&ccf, conf, command != appStartCmd.FullCommand()); err != nil {
utils.FatalError(err)
}

// Validate binary modules against the device trust configuration.
// Catches errors in file-based configs.
if conf.Auth.Enabled {
if err := dtconfig.ValidateConfigAgainstModules(conf.Auth.Preference.GetDeviceTrust()); err != nil {
utils.FatalError(err)
}
}

if !options.InitOnly {
err = OnStart(ccf, conf)
}
Expand Down
Loading