Skip to content

Commit

Permalink
ee license check
Browse files Browse the repository at this point in the history
os.Exit(0) on license check failure
docker-compose -- restart netmaker container on faiure vice always
  • Loading branch information
mattkasun committed Apr 12, 2023
1 parent 9390c06 commit e244dcb
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 14 deletions.
2 changes: 1 addition & 1 deletion compose/docker-compose-emqx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
netmaker:
container_name: netmaker
image: gravitl/netmaker:v0.18.6
restart: always
restart: on-failure
volumes:
- dnsconfig:/root/config/dnsconfig
- sqldata:/root/data
Expand Down
2 changes: 1 addition & 1 deletion compose/docker-compose.ee.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
netmaker:
container_name: netmaker
image: gravitl/netmaker:REPLACE_SERVER_IMAGE_TAG
restart: always
restart: on-failure
volumes:
- dnsconfig:/root/config/dnsconfig
- sqldata:/root/data
Expand Down
2 changes: 1 addition & 1 deletion compose/docker-compose.netclient.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ services:
image: 'gravitl/netclient:v0.18.6'
hostname: netmaker-1
network_mode: host
restart: always
restart: on-failure
environment:
TOKEN: "TOKEN_VALUE"
volumes:
Expand Down
2 changes: 1 addition & 1 deletion compose/docker-compose.reference.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
netmaker: # The Primary Server for running Netmaker
container_name: netmaker
image: gravitl/netmaker:REPLACE_SERVER_IMAGE_TAG
restart: always
restart: on-failure
volumes: # Volume mounts necessary for sql, coredns, and mqtt
- dnsconfig:/root/config/dnsconfig
- sqldata:/root/data
Expand Down
2 changes: 1 addition & 1 deletion compose/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ services:
netmaker:
container_name: netmaker
image: gravitl/netmaker:REPLACE_SERVER_IMAGE_TAG
restart: always
restart: on-failure
volumes:
- dnsconfig:/root/config/dnsconfig
- sqldata:/root/data
Expand Down
18 changes: 9 additions & 9 deletions ee/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,17 +44,17 @@ func ValidateLicense() error {
netmakerAccountID := servercfg.GetNetmakerAccountID()
logger.Log(0, "proceeding with Netmaker license validation...")
if len(licenseKeyValue) == 0 || len(netmakerAccountID) == 0 {
logger.FatalLog(errValidation.Error())
logger.FatalLog0(errValidation.Error())
}

apiPublicKey, err := getLicensePublicKey(licenseKeyValue)
if err != nil {
logger.FatalLog(errValidation.Error())
logger.FatalLog0(errValidation.Error())
}

tempPubKey, tempPrivKey, err := FetchApiServerKeys()
if err != nil {
logger.FatalLog(errValidation.Error())
logger.FatalLog0(errValidation.Error())
}

licenseSecret := LicenseSecret{
Expand All @@ -64,32 +64,32 @@ func ValidateLicense() error {

secretData, err := json.Marshal(&licenseSecret)
if err != nil {
logger.FatalLog(errValidation.Error())
logger.FatalLog0(errValidation.Error())
}

encryptedData, err := ncutils.BoxEncrypt(secretData, apiPublicKey, tempPrivKey)
if err != nil {
logger.FatalLog(errValidation.Error())
logger.FatalLog0(errValidation.Error())
}

validationResponse, err := validateLicenseKey(encryptedData, tempPubKey)
if err != nil || len(validationResponse) == 0 {
logger.FatalLog(errValidation.Error())
logger.FatalLog0(errValidation.Error())
}

var licenseResponse ValidatedLicense
if err = json.Unmarshal(validationResponse, &licenseResponse); err != nil {
logger.FatalLog(errValidation.Error())
logger.FatalLog0(errValidation.Error())
}

respData, err := ncutils.BoxDecrypt(base64decode(licenseResponse.EncryptedLicense), apiPublicKey, tempPrivKey)
if err != nil {
logger.FatalLog(errValidation.Error())
logger.FatalLog0(errValidation.Error())
}

license := LicenseKey{}
if err = json.Unmarshal(respData, &license); err != nil {
logger.FatalLog(errValidation.Error())
logger.FatalLog0(errValidation.Error())
}

Limits.Networks = math.MaxInt
Expand Down
6 changes: 6 additions & 0 deletions logger/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,12 @@ func FatalLog(message ...string) {
os.Exit(2)
}

// FatalLog0 - exits os after logging
func FatalLog0(message ...string) {
fmt.Printf("[%s] Fatal: %s \n", program, MakeString(" ", message...))
os.Exit(0)
}

// == private ==

// resetLogs - reallocates logs map
Expand Down

0 comments on commit e244dcb

Please sign in to comment.