Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
6 changes: 0 additions & 6 deletions pkg/subnet/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,9 @@ import (
"errors"
"log"

"github.com/minio/pkg/env"
"github.com/minio/pkg/licverifier"
)

// GetSubnetURL
func GetSubnetURL() string {
return env.Get(ConsoleSubnetURL, "https://subnet.min.io")
}

// GetLicenseInfoFromJWT will return license metadata from a jwt string license
func GetLicenseInfoFromJWT(license string, publicKeys []string) (*licverifier.LicenseInfo, error) {
if license == "" {
Expand Down
71 changes: 64 additions & 7 deletions pkg/subnet/subnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,14 @@
package subnet

import (
"bytes"
"encoding/json"
"errors"
"fmt"
"log"

"github.com/minio/pkg/licverifier"

"github.com/minio/console/models"
"github.com/minio/madmin-go"
mc "github.com/minio/mc/cmd"
Expand Down Expand Up @@ -81,31 +85,84 @@ func GetOrganizations(client cluster.HTTPClientI, token string) ([]*models.Subne
return organizations, nil
}

func Register(client cluster.HTTPClientI, admInfo madmin.InfoMessage, apiKey, token, accountID string) (string, error) {
type LicenseTokenConfig struct {
APIKey string
License string
}

func Register(client cluster.HTTPClientI, admInfo madmin.InfoMessage, apiKey, token, accountID string) (*LicenseTokenConfig, error) {
var headers map[string]string
regInfo := GetClusterRegInfo(admInfo)
regURL := subnetRegisterURL()
if apiKey != "" {
regURL += "?api_key=" + apiKey
} else {
if accountID == "" || token == "" {
return "", errors.New("missing accountID or authentication token")
return nil, errors.New("missing accountID or authentication token")
}
headers = subnetAuthHeaders(token)
regURL += "?aid=" + accountID
}
regToken, err := GenerateRegToken(regInfo)
if err != nil {
return "", err
return nil, err
}
reqPayload := mc.ClusterRegistrationReq{Token: regToken}
resp, err := subnetPostReq(client, regURL, reqPayload, headers)
if err != nil {
return "", err
return nil, err
}
subnetAPIKey := gjson.Parse(resp).Get("api_key").String()
respJSON := gjson.Parse(resp)
subnetAPIKey := respJSON.Get("api_key").String()
licenseJwt := respJSON.Get("license").String()

if subnetAPIKey != "" {
return subnetAPIKey, nil
return &LicenseTokenConfig{
APIKey: subnetAPIKey,
License: licenseJwt,
}, nil
}
return nil, errors.New("subnet api key not found")
}

const publicKey = "/downloads/license-pubkey.pem"

// downloadSubnetPublicKey will download the current subnet public key.
func downloadSubnetPublicKey(client cluster.HTTPClientI) (string, error) {
// Get the public key directly from Subnet
url := fmt.Sprintf("%s%s", subnetBaseURL(), publicKey)
resp, err := client.Get(url)
if err != nil {
return "", err
}
return "", errors.New("subnet api key not found")
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(client cluster.HTTPClientI, license string) (*licverifier.LicenseInfo, error) {
var publicKeys []string

subnetPubKey, err := downloadSubnetPublicKey(client)
if err != nil {
log.Print(err)
// there was an issue getting the subnet public key
// use hardcoded public keys instead
publicKeys = OfflinePublicKeys
} else {
publicKeys = append(publicKeys, subnetPubKey)
}

licenseInfo, err := GetLicenseInfoFromJWT(license, publicKeys)
if err != nil {
fmt.Println(err)
return nil, err
}

return licenseInfo, nil
}
Loading