完善动态系统服务安装安全策略
This commit is contained in:
1 parent
886e4da900
commit
b6f1ae490d
7 files changed
+242
-59
No files matched your search
@@ -10,11 +10,14 @@ import (
|
||||
|
||||
func TestRenderUnitFileIncludesExecutableConfigurationAndWorkDir(t *testing.T) {
|
||||
content, err := renderUnitFile(Options{
|
||||
Name: "Scert",
|
||||
Description: "Scert SSL 证书管理服务",
|
||||
Executable: filepath.Join("/opt", "Scert", "scert"),
|
||||
ConfigPath: filepath.Join("/opt", "Scert data", "scert.json"),
|
||||
WorkDir: filepath.Join("/opt", "Scert data"),
|
||||
Name: "Scert",
|
||||
Description: "Scert SSL 证书管理服务",
|
||||
Executable: filepath.Join("/opt", "Scert", "scert"),
|
||||
ConfigPath: filepath.Join("/opt", "Scert data", "scert.json"),
|
||||
WorkDir: filepath.Join("/opt", "Scert data"),
|
||||
User: "Scert",
|
||||
Group: "Scert",
|
||||
ReadWritePaths: []string{"/var/lib/scert", "/var/log/scert"},
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatalf("渲染 systemd unit 失败:%v", err)
|
||||
@@ -23,11 +26,17 @@ func TestRenderUnitFileIncludesExecutableConfigurationAndWorkDir(t *testing.T) {
|
||||
"[Unit]",
|
||||
"Description=Scert SSL 证书管理服务",
|
||||
"After=network-online.target",
|
||||
"ConditionPathExists=\"/opt/Scert data/scert.json\"",
|
||||
"[Service]",
|
||||
"Type=simple",
|
||||
"User=Scert",
|
||||
"Group=Scert",
|
||||
"WorkingDirectory=\"/opt/Scert data\"",
|
||||
"ExecStart=\"/opt/Scert/scert\" --config \"/opt/Scert data/scert.json\" serve",
|
||||
"Restart=on-failure",
|
||||
"ProtectSystem=full",
|
||||
"RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6",
|
||||
"ReadWritePaths=\"/var/lib/scert\" \"/var/log/scert\"",
|
||||
"[Install]",
|
||||
"WantedBy=multi-user.target",
|
||||
} {
|
||||
@@ -44,3 +53,13 @@ func TestUnitFilePathRejectsPathTraversal(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestRenderUnitFileRejectsRelativeWritablePath(t *testing.T) {
|
||||
_, err := renderUnitFile(Options{
|
||||
Name: "Scert", Executable: "/opt/scert", ConfigPath: "/opt/scert/scert.json", WorkDir: "/opt/scert",
|
||||
ReadWritePaths: []string{"relative/path"},
|
||||
})
|
||||
if err == nil {
|
||||
t.Fatal("相对可写路径未被拒绝")
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user