Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ module github.com/tuxerrante/kapparmor

go 1.25

require github.com/prometheus/client_golang v1.23.2

require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/kr/text v0.2.0 // indirect
github.com/kylelemons/godebug v1.1.0 // indirect
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
github.com/prometheus/client_golang v1.23.2 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.66.1 // indirect
github.com/prometheus/procfs v0.16.1 // indirect
Expand Down
23 changes: 23 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,23 @@ github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM=
github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw=
github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs=
github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs=
github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo=
github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA=
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o=
github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg=
github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk=
Expand All @@ -14,10 +27,20 @@ github.com/prometheus/common v0.66.1 h1:h5E0h5/Y8niHc5DlaLlWLArTQI7tMrsfQjHV+d9Z
github.com/prometheus/common v0.66.1/go.mod h1:gcaUsgf3KfRSwHY4dIMXLPV0K/Wg1oZ8+SbZk/HH/dA=
github.com/prometheus/procfs v0.16.1 h1:hZ15bTNuirocR6u0JZ6BAHHmwS1p8B4P6MRqxtzMyRg=
github.com/prometheus/procfs v0.16.1/go.mod h1:teAbpZRB1iIAJYREa1LsoWUXykVXA1KlTmWl8x/U+Is=
github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjRBZyWFQ=
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U=
github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U=
go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto=
go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE=
go.yaml.in/yaml/v2 v2.4.2 h1:DzmwEr2rDGHl7lsFgAHxmNz/1NlQ7xLIrlN2h5d1eGI=
go.yaml.in/yaml/v2 v2.4.2/go.mod h1:081UH+NErpNdqlCXm3TtEran0rJZGxAYx9hb/ELlsPU=
golang.org/x/sys v0.35.0 h1:vz1N37gP5bs89s7He8XuIYXpyY0+QlsKmzipCbUtyxI=
golang.org/x/sys v0.35.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k=
google.golang.org/protobuf v1.36.8 h1:xHScyCOEuuwZEc6UtSOvPbAT4zRh0xcNRYekJwfqyMc=
google.golang.org/protobuf v1.36.8/go.mod h1:fuxRtAxBytpl4zzqUh6/eyUujkJdNiuEkXntxiD/uRU=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
15 changes: 10 additions & 5 deletions src/app/filesystemOperations.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,15 @@ func compareLocalFiles(filePath1, filePath2 string) (bool, error) {
fileBytes1, err := os.ReadFile(filePath1) // #nosec G304 -- path validated
if err != nil {
slog.Default().Error("read file error", slog.Any("error", err))
os.Exit(1)

return false, fmt.Errorf("reading %s: %w", filePath1, err)
}

fileBytes2, err := os.ReadFile(filePath2) // #nosec G304 -- path validated
if err != nil {
slog.Default().Error("read file error", slog.Any("error", err))
os.Exit(1)

return false, fmt.Errorf("reading %s: %w", filePath2, err)
}

trimmedBytes1 := bytes.TrimSpace(fileBytes1)
Expand Down Expand Up @@ -207,7 +209,8 @@ func areProfilesReadable(folderName string) (bool, map[string]bool) {
files, err := os.ReadDir(folderName)
if err != nil {
slog.Default().Error("readdir error", slog.Any("error", err))
os.Exit(1)

return false, nil
}

if len(files) == 0 {
Expand Down Expand Up @@ -237,7 +240,8 @@ func areProfilesReadable(folderName string) (bool, map[string]bool) {
slog.String("folder", folderName),
slog.String("filename", filename),
slog.Any("error", err))
os.Exit(1)

return false, nil
}

slog.Default().Info("profile candidate", slog.String("name", filename))
Expand Down Expand Up @@ -463,7 +467,8 @@ func CopyFile(src, dst string) error {
sfi, err := os.Stat(src)
if err != nil {
slog.Default().Error("stat src error", slog.Any("error", err))
os.Exit(1)

return fmt.Errorf("CopyFile: stat source %s: %w", src, err)
}

if !sfi.Mode().IsRegular() {
Expand Down
2 changes: 1 addition & 1 deletion src/app/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ func unloadProfile(cfg *AppConfig, fileName string) error {
filePath := path.Join(cfg.EtcApparmord, safeFileName)

// Check if the file exists first.
if _, err := os.Stat(filePath); errors.Is(os.ErrNotExist, err) {
if _, err := os.Stat(filePath); errors.Is(err, os.ErrNotExist) {
slog.Default().Info("Profile file does not exist, skipping unload", slog.String("profile", filePath))

return nil // Nothing to do
Expand Down
17 changes: 17 additions & 0 deletions src/app/metrics/t_metrics_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,20 @@ func TestMetricsServerHandler(t *testing.T) {
t.Error("Il body della risposta non contiene il valore corretto per 'test-server-profilo'")
}
}

// TestProfileUpdated verifies that ProfileUpdated is an alias for ProfileModified.
func TestProfileUpdated(t *testing.T) {
resetMetrics()
testNodeName := getNodeNameFromEnv()

ProfileUpdated("profilo-updated")

expected := `
# HELP kapparmor_profile_operations_total Numero totale di operazioni sui profili (create, modify, delete).
# TYPE kapparmor_profile_operations_total counter
kapparmor_profile_operations_total{node_name="` + testNodeName + `",operation="modify",profile_name="profilo-updated"} 1
`
if err := testutil.CollectAndCompare(profileOperations, strings.NewReader(expected), "kapparmor_profile_operations_total"); err != nil {
t.Errorf("ProfileUpdated metric mismatch: %v", err)
}
}
2 changes: 1 addition & 1 deletion src/app/profiles_ops.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func printLoadedProfiles(p map[string]bool) {

// Sort alphabetically the profiles and print them
slog.Default().Info("Profiles already on this node", slog.Int("count", len(p)))
loadedProfileNames := make([]string, len(p))
loadedProfileNames := make([]string, 0, len(p))
for loadedProfileName := range p {
loadedProfileNames = append(loadedProfileNames, loadedProfileName)
}
Expand Down
Loading