Add secret

This commit is contained in:
Owen 2025-04-28 21:55:57 -04:00
parent e236364124
commit e4af990bf2
No known key found for this signature in database
GPG key ID: 8271FDFFD9E0CCBD
2 changed files with 18 additions and 0 deletions

View file

@ -22,6 +22,7 @@ server:
id: "P-Access-Token-Id"
token: "P-Access-Token"
resource_session_request_param: "p_session_request"
secret: {{.Secret}}
cors:
origins: ["https://{{.DashboardDomain}}"]
methods: ["GET", "POST", "PUT", "DELETE", "PATCH"]

View file

@ -16,6 +16,7 @@ import (
"text/template"
"time"
"unicode"
"math/rand"
"golang.org/x/term"
)
@ -50,6 +51,7 @@ type Config struct {
InstallGerbil bool
TraefikBouncerKey string
DoCrowdsecInstall bool
Secret string
}
func main() {
@ -63,6 +65,7 @@ func main() {
var config Config
config.DoCrowdsecInstall = false
config.Secret = generateRandomSecretKey()
// check if there is already a config file
if _, err := os.Stat("config/config.yml"); err != nil {
@ -603,3 +606,17 @@ func waitForContainer(containerName string) error {
return fmt.Errorf("container %s did not start within %v seconds", containerName, maxAttempts*int(retryInterval.Seconds()))
}
func generateRandomSecretKey() string {
const charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
const length = 32
var seededRand *rand.Rand = rand.New(
rand.NewSource(time.Now().UnixNano()))
b := make([]byte, length)
for i := range b {
b[i] = charset[seededRand.Intn(len(charset))]
}
return string(b)
}