Skip to content

Commit

Permalink
Avoid including " and $ characters in bootstrap admin's token
Browse files Browse the repository at this point in the history
  • Loading branch information
edigaryev committed Feb 6, 2025
1 parent 26c8808 commit 3b0d8da
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion internal/command/controller/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/pterm/pterm"
"github.com/sethvargo/go-password/password"
"os"
"strings"
)

const BootstrapAdminName = "bootstrap-admin"
Expand All @@ -31,7 +32,29 @@ func Bootstrap(controllerInstance *controller.Controller, controllerCert tls.Cer

// Generate a bootstrap admin token if not present in the environment variable
if !orchardBootstrapAdminTokenPresent {
orchardBootstrapAdminToken, err = password.Generate(32, 10, 10,
passwordGenerator, err := password.NewGenerator(&password.GeneratorInput{
LowerLetters: password.LowerLetters,
UpperLetters: password.UpperLetters,
Digits: password.Digits,
Symbols: strings.Map(func(r rune) rune {
// Avoid generating $ and " symbols
// as they cause issues in shell
switch r {
case '$':
fallthrough
case '"':
return -1
default:
return r
}
}, password.Symbols),
})
if err != nil {
return fmt.Errorf("failed to generate bootstrap admin token: "+
"failed to initialize password generator: %w", err)
}

orchardBootstrapAdminToken, err = passwordGenerator.Generate(32, 10, 10,
false, false)
if err != nil {
return fmt.Errorf("failed to generate bootstrap admin token: %w", err)
Expand Down

0 comments on commit 3b0d8da

Please sign in to comment.