mantle/platform: make the password for azure instances more secure
Use crypto/rand as requested in by in
package azure
import (
+ "crypto/rand"
"encoding/base64"
"fmt"
"io"
"io/ioutil"
- "math/rand"
+ "math"
+ "math/big"
"regexp"
- "strconv"
"time"
"github.com/Azure/azure-sdk-for-go/arm/compute"
@@ -55,8 +56,11 @@ func (a *API) getVMParameters(name, userdata, sshkey, storageAccountURI string,
// from the following: Contains an uppercase character, Contains a
// lowercase character, Contains a numeric digit, Contains a special
// character) Control characters are not allowed"
- password := fmt.Sprintf("%s%s%s", "ABC&", strconv.Itoa(rand.Int()), "xyz")
-
+ n, err := rand.Int(rand.Reader, big.NewInt(math.MaxInt64))
+ if err != nil {
+ panic(fmt.Sprintf("calling crypto/rand.Int() failed and that shouldn't happen: %v", err))
+ }
+ password := fmt.Sprintf("%s%s%s", "ABC&", n, "xyz")
osProfile := compute.OSProfile{
AdminUsername: util.StrToPtr("core"), // unused
AdminPassword: util.StrToPtr(password), // unused
