Skip to content

[Task] Add database account expiry monitoring metrics for MariaDB#4032

Open
turanalmammadov wants to merge 1 commit intoapache:masterfrom
turanalmammadov:feat/add-mariadb-account-expiry-monitoring
Open

[Task] Add database account expiry monitoring metrics for MariaDB#4032
turanalmammadov wants to merge 1 commit intoapache:masterfrom
turanalmammadov:feat/add-mariadb-account-expiry-monitoring

Conversation

@turanalmammadov
Copy link
Contributor

Related: #3737

📊 What's Changed?

Implemented password expiry monitoring metrics for MariaDB database to enable proactive security management and compliance tracking.

Changes Made

  1. Modified app-mariadb.yml - Added new metric collection
  2. Updated English documentation - Added metric set description
  3. Updated Chinese documentation - Maintained i18n consistency

✨ New Metric: account_expiry

Collected Fields

Field Type Unit Description
user string - Database user account name
host string - Host pattern for user connections
password_expired string - Password expiration status (Y/N)
password_lifetime number days Password validity period (0 = never expires)
password_last_changed string - Last password modification timestamp
days_until_expiry number days Calculated: Days remaining before expiry

SQL Query

SELECT 
    User, 
    Host, 
    password_expired, 
    IF(password_lifetime IS NULL OR password_lifetime = 0, 0, password_lifetime) as password_lifetime,
    password_last_changed 
FROM mysql.user 
WHERE User != '' 
ORDER BY password_last_changed ASC;

Calculated Field:

days_until_expiry = password_lifetime - DATEDIFF(CURDATE(), password_last_changed)

🎯 Use Cases

1. Security Compliance

  • Track password age across all accounts
  • Enforce password rotation policies
  • Meet regulatory requirements (PCI-DSS, HIPAA, SOC2)
  • Audit trail for password management

2. Proactive Alerting

Configure alert thresholds:

  • Warning: 30 days before expiry
  • Critical: 7 days before expiry
  • Emergency: Password expired

3. Prevent Access Issues

  • Avoid production outages from expired accounts
  • Notify administrators in advance
  • Maintain service continuity
  • Reduce incident response time

4. Multi-Database Management

  • Monitor all database users centrally
  • Track service accounts, admin accounts, app accounts
  • Identify dormant accounts
  • Security hygiene oversight

📸 Example Alert Configuration

# Alert when password expires in < 7 days
- name: MariaDB Account Expiring Soon
  metric: account_expiry
  expr: days_until_expiry < 7 && days_until_expiry >= 0
  priority: 2 # Critical
  times: 1

✅ Testing

  • ✅ SQL query tested on MariaDB 10.6+
  • ✅ Metric collection verified
  • ✅ Calculated field (days_until_expiry) working correctly
  • ✅ Alert configuration functional
  • ✅ Multi-row data returned properly
  • ✅ Handles accounts with no expiry (lifetime = 0)
  • ✅ i18n translations complete (EN, CN, JP)

Test Environment

  • MariaDB 10.6
  • MariaDB 10.11
  • Compatible with MySQL 8.0+ (same schema)

📋 Documentation Updates

English (home/docs/help/mariadb.md)

  • Added complete metric set documentation
  • Described all fields and units
  • Included use case explanation
  • Added alerting guidance note

Chinese (home/i18n/zh-cn/.../mariadb.md)

  • Added Chinese translations
  • Maintained formatting consistency
  • Included security monitoring explanation

🔧 Technical Details

Priority: 14 (non-critical, informational)
Query Type: multiRow (returns multiple user records)
Platform: mariadb
Protocol: JDBC

Handles Edge Cases:

  • Accounts with NULL password_lifetime (never expires)
  • Accounts with password_lifetime = 0 (never expires)
  • Empty username filtering (WHERE User != '')
  • Sorts by last_changed for easy identification of oldest passwords

🎓 MariaDB Password Management

MariaDB supports password expiry via:

ALTER USER 'user'@'host' PASSWORD EXPIRE INTERVAL 90 DAY;

This monitoring metric tracks these settings across all accounts.

✅ Task List Progress

From #3737:

  • app-mariadb.yml ✓ (this PR)

📝 Notes

Resolves #3737 (app-mariadb.yml portion)

Made with Cursor

Implement password expiry monitoring for MariaDB database accounts
to enable proactive security management and compliance tracking.

Changes:

1. Added new metric 'account_expiry' to app-mariadb.yml:
   - Queries mysql.user table for password expiration data
   - Tracks password_expired, password_lifetime, password_last_changed
   - Calculates days_until_expiry as a computed metric
   - Priority 14 for non-critical monitoring
   - Supports multi-row results for all database users
   - Includes proper i18n (Chinese, English, Japanese)

2. Updated English documentation (home/docs/help/mariadb.md):
   - Added account_expiry metric set documentation
   - Documented all 6 fields with descriptions
   - Explained use case for security monitoring
   - Added alerting guidance

3. Updated Chinese documentation:
   - Added corresponding Chinese translations
   - Maintains consistency with English docs

Metric Fields:
- user: Database user account name
- host: Allowed connection host
- password_expired: Expiration status (Y/N)
- password_lifetime: Days until expiration (0 = never)
- password_last_changed: Last password change timestamp
- days_until_expiry: Calculated remaining days

SQL Query:
SELECT User, Host, password_expired,
       IF(password_lifetime IS NULL OR password_lifetime = 0, 0, password_lifetime) as password_lifetime,
       password_last_changed
FROM mysql.user
WHERE User != ''
ORDER BY password_last_changed ASC;

Benefits:
- Proactive password expiry alerts
- Security compliance monitoring
- Prevents account lockouts
- Tracks password age across all users
- Enables automated alerting
- Supports multi-database monitoring

Use Cases:
- Alert 7 days before password expiry
- Compliance auditing (password rotation policies)
- Security best practices enforcement
- Prevent production access issues

Testing:
- Tested SQL query on MariaDB 10.x
- Verified metric collection
- Confirmed alerting capability
- Validated i18n translations

Related:
- Issue apache#3737 (task list: app-mariadb.yml ✓)
- Reference: PR apache#3674 (Oracle implementation)

Signed-off-by: Turan Almammadov <16321061+turanalmammadov@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions github-actions bot added doc Improvements or additions to documentation monitoring-template backend labels Feb 23, 2026
turanalmammadov added a commit to turanalmammadov/hertzbeat that referenced this pull request Feb 23, 2026
Implement user account and role monitoring for MongoDB database
to enable security auditing and access control visibility.

Changes:

1. Added new metric 'user_info' to app-mongodb.yml:
   - Uses MongoDB usersInfo command
   - Queries admin database for user information
   - Tracks user, db, roles, auth mechanisms, password digest
   - Priority 13 for security monitoring
   - Multi-user support with proper labeling
   - Includes i18n (Chinese, English, Japanese)

2. Updated English documentation (home/docs/help/mongodb.md):
   - Added user_info metric set documentation
   - Documented all fields with descriptions
   - Explained security monitoring use cases
   - Added alerting recommendations

3. Updated Chinese documentation:
   - Added Chinese translations
   - Maintains documentation consistency

Metric Fields:
- user: MongoDB user account name
- db: Authentication database
- roles: Assigned roles (JSON array)
- mechanisms: Available auth mechanisms (SCRAM-SHA-256, etc.)
- passwordDisgest: Password hashing method

MongoDB Command:
usersInfo (runs against admin database)

Benefits:
- User account visibility and auditing
- Role-based access control monitoring
- Authentication mechanism tracking
- Security compliance verification
- Unauthorized user detection
- Access control governance

Use Cases:
- Alert on new user creation
- Monitor role assignments
- Track authentication methods
- Audit security configurations
- Compliance reporting
- Access control reviews

Security Monitoring:
- Detects unauthorized user accounts
- Tracks privilege escalation
- Monitors authentication changes
- Supports security audits

Testing:
- Tested on MongoDB 4.x, 5.x, 6.x
- Verified usersInfo command execution
- Confirmed role data collection
- Validated i18n translations

Related:
- Issue apache#3737 (task list: app-mongodb.yml ✓)
- Reference: PR apache#3674 (Oracle), PR apache#4032 (MariaDB)

Signed-off-by: Turan Almammadov <16321061+turanalmammadov@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
turanalmammadov added a commit to turanalmammadov/hertzbeat that referenced this pull request Feb 23, 2026
Implement user account and role monitoring for MongoDB database
to enable security auditing and access control visibility.

Changes:

1. Added new metric 'user_info' to app-mongodb.yml:
   - Uses MongoDB usersInfo command
   - Queries admin database for user information
   - Tracks user, db, roles, auth mechanisms, password digest
   - Priority 13 for security monitoring
   - Multi-user support with proper labeling
   - Includes i18n (Chinese, English, Japanese)

2. Updated English documentation (home/docs/help/mongodb.md):
   - Added user_info metric set documentation
   - Documented all fields with descriptions
   - Explained security monitoring use cases
   - Added alerting recommendations

3. Updated Chinese documentation:
   - Added Chinese translations
   - Maintains documentation consistency

Metric Fields:
- user: MongoDB user account name
- db: Authentication database
- roles: Assigned roles (JSON array)
- mechanisms: Available auth mechanisms (SCRAM-SHA-256, etc.)
- passwordDisgest: Password hashing method

MongoDB Command:
usersInfo (runs against admin database)

Benefits:
- User account visibility and auditing
- Role-based access control monitoring
- Authentication mechanism tracking
- Security compliance verification
- Unauthorized user detection
- Access control governance

Use Cases:
- Alert on new user creation
- Monitor role assignments
- Track authentication methods
- Audit security configurations
- Compliance reporting
- Access control reviews

Security Monitoring:
- Detects unauthorized user accounts
- Tracks privilege escalation
- Monitors authentication changes
- Supports security audits

Testing:
- Tested on MongoDB 4.x, 5.x, 6.x
- Verified usersInfo command execution
- Confirmed role data collection
- Validated i18n translations

Related:
- Issue apache#3737 (task list: app-mongodb.yml ✓)
- Reference: PR apache#3674 (Oracle), PR apache#4032 (MariaDB)

Signed-off-by: Turan Almammadov <16321061+turanalmammadov@users.noreply.github.com>
Co-authored-by: Cursor <cursoragent@cursor.com>
database: ^_^database^_^
timeout: ^_^timeout^_^
queryType: multiRow
sql: SELECT User, Host, password_expired, IF(password_lifetime IS NULL OR password_lifetime = 0, 0, password_lifetime) as password_lifetime, password_last_changed FROM mysql.user WHERE User != '' ORDER BY password_last_changed ASC;
Copy link
Member

Choose a reason for hiding this comment

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

The current configuration performs redundant field mapping (e.g., user=User) and logic calculation in the application layer. This adds unnecessary overhead to the collector's expression engine.

I suggest moving this logic directly into the SQL statement using aliases and built-in functions. This follows the "calculation push-down" principle, improving efficiency and simplifying the YAML.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend doc Improvements or additions to documentation monitoring-template

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Task] Add database account expiry monitoring metrics

2 participants