Skip to content

Conversation

danilrwx
Copy link
Contributor

@danilrwx danilrwx commented Oct 22, 2025

Description

Improving audit events names. Also add ignoring system service acconts.

Checklist

  • The code is covered by unit tests.
  • e2e tests passed.
  • Documentation updated according to the changes.
  • Changes were tested in the Kubernetes cluster manually.

Changelog entries

section: module
type: fix
summary: Improving audit events names. Also add ignoring system service acconts.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 22, 2025

Reviewer's Guide

This PR refactors audit event naming to more descriptive messages including VM names and users, adds filters to ignore events from system service accounts, updates tests to align with new behavior, and adjusts server log levels.

Class diagram for updated audit event handling

classDiagram
    class VMAccess {
        +IsMatched() bool
        +Fill() error
        - eventLog.Name: now includes VM name, connection stage, subresource, and user
        - IsMatched: ignores system service accounts except d8-service-accounts
    }
    class IntegrityCheckVM {
        +IsMatched() bool
        +Fill() error
        - eventLog.Name: now includes VM name
        - IsMatched: ignores system service accounts except d8-service-accounts
    }
    class VMOPControl {
        +IsMatched() bool
        +Fill() error
        - eventLog.Name: now includes VM name and user for all actions (start, stop, restart, migrate, evict)
        - IsMatched: ignores system service accounts except d8-service-accounts
    }
    class VMControl {
        +Fill() error
        - eventLog.Name: now includes VM name for OS stop/restart, abnormal kill includes user
        - Fill: ignores system service accounts except d8-service-accounts
    }
    class VMManage {
        +IsMatched() bool
        +Fill() error
        - eventLog.Name: now includes VM name and user for create, update, delete
        - IsMatched: ignores system service accounts except d8-service-accounts
    }
    class ModuleComponentControl {
        +IsMatched() bool
        +Fill() error
        - eventLog.Name: now includes component name and user for create/delete
        - IsMatched: ignores system service accounts except d8-service-accounts
    }
    class Forbid {
        +IsMatched() bool
        +Fill() error
        - eventLog.Name: now includes user, verb, and resource in forbidden operation
        - IsMatched: ignores system service accounts except d8-service-accounts
    }
    class ModuleControl {
        +IsMatched() bool
        - IsMatched: ignores system service accounts except d8-service-accounts
    }
Loading

File-Level Changes

Change Details Files
Standardize and enhance audit event names
  • Replaced hardcoded names with formatted strings including resource name and user
  • Unified naming conventions across VMControl, VMOPControl, VMManage, VMAccess, IntegrityCheckVM, ModuleComponentControl, and Forbid events
pkg/audit/events/vm/vm_control.go
pkg/audit/events/vm/vmop_control.go
pkg/audit/events/vm/vm_manage.go
pkg/audit/events/vm/vm_access.go
pkg/audit/events/integrity/integrity_check_vm.go
pkg/audit/events/module/module_component_control.go
pkg/audit/events/forbid/forbid.go
Ignore events from system service accounts by default
  • Added Username prefix checks in IsMatched to skip system:* users except d8-service-accounts
  • Applied filtering in VMAccess, IntegrityCheckVM, VMOPControl, VMManage, ModuleComponentControl, ModuleControl, and Forbid
pkg/audit/events/vm/vm_access.go
pkg/audit/events/integrity/integrity_check_vm.go
pkg/audit/events/vm/vmop_control.go
pkg/audit/events/vm/vm_manage.go
pkg/audit/events/module/module_component_control.go
pkg/audit/events/forbid/forbid.go
pkg/audit/events/module/module_control.go
Update unit tests to match new event names and behavior
  • Adjusted expectedName assertions to the new formatted messages
  • Introduced shoulntLog flag and ShouldLog checks for ignored cases
  • Added VM name label injection in pod fixture for tests
pkg/audit/events/vm/vm_control_test.go
pkg/audit/events/vm/vmop_control_test.go
pkg/audit/events/vm/vm_access_test.go
pkg/audit/events/vm/vm_manage_test.go
pkg/audit/events/integrity/integrity_check_vm_test.go
pkg/audit/events/module/module_component_control_test.go
pkg/audit/events/forbid/forbid_test.go
Lower audit server log levels
  • Changed server startup and connection logs from Info to Debug
pkg/audit/server/server.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@danilrwx danilrwx added this to the v1.2.0 milestone Oct 22, 2025
@danilrwx danilrwx marked this pull request as ready for review October 22, 2025 12:10
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey there - I've reviewed your changes - here's some feedback:

  • The system user/serviceaccount filtering logic is duplicated in multiple matchers—consider extracting it into a shared helper so you don’t risk inconsistent behavior across event types.
  • Verify that your whitelist for serviceaccounts (only allowing “system:serviceaccount:d8-service-accounts”) actually covers all legitimate accounts (like “d8-virtualization” in your tests) so you don’t accidentally filter out valid audit events.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The system user/serviceaccount filtering logic is duplicated in multiple matchers—consider extracting it into a shared helper so you don’t risk inconsistent behavior across event types.
- Verify that your whitelist for serviceaccounts (only allowing “system:serviceaccount:d8-service-accounts”) actually covers all legitimate accounts (like “d8-virtualization” in your tests) so you don’t accidentally filter out valid audit events.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>

move  username checks to each event

Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>

fix names

Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>

add quotes

Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>

update name

Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>

fix tests

Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>

fix

Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>

fix test

Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
@danilrwx danilrwx force-pushed the fix/audit/rename-audit-events branch from 5552fd8 to 98d95dc Compare October 22, 2025 12:12
@danilrwx danilrwx merged commit 18e41f2 into main Oct 22, 2025
23 of 24 checks passed
@danilrwx danilrwx deleted the fix/audit/rename-audit-events branch October 22, 2025 12:14
danilrwx added a commit that referenced this pull request Oct 22, 2025
Description
Improving audit events names. Also add ignoring system service acconts.

Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
danilrwx added a commit that referenced this pull request Oct 22, 2025
Description
Improving audit events names. Also add ignoring system service acconts.

Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
diafour pushed a commit that referenced this pull request Oct 22, 2025
fix(audit): rename audit events (#1611)

Description
Improving audit events names. Also add ignoring system service acconts.

Signed-off-by: Daniil Antoshin <daniil.antoshin@flant.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants