分离五项配置与运行数据并实现无损目录迁移
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-08 17:16:09 +08:00
1 parent dc188b1ed8
commit d6cc81ed87
53 files changed
+909 -127

No files matched your search

+3 -3
View File
@@ -116,7 +116,7 @@ func SetSSL(sslType, priKey, crtKey string) error {
cfg.SSL = config.SSLConfig{
Management: config.SSLManagementProject,
Mode: config.ManagedSSLModeDefault,
DefaultDirectory: "config/ssl",
DefaultDirectory: "data/ssl",
}
if cfg.SSLType == config.SSLTypeAutoDNS {
cfg.SSL.Challenge = config.SSLChallengeDNS
@@ -190,12 +190,12 @@ func applyManagedSSLReference(cfg *config.Config, reference config.ManagedSSLRef
cfg.SSL = config.SSLConfig{
Management: management,
Mode: reference.Mode,
DefaultDirectory: "config/ssl",
DefaultDirectory: "data/ssl",
CertificateRef: reference.CertificateRef,
PrivateKeyRef: reference.PrivateKeyRef,
}
if reference.Mode == config.ManagedSSLModeUpload {
cfg.SSL.CustomDirectory = "config/ssl/managed/upload"
cfg.SSL.CustomDirectory = "data/ssl/managed/upload"
} else if cfg.SSLType == config.SSLTypeAutoDNS {
cfg.SSL.Challenge = config.SSLChallengeDNS
} else {
+2 -2
View File
@@ -31,7 +31,7 @@ func writeCertificateBundle(cfg *config.Config, privateKey, certificate, issuer
return err
}
defer workspaceRoot.Close()
baseRelative := filepath.Join("config", "ssl")
baseRelative := filepath.Join("data", "ssl")
if err := ensureSecureRootDirectory(workspaceRoot, baseRelative); err != nil {
return err
}
@@ -57,7 +57,7 @@ func writeCertificateBundle(cfg *config.Config, privateKey, certificate, issuer
}
relativePath, err := securefile.ControlledRelativePath(basePath, item.path)
if err != nil {
return errors.New("SSL file path must stay inside config/ssl")
return errors.New("SSL file path must stay inside data/ssl")
}
if _, exists := seen[relativePath]; exists {
return errors.New("SSL file paths must be unique")
+5 -5
View File
@@ -17,7 +17,7 @@ func TestWriteCertificateBundleUsesRestrictedAtomicStorage(t *testing.T) {
root := t.TempDir()
config.ROOT_PATH = root + string(os.PathSeparator)
t.Cleanup(func() { config.ROOT_PATH = oldRoot })
basePath := filepath.Join(root, "config", "ssl")
basePath := filepath.Join(root, "data", "ssl")
cfg := &config.Config{
SSLPrivateKeyPath: filepath.Join(basePath, "private.key"),
SSLPublicKeyPath: filepath.Join(basePath, "public.crt"),
@@ -52,7 +52,7 @@ func TestWriteCertificateBundleUsesRestrictedAtomicStorage(t *testing.T) {
}
}
if runtime.GOOS != "windows" {
for _, directory := range []string{filepath.Join(root, "config"), basePath} {
for _, directory := range []string{filepath.Join(root, "data"), basePath} {
info, err := os.Stat(directory)
if err != nil {
t.Fatal(err)
@@ -79,7 +79,7 @@ func TestWriteCertificateBundleRejectsSymlinkDirectory(t *testing.T) {
root := t.TempDir()
config.ROOT_PATH = root + string(os.PathSeparator)
t.Cleanup(func() { config.ROOT_PATH = oldRoot })
configDirectory := filepath.Join(root, "config")
configDirectory := filepath.Join(root, "data")
if err := os.Mkdir(configDirectory, 0700); err != nil {
t.Fatal(err)
}
@@ -103,7 +103,7 @@ func TestWriteCertificateBundleRejectsSymlinkFile(t *testing.T) {
root := t.TempDir()
config.ROOT_PATH = root + string(os.PathSeparator)
t.Cleanup(func() { config.ROOT_PATH = oldRoot })
basePath := filepath.Join(root, "config", "ssl")
basePath := filepath.Join(root, "data", "ssl")
if err := os.MkdirAll(basePath, 0700); err != nil {
t.Fatal(err)
}
@@ -139,7 +139,7 @@ func TestWriteCertificateBundleRejectsMismatchedPair(t *testing.T) {
root := t.TempDir()
config.ROOT_PATH = root + string(os.PathSeparator)
t.Cleanup(func() { config.ROOT_PATH = oldRoot })
basePath := filepath.Join(root, "config", "ssl")
basePath := filepath.Join(root, "data", "ssl")
cfg := &config.Config{
SSLPrivateKeyPath: filepath.Join(basePath, "private.key"),
SSLPublicKeyPath: filepath.Join(basePath, "public.crt"),
@@ -94,7 +94,7 @@ func TestApplyManagedSSLReferenceDoesNotPersistLegacyPaths(t *testing.T) {
if cfg.SSL.Mode != config.ManagedSSLModeUpload || cfg.SSL.CertificateRef != reference.CertificateRef || cfg.SSL.PrivateKeyRef != reference.PrivateKeyRef {
t.Fatalf("受控 SSL 内部引用写入错误: %+v", cfg.SSL)
}
if cfg.SSL.CustomDirectory != "config/ssl/managed/upload" {
if cfg.SSL.CustomDirectory != "data/ssl/managed/upload" {
t.Fatalf("自定义受控目录写入错误: %s", cfg.SSL.CustomDirectory)
}
}