Skip to content

Commit

Permalink
generate random windows password
Browse files Browse the repository at this point in the history
  • Loading branch information
r2k1 committed Nov 19, 2024
1 parent 9b08ee6 commit 92963b9
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
1 change: 1 addition & 0 deletions e2e/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type Configuration struct {
TagsToRun string `env:"TAGS_TO_RUN"`
TagsToSkip string `env:"TAGS_TO_SKIP"`
TestTimeout time.Duration `env:"TEST_TIMEOUT" envDefault:"35m"`
WindowsAdminPassword string `env:"WINDOWS_ADMIN_PASSWORD"`
}

func (c *Configuration) BlobStorageAccount() string {
Expand Down
36 changes: 35 additions & 1 deletion e2e/vmss.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
"errors"
"fmt"
"io"
"math/big"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -530,11 +531,44 @@ func getBaseVMSSModel(s *Scenario, customData, cseCmd string) armcompute.Virtual
model.Properties.VirtualMachineProfile.ExtensionProfile.Extensions[0].Properties.Type = to.Ptr("CustomScriptExtension")
model.Properties.VirtualMachineProfile.ExtensionProfile.Extensions[0].Properties.TypeHandlerVersion = to.Ptr("1.10")
model.Properties.VirtualMachineProfile.OSProfile.AdminUsername = to.Ptr("azureuser")
model.Properties.VirtualMachineProfile.OSProfile.AdminPassword = to.Ptr("pwnedPassword123!")
model.Properties.VirtualMachineProfile.OSProfile.AdminPassword = to.Ptr(generateWindowsPassword())
}
return model
}

func generateWindowsPassword() string {
if config.Config.WindowsAdminPassword != "" {
return config.Config.WindowsAdminPassword
}
return randomStringWithDigitsAndSymbols(16)
}

func randomStringWithDigitsAndSymbols(length int) string {
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
const digits = "0123456789"
const symbols = "!@#$%^&*()-_+="
b := make([]byte, length)

for i := range b {
if i < (length - 2) { // Ensure at least 2 characters are symbols
b[i] = charset[randomInt(len(charset))]
} else if i == (length - 2) {
b[i] = digits[randomInt(len(digits))]
} else {
b[i] = symbols[randomInt(len(symbols))]
}
}
return string(b)
}

func randomInt(bound int) int {
n, err := crand.Int(crand.Reader, big.NewInt(int64(bound)))
if err != nil {
panic(err) // Intentionally panic for simplicity; handle errors as needed
}
return int(n.Int64())
}

func getPrivateIP(res listVMSSVMNetworkInterfaceResult) (string, error) {
if len(res.Value) > 0 {
v := res.Value[0]
Expand Down
4 changes: 2 additions & 2 deletions packer.mk
Original file line number Diff line number Diff line change
Expand Up @@ -107,10 +107,10 @@ evaluate-build-performance: az-login
@./vhdbuilder/packer/build-performance/evaluate-build-performance.sh

generate-prefetch-scripts:
ifeq (${MODE},linuxVhdMode)
#ifeq (${MODE},linuxVhdMode)
@echo "${MODE}: Generating prefetch scripts"
@bash -c "pushd vhdbuilder/prefetch; go run cmd/main.go --components-path=../../parts/linux/cloud-init/artifacts/components.json --output-path=../packer/prefetch.sh || exit 1; popd"
endif
#endif

build-aks-node-controller:
@echo "Building aks-node-controller binaries"
Expand Down

0 comments on commit 92963b9

Please sign in to comment.