feat(config): Strict-YAML, Secret-Dateien, Env-Overrides, Dateirechte und Validierung

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NBHF4R9EAejDJUMdwr6C68
This commit is contained in:
Carsten Abele 2026-08-14 09:06:43 +02:00
parent fbfff90b38
commit b47ee11ba4
10 changed files with 777 additions and 0 deletions

40
internal/config/perms.go Normal file
View file

@ -0,0 +1,40 @@
package config
import (
"fmt"
"io/fs"
"os"
)
// CheckFileMode bricht ab, wenn die Datei mehr Rechte trägt als maxMode.
func CheckFileMode(path string, maxMode fs.FileMode) error {
info, err := os.Stat(path)
if err != nil {
return fmt.Errorf("Datei %s nicht lesbar: %w", path, err)
}
if info.IsDir() {
return fmt.Errorf("%s ist ein Verzeichnis, erwartet wurde eine Datei", path)
}
return checkMode(path, info.Mode().Perm(), maxMode)
}
// CheckDirMode bricht ab, wenn das Verzeichnis mehr Rechte trägt als maxMode.
func CheckDirMode(path string, maxMode fs.FileMode) error {
info, err := os.Stat(path)
if err != nil {
return fmt.Errorf("Verzeichnis %s nicht lesbar: %w", path, err)
}
if !info.IsDir() {
return fmt.Errorf("%s ist kein Verzeichnis", path)
}
return checkMode(path, info.Mode().Perm(), maxMode)
}
func checkMode(path string, actual, maxMode fs.FileMode) error {
if extra := actual &^ maxMode; extra != 0 {
return fmt.Errorf(
"%s hat zu weite Dateirechte %#o (erlaubt höchstens %#o). Beheben mit: chmod %#o %s",
path, actual, maxMode, maxMode, path)
}
return nil
}