From 7b20dc2958472a86bece2bb87d082b48ff29fb95 Mon Sep 17 00:00:00 2001
From: Shireesh Anjal <355479+anjalshireesh@users.noreply.github.com>
Date: Thu, 14 Jul 2022 06:55:30 +0530
Subject: [PATCH] Move `support register` to `license register` (#4150)
Also, introduce a new command `license info` to print information
from the license (when the license is available)
---
cmd/auto-complete.go | 3 +
cmd/license-info.go | 216 ++++++++++++++++++++++++++++++++++++
cmd/license-register.go | 240 ++++++++++++++++++++++++++++++++++++++++
cmd/license.go | 44 ++++++++
cmd/main.go | 1 +
cmd/subnet-utils.go | 112 +++++++++++++++----
cmd/support-register.go | 207 ++--------------------------------
cmd/support-status.go | 99 -----------------
cmd/support.go | 6 +-
go.mod | 2 +-
go.sum | 8 +-
11 files changed, 606 insertions(+), 332 deletions(-)
create mode 100644 cmd/license-info.go
create mode 100644 cmd/license-register.go
create mode 100644 cmd/license.go
delete mode 100644 cmd/support-status.go
diff --git a/cmd/auto-complete.go b/cmd/auto-complete.go
index a190cc8c..3d659c2a 100644
--- a/cmd/auto-complete.go
+++ b/cmd/auto-complete.go
@@ -430,6 +430,9 @@ var completeCmds = map[string]complete.Predictor{
"/support/metrics": aliasCompleter,
"/support/status": aliasCompleter,
+ "/license/register": aliasCompleter,
+ "/license/info": aliasCompleter,
+
"/update": nil,
"/ready": nil,
"/ping": nil,
diff --git a/cmd/license-info.go b/cmd/license-info.go
new file mode 100644
index 00000000..747d2d49
--- /dev/null
+++ b/cmd/license-info.go
@@ -0,0 +1,216 @@
+// Copyright (c) 2015-2022 MinIO, Inc.
+//
+// This file is part of MinIO Object Storage stack
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+
+package cmd
+
+import (
+ "fmt"
+ "strings"
+ "time"
+
+ "github.com/fatih/color"
+ "github.com/minio/cli"
+ json "github.com/minio/colorjson"
+ "github.com/minio/mc/pkg/probe"
+ "github.com/minio/pkg/console"
+ "github.com/olekukonko/tablewriter"
+)
+
+var licenseInfoCmd = cli.Command{
+ Name: "info",
+ Usage: "display license information",
+ OnUsageError: onUsageError,
+ Action: mainLicenseInfo,
+ Before: setGlobalsFromContext,
+ Flags: append(globalFlags, subnetCommonFlags...),
+ CustomHelpTemplate: `NAME:
+ {{.HelpName}} - {{.Usage}}
+
+USAGE:
+ {{.HelpName}} ALIAS
+
+FLAGS:
+ {{range .VisibleFlags}}{{.}}
+ {{end}}
+
+EXAMPLES:
+ 1. Display license configuration for cluster with alias 'play'
+ {{.Prompt}} {{.HelpName}} play
+`,
+}
+
+const (
+ licInfoMsgTag = "licenseInfoMessage"
+ licInfoErrTag = "licenseInfoError"
+ licInfoFieldTag = "licenseInfoField"
+ licInfoValTag = "licenseValueField"
+)
+
+type licInfoMessage struct {
+ Status string `json:"status"`
+ Info licInfo `json:"info,omitempty"`
+ Error string `json:"error,omitempty"`
+}
+
+type licInfo struct {
+ Organization string `json:"org,omitempty"` // Subnet organization name
+ Plan string `json:"plan,omitempty"` // Subnet plan
+ IssuedAt *time.Time `json:"issued_at,omitempty"` // Time of license issue
+ ExpiresAt *time.Time `json:"expires_at,omitempty"` // Time of license expiry
+ DeploymentID string `json:"deployment_id,omitempty"` // Cluster deployment ID
+ Message string `json:"message,omitempty"` // Message to be displayed
+}
+
+func licInfoField(s string) string {
+ return console.Colorize(licInfoFieldTag, s)
+}
+
+func licInfoVal(s string) string {
+ return console.Colorize(licInfoValTag, s)
+}
+
+func licInfoMsg(s string) string {
+ return console.Colorize(licInfoMsgTag, s)
+}
+
+func licInfoErr(s string) string {
+ return console.Colorize(licInfoErrTag, s)
+}
+
+// String colorized license info
+func (li licInfoMessage) String() string {
+ if len(li.Error) > 0 {
+ return licInfoErr(li.Error)
+ }
+
+ if len(li.Info.Message) > 0 {
+ return licInfoMsg(li.Info.Message)
+ }
+
+ return licInfoMsg(getLicInfoStr(li.Info))
+}
+
+// JSON jsonified license info
+func (li licInfoMessage) JSON() string {
+ jsonBytes, e := json.MarshalIndent(li, "", " ")
+ fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
+
+ return string(jsonBytes)
+}
+
+func getLicInfoStr(li licInfo) string {
+ var s strings.Builder
+
+ s.WriteString(color.WhiteString(""))
+ table := tablewriter.NewWriter(&s)
+ table.SetAutoWrapText(false)
+ table.SetHeaderAlignment(tablewriter.ALIGN_LEFT)
+ table.SetAlignment(tablewriter.ALIGN_LEFT)
+ table.SetBorder(true)
+ table.SetRowLine(false)
+
+ data := [][]string{
+ {licInfoField("Organization"), licInfoVal(li.Organization)},
+ {licInfoField("Deployment ID"), licInfoVal(li.DeploymentID)},
+ {licInfoField("Plan"), licInfoVal(li.Plan)},
+ {licInfoField("Issued at"), licInfoVal(li.IssuedAt.String())},
+ {licInfoField("Expires at"), licInfoVal(li.ExpiresAt.String())},
+ }
+ table.AppendBulk(data)
+ table.Render()
+
+ return s.String()
+}
+
+func getAGPLMessage() string {
+ return `You are using GNU AFFERO GENERAL PUBLIC LICENSE Verson 3 (https://www.gnu.org/licenses/agpl-3.0.txt)
+
+If you are building proprietary applications, you may want to choose the commercial license
+included as part of the Standard and Enterprise subscription plans. (https://min.io/signup?ref=mc)
+
+Applications must otherwise comply with all the GNU AGPLv3 License & Trademark obligations.`
+}
+
+func initLicInfoColors() {
+ console.SetColor(licInfoMsgTag, color.New(color.FgGreen, color.Bold))
+ console.SetColor(licInfoErrTag, color.New(color.FgRed, color.Bold))
+ console.SetColor(licInfoFieldTag, color.New(color.FgCyan))
+ console.SetColor(licInfoValTag, color.New(color.FgWhite))
+}
+
+func mainLicenseInfo(ctx *cli.Context) error {
+ if len(ctx.Args()) != 1 {
+ cli.ShowCommandHelpAndExit(ctx, "info", 1) // last argument is exit code
+ }
+
+ initLicInfoColors()
+
+ aliasedURL := ctx.Args().Get(0)
+ alias, _ := url2Alias(aliasedURL)
+
+ apiKey, lic, e := getSubnetCreds(alias)
+ fatalIf(probe.NewError(e), "Error in checking cluster registration status")
+
+ if len(apiKey) == 0 && len(lic) == 0 {
+ // Not registered. Default to AGPLv3
+ printMsg(licInfoMessage{
+ Status: "success",
+ Info: licInfo{
+ Plan: "AGPLv3",
+ Message: getAGPLMessage(),
+ },
+ })
+ return nil
+ }
+
+ var ssm licInfoMessage
+ if len(lic) > 0 {
+ // If set, the subnet public key will not be downloaded from subnet
+ // and the offline key embedded in mc will be used.
+ airgap := ctx.Bool("airgap")
+
+ li, e := parseLicense(lic, airgap)
+ if e != nil {
+ ssm = licInfoMessage{
+ Status: "error",
+ Error: e.Error(),
+ }
+ } else {
+ ssm = licInfoMessage{
+ Status: "success",
+ Info: licInfo{
+ Organization: li.Organization,
+ Plan: li.Plan,
+ IssuedAt: &li.IssuedAt,
+ ExpiresAt: &li.ExpiresAt,
+ DeploymentID: li.DeploymentID,
+ },
+ }
+ }
+ } else {
+ // Only api key is available, no license info
+ ssm = licInfoMessage{
+ Status: "success",
+ Info: licInfo{
+ Message: fmt.Sprintf("%s is registered with SUBNET. License info not available.", alias),
+ },
+ }
+ }
+
+ printMsg(ssm)
+ return nil
+}
diff --git a/cmd/license-register.go b/cmd/license-register.go
new file mode 100644
index 00000000..f2457ee4
--- /dev/null
+++ b/cmd/license-register.go
@@ -0,0 +1,240 @@
+// Copyright (c) 2015-2022 MinIO, Inc.
+//
+// This file is part of MinIO Object Storage stack
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+
+package cmd
+
+import (
+ "bufio"
+ "errors"
+ "fmt"
+ "os"
+ "strings"
+
+ "github.com/fatih/color"
+ "github.com/golang-jwt/jwt/v4"
+ "github.com/google/uuid"
+ "github.com/minio/cli"
+ "github.com/minio/mc/pkg/probe"
+ "github.com/minio/pkg/console"
+)
+
+var licenseRegisterFlags = append([]cli.Flag{
+ cli.StringFlag{
+ Name: "api-key",
+ Usage: "SUBNET API key",
+ },
+ cli.StringFlag{
+ Name: "name",
+ Usage: "Specify the name to associate to this MinIO cluster in SUBNET",
+ },
+}, subnetCommonFlags...)
+
+var licenseRegisterCmd = cli.Command{
+ Name: "register",
+ Usage: "register with MinIO Subscription Network",
+ OnUsageError: onUsageError,
+ Action: mainLicenseRegister,
+ Before: setGlobalsFromContext,
+ Flags: append(licenseRegisterFlags, globalFlags...),
+ CustomHelpTemplate: `NAME:
+ {{.HelpName}} - {{.Usage}}
+
+USAGE:
+ {{.HelpName}} TARGET
+
+FLAGS:
+ {{range .VisibleFlags}}{{.}}
+ {{end}}
+EXAMPLES:
+ 1. Register MinIO cluster at alias 'play' on SUBNET, using alias as the cluster name.
+ {{.Prompt}} {{.HelpName}} play
+
+ 2. Register MinIO cluster at alias 'play' on SUBNET, using the name "play-cluster".
+ {{.Prompt}} {{.HelpName}} play --name play-cluster
+`,
+}
+
+// checklicenseRegisterSyntax - validate arguments passed by a user
+func checklicenseRegisterSyntax(ctx *cli.Context) {
+ if len(ctx.Args()) == 0 || len(ctx.Args()) > 1 {
+ cli.ShowCommandHelpAndExit(ctx, "register", 1) // last argument is exit code
+ }
+}
+
+// ClusterRegistrationReq - JSON payload of the subnet api for cluster registration
+// Contains a registration token created by base64 encoding of the registration info
+type ClusterRegistrationReq struct {
+ Token string `json:"token"`
+}
+
+// ClusterRegistrationInfo - Information stored in the cluster registration token
+type ClusterRegistrationInfo struct {
+ DeploymentID string `json:"deployment_id"`
+ ClusterName string `json:"cluster_name"`
+ UsedCapacity uint64 `json:"used_capacity"`
+ Info ClusterInfo `json:"info"`
+}
+
+// ClusterInfo - The "info" sub-node of the cluster registration information struct
+// Intended to be extensible i.e. more fields will be added as and when required
+type ClusterInfo struct {
+ MinioVersion string `json:"minio_version"`
+ NoOfServerPools int `json:"no_of_server_pools"`
+ NoOfServers int `json:"no_of_servers"`
+ NoOfDrives int `json:"no_of_drives"`
+ NoOfBuckets uint64 `json:"no_of_buckets"`
+ NoOfObjects uint64 `json:"no_of_objects"`
+ TotalDriveSpace uint64 `json:"total_drive_space"`
+ UsedDriveSpace uint64 `json:"used_drive_space"`
+}
+
+// SubnetLoginReq - JSON payload of the SUBNET login api
+type SubnetLoginReq struct {
+ Username string `json:"username"`
+ Password string `json:"password"`
+}
+
+// SubnetMFAReq - JSON payload of the SUBNET mfa api
+type SubnetMFAReq struct {
+ Username string `json:"username"`
+ OTP string `json:"otp"`
+ Token string `json:"token"`
+}
+
+func validateAPIKey(apiKey string, offline bool) error {
+ if offline {
+ return errors.New("--api-key is not applicable in airgap mode")
+ }
+
+ _, e := uuid.Parse(apiKey)
+ if e != nil {
+ return e
+ }
+
+ return nil
+}
+
+func mainLicenseRegister(ctx *cli.Context) error {
+ console.SetColor("RegisterSuccessMessage", color.New(color.FgGreen, color.Bold))
+ checklicenseRegisterSyntax(ctx)
+
+ // Get the alias parameter from cli
+ aliasedURL := ctx.Args().Get(0)
+
+ offline := ctx.Bool("airgap") || ctx.Bool("offline")
+ if !offline {
+ fatalIf(checkURLReachable(subnetBaseURL()).Trace(aliasedURL), "Unable to reach %s register", subnetBaseURL())
+ }
+
+ accAPIKey := ctx.String("api-key")
+ if len(accAPIKey) > 0 {
+ e := validateAPIKey(accAPIKey, offline)
+ fatalIf(probe.NewError(e), "unable to parse input values")
+ }
+
+ // Create a new MinIO Admin Client
+ client := getClient(aliasedURL)
+
+ // Fetch info of all servers (cluster or single server)
+ admInfo, e := client.ServerInfo(globalContext)
+ fatalIf(probe.NewError(e), "Unable to fetch cluster info")
+
+ alias, _ := url2Alias(aliasedURL)
+ clusterName := ctx.String("name")
+ if len(clusterName) == 0 {
+ clusterName = alias
+ } else {
+ if offline {
+ fatalIf(errInvalidArgument(), "'--name' is not allowed in airgapped mode")
+ }
+ }
+
+ regInfo := getClusterRegInfo(admInfo, clusterName)
+
+ alreadyRegistered := false
+ apiKey, lic, e := getSubnetCreds(alias)
+ fatalIf(probe.NewError(e), "Error in fetching subnet credentials")
+ if len(apiKey) > 0 || len(lic) > 0 {
+ alreadyRegistered = true
+ }
+
+ if offline {
+ registerOffline(regInfo, alias)
+ } else {
+ registerOnline(regInfo, alias, accAPIKey)
+ }
+
+ action := "registered"
+ if alreadyRegistered {
+ action = "updated"
+ }
+
+ msg := console.Colorize("RegisterSuccessMessage", fmt.Sprintf("%s %s successfully.", clusterName, action))
+ fmt.Println(msg)
+ return nil
+}
+
+func registerOffline(clusterRegInfo ClusterRegistrationInfo, alias string) {
+ regToken, e := generateRegToken(clusterRegInfo)
+ fatalIf(probe.NewError(e), "Unable to generate registration token")
+
+ subnetRegisterPageURL := "https://subnet.min.io/cluster/register"
+
+ fmt.Print(`Step 1: Use the following token to register your cluster at ` + subnetRegisterPageURL + `
+
+` + regToken + `
+
+Step 2: Enter the key generated by SUBNET: `)
+
+ reader := bufio.NewReader(os.Stdin)
+ key, e := reader.ReadString('\n')
+ fatalIf(probe.NewError(e), "Error in reading the key")
+ key = strings.TrimSpace(key)
+
+ if len(key) > 0 {
+ _, e := uuid.Parse(key)
+ if e == nil {
+ // key is the api key
+ setSubnetCreds(alias, key, "")
+ return
+ }
+
+ // Not api-key (uuid). Must be license (jwt)
+ _, _, e = new(jwt.Parser).ParseUnverified(key, jwt.MapClaims{})
+ if e != nil {
+ fatalIf(probe.NewError(e), "Invalid key specified:")
+ }
+ setSubnetCreds(alias, "", key)
+ } else {
+ console.Fatalln("Invalid key specified. Please run the command again with a valid key to complete registration.")
+ }
+}
+
+func registerOnline(clusterRegInfo ClusterRegistrationInfo, alias string, accAPIKey string) {
+ var resp string
+ var e error
+
+ if len(accAPIKey) > 0 {
+ resp, e = registerClusterWithSubnetCreds(clusterRegInfo, accAPIKey, "")
+ } else {
+ resp, e = registerClusterOnSubnet(alias, clusterRegInfo)
+ }
+
+ fatalIf(probe.NewError(e), "Could not register cluster with SUBNET:")
+
+ extractAndSaveSubnetCreds(alias, resp)
+}
diff --git a/cmd/license.go b/cmd/license.go
new file mode 100644
index 00000000..6ec13313
--- /dev/null
+++ b/cmd/license.go
@@ -0,0 +1,44 @@
+// Copyright (c) 2015-2022 MinIO, Inc.
+//
+// This file is part of MinIO Object Storage stack
+//
+// This program is free software: you can redistribute it and/or modify
+// it under the terms of the GNU Affero General Public License as published by
+// the Free Software Foundation, either version 3 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU Affero General Public License for more details.
+//
+// You should have received a copy of the GNU Affero General Public License
+// along with this program. If not, see .
+
+package cmd
+
+import (
+ "github.com/minio/cli"
+)
+
+var licenseSubcommands = []cli.Command{
+ licenseRegisterCmd,
+ licenseInfoCmd,
+}
+
+var licenseCmd = cli.Command{
+ Name: "license",
+ Usage: "license related commands",
+ Action: mainlicense,
+ Before: setGlobalsFromContext,
+ Flags: globalFlags,
+ Subcommands: licenseSubcommands,
+ HideHelpCommand: true,
+}
+
+// mainlicense is the handle for "mc license" command.
+func mainlicense(ctx *cli.Context) error {
+ commandNotFound(ctx, licenseSubcommands)
+ return nil
+ // Sub-commands like "register", "info" have their own main.
+}
diff --git a/cmd/main.go b/cmd/main.go
index a898e0ae..f9a4a4ee 100644
--- a/cmd/main.go
+++ b/cmd/main.go
@@ -435,6 +435,7 @@ var appCmds = []cli.Command{
retentionCmd,
legalHoldCmd,
supportCmd,
+ licenseCmd,
shareCmd,
versionCmd,
ilmCmd,
diff --git a/cmd/subnet-utils.go b/cmd/subnet-utils.go
index 411be805..85991e05 100644
--- a/cmd/subnet-utils.go
+++ b/cmd/subnet-utils.go
@@ -36,6 +36,7 @@ import (
"github.com/minio/cli"
"github.com/minio/madmin-go"
"github.com/minio/mc/pkg/probe"
+ "github.com/minio/pkg/licverifier"
"github.com/tidwall/gjson"
"golang.org/x/crypto/ssh/terminal"
)
@@ -43,24 +44,44 @@ import (
const (
subnetRespBodyLimit = 1 << 20 // 1 MiB
minioSubscriptionURL = "https://min.io/subscription"
+ subnetPublicKeyPath = "/downloads/license-pubkey.pem"
)
-var subnetCommonFlags = []cli.Flag{
- cli.BoolFlag{
- Name: "airgap",
- Usage: "Use in environments without network access to SUBNET (e.g. airgapped, firewalled, etc.)",
- },
- cli.BoolFlag{
- Name: "dev",
- Usage: "Development mode - talks to local SUBNET",
- Hidden: true,
- },
- cli.BoolFlag{
- // Deprecated Oct 2021. Same as airgap, retaining as hidden for backward compatibility
- Name: "offline",
- Usage: "Use in environments without network access to SUBNET (e.g. airgapped, firewalled, etc.)",
- Hidden: true,
- },
+var (
+ subnetPublicKeyProd = `-----BEGIN PUBLIC KEY-----
+MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEaK31xujr6/rZ7ZfXZh3SlwovjC+X8wGq
+qkltaKyTLRENd4w3IRktYYCRgzpDLPn/nrf7snV/ERO5qcI7fkEES34IVEr+2Uff
+JkO2PfyyAYEO/5dBlPh1Undu9WQl6J7B
+-----END PUBLIC KEY-----` // https://subnet.min.io/downloads/license-pubkey.pem
+ subnetPublicKeyDev = `-----BEGIN PUBLIC KEY-----
+MHYwEAYHKoZIzj0CAQYFK4EEACIDYgAEbo+e1wpBY4tBq9AONKww3Kq7m6QP/TBQ
+mr/cKCUyBL7rcAvg0zNq1vcSrUSGlAmY3SEDCu3GOKnjG/U4E7+p957ocWSV+mQU
+9NKlTdQFGF3+aO6jbQ4hX/S5qPyF+a3z
+-----END PUBLIC KEY-----` // https://localhost:9000/downloads/license-pubkey.pem
+ subnetCommonFlags = []cli.Flag{
+ cli.BoolFlag{
+ Name: "airgap",
+ Usage: "Use in environments without network access to SUBNET (e.g. airgapped, firewalled, etc.)",
+ },
+ cli.BoolFlag{
+ Name: "dev",
+ Usage: "Development mode - talks to local SUBNET",
+ Hidden: true,
+ },
+ cli.BoolFlag{
+ // Deprecated Oct 2021. Same as airgap, retaining as hidden for backward compatibility
+ Name: "offline",
+ Usage: "Use in environments without network access to SUBNET (e.g. airgapped, firewalled, etc.)",
+ Hidden: true,
+ },
+ }
+)
+
+func subnetOfflinePublicKey() string {
+ if globalDevMode {
+ return subnetPublicKeyDev
+ }
+ return subnetPublicKeyProd
}
func subnetBaseURL() string {
@@ -143,12 +164,16 @@ func subnetAuthHeaders(authToken string) map[string]string {
return map[string]string{"Authorization": "Bearer " + authToken}
}
-func subnetHTTPDo(req *http.Request) (*http.Response, error) {
+func getSubnetClient() *http.Client {
client := httpClient(10 * time.Second)
if globalSubnetProxyURL != nil {
client.Transport.(*http.Transport).Proxy = http.ProxyURL(globalSubnetProxyURL)
}
- return client.Do(req)
+ return client
+}
+
+func subnetHTTPDo(req *http.Request) (*http.Response, error) {
+ return getSubnetClient().Do(req)
}
func subnetReqDo(r *http.Request, headers map[string]string) (string, error) {
@@ -484,11 +509,11 @@ func getSubnetCreds(alias string) (string, string, error) {
return "", "", e
}
- apiKey := getSubnetAPIKeyFromConfig(alias)
+ lic := getSubnetLicenseFromConfig(alias)
- lic := ""
- if len(apiKey) == 0 {
- lic = getSubnetLicenseFromConfig(alias)
+ apiKey := ""
+ if len(lic) == 0 {
+ apiKey = getSubnetAPIKeyFromConfig(alias)
}
return apiKey, lic, nil
@@ -502,3 +527,46 @@ func extractAndSaveSubnetCreds(alias string, resp string) {
setSubnetCreds(alias, subnetAPIKey, subnetLic)
}
}
+
+// 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, airgap bool) (*licverifier.LicenseInfo, error) {
+ var publicKey string
+
+ if airgap {
+ 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
+ }
+ }
+
+ lv, e := licverifier.NewLicenseVerifier([]byte(publicKey))
+ if e != nil {
+ return nil, e
+ }
+
+ li, e := lv.Verify(license)
+ return &li, e
+}
diff --git a/cmd/support-register.go b/cmd/support-register.go
index 09581844..56c3aa6d 100644
--- a/cmd/support-register.go
+++ b/cmd/support-register.go
@@ -18,17 +18,7 @@
package cmd
import (
- "bufio"
- "errors"
- "fmt"
- "os"
- "strings"
-
- "github.com/fatih/color"
- "github.com/golang-jwt/jwt/v4"
- "github.com/google/uuid"
"github.com/minio/cli"
- "github.com/minio/mc/pkg/probe"
"github.com/minio/pkg/console"
)
@@ -44,197 +34,16 @@ var supportRegisterFlags = append([]cli.Flag{
}, subnetCommonFlags...)
var supportRegisterCmd = cli.Command{
- Name: "register",
- Usage: "register with MinIO subscription network",
- OnUsageError: onUsageError,
- Action: mainSupportRegister,
- Before: setGlobalsFromContext,
- Flags: append(supportRegisterFlags, globalFlags...),
- CustomHelpTemplate: `NAME:
- {{.HelpName}} - {{.Usage}}
-
-USAGE:
- {{.HelpName}} TARGET
-
-FLAGS:
- {{range .VisibleFlags}}{{.}}
- {{end}}
-EXAMPLES:
- 1. Register MinIO cluster at alias 'play' on SUBNET, using alias as the cluster name.
- {{.Prompt}} {{.HelpName}} play
-
- 2. Register MinIO cluster at alias 'play' on SUBNET, using the name "play-cluster".
- {{.Prompt}} {{.HelpName}} play --name play-cluster
-`,
-}
-
-// checkSupportRegisterSyntax - validate arguments passed by a user
-func checkSupportRegisterSyntax(ctx *cli.Context) {
- if len(ctx.Args()) == 0 || len(ctx.Args()) > 1 {
- cli.ShowCommandHelpAndExit(ctx, "register", 1) // last argument is exit code
- }
-}
-
-// ClusterRegistrationReq - JSON payload of the subnet api for cluster registration
-// Contains a registration token created by base64 encoding of the registration info
-type ClusterRegistrationReq struct {
- Token string `json:"token"`
-}
-
-// ClusterRegistrationInfo - Information stored in the cluster registration token
-type ClusterRegistrationInfo struct {
- DeploymentID string `json:"deployment_id"`
- ClusterName string `json:"cluster_name"`
- UsedCapacity uint64 `json:"used_capacity"`
- Info ClusterInfo `json:"info"`
-}
-
-// ClusterInfo - The "info" sub-node of the cluster registration information struct
-// Intended to be extensible i.e. more fields will be added as and when required
-type ClusterInfo struct {
- MinioVersion string `json:"minio_version"`
- NoOfServerPools int `json:"no_of_server_pools"`
- NoOfServers int `json:"no_of_servers"`
- NoOfDrives int `json:"no_of_drives"`
- NoOfBuckets uint64 `json:"no_of_buckets"`
- NoOfObjects uint64 `json:"no_of_objects"`
- TotalDriveSpace uint64 `json:"total_drive_space"`
- UsedDriveSpace uint64 `json:"used_drive_space"`
-}
-
-// SubnetLoginReq - JSON payload of the SUBNET login api
-type SubnetLoginReq struct {
- Username string `json:"username"`
- Password string `json:"password"`
-}
-
-// SubnetMFAReq - JSON payload of the SUBNET mfa api
-type SubnetMFAReq struct {
- Username string `json:"username"`
- OTP string `json:"otp"`
- Token string `json:"token"`
-}
-
-func validateAPIKey(apiKey string, offline bool) error {
- if offline {
- return errors.New("--api-key is not applicable in airgap mode")
- }
-
- _, e := uuid.Parse(apiKey)
- if e != nil {
- return e
- }
-
- return nil
+ Name: "register",
+ Usage: "register with MinIO subscription network",
+ OnUsageError: onUsageError,
+ Action: mainSupportRegister,
+ Before: setGlobalsFromContext,
+ Flags: append(supportRegisterFlags, globalFlags...),
+ CustomHelpTemplate: "Please use 'mc license register'",
}
func mainSupportRegister(ctx *cli.Context) error {
- console.SetColor("RegisterSuccessMessage", color.New(color.FgGreen, color.Bold))
- checkSupportRegisterSyntax(ctx)
-
- // Get the alias parameter from cli
- aliasedURL := ctx.Args().Get(0)
-
- offline := ctx.Bool("airgap") || ctx.Bool("offline")
- if !offline {
- fatalIf(checkURLReachable(subnetBaseURL()).Trace(aliasedURL), "Unable to reach %s register", subnetBaseURL())
- }
-
- accAPIKey := ctx.String("api-key")
- if len(accAPIKey) > 0 {
- e := validateAPIKey(accAPIKey, offline)
- fatalIf(probe.NewError(e), "unable to parse input values")
- }
-
- // Create a new MinIO Admin Client
- client := getClient(aliasedURL)
-
- // Fetch info of all servers (cluster or single server)
- admInfo, e := client.ServerInfo(globalContext)
- fatalIf(probe.NewError(e), "Unable to fetch cluster info")
-
- alias, _ := url2Alias(aliasedURL)
- clusterName := ctx.String("name")
- if len(clusterName) == 0 {
- clusterName = alias
- } else {
- if offline {
- fatalIf(errInvalidArgument(), "'--name' is not allowed in airgapped mode")
- }
- }
-
- regInfo := getClusterRegInfo(admInfo, clusterName)
-
- alreadyRegistered := false
- apiKey, lic, e := getSubnetCreds(alias)
- fatalIf(probe.NewError(e), "Error in fetching subnet credentials")
- if len(apiKey) > 0 || len(lic) > 0 {
- alreadyRegistered = true
- }
-
- if offline {
- registerOffline(regInfo, alias)
- } else {
- registerOnline(regInfo, alias, accAPIKey)
- }
-
- action := "registered"
- if alreadyRegistered {
- action = "updated"
- }
-
- msg := console.Colorize("RegisterSuccessMessage", fmt.Sprintf("%s %s successfully.", clusterName, action))
- fmt.Println(msg)
+ console.Infoln("Please use 'mc license register'")
return nil
}
-
-func registerOffline(clusterRegInfo ClusterRegistrationInfo, alias string) {
- regToken, e := generateRegToken(clusterRegInfo)
- fatalIf(probe.NewError(e), "Unable to generate registration token")
-
- subnetRegisterPageURL := "https://subnet.min.io/cluster/register"
-
- fmt.Print(`Step 1: Use the following token to register your cluster at ` + subnetRegisterPageURL + `
-
-` + regToken + `
-
-Step 2: Enter the key generated by SUBNET: `)
-
- reader := bufio.NewReader(os.Stdin)
- key, e := reader.ReadString('\n')
- fatalIf(probe.NewError(e), "Error in reading the key")
- key = strings.TrimSpace(key)
-
- if len(key) > 0 {
- _, e := uuid.Parse(key)
- if e == nil {
- // key is the api key
- setSubnetCreds(alias, key, "")
- return
- }
-
- // Not api-key (uuid). Must be license (jwt)
- _, _, e = new(jwt.Parser).ParseUnverified(key, jwt.MapClaims{})
- if e != nil {
- fatalIf(probe.NewError(e), "Invalid key specified:")
- }
- setSubnetCreds(alias, "", key)
- } else {
- console.Fatalln("Invalid key specified. Please run the command again with a valid key to complete registration.")
- }
-}
-
-func registerOnline(clusterRegInfo ClusterRegistrationInfo, alias string, accAPIKey string) {
- var resp string
- var e error
-
- if len(accAPIKey) > 0 {
- resp, e = registerClusterWithSubnetCreds(clusterRegInfo, accAPIKey, "")
- } else {
- resp, e = registerClusterOnSubnet(alias, clusterRegInfo)
- }
-
- fatalIf(probe.NewError(e), "Could not register cluster with SUBNET:")
-
- extractAndSaveSubnetCreds(alias, resp)
-}
diff --git a/cmd/support-status.go b/cmd/support-status.go
deleted file mode 100644
index afae0659..00000000
--- a/cmd/support-status.go
+++ /dev/null
@@ -1,99 +0,0 @@
-// Copyright (c) 2015-2022 MinIO, Inc.
-//
-// This file is part of MinIO Object Storage stack
-//
-// This program is free software: you can redistribute it and/or modify
-// it under the terms of the GNU Affero General Public License as published by
-// the Free Software Foundation, either version 3 of the License, or
-// (at your option) any later version.
-//
-// This program is distributed in the hope that it will be useful
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
-// GNU Affero General Public License for more details.
-//
-// You should have received a copy of the GNU Affero General Public License
-// along with this program. If not, see .
-
-package cmd
-
-import (
- "fmt"
-
- "github.com/fatih/color"
- "github.com/minio/cli"
- json "github.com/minio/colorjson"
- "github.com/minio/mc/pkg/probe"
- "github.com/minio/pkg/console"
-)
-
-var supportStatusCmd = cli.Command{
- Name: "status",
- Usage: "Display support configuration",
- OnUsageError: onUsageError,
- Action: mainSupportStatus,
- Before: setGlobalsFromContext,
- Flags: globalFlags,
- CustomHelpTemplate: `NAME:
- {{.HelpName}} - {{.Usage}}
-
-USAGE:
- {{.HelpName}} ALIAS
-
-EXAMPLES:
- 1. Display support configuration for cluster with alias 'play'
- {{.Prompt}} {{.HelpName}} play
-`,
-}
-
-type supportStatusMessage struct {
- Status string `json:"status"`
- Registered bool `json:"registered"`
- LogsStatus string `json:"logs"`
- CallhomeStatus string `json:"callhome"`
-}
-
-// String colorized status message.
-func (s supportStatusMessage) String() string {
- str := "Cluster is "
- if !s.Registered {
- str += "not "
- }
- str += fmt.Sprintln("registered with SUBNET")
- str += fmt.Sprintln("Logs:", s.LogsStatus)
- str += fmt.Sprint("Callhome: ", s.CallhomeStatus)
-
- return console.Colorize(featureStatusMessageTag, str)
-}
-
-// JSON jsonified status message.
-func (s supportStatusMessage) JSON() string {
- s.Status = "success"
- jsonBytes, e := json.MarshalIndent(s, "", " ")
- fatalIf(probe.NewError(e), "Unable to marshal into JSON.")
-
- return string(jsonBytes)
-}
-
-func mainSupportStatus(ctx *cli.Context) error {
- console.SetColor(featureStatusMessageTag, color.New(color.FgGreen, color.Bold))
-
- if len(ctx.Args()) != 1 {
- cli.ShowCommandHelpAndExit(ctx, "status", 1) // last argument is exit code
- }
-
- aliasedURL := ctx.Args().Get(0)
- alias, _ := url2Alias(aliasedURL)
-
- apiKey, lic, e := getSubnetCreds(alias)
- fatalIf(probe.NewError(e), "Error in checking cluster registration status")
-
- ssm := supportStatusMessage{
- Registered: len(apiKey) > 0 || len(lic) > 0,
- LogsStatus: featureStatusStr(isSupportLogsEnabled(alias)),
- CallhomeStatus: featureStatusStr(isSupportCallhomeEnabled(alias)),
- }
-
- printMsg(ssm)
- return nil
-}
diff --git a/cmd/support.go b/cmd/support.go
index 8ec2ec7f..2cc725dd 100644
--- a/cmd/support.go
+++ b/cmd/support.go
@@ -27,10 +27,7 @@ import (
"github.com/minio/pkg/console"
)
-const (
- featureToggleMessageTag = "FeatureToggleMessage"
- featureStatusMessageTag = "FeatureStatusMessage"
-)
+const featureToggleMessageTag = "FeatureToggleMessage"
var supportSubcommands = []cli.Command{
supportRegisterCmd,
@@ -40,7 +37,6 @@ var supportSubcommands = []cli.Command{
supportPerfCmd,
supportInspectCmd,
supportProfileCmd,
- supportStatusCmd,
}
var supportCmd = cli.Command{
diff --git a/go.mod b/go.mod
index 5114b0c7..54218f93 100644
--- a/go.mod
+++ b/go.mod
@@ -22,7 +22,7 @@ require (
github.com/minio/madmin-go v1.4.4
github.com/minio/md5-simd v1.1.2 // indirect
github.com/minio/minio-go/v7 v7.0.31
- github.com/minio/pkg v1.1.22
+ github.com/minio/pkg v1.2.0
github.com/minio/selfupdate v0.4.0
github.com/minio/sha256-simd v1.0.0
github.com/mitchellh/go-homedir v1.1.0
diff --git a/go.sum b/go.sum
index f0de88f6..683d6052 100644
--- a/go.sum
+++ b/go.sum
@@ -60,7 +60,6 @@ github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6r
github.com/bgentry/speakeasy v0.1.0/go.mod h1:+zsyZBPWlz7T6j88CTgSN5bM796AkVf0kBD4zp0CCIs=
github.com/bketelsen/crypt v0.0.4/go.mod h1:aI6NrJ0pMGgvZKL1iVgXLnfIFJtfV+bKCoqOes/6LfM=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
-github.com/cespare/xxhash v1.1.0 h1:a6HrQnmkObjyL+Gs60czilIUGqrzKutQD6XZog3p+ko=
github.com/cespare/xxhash v1.1.0/go.mod h1:XrSqR1VqqWfGrhpAt58auRo0WTKS1nRRg3ghfAqPWnc=
github.com/cespare/xxhash/v2 v2.1.1/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/cespare/xxhash/v2 v2.1.2 h1:YRXhKfTDauu4ajMg1TPgFO5jnlC2HCbmLXMcTG5cbYE=
@@ -272,7 +271,6 @@ github.com/klauspost/compress v1.13.5/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47e
github.com/klauspost/compress v1.13.6 h1:P76CopJELS0TiO2mebmnzgWaajssP/EszplttgQxcgc=
github.com/klauspost/compress v1.13.6/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk=
github.com/klauspost/cpuid v1.2.3/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
-github.com/klauspost/cpuid v1.3.1 h1:5JNjFYYQrZeKRJ0734q51WCEEn2huer72Dc7K+R/b6s=
github.com/klauspost/cpuid v1.3.1/go.mod h1:bYW4mA6ZgKPob1/Dlai2LviZJO7KGI3uoWLd42rAQw4=
github.com/klauspost/cpuid/v2 v2.0.1/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
github.com/klauspost/cpuid/v2 v2.0.4/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg=
@@ -342,8 +340,6 @@ github.com/minio/colorjson v1.0.2/go.mod h1:JWxcL2n8T8JVf+NY6awl6kn5nK49aAzHOeQE
github.com/minio/filepath v1.0.0 h1:fvkJu1+6X+ECRA6G3+JJETj4QeAYO9sV43I79H8ubDY=
github.com/minio/filepath v1.0.0/go.mod h1:/nRZA2ldl5z6jT9/KQuvZcQlxZIMQoFFQPvEXx9T/Bw=
github.com/minio/madmin-go v1.3.5/go.mod h1:vGKGboQgGIWx4DuDUaXixjlIEZOCIp6ivJkQoiVaACc=
-github.com/minio/madmin-go v1.3.11/go.mod h1:ez87VmMtsxP7DRxjKJKD4RDNW+nhO2QF9KSzwxBDQ98=
-github.com/minio/madmin-go v1.3.11/go.mod h1:ez87VmMtsxP7DRxjKJKD4RDNW+nhO2QF9KSzwxBDQ98=
github.com/minio/madmin-go v1.4.4 h1:6nf5Ut4szFvG1yeoOD5Tuvl7uRHF/XXh7LSuBTlKzL0=
github.com/minio/madmin-go v1.4.4/go.mod h1:ez87VmMtsxP7DRxjKJKD4RDNW+nhO2QF9KSzwxBDQ98=
github.com/minio/md5-simd v1.1.0/go.mod h1:XpBqgZULrMYD3R+M28PcmP0CkI7PEMzB3U77ZrKZ0Gw=
@@ -353,8 +349,8 @@ github.com/minio/minio-go/v7 v7.0.23/go.mod h1:ei5JjmxwHaMrgsMrn4U/+Nmg+d8MKS1U2
github.com/minio/minio-go/v7 v7.0.31 h1:zsJ3qPDeU3bC5UMVi9HJ4ED0lyEzrNd3iQguglZS5FE=
github.com/minio/minio-go/v7 v7.0.31/go.mod h1:/sjRKkKIA75CKh1iu8E3qBy7ktBmCCDGII0zbXGwbUk=
github.com/minio/pkg v1.1.20/go.mod h1:Xo7LQshlxGa9shKwJ7NzQbgW4s8T/Wc1cOStR/eUiMY=
-github.com/minio/pkg v1.1.22 h1:Fm3oPu9LJag0FhD5BjFxj0Ut+M8S8IkiPHaq5OAoZaM=
-github.com/minio/pkg v1.1.22/go.mod h1:z9PfmEI804KFkF6eY4LoGe8IDVvTCsYGVuaf58Dr0WI=
+github.com/minio/pkg v1.2.0 h1:R+c48US/+Qlxq8L20cWaml9sipqMX0jdaXLNw6j/4lo=
+github.com/minio/pkg v1.2.0/go.mod h1:z9PfmEI804KFkF6eY4LoGe8IDVvTCsYGVuaf58Dr0WI=
github.com/minio/selfupdate v0.4.0 h1:A7t07pN4Ch1tBTIRStW0KhUVyykz+2muCqFsITQeEW8=
github.com/minio/selfupdate v0.4.0/go.mod h1:mcDkzMgq8PRcpCRJo/NlPY7U45O5dfYl2Y0Rg7IustY=
github.com/minio/sha256-simd v0.1.1/go.mod h1:B5e1o+1/KgNmWrSQK08Y6Z1Vb5pwIktudl0J58iy0KM=