Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

refactor(enterprise): consolidate and simplify license service (#18357)

Danny Xudd2515af3863
diff --git a/backend/enterprise/config/config.go b/backend/enterprise/config/config.go
deleted file mode 100644
index 675212c51e..0000000000
--- a/backend/enterprise/config/config.go
+++ /dev/null
@@ -1,61 +0,0 @@
-// Package config provides configuration interface for enterprise licensing.
-package config
-
-import (
- "crypto/rsa"
- "embed"
- "fmt"
- "io/fs"
-
- "github.com/golang-jwt/jwt/v5"
- "github.com/pkg/errors"
-
- "github.com/bytebase/bytebase/backend/common"
-)
-
-//go:embed keys
-var keysFS embed.FS
-
-// Config is the API message for enterprise config.
-type Config struct {
- // PublicKey is the parsed RSA public key.
- PublicKey *rsa.PublicKey
- // Version is the JWT key version.
- Version string
- // Issuer is the license issuer, it should always be "bytebase".
- Issuer string
- // Audience is the license audience, it should always be "bb.license".
- Audience string
- // Mode can be "prod" or "dev"
- Mode common.ReleaseMode
-}
-
-const (
- // keyID is the license key version.
- keyID = "v1"
- // issuer is the license issuer.
- issuer = "bytebase"
- // audience is the license token audience.
- audience = "bb.license"
-)
-
-// NewConfig will create a new enterprise config instance.
-func NewConfig(mode common.ReleaseMode) (*Config, error) {
- licensePubKey, err := fs.ReadFile(keysFS, fmt.Sprintf("keys/%s.pub.pem", mode))
- if err != nil {
- return nil, errors.Errorf("cannot read license public key for env %s", mode)
- }
-
- key, err := jwt.ParseRSAPublicKeyFromPEM(licensePubKey)
- if err != nil {
- return nil, errors.Wrapf(err, "failed to parse license public key for env %s", mode)
- }
-
- return &Config{
- PublicKey: key,
- Version: keyID,
- Issuer: issuer,
- Audience: audience,
- Mode: mode,
- }, nil
-}
diff --git a/backend/enterprise/config/keys/README.md b/backend/enterprise/keys/README.md
similarity index 100%
rename from backend/enterprise/config/keys/README.md
rename to backend/enterprise/keys/README.md
diff --git a/backend/enterprise/config/keys/dev.pub.pem b/backend/enterprise/keys/dev.pub.pem
similarity index 100%
rename from backend/enterprise/config/keys/dev.pub.pem
rename to backend/enterprise/keys/dev.pub.pem
diff --git a/backend/enterprise/config/keys/prod.pub.pem b/backend/enterprise/keys/prod.pub.pem
similarity index 100%
rename from backend/enterprise/config/keys/prod.pub.pem
rename to backend/enterprise/keys/prod.pub.pem
diff --git a/backend/enterprise/license.go b/backend/enterprise/license.go
index 5e4e44c38d..7e117e7f3e 100644
--- a/backend/enterprise/license.go
+++ b/backend/enterprise/license.go
@@ -3,40 +3,151 @@ package enterprise
import (
"context"
+ "crypto/rsa"
+ "embed"
+ "encoding/json"
+ "fmt"
+ "io/fs"
+ "log/slog"
"math"
+ "slices"
"sync"
"time"
+ "github.com/golang-jwt/jwt/v5"
"github.com/pkg/errors"
+ "google.golang.org/protobuf/encoding/protojson"
+ "google.golang.org/protobuf/types/known/timestamppb"
+ "gopkg.in/yaml.v3"
"github.com/bytebase/bytebase/backend/common"
- "github.com/bytebase/bytebase/backend/enterprise/plugin"
+ "github.com/bytebase/bytebase/backend/common/log"
v1pb "github.com/bytebase/bytebase/backend/generated-go/v1"
"github.com/bytebase/bytebase/backend/store"
)
+//go:embed keys
+var keysFS embed.FS
+
+//go:embed plan.yaml
+var planConfigStr string
+
+var userLimitValues = map[v1pb.PlanType]int{}
+var instanceLimitValues = map[v1pb.PlanType]int{}
+
+// planFeatureMatrix maps plans to their available features
+var planFeatureMatrix = make(map[v1pb.PlanType]map[v1pb.PlanFeature]bool)
+
+var defaultFreeSubscription = &v1pb.Subscription{
+ Plan: v1pb.PlanType_FREE,
+}
+
+func init() {
+ // First unmarshal YAML to a generic map, then convert to JSON for protojson
+ var yamlData map[string]any
+ if err := yaml.Unmarshal([]byte(planConfigStr), &yamlData); err != nil {
+ panic("failed to unmarshal plan.yaml: " + err.Error())
+ }
+
+ // Convert YAML data to JSON bytes
+ jsonBytes, err := json.Marshal(yamlData)
+ if err != nil {
+ panic("failed to convert plan.yaml to JSON: " + err.Error())
+ }
+
+ conf := &v1pb.PlanConfig{}
+ //nolint:forbidigo
+ if err := protojson.Unmarshal(jsonBytes, conf); err != nil {
+ panic("failed to unmarshal plan config proto: " + err.Error())
+ }
+
+ for _, plan := range conf.Plans {
+ userLimitValues[plan.Type] = int(plan.MaximumSeatCount)
+ instanceLimitValues[plan.Type] = int(plan.MaximumInstanceCount)
+
+ planFeatureMatrix[plan.Type] = make(map[v1pb.PlanFeature]bool)
+ for _, feature := range plan.Features {
+ planFeatureMatrix[plan.Type][feature] = true
+ }
+ }
+}
+
+// Config is the API message for enterprise config.
+type Config struct {
+ // PublicKey is the parsed RSA public key.
+ PublicKey *rsa.PublicKey
+ // Version is the JWT key version.
+ Version string
+ // Issuer is the license issuer, it should always be "bytebase".
+ Issuer string
+ // Audience is the license audience, it should always be "bb.license".
+ Audience string
+ // Mode can be "prod" or "dev"
+ Mode common.ReleaseMode
+}
+
+const (
+ // keyID is the license key version.
+ keyID = "v1"
+ // issuer is the license issuer.
+ issuer = "bytebase"
+ // audience is the license token audience.
+ audience = "bb.license"
+)
+
+// NewConfig will create a new enterprise config instance.
+func NewConfig(mode common.ReleaseMode) (*Config, error) {
+ licensePubKey, err := fs.ReadFile(keysFS, fmt.Sprintf("keys/%s.pub.pem", mode))
+ if err != nil {
+ return nil, errors.Errorf("cannot read license public key for env %s", mode)
+ }
+
+ key, err := jwt.ParseRSAPublicKeyFromPEM(licensePubKey)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to parse license public key for env %s", mode)
+ }
+
+ return &Config{
+ PublicKey: key,
+ Version: keyID,
+ Issuer: issuer,
+ Audience: audience,
+ Mode: mode,
+ }, nil
+}
+
// LicenseService is the service for enterprise license.
type LicenseService struct {
store *store.Store
cachedSubscription *v1pb.Subscription
mu sync.RWMutex
- provider plugin.LicenseProvider
+ config *Config
+}
+
+// claims creates a struct that will be encoded to a JWT.
+// We add jwt.RegisteredClaims as an embedded type, to provide fields such as name.
+type claims struct {
+ ActiveInstances int `json:"instanceCount"`
+ Instances int `json:"instance"`
+ Seats int `json:"seat"`
+ Trialing bool `json:"trialing"`
+ Plan string `json:"plan"`
+ OrgName string `json:"orgName"`
+ WorkspaceID string `json:"workspaceId"`
+ jwt.RegisteredClaims
}
// NewLicenseService will create a new enterprise license service.
func NewLicenseService(mode common.ReleaseMode, store *store.Store) (*LicenseService, error) {
- provider, err := getLicenseProvider(&plugin.ProviderConfig{
- Mode: mode,
- Store: store,
- })
+ config, err := NewConfig(mode)
if err != nil {
return nil, err
}
return &LicenseService{
- store: store,
- provider: provider,
+ store: store,
+ config: config,
}, nil
}
@@ -44,46 +155,66 @@ func NewLicenseService(mode common.ReleaseMode, store *store.Store) (*LicenseSer
// If there is no license, we will return a free plan subscription without expiration time.
// If there is expired license, we will return a free plan subscription with the expiration time of the expired license.
func (s *LicenseService) LoadSubscription(ctx context.Context) *v1pb.Subscription {
- s.mu.RLock()
- cached := s.cachedSubscription
- s.mu.RUnlock()
-
- if cached != nil {
- // Invalidate the cache if expired.
- if cached.ExpiresTime != nil && cached.ExpiresTime.AsTime().Before(time.Now()) {
- // refresh expired subscription
- s.mu.Lock()
- s.cachedSubscription = nil
- s.mu.Unlock()
- cached = nil
- }
- }
- if cached != nil {
- return cached
- }
-
- // Cache the subscription.
s.mu.Lock()
defer s.mu.Unlock()
- subscription := s.provider.LoadSubscription(ctx)
- if subscription == nil {
- // Never had a subscription, set to free plan.
- subscription = &v1pb.Subscription{
- Plan: v1pb.PlanType_FREE,
+ if s.cachedSubscription != nil && !isExpired(s.cachedSubscription) {
+ return s.cachedSubscription
+ }
+
+ // Try to load the subscription from the store.
+ // We use an IIFE (Immediately Invoked Function Expression) to handle the error return flow cleanly
+ // before we decide on the fallback.
+ subscription, err := func() (*v1pb.Subscription, error) {
+ setting, err := s.store.GetSystemSetting(ctx)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to get system setting")
+ }
+
+ if setting.License == "" {
+ return defaultFreeSubscription, nil
+ }
+
+ subscription, err := s.parseLicense(setting.License, setting.WorkspaceId)
+ if err != nil {
+ return nil, errors.Wrapf(err, "failed to parse enterprise license")
}
+
+ slog.Debug(
+ "Load valid license",
+ slog.String("plan", subscription.Plan.String()),
+ slog.Time("expiresAt", subscription.ExpiresTime.AsTime()),
+ slog.Int("activeInstances", int(subscription.ActiveInstances)),
+ slog.Int("instances", int(subscription.Instances)),
+ slog.Int("seats", int(subscription.Seats)),
+ )
+ return subscription, nil
+ }()
+
+ if err != nil {
+ slog.Debug("failed to load enterprise license", log.BBError(err))
+ subscription = defaultFreeSubscription
}
+
// Switch to free plan if the subscription is expired.
- if subscription.ExpiresTime != nil && subscription.ExpiresTime.AsTime().Before(time.Now()) {
+ if isExpired(subscription) {
subscription = &v1pb.Subscription{
Plan: v1pb.PlanType_FREE,
ExpiresTime: subscription.ExpiresTime,
}
}
s.cachedSubscription = subscription
+
return subscription
}
+func isExpired(sub *v1pb.Subscription) bool {
+ if sub == nil {
+ return false
+ }
+ return sub.ExpiresTime != nil && sub.ExpiresTime.AsTime().Before(time.Now())
+}
+
// GetEffectivePlan gets the effective plan.
func (s *LicenseService) GetEffectivePlan() v1pb.PlanType {
ctx := context.Background()
@@ -172,7 +303,17 @@ func (s *LicenseService) GetInstanceLimit(ctx context.Context) int {
// StoreLicense will store license into file.
func (s *LicenseService) StoreLicense(ctx context.Context, license string) error {
- if err := s.provider.StoreLicense(ctx, license); err != nil {
+ if license != "" {
+ systemSetting, err := s.store.GetSystemSetting(ctx)
+ if err != nil {
+ return errors.Wrapf(err, "failed to get system setting")
+ }
+ if _, err := s.parseLicense(license, systemSetting.WorkspaceId); err != nil {
+ return err
+ }
+ }
+
+ if err := s.store.UpdateLicense(ctx, license); err != nil {
return err
}
@@ -219,3 +360,73 @@ func (s *LicenseService) GetAuditLogRetentionCutoff() *time.Time {
cutoff := time.Now().AddDate(0, 0, -days)
return &cutoff
}
+
+func (s *LicenseService) parseLicense(license, workspaceID string) (*v1pb.Subscription, error) {
+ claim := &claims{}
+ token, err := jwt.ParseWithClaims(license, claim, func(token *jwt.Token) (any, error) {
+ if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
+ return nil, common.Errorf(common.Invalid, "unexpected signing method: %v", token.Header["alg"])
+ }
+
+ kid, ok := token.Header["kid"].(string)
+ if !ok || kid != s.config.Version {
+ return nil, common.Errorf(common.Invalid, "version '%v' is not valid. expect %s", token.Header["kid"], s.config.Version)
+ }
+
+ return s.config.PublicKey, nil
+ })
+ if err != nil {
+ return nil, common.Wrap(err, common.Invalid)
+ }
+
+ if !token.Valid {
+ return nil, common.Errorf(common.Invalid, "invalid token")
+ }
+
+ if s.config.Issuer != claim.Issuer {
+ return nil, common.Errorf(common.Invalid, "iss is not valid, expect %s but found '%v'", s.config.Issuer, claim.Issuer)
+ }
+ if !slices.Contains(claim.Audience, s.config.Audience) {
+ return nil, common.Errorf(common.Invalid, "aud is not valid, expect %s but found '%v'", s.config.Audience, claim.Audience)
+ }
+
+ v, ok := v1pb.PlanType_value[claim.Plan]
+ if !ok {
+ return nil, common.Errorf(common.Invalid, "plan type %q is not valid", claim.Plan)
+ }
+ planType := v1pb.PlanType(v)
+
+ if claim.WorkspaceID != "" && planType == v1pb.PlanType_ENTERPRISE && !claim.Trialing {
+ if workspaceID != claim.WorkspaceID {
+ return nil, common.Errorf(common.Invalid, "the workspace id not match")
+ }
+ }
+
+ switch planType {
+ case v1pb.PlanType_FREE, v1pb.PlanType_TEAM, v1pb.PlanType_ENTERPRISE:
+ default:
+ return nil, errors.Errorf("plan %q is not valid, expect %s or %s",
+ planType.String(),
+ v1pb.PlanType_TEAM.String(),
+ v1pb.PlanType_ENTERPRISE.String(),
+ )
+ }
+
+ var expiresTime *timestamppb.Timestamp
+ if claim.ExpiresAt != nil && !claim.ExpiresAt.IsZero() {
+ expiresTime = timestamppb.New(claim.ExpiresAt.Time)
+ }
+ if expiresTime != nil && expiresTime.AsTime().Before(time.Now()) {
+ return nil, errors.Errorf("license has expired at %v", expiresTime.AsTime())
+ }
+
+ return &v1pb.Subscription{
+ ActiveInstances: int32(claim.ActiveInstances),
+ Instances: int32(claim.Instances),
+ Seats: int32(claim.Seats),
+ ExpiresTime: expiresTime,
+ Plan: planType,
+ Trialing: claim.Trialing,
+ OrgName: claim.OrgName,
+ }, nil
+}
diff --git a/backend/enterprise/limit.go b/backend/enterprise/limit.go
deleted file mode 100644
index dab595f4dc..0000000000
--- a/backend/enterprise/limit.go
+++ /dev/null
@@ -1,50 +0,0 @@
-package enterprise
-
-import (
- _ "embed"
- "encoding/json"
-
- "google.golang.org/protobuf/encoding/protojson"
- "gopkg.in/yaml.v3"
-
- v1pb "github.com/bytebase/bytebase/backend/generated-go/v1"
-)
-
-//go:embed plan.yaml
-var planConfigStr string
-
-var userLimitValues = map[v1pb.PlanType]int{}
-var instanceLimitValues = map[v1pb.PlanType]int{}
-
-// planFeatureMatrix maps plans to their available features
-var planFeatureMatrix = make(map[v1pb.PlanType]map[v1pb.PlanFeature]bool)
-
-func init() {
- // First unmarshal YAML to a generic map, then convert to JSON for protojson
- var yamlData map[string]any
- if err := yaml.Unmarshal([]byte(planConfigStr), &yamlData); err != nil {
- panic("failed to unmarshal plan.yaml: " + err.Error())
- }
-
- // Convert YAML data to JSON bytes
- jsonBytes, err := json.Marshal(yamlData)
- if err != nil {
- panic("failed to convert plan.yaml to JSON: " + err.Error())
- }
-
- conf := &v1pb.PlanConfig{}
- //nolint:forbidigo
- if err := protojson.Unmarshal(jsonBytes, conf); err != nil {
- panic("failed to unmarshal plan config proto: " + err.Error())
- }
-
- for _, plan := range conf.Plans {
- userLimitValues[plan.Type] = int(plan.MaximumSeatCount)
- instanceLimitValues[plan.Type] = int(plan.MaximumInstanceCount)
-
- planFeatureMatrix[plan.Type] = make(map[v1pb.PlanFeature]bool)
- for _, feature := range plan.Features {
- planFeatureMatrix[plan.Type][feature] = true
- }
- }
-}
diff --git a/backend/enterprise/plugin/aws/aws.go b/backend/enterprise/plugin/aws/aws.go
deleted file mode 100644
index d5a7ebb959..0000000000
--- a/backend/enterprise/plugin/aws/aws.go
+++ /dev/null
@@ -1,144 +0,0 @@
-package aws
-
-import (
- "context"
- "log/slog"
- "os"
- "time"
-
- "github.com/pkg/errors"
- "google.golang.org/protobuf/types/known/timestamppb"
-
- "github.com/bytebase/bytebase/backend/common/log"
- "github.com/bytebase/bytebase/backend/enterprise/plugin"
- v1pb "github.com/bytebase/bytebase/backend/generated-go/v1"
-
- "github.com/aws/aws-sdk-go-v2/aws"
- "github.com/aws/aws-sdk-go-v2/config"
- "github.com/aws/aws-sdk-go-v2/service/licensemanager"
- "github.com/aws/aws-sdk-go-v2/service/licensemanager/types"
- "github.com/aws/aws-sdk-go-v2/service/sts"
-)
-
-var _ plugin.LicenseProvider = (*Provider)(nil)
-
-// Provider is the AWS license provider.
-type Provider struct {
- projectID string
- licenseManager *licensemanager.Client
- identity *sts.GetCallerIdentityOutput
-}
-
-// NewProvider will create a new AWS license provider.
-// To use the aws provider in local development, you need to follow the guide https://catalog.workshops.aws/mpseller/en-US/container/integrate-contract#task-1:-create-a-test-license
-// to subscribe our test product in the marketplace,
-// and expose AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY, AWS_REGION and PRODUCT_ID in the environment.
-// And the AWS account must have the permission to access the AWS license manager.
-func NewProvider(_ *plugin.ProviderConfig) (plugin.LicenseProvider, error) {
- projectID := os.Getenv("AWS_PRODUCT_ID")
- if projectID == "" {
- return nil, errors.Errorf("cannot find aws project id")
- }
-
- ctx := context.Background()
- cfg, err := config.LoadDefaultConfig(ctx)
- if err != nil {
- return nil, err
- }
-
- client := sts.NewFromConfig(cfg)
- identity, err := client.GetCallerIdentity(ctx, &sts.GetCallerIdentityInput{})
- if err != nil {
- return nil, err
- }
-
- return &Provider{
- projectID: projectID,
- identity: identity,
- licenseManager: licensemanager.NewFromConfig(cfg),
- }, nil
-}
-
-// StoreLicense will store the aws license.
-func (*Provider) StoreLicense(_ context.Context, _ string) error {
- return nil
-}
-
-// LoadSubscription will load the aws subscription.
-func (p *Provider) LoadSubscription(ctx context.Context) *v1pb.Subscription {
- license, err := p.checkoutLicense(ctx)
- if err != nil {
- slog.Error("failed to checkout license",
- log.BBError(err),
- )
- return nil
- }
-
- if license.Status != types.LicenseStatusAvailable {
- return nil
- }
-
- subscription := &v1pb.Subscription{
- Plan: v1pb.PlanType_ENTERPRISE,
- OrgName: aws.ToString(p.identity.Account),
- }
-
- if v := license.Validity; v != nil {
- end, err := time.Parse(time.RFC3339, aws.ToString(v.End))
- if err != nil {
- slog.Error("failed to parse subscription end time",
- slog.String("end", *v.Begin),
- log.BBError(err),
- )
- return nil
- }
- subscription.ExpiresTime = timestamppb.New(end.UTC())
- }
-
- for _, entitlement := range license.Entitlements {
- name := entitlement.Name
- if name == nil {
- continue
- }
- switch *name {
- case "instance":
- subscription.ActiveInstances = int32(aws.ToInt64(entitlement.MaxCount))
- subscription.Instances = subscription.ActiveInstances
- case "seat":
- subscription.Seats = int32(aws.ToInt64(entitlement.MaxCount))
- default:
- // Ignore unknown entitlement names
- }
- }
-
- return subscription
-}
-
-func (p *Provider) checkoutLicense(ctx context.Context) (*types.GrantedLicense, error) {
- productSKUField := "ProductSKU"
- issuerNameField := "IssuerName"
- var maxResults int32 = 1
-
- res, err := p.licenseManager.ListReceivedLicenses(ctx, &licensemanager.ListReceivedLicensesInput{
- Filters: []types.Filter{
- {
- Name: &productSKUField,
- Values: []string{p.projectID},
- },
- {
- Name: &issuerNameField,
- Values: []string{"AWS/Marketplace"},
- },
- },
- MaxResults: &maxResults,
- })
- if err != nil {
- return nil, err
- }
-
- if len(res.Licenses) != 1 {
- return nil, errors.Errorf("failed to list aws license")
- }
-
- return &res.Licenses[0], nil
-}
diff --git a/backend/enterprise/plugin/hub/hub.go b/backend/enterprise/plugin/hub/hub.go
deleted file mode 100644
index ea83092515..0000000000
--- a/backend/enterprise/plugin/hub/hub.go
+++ /dev/null
@@ -1,169 +0,0 @@
-package hub
-
-import (
- "context"
- "log/slog"
- "slices"
- "time"
-
- "github.com/golang-jwt/jwt/v5"
- "github.com/pkg/errors"
- "google.golang.org/protobuf/types/known/timestamppb"
-
- "github.com/bytebase/bytebase/backend/common"
- "github.com/bytebase/bytebase/backend/common/log"
- "github.com/bytebase/bytebase/backend/enterprise/config"
- "github.com/bytebase/bytebase/backend/enterprise/plugin"
- v1pb "github.com/bytebase/bytebase/backend/generated-go/v1"
- "github.com/bytebase/bytebase/backend/store"
-)
-
-var _ plugin.LicenseProvider = (*Provider)(nil)
-
-// Provider is the Bytebase Hub license provider.
-type Provider struct {
- config *config.Config
- store *store.Store
-}
-
-// claims creates a struct that will be encoded to a JWT.
-// We add jwt.RegisteredClaims as an embedded type, to provide fields such as name.
-type claims struct {
- ActiveInstances int `json:"instanceCount"`
- Instances int `json:"instance"`
- Seats int `json:"seat"`
- Trialing bool `json:"trialing"`
- Plan string `json:"plan"`
- OrgName string `json:"orgName"`
- WorkspaceID string `json:"workspaceId"`
- jwt.RegisteredClaims
-}
-
-// validateSubscription validates if the subscription is expired or has correct plan type.
-
-// NewProvider will create a new hub license provider.
-func NewProvider(providerConfig *plugin.ProviderConfig) (plugin.LicenseProvider, error) {
- config, err := config.NewConfig(providerConfig.Mode)
- if err != nil {
- return nil, err
- }
-
- return &Provider{
- store: providerConfig.Store,
- config: config,
- }, nil
-}
-
-// StoreLicense will store the hub license.
-func (p *Provider) StoreLicense(ctx context.Context, license string) error {
- if license != "" {
- systemSetting, err := p.store.GetSystemSetting(ctx)
- if err != nil {
- return errors.Wrapf(err, "failed to get system setting")
- }
- if _, err := p.parseLicense(license, systemSetting.WorkspaceId); err != nil {
- return err
- }
- }
- return p.store.UpdateLicense(ctx, license)
-}
-
-// LoadSubscription will load the hub subscription.
-func (p *Provider) LoadSubscription(ctx context.Context) *v1pb.Subscription {
- systemSetting, err := p.store.GetSystemSetting(ctx)
- if err != nil {
- slog.Debug("failed to load enterprise license", log.BBError(errors.Wrapf(err, "failed to get system setting")))
- return nil
- }
-
- if systemSetting.License == "" {
- return nil
- }
-
- license, err := p.parseLicense(systemSetting.License, systemSetting.WorkspaceId)
- if err != nil {
- slog.Debug("failed to load enterprise license", log.BBError(errors.Wrapf(err, "failed to parse enterprise license")))
- return nil
- }
-
- slog.Debug(
- "Load valid license",
- slog.String("plan", license.Plan.String()),
- slog.Time("expiresAt", license.ExpiresTime.AsTime()),
- slog.Int("activeInstances", int(license.ActiveInstances)),
- slog.Int("instances", int(license.Instances)),
- slog.Int("seats", int(license.Seats)),
- )
-
- return license
-}
-
-func (p *Provider) parseLicense(license, workspaceID string) (*v1pb.Subscription, error) {
- claim := &claims{}
- token, err := jwt.ParseWithClaims(license, claim, func(token *jwt.Token) (any, error) {
- if _, ok := token.Method.(*jwt.SigningMethodRSA); !ok {
- return nil, common.Errorf(common.Invalid, "unexpected signing method: %v", token.Header["alg"])
- }
-
- kid, ok := token.Header["kid"].(string)
- if !ok || kid != p.config.Version {
- return nil, common.Errorf(common.Invalid, "version '%v' is not valid. expect %s", token.Header["kid"], p.config.Version)
- }
-
- return p.config.PublicKey, nil
- })
- if err != nil {
- return nil, common.Wrap(err, common.Invalid)
- }
-
- if !token.Valid {
- return nil, common.Errorf(common.Invalid, "invalid token")
- }
-
- if p.config.Issuer != claim.Issuer {
- return nil, common.Errorf(common.Invalid, "iss is not valid, expect %s but found '%v'", p.config.Issuer, claim.Issuer)
- }
- if !slices.Contains(claim.Audience, p.config.Audience) {
- return nil, common.Errorf(common.Invalid, "aud is not valid, expect %s but found '%v'", p.config.Audience, claim.Audience)
- }
-
- v, ok := v1pb.PlanType_value[claim.Plan]
- if !ok {
- return nil, common.Errorf(common.Invalid, "plan type %q is not valid", claim.Plan)
- }
- planType := v1pb.PlanType(v)
-
- if claim.WorkspaceID != "" && planType == v1pb.PlanType_ENTERPRISE && !claim.Trialing {
- if workspaceID != claim.WorkspaceID {
- return nil, common.Errorf(common.Invalid, "the workspace id not match")
- }
- }
-
- switch planType {
- case v1pb.PlanType_FREE, v1pb.PlanType_TEAM, v1pb.PlanType_ENTERPRISE:
- default:
- return nil, errors.Errorf("plan %q is not valid, expect %s or %s",
- planType.String(),
- v1pb.PlanType_TEAM.String(),
- v1pb.PlanType_ENTERPRISE.String(),
- )
- }
-
- var expiresTime *timestamppb.Timestamp
- if claim.ExpiresAt != nil && !claim.ExpiresAt.IsZero() {
- expiresTime = timestamppb.New(claim.ExpiresAt.Time)
- }
- if expiresTime != nil && expiresTime.AsTime().Before(time.Now()) {
- return nil, errors.Errorf("license has expired at %v", expiresTime.AsTime())
- }
-
- return &v1pb.Subscription{
- ActiveInstances: int32(claim.ActiveInstances),
- Instances: int32(claim.Instances),
- Seats: int32(claim.Seats),
- ExpiresTime: expiresTime,
- Plan: planType,
- Trialing: claim.Trialing,
- OrgName: claim.OrgName,
- }, nil
-}
diff --git a/backend/enterprise/plugin/license.go b/backend/enterprise/plugin/license.go
deleted file mode 100644
index dc51d1024e..0000000000
--- a/backend/enterprise/plugin/license.go
+++ /dev/null
@@ -1,23 +0,0 @@
-package plugin
-
-import (
- "context"
-
- "github.com/bytebase/bytebase/backend/common"
- v1pb "github.com/bytebase/bytebase/backend/generated-go/v1"
- "github.com/bytebase/bytebase/backend/store"
-)
-
-// LicenseProvider is the license provider.
-type LicenseProvider interface {
- // StoreLicense will store the license.
- StoreLicense(ctx context.Context, license string) error
- // LoadSubscription will load the subscription.
- LoadSubscription(ctx context.Context) *v1pb.Subscription
-}
-
-// ProviderConfig is the provider configuration.
-type ProviderConfig struct {
- Mode common.ReleaseMode
- Store *store.Store
-}
diff --git a/backend/enterprise/provider_aws.go b/backend/enterprise/provider_aws.go
deleted file mode 100644
index 4b5895effd..0000000000
--- a/backend/enterprise/provider_aws.go
+++ /dev/null
@@ -1,12 +0,0 @@
-//go:build aws
-
-package enterprise
-
-import (
- "github.com/bytebase/bytebase/backend/enterprise/plugin"
- "github.com/bytebase/bytebase/backend/enterprise/plugin/aws"
-)
-
-func getLicenseProvider(providerConfig *plugin.ProviderConfig) (plugin.LicenseProvider, error) {
- return aws.NewProvider(providerConfig)
-}
diff --git a/backend/enterprise/provider_hub.go b/backend/enterprise/provider_hub.go
deleted file mode 100644
index 585a6990c9..0000000000
--- a/backend/enterprise/provider_hub.go
+++ /dev/null
@@ -1,12 +0,0 @@
-//go:build !aws
-
-package enterprise
-
-import (
- "github.com/bytebase/bytebase/backend/enterprise/plugin"
- "github.com/bytebase/bytebase/backend/enterprise/plugin/hub"
-)
-
-func getLicenseProvider(providerConfig *plugin.ProviderConfig) (plugin.LicenseProvider, error) {
- return hub.NewProvider(providerConfig)
-}
diff --git a/go.mod b/go.mod
index e3bb329858..a6b3cc3a2b 100644
--- a/go.mod
+++ b/go.mod
@@ -27,7 +27,6 @@ require (
github.com/aws/aws-sdk-go-v2/config v1.32.3
github.com/aws/aws-sdk-go-v2/credentials v1.19.3
github.com/aws/aws-sdk-go-v2/feature/rds/auth v1.6.15
- github.com/aws/aws-sdk-go-v2/service/licensemanager v1.37.2
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.40.3
github.com/beltran/gohive v1.8.1
github.com/blang/semver/v4 v4.0.0
diff --git a/go.sum b/go.sum
index b299673dbb..63b744cfb0 100644
--- a/go.sum
+++ b/go.sum
@@ -795,8 +795,6 @@ github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.15 h1:3/u/4yZO
github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.13.15/go.mod h1:4Zkjq0FKjE78NKjabuM4tRXKFzUJWXgP0ItEZK8l7JU=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.7 h1:u3VbDKUCWarWiU+aIUK4gjTr/wQFXV17y3hgNno9fcA=
github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.7/go.mod h1:/OuMQwhSyRapYxq6ZNpPer8juGNrB4P5Oz8bZ2cgjQE=
-github.com/aws/aws-sdk-go-v2/service/licensemanager v1.37.2 h1:MsEOmcB1rIV3dOiAsNqNAYixqW1jtApHQ6haGymsELk=
-github.com/aws/aws-sdk-go-v2/service/licensemanager v1.37.2/go.mod h1:qEC2TTisX86gtsIA8ljB3I9G/ctOcLBZOZcHF3vsiq4=
github.com/aws/aws-sdk-go-v2/service/s3 v1.88.1 h1:+RpGuaQ72qnU83qBKVwxkznewEdAGhIWo/PQCmkhhog=
github.com/aws/aws-sdk-go-v2/service/s3 v1.88.1/go.mod h1:xajPTguLoeQMAOE44AAP2RQoUhF8ey1g5IFHARv71po=
github.com/aws/aws-sdk-go-v2/service/secretsmanager v1.40.3 h1:QYBY43OlvzRPww1gSZ1kihyqzXg32rweA3fql5ubSLA=
diff --git a/scripts/Dockerfile.aws b/scripts/Dockerfile.aws
deleted file mode 100644
index 9275be653a..0000000000
--- a/scripts/Dockerfile.aws
+++ /dev/null
@@ -1,75 +0,0 @@
-FROM node:24.11.1-slim AS frontend
-ARG GIT_COMMIT
-
-RUN npm i -g [email protected]
-
-WORKDIR /frontend-build
-
-COPY . .
-
-RUN pnpm --dir ./frontend i
-RUN pnpm --dir ./frontend release-aws
-
-FROM golang:1.25.5-alpine3.23 AS backend
-ARG VERSION
-ARG GIT_COMMIT
-ARG RELEASE="release"
-
-ADD go.mod go.sum /
-
-RUN go mod download
-RUN apk add --no-cache clang krb5-dev binutils-gold
-
-WORKDIR /backend-build
-
-COPY . .
-
-# Copy frontend asset
-COPY --from=frontend /frontend-build/frontend/dist ./backend/server/dist
-
-# -ldflags="-w -s" means omit DWARF symbol table and the symbol table and debug information
-RUN CC=clang go build \
- --tags "${RELEASE},embed_frontend,aws" \
- -ldflags="-extldflags '-Wl,-z,stack-size=0x1000000' -w -s -X 'github.com/bytebase/bytebase/backend/bin/server/cmd.version=${VERSION}' -X 'github.com/bytebase/bytebase/backend/bin/server/cmd.gitcommit=${GIT_COMMIT}'" \
- -o bytebase ./backend/bin/server/main.go
-
-FROM alpine:3.23 AS monolithic
-ARG VERSION
-ARG GIT_COMMIT
-
-# See https://github.com/opencontainers/image-spec/blob/master/annotations.md
-LABEL org.opencontainers.image.version=${VERSION}
-LABEL org.opencontainers.image.revision=${GIT_COMMIT}
-
-# Create user "bytebase" for running Postgres database and server.
-RUN addgroup --gid 113 --system bytebase && adduser --uid 113 --system bytebase && adduser bytebase bytebase
-# Directory to store the data, which can be referenced as the mounting point.
-RUN mkdir -p /var/opt/bytebase
-# Directory to store the demo data.
-RUN mkdir -p /var/opt/bytebase/pgdata-demo
-RUN apk update
-RUN apk add --no-cache gnupg curl psmisc procps ncurses krb5
-# Install postgresql.
-RUN apk add postgresql16
-# Generate en_US.UTF-8 locale which is needed to start postgres server.
-# Fix the posgres server issue (invalid value for parameter "lc_messages": "en_US.UTF-8").
-#RUN echo "en_US.UTF-8 UTF-8" > /etc/locale.gen && locale-gen
-
-# Install mongosh.
-RUN apk add --no-cache npm
-RUN npm install -g [email protected]
-
-# The file indicates running in docker environment.
-RUN touch /etc/bb.env
-COPY --from=backend /backend-build/bytebase /usr/local/bin/
-COPY --from=backend /etc/ssl/certs /etc/ssl/certs
-
-ENV OPENSSL_CONF=/etc/ssl/
-ENV GOGC=50
-ENV AWS_PRODUCT_ID="prod-n4dmmye4e6hjo"
-
-CMD ["--port", "8080", "--data", "/var/opt/bytebase"]
-
-HEALTHCHECK --interval=5m --timeout=60s CMD curl -f http://localhost:8080/healthz || exit 1
-
-ENTRYPOINT ["bytebase"]
diff --git a/scripts/build_bytebase_aws.sh b/scripts/build_bytebase_aws.sh
deleted file mode 100755
index 1571fbc367..0000000000
--- a/scripts/build_bytebase_aws.sh
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/sh
-# ===========================================================================
-# File: build_bytebase_aws.sh
-# Description: usage: ./build_bytebase_aws.sh
-# ===========================================================================
-
-# exit when any command fails
-set -e
-
-cd "$(dirname "$0")/../"
-. ./scripts/build_init.sh
-
-echo "Start building Bytebase docker image ${VERSION}..."
-
-docker build -f ./scripts/Dockerfile.aws \
- --build-arg VERSION="${VERSION}" \
- --build-arg GIT_COMMIT=${GIT_COMMIT}" \
- -t bytebase/bytebase .
-
-echo "${GREEN}Completed building Bytebase docker image ${VERSION}.${NC}"
-echo ""
-echo "Command to tag and push the image"
-echo ""
-echo "$ docker tag bytebase/bytebase bytebase/bytebase:${VERSION}; docker push bytebase/bytebase:${VERSION}"
-echo ""
-echo "Command to start Bytebase on port 8080"
-echo ""
-echo "$ docker run --init --name bytebase --restart always --publish 8080:8080 --volume ~/.bytebase/data:/var/opt/bytebase bytebase/bytebase:${VERSION} --data /var/opt/bytebase --port 8080"
-echo ""