Skip to content

Commit 929ab0f

Browse files
authored
Merge pull request #18 from klouddb/release-v2.3
PostgreSQL 17 Support (Commit: 87a6f0f) postgres/check.go: Added new checks for PostgreSQL 17 across multiple categories postgres/installation/installation.go: Added systemd service verification for PostgreSQL 17 SSL Handling and Structure Improvements (Commit: 830c261) Configuration: Updated config handling for SSL and ping check flags Database Connections: Enhanced PostgreSQL and MySQL connection handling Log Parser: Improved log parsing with better SSL handling Templates: Updated HTML report templates Integration Tests: Enhanced test case structure
2 parents 81b0eb6 + 5ed452d commit 929ab0f

File tree

22 files changed

+565
-52
lines changed

22 files changed

+565
-52
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,4 +49,6 @@ detailed_output.csv
4949
all_checks.json
5050

5151
postgresql.conf
52-
testoutput.log
52+
testoutput.log
53+
54+
*.prof

README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,11 @@ port="5432"
100100
user="postgres"
101101
dbname="postgres"
102102
password="xxxxx"
103+
sslmode="require"
104+
sslcert="path/to/cert"
105+
sslkey="path/to/key"
106+
sslrootcert="path/to/rootcert"
107+
pingCheck=true
103108
maxIdleConn = 2
104109
maxOpenConn = 2
105110

cmd/ciscollector/logparserrunner.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ func runLogParserWithMultipleParser(ctx context.Context, runCmd bool, logParserC
112112
logparser.PrintTerminalResultsForLogParser(ctx, allParser, outputType)
113113
}
114114

115-
htmlReportHelper.RenderLogparserResponse(ctx, store, allParser)
115+
htmlReportHelper.RenderLogparserResponse(ctx, allParser)
116116
return nil
117117
}
118118

docker_testing/integrationtest/testcase.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func testUnusedHbaLines(prefix, file string) {
188188
}
189189

190190
out := buf.String()
191-
if strings.Contains(out, "In logline prefix, please set '%u' and '%d'") || strings.Contains(out, "Please set log_line_prefix to '%h' or '%r' or enable log_connections") {
191+
if strings.Contains(out, "In logline prefix, please set '%u' and '%d'") || strings.Contains(out, "please set log_line_prefix") {
192192
fmt.Println("skipping test for unused files as required details are not available in prefix:", prefix)
193193
return
194194
}
@@ -199,7 +199,7 @@ func testUnusedHbaLines(prefix, file string) {
199199
os.Exit(1)
200200
}
201201

202-
if strings.Contains(out, `Unused lines found from given log file: [11 23 28]`) {
202+
if strings.Contains(out, `Unused lines found from given log file: [11 23 28]`) || strings.Contains(out, `Unused lines found from given log file: [11 16 17 23 28]`) {
203203
fmt.Println("unused lines test is working fine for prefix:", prefix)
204204
return
205205
}

htmlreport/logparser_helper.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package htmlreport
22

33
import (
44
"context"
5-
"database/sql"
65
"strings"
76

87
"github.com/klouddb/klouddbshield/pkg/hbarules"
@@ -12,7 +11,7 @@ import (
1211
)
1312

1413
type LogparserHTMLReport struct {
15-
Error string
14+
Error []string
1615
InactiveUsers *SimplifiedInactiveUserData
1716
UniqueIPs *UniqueIPRenderData
1817
UnusedHBALines *UnusedHBALinesRenderData
@@ -61,11 +60,11 @@ func GetSimplifiedInactiveUsers(userdata [][]string) *SimplifiedInactiveUserData
6160

6261
func (h *HtmlReportHelper) RanderLogParserError(err error) {
6362
h.AddTab("Log Parser", LogparserHTMLReport{
64-
Error: err.Error(),
63+
Error: []string{err.Error()},
6564
})
6665
}
6766

68-
func (h *HtmlReportHelper) RenderLogparserResponse(ctx context.Context, store *sql.DB, parsers []runner.Parser) {
67+
func (h *HtmlReportHelper) RenderLogparserResponse(ctx context.Context, parsers []runner.Parser) {
6968
data := LogparserHTMLReport{}
7069

7170
for _, r := range parsers {
@@ -92,6 +91,8 @@ func (h *HtmlReportHelper) RenderLogparserResponse(ctx context.Context, store *s
9291
data.SQLInjection = &SQLInjectionRenderData{
9392
Logs: r.GetResult(ctx),
9493
}
94+
case *logparser.ErrorHelper:
95+
data.Error = append(data.Error, r.Error())
9596
}
9697
}
9798

htmlreport/template/logparser.tmpl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
{{ define "logparserbody" }}
22
<div class="wrapper">
33
<div class="myContainer">
4-
{{ if .Error }}
5-
<h3> Becuase of some error we were not able to generate the report for Log Parser.</h3>
6-
<p>{{ .Error }}</p>
4+
{{ if and (not (eq .Error nil)) (gt (len .Error) 0) }}
5+
<h3>There are some errors while parsing the log file. Please check the following:</h3>
6+
{{ range .Error }}
7+
<p style="color: #a72727;">{{ . }}</p>
8+
{{ end }}
79
{{ end }}
810
{{ if .InactiveUsers }}
911
<div class="data-container">

kshieldconfig_example.toml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
# port = "5432"
66
# user = "postgres"
77
# password = "password123"
8+
# sslmode = "disable"
9+
# sslcert="path/to/cert"
10+
# sslkey="path/to/key"
11+
# sslrootcert="path/to/rootcert"
12+
# pingCheck = true
813
# dbname = "mydb"
14+
# sslmode = "disable"
15+
# pingCheck = true
916
# maxIdleConn = 10
1017
# maxOpenConn = 100
1118

@@ -14,6 +21,7 @@
1421
# port="3306"
1522
# user="root"
1623
# password="mysql111"
24+
# pingCheck = true
1725
# maxIdleConn = 2
1826
# maxOpenConn = 2
1927

pkg/config/config.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -217,8 +217,9 @@ type MySQL struct {
217217
Password string `toml:"password"`
218218
// DBName string `toml:"dbname"`
219219
// SSLmode string `toml:"sslmode"`
220-
MaxIdleConn int `toml:"maxIdleConn"`
221-
MaxOpenConn int `toml:"maxOpenConn"`
220+
PingCheck bool `toml:"pingCheck"`
221+
MaxIdleConn int `toml:"maxIdleConn"`
222+
MaxOpenConn int `toml:"maxOpenConn"`
222223
}
223224

224225
func (p *MySQL) HtmlReportName() string {
@@ -858,6 +859,12 @@ func LoadConfig(configPath string) (*Config, error) {
858859
return c, fmt.Errorf("unmarshal: %v", err)
859860
}
860861

862+
if c.Postgres != nil {
863+
if c.Postgres.SSLmode == "" {
864+
c.Postgres.SSLmode = "disable"
865+
}
866+
}
867+
861868
return c, nil
862869
}
863870

pkg/logparser/hba_unused_lines.go

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,21 @@ func NewUnusedHBALineHelper(store *sql.DB) *UnusedHBALineHelper {
2424

2525
func (i *UnusedHBALineHelper) Init(ctx context.Context, logParserCnf *config.LogParser) error {
2626
// check if postgres setting contains required variable or connection logs
27-
if !strings.Contains(logParserCnf.PgSettings.LogLinePrefix, "%h") && !strings.Contains(logParserCnf.PgSettings.LogLinePrefix, "%r") {
28-
return fmt.Errorf("Please set log_line_prefix to '%%h' or '%%r' or enable log_connections")
29-
}
27+
// for unused hba parsing we need to have any 2 of the following
28+
// 1. log_line_prefix contains %h or %r
29+
// 2. log_connections is enabled
30+
// 3. log_line_prefix contains %u and %d
3031

31-
if !strings.Contains(logParserCnf.PgSettings.LogLinePrefix, "%u") || !strings.Contains(logParserCnf.PgSettings.LogLinePrefix, "%d") {
32-
return fmt.Errorf("In logline prefix, please set '%s' and '%s'\n", "%u", "%d") // using printf to avoid the warning for %d in println
32+
if logParserCnf.PgSettings.LogConnections {
33+
if !(strings.Contains(logParserCnf.PgSettings.LogLinePrefix, "%h") || strings.Contains(logParserCnf.PgSettings.LogLinePrefix, "%r")) &&
34+
!(strings.Contains(logParserCnf.PgSettings.LogLinePrefix, "%u") && strings.Contains(logParserCnf.PgSettings.LogLinePrefix, "%d")) {
35+
return fmt.Errorf("with log_connections enabled, please set log_line_prefix to '%%h' or '%%r' or '%%u' and '%%d'")
36+
}
37+
} else {
38+
if !(strings.Contains(logParserCnf.PgSettings.LogLinePrefix, "%h") || strings.Contains(logParserCnf.PgSettings.LogLinePrefix, "%r")) ||
39+
!(strings.Contains(logParserCnf.PgSettings.LogLinePrefix, "%u") && strings.Contains(logParserCnf.PgSettings.LogLinePrefix, "%d")) {
40+
return fmt.Errorf("please set log_line_prefix to '%%h' or '%%r' or '%%u' and '%%d'")
41+
}
3342
}
3443

3544
var hbaRules []model.HBAFIleRules

pkg/logparser/inactive_users.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func NewInactiveUsersHelper(store *sql.DB) *InactiveUsersHelper {
2626
func (i *InactiveUsersHelper) Init(ctx context.Context, logParserCnf *config.LogParser) error {
2727
// check if postgres setting contains required variable or connection logs
2828
if !strings.Contains(logParserCnf.PgSettings.LogLinePrefix, "%u") && !logParserCnf.PgSettings.LogConnections {
29-
return fmt.Errorf("Please set log_line_prefix to '%%u' or enable log_connections")
29+
return fmt.Errorf("please set log_line_prefix to '%%u' or enable log_connections")
3030
}
3131

3232
i.UniqueUserParser = parselog.NewUserParser(logParserCnf)

0 commit comments

Comments
 (0)