sqlinsight-pro/SQL Scripts/SQLI-CFG-010.sql
Søren Eggert Lundsteen Olsen 2284e7f082 SQL Scripts: one reviewable script per rule
A DBA should be able to review every statement SQLInsight sends to a
monitored server before granting it access. "SQL Scripts/<rule-id>.sql"
holds, per rule (82 built-in, 16 community), a Danish header (what and
why, how C# judges the data, thresholds with config keys, severity,
exact GRANTs, versions, collector file and member) and the collector's
SQL verbatim, every version variant as its own batch.
"_collectors/<Collector>.sql" holds each collector's queries once.

The only statement that is not strictly read-only is documented in the
scripts: the deadlock collector's session temp table (#system_health).

Inline SQL in the collectors moved to internal constants and Build*Sql
methods (no text changed), so SqlScriptTests can check that the scripts
still contain the SQL the code sends, that every rule has a script, that
every collector query is registered, and that nothing writes.

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-02 13:20:06 +02:00

66 lines
3.9 KiB
Transact-SQL

-- ===================================================================================================================
-- SQLI-CFG-010: Dedicated Admin Connection kan kun bruges lokalt
-- ===================================================================================================================
-- Regel-id: SQLI-CFG-010
-- Titel: Dedicated Admin Connection kan kun bruges lokalt
-- Alvor: Low
-- Versioner: SQL Server 2005 og nyere (på 2000 findes indstillingen ikke: "ikke målbar"). Ikke relevant på Azure
-- SQL Managed Instance.
--
-- Hvad tjekkes, og hvorfor:
-- Om Dedicated Admin Connection (DAC) kun kan bruges fra selve serveren.
--
-- Vurdering (sker i C# ud fra de indsamlede data, ikke i SQL'en, medmindre andet er nævnt):
-- Fund hvis value_in_use for 'remote admin connections' = 0.
--
-- Grænseværdier (konfigurationsnøgle i agentens appsettings.json og standardværdi):
-- Ingen.
--
-- Rettigheder til agentens login (se db/permissions/grant-least-privilege.sql; [agent] = agentens login):
-- Ingen ekstra rettighed: public må læse dette (SERVERPROPERTY, sys.configurations, DBCC TRACESTATUS, xp_msver).
--
-- Data kommer fra (collector, fil : medlemmer, interval):
-- ConfigurationCollector
-- Fil: src/SQLInsight.Collectors/Instance/ConfigurationCollector.cs
-- Medlemmer: ConfigurationCollector.Sql2005, ConfigurationCollector.Sql2000
-- Interval: 15 min som standard (SQLInsight:CollectorIntervals:configuration)
-- Delt script: SQL Scripts/_collectors/ConfigurationCollector.sql
-- Regelkode: src/SQLInsight.Rules/Configuration/ConfigurationRules.cs : SimpleConfigurationRules.Create
-- (ConfigurationOptionRule "remote admin connections")
--
-- Read-only: Ja: kun SELECT samt SET-sessionsindstillinger. Intet ændrer data, indstillinger eller objekter.
-- Kørsel: Kør i SSMS som agentens login (eller et login med samme rettigheder). Hver variant er sin egen batch
-- (GO); en variant for en anden SQL Server-version end din kan fejle - det er forventet.
-- Per-database-forespørgsler er vist for databasen msdb, som findes overalt: ret navnet til den
-- database, du vil se.
-- ===================================================================================================================
-- -------------------------------------------------------------------------------------------------------------------
-- Forbindelsen: Sessionsindstillinger, agenten sætter på hver forbindelse
-- -------------------------------------------------------------------------------------------------------------------
-- Variant: Alle versioner: sættes på hver forbindelse, agenten åbner
-- Kilde: SqlConnectionFactory.SessionSettings
-- Kode: src/SQLInsight.Connectivity/SqlConnectionFactory.cs : SqlConnectionFactory.SessionSettings
SET LOCK_TIMEOUT 5000; SET DEADLOCK_PRIORITY LOW; SET TRANSACTION ISOLATION LEVEL READ UNCOMMITTED;
GO
-- -------------------------------------------------------------------------------------------------------------------
-- ConfigurationCollector: sp_configure: konfigureret værdi og værdi i brug for alle serverindstillinger.
-- -------------------------------------------------------------------------------------------------------------------
-- Variant: SQL Server 2005 og nyere
-- Kilde: ConfigurationCollector.Sql2005
-- Kode: src/SQLInsight.Collectors/Instance/ConfigurationCollector.cs : ConfigurationCollector.Sql2005
SELECT name, CAST(value AS bigint), CAST(value_in_use AS bigint) FROM sys.configurations
GO
-- Variant: SQL Server 2000 (legacy ODBC-sti)
-- Kilde: ConfigurationCollector.Sql2000
-- Kode: src/SQLInsight.Collectors/Instance/ConfigurationCollector.cs : ConfigurationCollector.Sql2000
SELECT v.name, CAST(c.value AS bigint), CAST(r.value AS bigint)
FROM master.dbo.spt_values v
JOIN master.dbo.sysconfigures c ON c.config = v.number
JOIN master.dbo.syscurconfigs r ON r.config = v.number
WHERE v.type = 'C'
GO