Skip to content

Commit 4bbda55

Browse files
committed
Invalidate license cache if feature flags mismatchs
Signed-off-by: Imtiaz Uddin <[email protected]>
1 parent 5a4b1f6 commit 4bbda55

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

pkg/server/issuer.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"encoding/json"
2323
"fmt"
2424
"path"
25+
"reflect"
26+
"strings"
2527
"time"
2628

2729
licenseapi "go.bytebuilders.dev/license-verifier/apis/licenses/v1alpha1"
@@ -74,7 +76,7 @@ func IssueEnterpriseLicense(fs blobfs.Interface, certs *certstore.CertStore, inf
7476
Product: info.Product(),
7577
Agreement: &LicenseAgreement{
7678
NumClusters: 1, // is not used currently
77-
ExpiryDate: metav1.NewTime(time.Now().Add(extendBy).UTC()),
79+
ExpiryDate: metav1.NewTime(time.Now().Add(extendBy).UTC().Truncate(time.Second)),
7880
},
7981
}
8082

@@ -96,7 +98,17 @@ func IssueEnterpriseLicense(fs blobfs.Interface, certs *certstore.CertStore, inf
9698
return nil, nil, fmt.Errorf("multiple certificates found in %s", license.LicenseCertPath(info.Cluster))
9799
}
98100

99-
if !certs[0].NotAfter.Before(license.Agreement.ExpiryDate.Time) {
101+
existingFeatureFlags := licenseapi.FeatureFlags{}
102+
for _, ff := range certs[0].Subject.Locality {
103+
parts := strings.SplitN(ff, "=", 2)
104+
if len(parts) == 2 {
105+
existingFeatureFlags[licenseapi.FeatureFlag(parts[0])] = parts[1]
106+
}
107+
}
108+
109+
if !certs[0].NotAfter.Before(license.Agreement.ExpiryDate.Time) &&
110+
reflect.DeepEqual(existingFeatureFlags, ff) {
111+
100112
// Original license is sufficiently valid. Keep using that.
101113
crtLicense = cert.EncodeCertPEM(certs[0])
102114
license.Agreement.ExpiryDate = metav1.NewTime(certs[0].NotAfter.UTC())

0 commit comments

Comments
 (0)