Skip to content

feat: add support for telemetry-required licenses #6194

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

Merged
merged 5 commits into from
Feb 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 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
11 changes: 6 additions & 5 deletions codersdk/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,12 @@ type Feature struct {
}

type Entitlements struct {
Features map[FeatureName]Feature `json:"features"`
Warnings []string `json:"warnings"`
Errors []string `json:"errors"`
HasLicense bool `json:"has_license"`
Trial bool `json:"trial"`
Features map[FeatureName]Feature `json:"features"`
Warnings []string `json:"warnings"`
Errors []string `json:"errors"`
HasLicense bool `json:"has_license"`
Trial bool `json:"trial"`
RequireTelemetry bool `json:"require_telemetry"`

// DEPRECATED: use Experiments instead.
Experimental bool `json:"experimental"`
Expand Down
11 changes: 11 additions & 0 deletions enterprise/coderd/coderd.go
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,17 @@ func (api *API) updateEntitlements(ctx context.Context) error {
if err != nil {
return err
}

if entitlements.RequireTelemetry && !api.DeploymentConfig.Telemetry.Enable.Value {
// We can't fail because then the user couldn't remove the offending
// license w/o a restart.
api.entitlements.Errors = []string{
"License requires telemetry but telemetry is disabled",
}
api.Logger.Error(ctx, "license requires telemetry enabled")
return nil
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@kylecarbs — is it safe to return early here to your knowledge?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you return early it doesn't seem like any of the enterprise features would work, if that's your goal. I think it'd probably be better to just append to the entitlements created above instead of overwriting and let the rest of the function run.

entitlements.Experimental = api.DeploymentConfig.Experimental.Value || len(api.AGPL.Experiments) != 0

featureChanged := func(featureName codersdk.FeatureName) (changed bool, enabled bool) {
Expand Down
16 changes: 9 additions & 7 deletions enterprise/coderd/license/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ func Entitlements(
if claims.AllFeatures {
allFeatures = true
}
entitlements.RequireTelemetry = entitlements.RequireTelemetry || claims.RequireTelemetry
}

if allFeatures {
Expand Down Expand Up @@ -224,13 +225,14 @@ type Claims struct {
// the end of the grace period (identical to LicenseExpires if there is no grace period).
// The reason we use the standard claim for the end of the grace period is that we want JWT
// processing libraries to consider the token "valid" until then.
LicenseExpires *jwt.NumericDate `json:"license_expires,omitempty"`
AccountType string `json:"account_type,omitempty"`
AccountID string `json:"account_id,omitempty"`
Trial bool `json:"trial"`
AllFeatures bool `json:"all_features"`
Version uint64 `json:"version"`
Features Features `json:"features"`
LicenseExpires *jwt.NumericDate `json:"license_expires,omitempty"`
AccountType string `json:"account_type,omitempty"`
AccountID string `json:"account_id,omitempty"`
Trial bool `json:"trial"`
AllFeatures bool `json:"all_features"`
Version uint64 `json:"version"`
Features Features `json:"features"`
RequireTelemetry bool `json:"require_telemetry,omitempty"`
}

// ParseRaw consumes a license and returns the claims.
Expand Down