保存模拟部署迁移与最新构建校验阶段成果
Security Checks / security (push) Waiting to run

This commit is contained in:
xuans committed 2026-09-08 18:33:21 +08:00
1 parent 519e2b4a5f
commit d7837de561
45 files changed
+1588 -109

No files matched your search

+2 -1
View File
@@ -12,6 +12,7 @@ import (
"git.pcux.cn/xuans/Smail/models"
"git.pcux.cn/xuans/Smail/utils/context"
"git.pcux.cn/xuans/Smail/utils/password"
"git.pcux.cn/xuans/Smail/utils/runtimepath"
"git.pcux.cn/xuans/Smail/utils/validation"
log "github.com/sirupsen/logrus"
)
@@ -117,7 +118,7 @@ func HasAuth(ctx *context.Context, email *models.Email) bool {
}
func DkimGen() (string, error) {
basePath := filepath.Join(config.ROOT_PATH, "data", "dkim")
basePath := runtimepath.DKIMDirectory(config.ROOT_PATH)
cfg := config.CurrentConfig()
if cfg == nil {
return "", fmt.Errorf("runtime configuration is unavailable")
+1 -1
View File
@@ -48,7 +48,7 @@ func NewVault(root string) (*Vault, error) {
return nil, ErrVaultUnavailable
}
}
configDir, err := runtimepath.Directory(root)
configDir, err := runtimepath.SecureDirectory(root, filepath.Base(runtimepath.KeyDirectory(root)))
if err != nil {
return nil, ErrVaultUnavailable
}
+4 -3
View File
@@ -12,6 +12,7 @@ import (
"git.pcux.cn/xuans/Smail/signal"
"git.pcux.cn/xuans/Smail/utils/async"
"git.pcux.cn/xuans/Smail/utils/errors"
"git.pcux.cn/xuans/Smail/utils/runtimepath"
"github.com/go-acme/lego/v4/certificate"
"github.com/go-acme/lego/v4/challenge/dns01"
log "github.com/sirupsen/logrus"
@@ -116,7 +117,7 @@ func SetSSL(sslType, priKey, crtKey string) error {
cfg.SSL = config.SSLConfig{
Management: config.SSLManagementProject,
Mode: config.ManagedSSLModeDefault,
DefaultDirectory: "data/ssl",
DefaultDirectory: runtimepath.SSLReference(config.ROOT_PATH, "data/ssl"),
}
if cfg.SSLType == config.SSLTypeAutoDNS {
cfg.SSL.Challenge = config.SSLChallengeDNS
@@ -190,12 +191,12 @@ func applyManagedSSLReference(cfg *config.Config, reference config.ManagedSSLRef
cfg.SSL = config.SSLConfig{
Management: management,
Mode: reference.Mode,
DefaultDirectory: "data/ssl",
DefaultDirectory: runtimepath.SSLReference(config.ROOT_PATH, "data/ssl"),
CertificateRef: reference.CertificateRef,
PrivateKeyRef: reference.PrivateKeyRef,
}
if reference.Mode == config.ManagedSSLModeUpload {
cfg.SSL.CustomDirectory = "data/ssl/managed/upload"
cfg.SSL.CustomDirectory = runtimepath.SSLReference(config.ROOT_PATH, "data/ssl/managed/upload")
} else if cfg.SSLType == config.SSLTypeAutoDNS {
cfg.SSL.Challenge = config.SSLChallengeDNS
} else {
+3 -2
View File
@@ -10,6 +10,7 @@ import (
"git.pcux.cn/xuans/Smail/config"
"git.pcux.cn/xuans/Smail/utils/atomicfile"
securefile "git.pcux.cn/xuans/Smail/utils/file"
"git.pcux.cn/xuans/Smail/utils/runtimepath"
)
func writeCertificateBundle(cfg *config.Config, privateKey, certificate, issuer []byte) error {
@@ -31,7 +32,7 @@ func writeCertificateBundle(cfg *config.Config, privateKey, certificate, issuer
return err
}
defer workspaceRoot.Close()
baseRelative := filepath.Join("data", "ssl")
baseRelative := filepath.FromSlash(runtimepath.SSLReference(rootPath, "data/ssl"))
if err := ensureSecureRootDirectory(workspaceRoot, baseRelative); err != nil {
return err
}
@@ -57,7 +58,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 data/ssl")
return errors.New("证书文件必须位于受保护的 SSL 目录中")
}
if _, exists := seen[relativePath]; exists {
return errors.New("SSL file paths must be unique")