Skip to content

feat: add ReadIMARuntimeMeasurementsCount exported helper#58

Merged
leodido merged 3 commits into
mainfrom
add-read-ima-runtime-measurements-count
May 12, 2026
Merged

feat: add ReadIMARuntimeMeasurementsCount exported helper#58
leodido merged 3 commits into
mainfrom
add-read-ima-runtime-measurements-count

Conversation

@leodido
Copy link
Copy Markdown
Owner

@leodido leodido commented May 12, 2026

Added

ReadIMARuntimeMeasurementsCount() (int, error) — exported helper that reads /sys/kernel/security/ima/runtime_measurements_count and returns the current count. No side effects, no caching. Linux-only (same build constraint as the other IMA probes).

Motivation

Callers building eBPF/IMA integrations need the raw measurement count to construct their own before/after probes (e.g., "did executing this binary increase the count?"). The existing probeIMAAnyMeasurementActive uses this internally but doesn't expose the count. Exporting it gives callers a building block without duplicating the file-read logic.

This is the first of three follow-up PRs after #57:

  1. This PRReadIMARuntimeMeasurementsCount
  2. ProbeIMAExecMeasurementActive — fresh temp binary, no count>1 shortcut
  3. ProbeIMAFileCheckMeasurementActive — fresh temp file, same pattern

Design notes

  • Not added to SystemFeatures or format.go String() output: the count is a point-in-time read, not a cached probe result. Adding it to SystemFeatures would change the struct's semantics from "snapshot of feature availability" to "snapshot of runtime state".
  • No non-Linux stub needed: follows the same pattern as ProbeIMAAnyMeasurementActive (Linux-only exported function, compiles cleanly on other platforms because nothing cross-platform references it).

Exposes the IMA runtime measurement count from
/sys/kernel/security/ima/runtime_measurements_count. No side effects.
Useful for diagnostics and for callers building before/after probes.

Co-authored-by: Ona <no-reply@ona.com>
@github-actions github-actions Bot added the enhancement New feature or request label May 12, 2026
@leodido leodido self-assigned this May 12, 2026
leodido and others added 2 commits May 12, 2026 11:26
Extract path parameter from readMeasurementCount so tests can supply
temp files instead of requiring /sys/kernel/security/ima.

Co-authored-by: Ona <no-reply@ona.com>
Covers valid count, zero, whitespace, malformed content, empty file,
and missing file.

Co-authored-by: Ona <no-reply@ona.com>
@leodido leodido merged commit 8b969c7 into main May 12, 2026
6 checks passed
@leodido leodido deleted the add-read-ima-runtime-measurements-count branch May 12, 2026 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant