---
title: Run custom SQL monitoring statements and actions securely with Nodinite Database Monitoring Agent
description: Learn how to run custom SQL monitoring statements and user action scripts securely with the Nodinite Database Monitoring Agent, including least privilege, impersonation, connection string isolation, and credential management.
---

# <i class="fal fa-shield-halved" aria-hidden="true"></i> Run custom SQL monitoring statements and actions securely with Nodinite

Use custom SQL monitoring and on-demand actions to extend <span class="nodinite-product-name" title="The node that unites different systems. Or as we call it Nodinite">Nodinite</span>, but keep the execution model strict. The [Database Monitoring Agent][] can run monitoring statements, user action scripts, impersonated identities, and custom connection strings. This flexibility gives strong operational value and also introduces clear security boundaries you must manage.

This guide centralizes the security model for all Database feature pages that use custom SQL logic, [Remote Actions][], impersonation, and connection string overrides.

<aside aria-label="Note" class="nodinite-note nodinite-note--note">
<p class="nodinite-note__label" aria-hidden="true"><i class="far fa-fw fa-note"></i> Note</p>
<div class="nodinite-note__content"><p>This guidance applies to SQL Server, <a href="https://docs.nodinite.com/logging-and-monitoring/database/features/azure-sql-database/overview/">Azure SQL Database</a>, and PostgreSQL scenarios where you configure custom SQL statements, authentication overrides, or user action scripts.</p></div>
</aside>

## Security model at a glance

<div class="mermaid">
flowchart LR
A["fa<i class="fal fa-user-shield" aria-hidden="true"></i> Administrator"]:::actor --> B["fa<i class="fal fa-desktop" aria-hidden="true"></i> Web Client"]:::client
B --> C["fa<i class="fal fa-gears" aria-hidden="true"></i> Database Monitoring Agent"]:::agent
C --> D["fa<i class="fal fa-code" aria-hidden="true"></i> Monitoring Statement"]:::script
C --> E["fa<i class="fal fa-bolt" aria-hidden="true"></i> User Action Script"]:::script
D --> F["fa<i class="fal fa-key" aria-hidden="true"></i> Connection String"]:::identity
E --> G["fa<i class="fal fa-user-secret" aria-hidden="true"></i> Optional Impersonation"]:::identity
F --> H["fa<i class="fal fa-database" aria-hidden="true"></i> Target Database"]:::target
G --> H
classDef actor fill:#93d16d,stroke:#2E7D4E,stroke-width:2px,color:#000
classDef client fill:#2678BD,stroke:#2E5C8A,stroke-width:2px,color:#000
classDef agent fill:#FFD525,stroke:#A67C00,stroke-width:2px,color:#000
classDef script fill:#D6EAF8,stroke:#5B7FA3,stroke-width:2px,color:#000
classDef identity fill:#FFB347,stroke:#B86B00,stroke-width:2px,color:#000
classDef target fill:#FADBD8,stroke:#B03A2E,stroke-width:2px,color:#000
</div>

*Diagram: Database Monitoring Agent execution flow where monitoring statements and user action scripts run through explicit connection strings and optional impersonation into target databases.*

## Identity grouping per SQL Statement

Security isolation is configured per [SQL Statement][SQL Server - Statements]. A SQL Statement holds one connection string and optional impersonation credentials on its **Authentication** tab, and all its monitoring statements and User Action Scripts run with that identity.

Group the monitoring statements and scripts that need the same rights in one SQL Statement. Put a statement that needs other rights, such as a script that writes, in a separate SQL Statement with its own least-privilege connection. This credential isolation per SQL Statement is your primary control.

|Area|Current model|Upcoming model (planned)|
|---|---|---|
|<i class="fal fa-user" aria-hidden="true"></i> Execution identity|Per statement/script configuration|Grouped identity boundary|
|<i class="fal fa-key" aria-hidden="true"></i> Credential handling|Connection string + optional impersonation fields|Centralized group identity with simpler administration|
|<i class="fal fa-shield-halved" aria-hidden="true"></i> Security outcome|Strong when least privilege is applied consistently|Same principle, easier governance and review|

## Why this matters

Custom SQL execution can read, modify, or delete data depending on granted permissions. A weak configuration can expose system tables, production data, and credentials.

Use a least-privilege design where each statement only has the minimum rights needed for that statement.

## Security baseline

|<i class="fal fa-route" aria-hidden="true"></i> Area|✅ Recommended practice|❌ Avoid|
|---|---|---|
|<i class="fal fa-key" aria-hidden="true"></i> Connection strings|Use dedicated connection strings per monitoring or action scope.|Use a shared high-privilege connection string for all scripts.|
|<i class="fal fa-user-lock" aria-hidden="true"></i> Permissions|Grant minimal permissions (`SELECT`, specific `EXECUTE`) only where required.|Grant `sysadmin`, `db_owner`, or broad DDL permissions by default.|
|<i class="fal fa-user-secret" aria-hidden="true"></i> Credentials|Use dedicated service identities for SQL statement execution.|Reuse the Database Monitoring Agent service account.|
|<i class="fal fa-filter" aria-hidden="true"></i> Scope|Point each connection string to a specific target database when possible.|Use system databases (`master`, `msdb`) for custom monitoring logic.|
|<i class="fal fa-user-ninja" aria-hidden="true"></i> Impersonation|Use impersonation only when required and document ownership.|Enable impersonation broadly without ownership and review.|
|<i class="fal fa-file-signature" aria-hidden="true"></i> Script governance|Review, test, and version all statements before production rollout.|Allow unreviewed statements to run in production.|
|<i class="fal fa-rotate" aria-hidden="true"></i> Lifecycle|Rotate secrets regularly and review usage logs.|Keep credentials static for long periods without audits.|

For the platform-wide SQL rights model that explains when `sysadmin` is actually required, see [SQL Server Sysadmin Requirements][].

## Core guidance

### Connection string isolation

Use separate connection strings for different risk levels:

* Read-only monitoring logic.
* Restricted management actions.
* Environment-specific scopes (production, non-production).

This design limits blast radius if one credential is misused or leaked.

### Impersonation and authentication overrides

If you use impersonation in the Authentication tab:

* Use a dedicated account for that specific script scope.
* Keep the account permissions lower than the agent service account.
* Never reuse the Database Monitoring Agent service identity.

### Least privilege for monitoring and actions

Treat monitoring statements and user action scripts differently:

* Monitoring statements should usually require read-only access.
* User action scripts may need write or `EXECUTE`, but only for explicitly approved procedures.
* Deny broad DDL operations unless there is a controlled exception and review.

#### Example least-privilege SQL Server configuration

Use this as a starting template and adapt it to your database names, schemas, and procedures:

```sql
-- Create dedicated monitoring login
CREATE LOGIN NodiniteMonitor WITH PASSWORD = 'Complex!Password123';
CREATE USER NodiniteMonitor FOR LOGIN NodiniteMonitor;

-- Grant only required permissions on target database
USE YourMonitoringDatabase;
GRANT SELECT ON SCHEMA::dbo TO NodiniteMonitor;

-- If required, allow execute on explicit procedures only
GRANT EXECUTE ON dbo.SP_CheckConnectionFailures TO NodiniteMonitor;

-- Explicitly deny dangerous permissions
DENY DROP ANY DATABASE TO NodiniteMonitor;
DENY ALTER ANY DATABASE TO NodiniteMonitor;
DENY CREATE TABLE TO NodiniteMonitor;
```

#### Example connection string isolation

```text
Monitoring statement (read-only):
Server=SQL01;Database=IntegrationDB;User ID=NodiniteMonitorRO;Password=***;Encrypt=True;...

User action script (limited management):
Server=SQL01;Database=IntegrationDB;User ID=NodiniteManageLimited;Password=***;Encrypt=True;...
```

Use separate credentials to isolate risk between read-only monitoring and administrative actions.

#### Risk examples if isolation is not applied

* Shared high-privilege credentials can let any configured script modify or delete production data.
* A script bug can perform unintended writes at scale if permissions are too broad.
* Compromised configuration access can become broad database access if all statements share one powerful identity.
* Compliance control weakens when script-level access boundaries are missing.

### Script review and operational controls

Before enabling a statement or user action script:

* Validate in non-production first.
* Confirm timeout behavior and performance impact.
* Verify output does not expose sensitive data.
* Keep change history for who modified statement text and credentials.

## Practical checklist

Before publishing or enabling a custom SQL statement or action script, confirm:

* A dedicated connection string is in use for this scope.
* Permissions are least privilege for this specific script.
* Agent service account credentials are not reused.
* Impersonation (if enabled) is justified and documented.
* Script logic is reviewed and tested in non-production.
* Secrets are rotated and ownership is clear.

## Additional resources

* SQL Server Principal Design: <https://learn.microsoft.com/en-us/sql/relational-databases/security/authentication-access/principals-database-engine>
* Least Privilege Principle: <https://learn.microsoft.com/en-us/sql/relational-databases/security/securing-sql-server>
* <i class="fal fa-link-horizontal" aria-hidden="true"></i> [SQL Connection Strings][] - Nodinite connection string configuration guide

## Cross-agent security pattern

The same secure execution principles apply across both agents:

* Database SQL statements and user action scripts.
* [Windows Server][] custom PowerShell scripts and user actions.

Use this guide together with the Windows Server PowerShell security guide to keep a consistent security model across monitoring agents.

## <i class="fal fa-hand-point-right" aria-hidden="true"></i> Next Steps

* <i class="fal fa-code" aria-hidden="true"></i> [SQL Server - Statements][]  
* <i class="fal fa-display" aria-hidden="true"></i> [FAQ and Troubleshooting Guide for the Nodinite Database Monitoring Agent][]  

## <i class="fal fa-link-horizontal" aria-hidden="true"></i> Related Topics

* <i class="fal fa-shield-halved" aria-hidden="true"></i> [How to run custom PowerShell scripts securely with Nodinite][]  
* <i class="fal fa-database" aria-hidden="true"></i> [Database Monitoring Agent][]  
* <i class="fal fa-link" aria-hidden="true"></i> [SQL Connection Strings][]  
* <i class="fal fa-display" aria-hidden="true"></i> [Monitor Views][]  
* <i class="fal fa-bolt" aria-hidden="true"></i> [Remote Actions][]  

[Azure SQL Database]:https://docs.nodinite.com/logging-and-monitoring/database/features/azure-sql-database/overview/
[Database Monitoring Agent]:https://docs.nodinite.com/logging-and-monitoring/database/overview/
[FAQ and Troubleshooting Guide for the Nodinite Database Monitoring Agent]:https://docs.nodinite.com/logging-and-monitoring/database/troubleshooting/overview/
[How to run custom PowerShell scripts securely with Nodinite]:https://docs.nodinite.com/logging-and-monitoring/windows-server/troubleshooting/how-to-run-custom-powershell-scripts-securely/
[Monitor Views]:https://docs.nodinite.com/administration/monitor-management/monitor-views/features/what-is-a-monitor-view/
[Remote Actions]:https://docs.nodinite.com/getting-started/monitor/remote-actions/
[SQL Connection Strings]:https://docs.nodinite.com/install-and-update/troubleshooting/sql-server/connection-strings/
[SQL Server - Statements]:https://docs.nodinite.com/logging-and-monitoring/database/features/sql-statements/sql-server-statements/
[SQL Server Sysadmin Requirements]:https://docs.nodinite.com/install-and-update/troubleshooting/sql-server/sql-server-sysadmin-requirements/
[Windows Server]:https://docs.nodinite.com/logging-and-monitoring/windows-server/features/windows-server/