Skip to content

Commit

Permalink
generate rails secrets inline rather than shelling out (#3958)
Browse files Browse the repository at this point in the history
generate rails secrets inline rather than shelling out
  • Loading branch information
rubys committed Sep 24, 2024
1 parent e6cdd34 commit af22df9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 11 additions & 0 deletions helpers/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package helpers

import (
"crypto/rand"
"encoding/hex"
"math/big"
mrand "math/rand"
"time"
Expand Down Expand Up @@ -39,3 +40,13 @@ func RandBytes(n int) ([]byte, error) {

return token, nil
}

// RandHex generates a random hex string of a given length*2
func RandHex(n int) (string, error) {
bytes, err := RandBytes(n)
if err != nil {
return "", err
}

return hex.EncodeToString(bytes), nil
}
5 changes: 3 additions & 2 deletions scanner/rails.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import (
"strings"

"github.com/pkg/errors"
"github.com/superfly/flyctl/helpers"
"github.com/superfly/flyctl/internal/command/launch/plan"
"github.com/superfly/flyctl/internal/flyerr"
"gopkg.in/yaml.v2"
Expand Down Expand Up @@ -233,14 +234,14 @@ func configureRails(sourceDir string, config *ScannerConfig) (*SourceInfo, error
// support Rails 4 through 5.1 applications, ones that started out
// there and never were fully upgraded, and ones that intentionally
// avoid using Rails encrypted credentials.
out, err := exec.Command(binrails, "secret").Output()
out, err := helpers.RandHex(64)

if err == nil {
s.Secrets = []Secret{
{
Key: "SECRET_KEY_BASE",
Help: "Secret key used to verify the integrity of signed cookies",
Value: strings.TrimSpace(string(out)),
Value: out,
},
}
}
Expand Down

0 comments on commit af22df9

Please sign in to comment.