Skip to content

Commit 8221cd0

Browse files
committed
modified: docs/install.example.json
1 parent 3c33b09 commit 8221cd0

5 files changed

Lines changed: 337 additions & 15 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ sudo cp docs/install.example.json /etc/ols-cli/install.json
141141
sudo ols install
142142
```
143143

144+
`install.json` also supports `owasp_crs_version` (for example, `"owasp_crs_version": "4.21.0"`), which is used when enabling OWASP via `site create/update --enable-owasp`.
145+
144146
Override config values with flags when needed:
145147

146148
```bash

docs/install.example.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,6 @@
55
"http_port": 80,
66
"https_port": 443,
77
"ssl_cert_file": "/usr/local/lsws/admin/conf/webadmin.crt",
8-
"ssl_key_file": "/usr/local/lsws/admin/conf/webadmin.key"
8+
"ssl_key_file": "/usr/local/lsws/admin/conf/webadmin.key",
9+
"owasp_crs_version": "4.21.0"
910
}

internal/service/install_config.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ type RuntimeInstallConfig struct {
2424
HTTPSPort int `json:"https_port"`
2525
SSLCertFile string `json:"ssl_cert_file"`
2626
SSLKeyFile string `json:"ssl_key_file"`
27+
OWASPCRSVersion string `json:"owasp_crs_version"`
2728
}
2829

2930
type resolvedInstallPlan struct {
@@ -36,6 +37,7 @@ type resolvedInstallPlan struct {
3637
HTTPSPort int
3738
SSLCertFile string
3839
SSLKeyFile string
40+
OWASPCRSVersion string
3941
}
4042

4143
func defaultRuntimeInstallConfig(lswsRoot string) RuntimeInstallConfig {
@@ -48,6 +50,7 @@ func defaultRuntimeInstallConfig(lswsRoot string) RuntimeInstallConfig {
4850
HTTPSPort: 443,
4951
SSLCertFile: filepath.Join(lswsRoot, "admin", "conf", "webadmin.crt"),
5052
SSLKeyFile: filepath.Join(lswsRoot, "admin", "conf", "webadmin.key"),
53+
OWASPCRSVersion: defaultOWASPCRSVersion,
5154
}
5255
}
5356

@@ -106,6 +109,9 @@ func mergeRuntimeInstallConfig(base, override RuntimeInstallConfig) RuntimeInsta
106109
if v := strings.TrimSpace(override.SSLKeyFile); v != "" {
107110
base.SSLKeyFile = v
108111
}
112+
if v := strings.TrimSpace(override.OWASPCRSVersion); v != "" {
113+
base.OWASPCRSVersion = v
114+
}
109115
return base
110116
}
111117

@@ -162,6 +168,10 @@ func resolveInstallPlan(opts InstallOptions, info platform.Info, lswsRoot string
162168
if v := strings.TrimSpace(opts.SSLKeyFile); v != "" {
163169
sslKeyFile = v
164170
}
171+
owaspCRSVersion := strings.TrimSpace(cfg.OWASPCRSVersion)
172+
if owaspCRSVersion == "" {
173+
owaspCRSVersion = defaultOWASPCRSVersion
174+
}
165175

166176
if err := validatePort(httpPort, "http_port"); err != nil {
167177
return resolvedInstallPlan{}, err
@@ -194,6 +204,7 @@ func resolveInstallPlan(opts InstallOptions, info platform.Info, lswsRoot string
194204
HTTPSPort: httpsPort,
195205
SSLCertFile: sslCertFile,
196206
SSLKeyFile: sslKeyFile,
207+
OWASPCRSVersion: owaspCRSVersion,
197208
}, nil
198209
}
199210

internal/service/install_config_test.go

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package service
33
import (
44
"bytes"
55
"context"
6+
"os"
67
"path/filepath"
78
"testing"
89

@@ -35,6 +36,9 @@ func TestResolveInstallPlanDefaults(t *testing.T) {
3536
if plan.HTTPPort != 80 || plan.HTTPSPort != 443 {
3637
t.Fatalf("expected default ports 80/443, got %d/%d", plan.HTTPPort, plan.HTTPSPort)
3738
}
39+
if plan.OWASPCRSVersion != defaultOWASPCRSVersion {
40+
t.Fatalf("expected default owasp crs version %s, got %s", defaultOWASPCRSVersion, plan.OWASPCRSVersion)
41+
}
3842
}
3943

4044
func TestResolveInstallPlanOverrides(t *testing.T) {
@@ -74,6 +78,31 @@ func TestResolveInstallPlanOverrides(t *testing.T) {
7478
}
7579
}
7680

81+
func TestLoadRuntimeInstallConfigIncludesOWASPCRSVersion(t *testing.T) {
82+
configPath := filepath.Join(t.TempDir(), "install.json")
83+
content := `{
84+
"php_version": "85",
85+
"database": "mariadb",
86+
"configure_listeners": true,
87+
"http_port": 80,
88+
"https_port": 443,
89+
"ssl_cert_file": "/usr/local/lsws/admin/conf/webadmin.crt",
90+
"ssl_key_file": "/usr/local/lsws/admin/conf/webadmin.key",
91+
"owasp_crs_version": "4.22.0"
92+
}`
93+
if err := os.WriteFile(configPath, []byte(content), 0o644); err != nil {
94+
t.Fatalf("write config: %v", err)
95+
}
96+
97+
cfg, _, err := loadRuntimeInstallConfig(configPath, "/usr/local/lsws")
98+
if err != nil {
99+
t.Fatalf("unexpected load error: %v", err)
100+
}
101+
if cfg.OWASPCRSVersion != "4.22.0" {
102+
t.Fatalf("expected owasp_crs_version 4.22.0, got %s", cfg.OWASPCRSVersion)
103+
}
104+
}
105+
77106
func TestResolveInstallPlanDatabaseNone(t *testing.T) {
78107
plan, err := resolveInstallPlan(
79108
InstallOptions{ConfigPath: filepath.Join(t.TempDir(), "install.json"), DatabaseEngine: "none"},
@@ -102,12 +131,12 @@ func TestResolveInstallPlanInvalidDatabase(t *testing.T) {
102131
func TestResolveInstallPlanRejectsUnsafeSSLPaths(t *testing.T) {
103132
_, err := resolveInstallPlan(
104133
InstallOptions{
105-
ConfigPath: filepath.Join(t.TempDir(), "install.json"),
106-
SSLCertFile: "/etc/ssl/certs/server.crt\nmalicious 1",
107-
SSLKeyFile: "/etc/ssl/private/server.key",
108-
HTTPPort: 80,
109-
HTTPSPort: 443,
110-
PHPVersion: "85",
134+
ConfigPath: filepath.Join(t.TempDir(), "install.json"),
135+
SSLCertFile: "/etc/ssl/certs/server.crt\nmalicious 1",
136+
SSLKeyFile: "/etc/ssl/private/server.key",
137+
HTTPPort: 80,
138+
HTTPSPort: 443,
139+
PHPVersion: "85",
111140
DatabaseEngine: "mariadb",
112141
},
113142
platform.Info{PackageManager: platform.PackageManagerAPT},
@@ -134,4 +163,3 @@ func TestInstallRuntimeDryRunIncludesResolvedPlan(t *testing.T) {
134163
t.Fatalf("expected no runner calls in dry-run, got %d", len(r.calls))
135164
}
136165
}
137-

0 commit comments

Comments
 (0)