audit and harden workspace

This commit is contained in:
2026-08-10 11:42:45 +08:00
parent c883cc52a2
commit 1a1fa521c0
140 changed files with 640 additions and 475 deletions

View File

@@ -3,9 +3,11 @@ package main
import (
"context"
"flag"
"fmt"
"net/http"
"os"
"os/signal"
"regexp"
"strings"
"syscall"
"time"
@@ -18,12 +20,24 @@ import (
var ServiceKey = "default"
var workspacePattern = regexp.MustCompile(`^[a-zA-Z0-9][a-zA-Z0-9_-]{0,63}$`)
func normalizeWorkspace(value string) (string, error) {
value = strings.ToLower(strings.TrimSpace(value))
if !workspacePattern.MatchString(value) {
return "", fmt.Errorf("workspace must match %s", workspacePattern.String())
}
return value, nil
}
func main() {
workspace := flag.String("workspace", ServiceKey, "workspace used to select etc/{workspace}_{runtime}.yaml")
flag.Parse()
if value := strings.TrimSpace(*workspace); value != "" {
ServiceKey = value
value, err := normalizeWorkspace(*workspace)
if err != nil {
panic(err)
}
ServiceKey = value
config.New(ServiceKey)
impl.NewImpl()