Use subnet package in pkg for license validation (#4784)

Most of the code related to license validation is now available in
`minio/pkg`. So remove it from mc and use the function(s) from `pkg`.
This commit is contained in:
Shireesh Anjal
2023-12-11 09:06:09 -08:00
committed by GitHub
parent 1ba9435365
commit bb65ba8874
3 changed files with 16 additions and 78 deletions
+13 -73
View File
@@ -38,6 +38,7 @@ import (
"github.com/minio/madmin-go/v3"
"github.com/minio/mc/pkg/probe"
"github.com/minio/pkg/v2/licverifier"
"github.com/minio/pkg/v2/subnet"
"github.com/tidwall/gjson"
"golang.org/x/term"
)
@@ -49,43 +50,14 @@ const (
minioDeploymentIDHeader = "x-minio-deployment-id"
)
var (
// https://subnet.min.io/downloads/license-pubkey.pem
subnetPublicKeyProd = `-----BEGIN PUBLIC KEY-----
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEaK31xujr6/rZ7ZfXZh3SlwovjC+X8wGq
qkltaKyTLRENd4w3IRktYYCRgzpDLPn/nrf7snV/ERO5qcI7fkEES34IVEr+2Uff
JkO2PfyyAYEO/5dBlPh1Undu9WQl6J7B
-----END PUBLIC KEY-----`
// https://localhost:9000/downloads/license-pubkey.pem
subnetPublicKeyDev = `-----BEGIN PUBLIC KEY-----
MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEbo+e1wpBY4tBq9AONKww3Kq7m6QP/TBQ
mr/cKCUyBL7rcAvg0zNq1vcSrUSGlAmY3SEDCu3GOKnjG/U4E7+p957ocWSV+mQU
9NKlTdQFGF3+aO6jbQ4hX/S5qPyF+a3z
-----END PUBLIC KEY-----`
subnetCommonFlags = append(supportGlobalFlags, cli.StringFlag{
Name: "api-key",
Usage: "API Key of the account on SUBNET",
EnvVar: "_MC_SUBNET_API_KEY",
})
)
func subnetOfflinePublicKey() string {
if globalDevMode {
return subnetPublicKeyDev
}
return subnetPublicKeyProd
}
var subnetCommonFlags = append(supportGlobalFlags, cli.StringFlag{
Name: "api-key",
Usage: "API Key of the account on SUBNET",
EnvVar: "_MC_SUBNET_API_KEY",
})
func subnetBaseURL() string {
if globalDevMode {
subnetURLDev := os.Getenv("SUBNET_URL_DEV")
if len(subnetURLDev) > 0 {
return subnetURLDev
}
return "http://localhost:9000"
}
return "https://subnet.min.io"
return subnet.BaseURL(globalDevMode)
}
func subnetLogWebhookURL() string {
@@ -655,47 +627,15 @@ func extractSubnetCred(key string, resp gjson.Result) (string, error) {
return result.String(), nil
}
// downloadSubnetPublicKey will download the current subnet public key.
func downloadSubnetPublicKey() (string, error) {
// Get the public key directly from Subnet
url := fmt.Sprintf("%s%s", subnetBaseURL(), subnetPublicKeyPath)
resp, err := getSubnetClient().Get(url)
if err != nil {
return "", err
}
defer resp.Body.Close()
buf := new(bytes.Buffer)
_, err = buf.ReadFrom(resp.Body)
if err != nil {
return "", err
}
return buf.String(), err
}
// parseLicense parses the license with the bundle public key and return it's information
func parseLicense(license string) (*licverifier.LicenseInfo, error) {
var publicKey string
if globalAirgapped {
publicKey = subnetOfflinePublicKey()
} else {
subnetPubKey, e := downloadSubnetPublicKey()
if e != nil {
// there was an issue getting the subnet public key
// use hardcoded public keys instead
publicKey = subnetOfflinePublicKey()
} else {
publicKey = subnetPubKey
}
client := getSubnetClient()
lv := subnet.LicenseValidator{
Client: *client,
ExpiryGracePeriod: 0,
}
lv, e := licverifier.NewLicenseVerifier([]byte(publicKey))
if e != nil {
return nil, e
}
li, e := lv.Verify(license)
return &li, e
lv.Init(globalDevMode)
return lv.ParseLicense(license)
}
func prepareSubnetUploadURL(uploadURL, alias, apiKey string) (string, map[string]string) {
+1 -1
View File
@@ -47,7 +47,7 @@ require (
github.com/golang-jwt/jwt/v4 v4.5.0
github.com/juju/ratelimit v1.0.2
github.com/minio/madmin-go/v3 v3.0.34
github.com/minio/pkg/v2 v2.0.4
github.com/minio/pkg/v2 v2.0.5
github.com/muesli/reflow v0.3.0
github.com/navidys/tvxwidgets v0.3.0
github.com/olekukonko/tablewriter v0.0.5
+2 -4
View File
@@ -144,14 +144,12 @@ github.com/minio/madmin-go/v3 v3.0.34 h1:MGPQYIWm52liSubofK24FhrznPYnRpQrDNddZJE
github.com/minio/madmin-go/v3 v3.0.34/go.mod h1:4QN2NftLSV7MdlT50dkrenOMmNVHluxTvlqJou3hte8=
github.com/minio/md5-simd v1.1.2 h1:Gdi1DZK69+ZVMoNHRXJyNcxrMA4dSxoYHZSQbirFg34=
github.com/minio/md5-simd v1.1.2/go.mod h1:MzdKDxYpY2BT9XQFocsiZf/NKVtR7nkE4RoEpN+20RM=
github.com/minio/minio-go/v7 v7.0.65-0.20231122233251-1f7dd6b7e3e1 h1:oGua0HckYk7JuIW/c1IuInHe9MCef1U6Q2Qf9ea/V5U=
github.com/minio/minio-go/v7 v7.0.65-0.20231122233251-1f7dd6b7e3e1/go.mod h1:R4WVUR6ZTedlCcGwZRauLMIKjgyaWxhs4Mqi/OMPmEc=
github.com/minio/minio-go/v7 v7.0.65-0.20231130060928-54e115c40e66 h1:9pgbcTmr0yvwlQJHsS72QDyNkZajKXCxnszpJtM5B4I=
github.com/minio/minio-go/v7 v7.0.65-0.20231130060928-54e115c40e66/go.mod h1:R4WVUR6ZTedlCcGwZRauLMIKjgyaWxhs4Mqi/OMPmEc=
github.com/minio/mux v1.9.0 h1:dWafQFyEfGhJvK6AwLOt83bIG5bxKxKJnKMCi0XAaoA=
github.com/minio/mux v1.9.0/go.mod h1:1pAare17ZRL5GpmNL+9YmqHoWnLmMZF9C/ioUCfy0BQ=
github.com/minio/pkg/v2 v2.0.4 h1:vHQOqxD7AdsJq3X9GylO0PO6WCpcK7aePsVfk0oRYh0=
github.com/minio/pkg/v2 v2.0.4/go.mod h1:ya1jPY/rtVp3HarxwDQJkclR8Rd2QxwxA9kwS436ovs=
github.com/minio/pkg/v2 v2.0.5 h1:I5LGA7rMwo/T8qRp3UDoPCZKtnUHDBoXP025TvxUqCc=
github.com/minio/pkg/v2 v2.0.5/go.mod h1:ya1jPY/rtVp3HarxwDQJkclR8Rd2QxwxA9kwS436ovs=
github.com/minio/selfupdate v0.6.0 h1:i76PgT0K5xO9+hjzKcacQtO7+MjJ4JKA8Ak8XQ9DDwU=
github.com/minio/selfupdate v0.6.0/go.mod h1:bO02GTIPCMQFTEvE5h4DjYB58bCoZ35XLeBf0buTDdM=
github.com/minio/sha256-simd v1.0.1 h1:6kaan5IFmwTNynnKKpDHe6FWHohJOHhCPchzK49dzMM=