Skip to content

Commit

Permalink
Include BuildCommunity in built type checks (#42391)
Browse files Browse the repository at this point in the history
* Include BuildCommunity in built type checks

This commit will add two new methods to the modules interface,
IsEnterprise and IsOSS. This is to help alieviate any pain around the
code base that used to look specifically for BuildOSS. Now that we have
two "oss types" (oss and community), we can use these methods to do
enterprise/oss checks, rather than specifically looking at the build
type. This also will allow any future build types to not affect these
checks again in the future.

* Update e
  • Loading branch information
avatus authored Jun 4, 2024
1 parent ca1880d commit b85d1a6
Show file tree
Hide file tree
Showing 11 changed files with 51 additions and 9 deletions.
2 changes: 1 addition & 1 deletion e
Submodule e updated from c63530 to 828d9d
4 changes: 2 additions & 2 deletions lib/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -1285,7 +1285,7 @@ func (a *Server) runPeriodicOperations() {
defer instancePeriodics.Stop()

var ossDesktopsCheck <-chan time.Time
if modules.GetModules().BuildType() == modules.BuildOSS {
if modules.GetModules().IsOSSBuild() {
ossDesktopsCheck = interval.New(interval.Config{
Duration: OSSDesktopsCheckPeriod,
FirstDuration: utils.HalfJitter(time.Second * 10),
Expand Down Expand Up @@ -5521,7 +5521,7 @@ func (a *Server) syncDesktopsLimitAlert(ctx context.Context) {

// desktopsLimitExceeded checks if number of non-AD desktops exceeds limit for OSS distribution. Returns always false for Enterprise.
func (a *Server) desktopsLimitExceeded(ctx context.Context) (bool, error) {
if modules.GetModules().BuildType() != modules.BuildOSS {
if modules.GetModules().IsEnterpriseBuild() {
return false, nil
}

Expand Down
2 changes: 1 addition & 1 deletion lib/auth/auth_with_roles.go
Original file line number Diff line number Diff line change
Expand Up @@ -4427,7 +4427,7 @@ func (a *ServerWithRoles) DeleteRole(ctx context.Context, name string) error {
// It's OK to delete this code alongside migrateOSS code in auth.
// It prevents 6.0 from migrating resources multiple times
// and the role is used for `tctl users add` code too.
if modules.GetModules().BuildType() == modules.BuildOSS && name == teleport.AdminRoleName {
if modules.GetModules().IsOSSBuild() && name == teleport.AdminRoleName {
return trace.AccessDenied("can not delete system role %q", name)
}

Expand Down
2 changes: 1 addition & 1 deletion lib/devicetrust/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import (
// `dt` and the current modules.
func GetEffectiveMode(dt *types.DeviceTrust) string {
// OSS doesn't support device trust.
if modules.GetModules().BuildType() == modules.BuildOSS {
if modules.GetModules().IsOSSBuild() {
return constants.DeviceTrustModeOff
}

Expand Down
14 changes: 14 additions & 0 deletions lib/modules/modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,10 @@ type Modules interface {
SetFeatures(Features)
// BuildType returns build type (OSS, Community or Enterprise)
BuildType() string
// IsEnterpriseBuild returns if the binary was built with enterprise modules
IsEnterpriseBuild() bool
// IsOSSBuild returns if the binary was built without enterprise modules
IsOSSBuild() bool
// AttestHardwareKey attests a hardware key and returns its associated private key policy.
AttestHardwareKey(context.Context, interface{}, *keys.AttestationStatement, crypto.PublicKey, time.Duration) (*keys.AttestationData, error)
// GenerateAccessRequestPromotions generates a list of valid promotions for given access request.
Expand Down Expand Up @@ -379,6 +383,16 @@ func (p *defaultModules) BuildType() string {
return teleportBuildType
}

// IsEnterpriseBuild returns false for [defaultModules].
func (p *defaultModules) IsEnterpriseBuild() bool {
return false
}

// IsOSSBuild returns true for [defaultModules].
func (p *defaultModules) IsOSSBuild() bool {
return true
}

// PrintVersion prints the Teleport version.
func (p *defaultModules) PrintVersion() {
fmt.Printf("Teleport v%s git:%s %s\n", teleport.Version, teleport.Gitref, runtime.Version())
Expand Down
8 changes: 8 additions & 0 deletions lib/modules/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,14 @@ func (m *TestModules) BuildType() string {
return m.TestBuildType
}

func (m *TestModules) IsEnterpriseBuild() bool {
return m.BuildType() == BuildEnterprise
}

func (m *TestModules) IsOSSBuild() bool {
return m.BuildType() != BuildEnterprise
}

// AttestHardwareKey attests a hardware key.
func (m *TestModules) AttestHardwareKey(ctx context.Context, obj interface{}, as *keys.AttestationStatement, pk crypto.PublicKey, d time.Duration) (*keys.AttestationData, error) {
if m.MockAttestationData != nil {
Expand Down
2 changes: 1 addition & 1 deletion lib/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -1345,7 +1345,7 @@ func (process *TeleportProcess) enterpriseServicesEnabled() bool {
// enterpriseServicesEnabledWithCommunityBuild will return true if any
// enterprise services are enabled with an OSS teleport build.
func (process *TeleportProcess) enterpriseServicesEnabledWithCommunityBuild() bool {
return modules.GetModules().BuildType() == modules.BuildOSS &&
return modules.GetModules().IsOSSBuild() &&
(process.Config.Okta.Enabled || process.Config.Jamf.Enabled())
}

Expand Down
2 changes: 1 addition & 1 deletion lib/services/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ func MarshalOSSGithubConnector(githubConnector types.GithubConnector, opts ...Ma
// Only return an error if the endpoint url is set and the build is OSS
// so that the enterprise marshaler can call this marshaler to produce
// the final output without receiving an error.
if modules.GetModules().BuildType() == modules.BuildOSS &&
if modules.GetModules().IsOSSBuild() &&
githubConnector.Spec.EndpointURL != "" {
return nil, fmt.Errorf("GitHub endpoint URL is set: %w", ErrRequiresEnterprise)
}
Expand Down
4 changes: 2 additions & 2 deletions tool/teleport/common/teleport.go
Original file line number Diff line number Diff line change
Expand Up @@ -786,7 +786,7 @@ func onConfigDump(flags dumpFlags) error {
return nil
}

if modules.GetModules().BuildType() != modules.BuildOSS {
if modules.GetModules().IsEnterpriseBuild() {
flags.LicensePath = filepath.Join(flags.DataDir, "license.pem")
}

Expand Down Expand Up @@ -847,7 +847,7 @@ func onConfigDump(flags dumpFlags) error {
requiresRoot := !canWriteToDataDir || !canWriteToConfDir

fmt.Fprintf(flags.stdout, "\nA Teleport configuration file has been created at %q.\n", configPath)
if modules.GetModules().BuildType() != modules.BuildOSS {
if modules.GetModules().IsEnterpriseBuild() {
fmt.Fprintf(flags.stdout, "Add your Teleport license file to %q.\n", flags.LicensePath)
}
fmt.Fprintf(flags.stdout, "To start Teleport with this configuration file, run:\n\n")
Expand Down
10 changes: 10 additions & 0 deletions tool/teleport/testenv/test_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,16 @@ func (p *cliModules) BuildType() string {
return "CLI"
}

// IsEnterpriseBuild returns false for [cliModules].
func (p *cliModules) IsEnterpriseBuild() bool {
return false
}

// IsOSSBuild returns false for [cliModules].
func (p *cliModules) IsOSSBuild() bool {
return false
}

// PrintVersion prints the Teleport version.
func (p *cliModules) PrintVersion() {
fmt.Println("Teleport CLI")
Expand Down
10 changes: 10 additions & 0 deletions tool/tsh/common/tsh_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,16 @@ func (p *cliModules) BuildType() string {
return "CLI"
}

// IsEnterpriseBuild returns false for [cliModules].
func (p *cliModules) IsEnterpriseBuild() bool {
return false
}

// IsOSSBuild returns false for [cliModules].
func (p *cliModules) IsOSSBuild() bool {
return false
}

// PrintVersion prints the Teleport version.
func (p *cliModules) PrintVersion() {
fmt.Printf("Teleport CLI\n")
Expand Down

0 comments on commit b85d1a6

Please sign in to comment.