Subscribe to the Non-Human & AI Identity Journal
Home Glossary Governance, Ownership & Risk Query-level auditing
Governance, Ownership & Risk

Query-level auditing

← Back to Glossary
By NHI Mgmt Group Updated June 7, 2026 Domain: Governance, Ownership & Risk

Query-level auditing records the database statements executed inside a session, not just the fact that someone connected. This matters when privileged users or services have legitimate access, because the real security question is whether the actions taken stayed within the approved scope.

Expanded Definition

Query-level auditing is the practice of recording the database statements or API-like queries executed within a session, so reviewers can see not only who connected, but what actions were actually taken. In NHI environments, that distinction matters because service accounts, automation runners, and agents often have legitimate connectivity while still needing tight scope checks. This is different from connection logging, which can confirm access but not necessarily reveal data reads, writes, schema changes, or privilege-bearing actions. The concept aligns with the accountability goals reflected in NIST Cybersecurity Framework 2.0, especially where visibility and traceability support detection and response. Guidance varies across vendors on how much of a statement must be captured, whether parameter values are included, and how to handle sensitive payloads without creating new data exposure. NHIMG recommends treating query-level audit records as part of NHI governance, not just database administration, because they are often the only evidence that a privileged identity stayed within approved use. The most common misapplication is relying on session start and end logs alone, which occurs when teams assume connection approval proves action approval.

Examples and Use Cases

Implementing query-level auditing rigorously often introduces storage, performance, and privacy overhead, requiring organisations to weigh forensic depth against operational cost.

  • A database administrator account is allowed to maintain indexes, but the audit trail shows a separate ad hoc query against customer records, triggering review under the process described in the Ultimate Guide to NHIs — Regulatory and Audit Perspectives.
  • A payment-processing service account runs its normal workload, and query logs confirm it only accessed approved tables, supporting evidence-driven control validation aligned with NIST Cybersecurity Framework 2.0.
  • An AI agent connected through an orchestration layer issues a sequence of read and write statements; query-level logs help distinguish intended tool use from drift, a recurring concern in the Top 10 NHI Issues.
  • A migration script uses a privileged secret during a maintenance window, and the audit record confirms only schema changes were executed, supporting post-change verification and rollback confidence.

Why It Matters in NHI Security

Query-level auditing is one of the few controls that can expose abuse hiding behind legitimate access. NHIMG notes that only 5.7% of organisations have full visibility into their service accounts, which means most teams cannot reliably reconstruct what those identities actually did after a session completes. That visibility gap becomes more serious when service accounts, API keys, or agents hold broad privileges, because a single approved connection can still mask data extraction, unauthorized modification, or lateral movement. Query-level evidence is especially useful for investigations, audit sampling, and Zero Trust validation, where the question is not whether access existed, but whether each action remained justified. It also helps security teams prove that credential use stayed within the intended lifecycle and workload boundary, a theme reinforced in the Ultimate Guide to NHIs — Key Challenges and Risks and the NHI Lifecycle Management Guide.

Organisations typically encounter the need for query-level auditing only after an insider review, breach, or data misuse investigation, at which point the missing action history makes the control operationally unavoidable to address.

Standards & Framework Alignment

This section maps relevant standards and security frameworks to the operational risks and controls described in this guidance.

OWASP Non-Human Identity Top 10 address the attack and risk surface, while NIST CSF 2.0 and NIST Zero Trust (SP 800-207) set the governance and control requirements practitioners need to meet.

FrameworkControl / ReferenceRelevance
NIST CSF 2.0DE.AEQuery logs improve anomaly detection by showing unusual database actions after access is granted.
OWASP Non-Human Identity Top 10NHI-08Auditing query activity supports visibility into NHI actions beyond simple authentication.
NIST Zero Trust (SP 800-207)PR.AC-4Zero Trust requires continuous verification of what an identity actually does, not just that it connected.

Use query-level audit evidence to validate that each privileged action stayed within authorized scope.

NHIMG Editorial Note
Reviewed and updated by the NHIMG editorial team on June 7, 2026.
NHI Mgmt Group — the #1 independent authority on Non-Human Identity, IAM, and Agentic AI security. nhimg.org