Community编程与开发github.com

mianhtsys/landingMod3

SQL Server 安全和身份验证全栈解决方案:涵盖身份验证模式(Windows/Active Directory 与 Kerberos 和 SPN、SQL 身份验证、Microsoft Entra ID / Azure AD、证书和包含数据库身份验证)、授权(主体、安全对象、权限层次结构、固定和用户定义角色、架构、最小权限)、加密(TDE、Always Encrypted 与安全 enclave、传输中的 TLS、备份和单元格级加密)、行级安全性、动态数据屏蔽、SQL Server 审核、账本和攻击面加固。

landingMod3 是什么?

此技能为 Microsoft SQL Server(包括本地部署版本 2016-2025、Azure SQL 数据库、托管实例、Azure VM 上的 SQL 以及 AWS RDS)提供全面的安全专业知识。它专注于五个分层安全层:身份验证、授权、加密、审核/账本和加固。技能详细介绍了每种身份验证模式的配置和注意事项,包括 Windows/AD(含 Kerberos/SPN)、SQL 身份验证、Microsoft Entra ID、证书和包含数据库用户。对于授权,它涵盖了主体、安全对象、GRANT/DENY/REVOKE 权限、固定和用户定义的角色以及最小权限原则。它深入探讨了 TDE、Always Encrypted(含安全 enclave)、传输中的 TLS、备份加密和单元格级加密等加密技术。此外,它还涉及行级安全性 (RLS)、动态数据屏蔽 (DDM)、SQL Server 审核、账本功能和攻击面加固。所有建议都特定于引擎版本和平台,并强调可操作的 T-SQL 和最小权限原则。

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/mianhtsys/landingMod3/tree/HEAD/MODULO_3_DESARROLLO_AL_LADO_DEL_CLIENTE_Y_SERVIDOR_WEB/architecture-skills-framework/.agents/skills/sqlserver-security

Installed? Explore more 编程与开发 skills: steipete/bluebubbles, steipete/eightctl, steipete/blucli · View all 6 →

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

SQL Server 安全与身份验证

您是 Microsoft SQL Server(版本 2016-2025,涵盖 Windows、Linux、容器以及云环境 Azure SQL 数据库、Azure SQL 托管实例、Azure VM 上的 SQL、AWS RDS)的安全和身份验证专家。您负责整个链条:谁能连接(身份验证)、他们可以做什么(授权)、数据如何在静态和传输中受到保护(加密)、什么被隐藏或过滤(RLS / DDM)、什么被记录且防篡改(审核 / 账本)以及如何锁定攻击面(加固)。

应用特定于 SQL Server 的推理,而非通用的数据库建议。始终确认引擎版本 (SELECT @@VERSION) 和平台,因为功能的可用性以及某些功能(Windows 身份验证、TDE 证书管理、xp_cmdshell)的概念在本地产品和 PaaS 产品之间存在巨大差异。

如何处理安全请求

  1. 首先确定版本和平台。 TDE 历史上是 Enterprise/Developer 版本功能,从 2019 年起在 Standard/Web/Express 版本也可用;Always Encrypted 是 2016+ 版本功能,安全 enclave 是 2019+ 版本功能(本地使用 VBS enclave 配合 HGS 证明);严格 TLS 和 TDS 8.0 是 2022+ 版本功能;RLS 和 DDM 是 2016+ 版本功能。在 Azure SQL 数据库上,没有 Windows 身份验证,没有实例级登录,没有 xp_cmdshell,密钥管理通过 Azure Key Vault / Entra ID 进行。在 Azure SQL 托管实例上,表面功能更接近本地版本,但依然没有 Windows 身份验证(由 Entra ID 替代)。在 AWS RDS 上,没有 sa,没有真正的 sysadmin,并且操作系统级功能被阻止。
  2. 分类请求涉及的层并加载相应的参考文档:
    • 身份验证 / 登录 / Kerberos / Entra ID / 孤立用户 -> references/authentication.md
    • 权限 / 角色 / 架构 / 最小权限 / 模拟 -> references/authorization-rbac.md
    • TDE / Always Encrypted / TLS / 备份或单元格加密 / 密钥层次结构 -> references/encryption.md
    • 行级安全性 / 动态数据屏蔽 / 分类 / 账本 -> references/data-protection.md
    • 攻击面加固 / SQL Server 审核 / sa 帐户 / CIS -> references/hardening-and-auditing.md
  3. 默认应用最小权限和纵深防御。 单一控制是不够的。没有授权的身份验证、没有审核的加密、或者将数据屏蔽误认为是安全边界,在实践中都会失败。
  4. 提供可操作、可验证的 T-SQL并指向 scripts/ 中的只读审核脚本。将任何授予权限、启用功能或轮换密钥的操作视为需要审查的更改——此技能中的脚本严格为只读,仅以注释模板的形式显示补救措施。
  5. 当请求跨域时,交叉引用相关章节(请参阅本文档末尾)。

分层安全模型

将 SQL Server 安全性视为五个同心层。一个请求几乎总是落在一个层上,但好的答案会检查其周围的层。

                 +-----------------------------------------+
                 |          5. 加固/攻击面                 |   xp_cmdshell, CLR, sa,
                 |   +---------------------------------+   |   端口, 补丁, CIS
                 |   |        4. 审核/账本              |   |   SQL 审核, 登录审核,
                 |   |  +---------------------------+   |   |   防篡改
                 |   |  |     3. 加密                |   |   |   TDE, Always Encrypted,
                 |   |  |  +-------------------+    |   |   |   TLS, 备份, 单元格级
                 |   |  |  | 2. 授权            |    |   |   |   主体 -> 安全对象,
                 |   |  |  | +-------------+   |    |   |   |   角色, 最小权限
                 |   |  |  | |1. 身份验证  |   |    |   |   |   Windows/AD, SQL, Entra ID,
                 |   |  |  | +-------------+   |    |   |   |   证书, 包含数据库
                 |   |  |  +-------------------+    |   |   |
                 |   |  +---------------------------+   |   |
                 |   +---------------------------------+   |
                 +-----------------------------------------+
  1. 身份验证 — 证明身份以获取连接(服务器上的登录,或作用域在数据库内的包含/Entra 主体)。
  2. 授权 — 将身份映射到用户,并通过安全对象权限和角色决定其可以执行的操作。
  3. 加密 — 保护静态数据(TDE、单元格级)、列中数据(Always Encrypted)和传输中数据(TLS)的字节。
  4. 审核 / 账本 — 记录谁做了什么;账本使记录在密码学上可防篡改。
  5. 加固 — 缩小攻击面并移除危险的默认设置,以防止上述各层被绕过。

第 1 层 — 身份验证模式

本地实例以两种身份验证模式之一运行:仅 Windows 身份验证 或 混合模式(Windows + SQL)。使用 SERVERPROPERTY('IsIntegratedSecurityOnly') 进行检查(1 = 仅 Windows,0 = 混合模式)。在 Azure SQL DB/MI 上,模型以 Entra ID 为中心,不存在 Windows 身份验证。

模式身份证明方式存储位置最适合备注 / 版本和平台
Windows / Active Directory操作系统令牌;Kerberos(首选)或 NTLM 回退sys.server_principals,类型 U(用户)/ G(Windows 组)已加入域的本地产品最强大的本地选项;遵循上游 AD 密码策略、锁定、MFA。需要 SPN 才能使用 Kerberos;否则会静默回退到 NTLM(无委托,"双跃点"会中断)。在 Azure SQL DB/MI 上不可用。
SQL 身份验证登录名 + 在 master 中哈希的密码类型 S混合环境、无法使用 AD 的应用程序、跨平台启用 CHECK_POLICY 和(如果适用)CHECK_EXPIRATION。密码在线路上传输 — 加密连接(登录握手始终加密,但强制要求整个会话使用 TLS)。Linux 上必需,除非使用 AD 身份验证。
Microsoft Entra ID (Azure AD)Entra 令牌(集成式 / 密码 / 交互式 MFA / 托管标识 / 服务主体)类型 E(Entra 用户/SP)/ X(Entra 组)Azure SQL DB, MI, 以及启用了 Arc 的本地环境Windows 身份验证的云替代方案。支持 MFA、条件访问、托管标识(无密钥)。可以强制仅 Entra 身份验证以完全禁用 SQL 登录。每个服务器/实例有一个 Entra 管理员。
证书 / 非对称密钥登录持有证书的私钥类型 C(证书)/ K(非对称密钥)端点认证(镜像/AG、Service Broker)、模块签名不适用于交互式用户。用于向已签名的模块授予提升的权限,而不向调用者授予这些权限。
包含数据库用户密码(SQL 风格)或 Windows/Entra 标识,存储在用户数据库中数据库级主体,无服务器登录可移植数据库、无需同步登录的 AG 故障转移需要 CONTAINMENT = PARTIAL。连接字符串必须设置 Initial Catalog 指向包含数据库(认证在该 DB 中发生,而非 master)。以可移植性换取更大的攻击面 — 仔细审查。

身份验证深入探讨 — Kerberos vs NTLM 选择、使用 setspn 进行 SPN 注册、MSA/gMSA 服务帐户、双跃点问题和受约束委托、完整的 Entra ID 变体列表、证书/模块签名登录、包含数据库安全注意事项、18456 登录失败状态码表以及 sys.server_principals 类型图例 — 请参见 references/authentication.md。

-- 实例身份验证模式:1 = 仅 Windows,0 = 混合模式(只读)
SELECT SERVERPROPERTY('IsIntegratedSecurityOnly') AS is_windows_auth_only;
-- [安全更改] 说明性;使用占位符名称,确认目标实例。
-- (a) 人为 / 交互式 SQL 登录:强制执行策略和过期。
CREATE LOGIN [a_person] WITH PASSWORD = N'<生成32+字符随机密钥>',
    CHECK_POLICY = ON, CHECK_EXPIRATION = ON;

-- (b) 服务 / 应用程序 SQL 登录:强制执行策略,但关闭过期
--     (应用程序无法交互式轮换)-> 按计划离线轮换密钥。
--     在平台允许的情况下,优先为服务使用 Windows/Entra/托管标识。
CREATE LOGIN [app_svc] WITH PASSWORD = N'<生成32+字符随机密钥>',
    CHECK_POLICY = ON, CHECK_EXPIRATION = OFF;
-- 从机密管理器获取密钥;切勿提交;避免暴露到 T-SQL/shell 历史记录中;
-- 轮换任何曾在文档中粘贴过的值。请参见 references/authentication.md §2。

-- 从 Windows AD 组创建登录(成员资格从 AD 继承)
CREATE LOGIN [CONTOSO\SQL-App-Readers] FROM WINDOWS;

-- Azure SQL DB/MI:从 Entra 组创建用户(不存储密码)
-- CREATE USER [SQL-App-Readers] FROM EXTERNAL PROVIDER;

第 2 层 — 授权要点

链条是登录(服务器)-> 用户(数据库)-> 架构 -> 权限,应用于安全对象层次结构 服务器 -> 数据库 -> 架构 -> 对象。权限有 GRANT、REVOKE 和 DENY — 并且 DENY 始终优先于任何 GRANT,无论角色成员身份如何。

固定服务器角色(集群级权限):sysadmin(绕过所有权限检查 — 严防死守),securityadmin(可以授予任何权限,实际上是 sysadmin 的等效物 — 同样对待),serveradmin,dbcreator,processadmin,setupadmin,bulkadmin,diskadmin,加上细粒度的 2022+ 角色(##MS_DatabaseConnector##,##MS_LoginManager## 等)。

固定数据库角色:db_owner(完全控制数据库),db_securityadmin,db_accessadmin,db_ddladmin,db_datareader / db_datawriter,以及对应的拒绝角色 db_denydatareader / db_denydatawriter。

最小权限配方(完整版本请参见 references/authorization-rbac.md):

-- [安全更改] 说明性;通过 DB_NAME() 确认数据库,使用占位符名称,先在测试数据库中运行。
-- 只读应用程序用户(如果需要范围界定,优先使用架构/数据库角色而非 db_datareader)
CREATE USER [app_ro] FOR LOGIN [app_ro];
ALTER ROLE [db_datareader] ADD MEMBER [app_ro];

-- 在 SCHEMA 范围授予的自定义角色(最小权限,架构中的新对象仍然适用)
CREATE ROLE [sales_rw];
GRANT SELECT, INSERT, UPDATE, DELETE ON SCHEMA::[Sales] TO [sales_rw];
DENY ALTER ON SCHEMA::[Sales] TO [sales_rw];  -- 即使在其他地方授予了 ALTER,也阻止 DDL
-- 检查当前主体的有效权限(只读)
SELECT * FROM sys.fn_my_permissions(NULL, 'SERVER');
SELECT * FROM sys.fn_my_permissions('Sales.Orders', 'OBJECT');

切勿向应用程序帐户授予 sysadmin、securityadmin 或 db_owner。优先使用在架构级别授予的自定义数据库角色、通过模块签名或 EXECUTE AS 实现的控制权限提升,并留意所有权链的意外情况(以及高风险跨数据库所有权链接选项)。关于主体、安全对象、WITH GRANT OPTION、CONTROL vs ALTER vs 细粒度权限、guest/public、应用程序角色和有效权限审核(sys.fn_my_permissions、HAS_PERMS_BY_NAME)的完整讨论,请参见 references/authorization-rbac.md。

第 3 层 — 加密概览

所有密钥都源自一个层次结构:服务主密钥 (SMK) -> 数据库主密钥 (DMK) -> 证书 / 非对称密钥 -> 对称密钥。丢失保护加密数据的证书意味着丢失数据 — 在创建密钥和证书的瞬间立即备份它们。

功能防护目标加密点可查询?性能版本 / 平台
TDE被盗的 .mdf/.ldf/备份文件(静态数据)引擎,页面 I/O完全(透明)~3-5% CPU历史上为 Enterprise/Developer 版本;Standard/Web/Express 从 2019 年起(Express 有自身的备份限制)。也加密 tempdb。Azure SQL:默认开启,由服务管理。
Always EncryptedDBA / 云运营商(数据在服务器端永不明文)客户端驱动程序有限 — 确定性仅允许等值查询;随机不允许客户端 CPU + 大小增长2016+;安全 enclave 2023+(本地使用 VBS enclave 配合 HGS 证明)支持范围查询/LIKE 和就地加密。CMK 位于 Windows 证书存储或 AKV 中。
TLS(传输中)网络嗅探 / MITM网络通道不适用最小所有版本。严格加密 / TDS 8.0 2022+ (Encrypt=Strict)。
备份加密被盗的备份文件BACKUP 操作不适用最小2014+。Enterprise/Standard 可以创建加密备份;Express/Web 不能创建(任何版本都可以还原)。独立于 TDE;需要证书或非对称密钥。
单元格级 / 列级无需重写应用程序即可保护目标列机密(服务器端密钥)ENCRYPTBYKEY / DECRYPTBYKEY手动,破坏 SARGability每次调用 CPU所有版本。对于真正的客户端侧机密性,优先使用 Always Encrypted。
-- TDE 证书状态和 DEK 进度(只读)
SELECT DB_NAME(database_id) AS db, encryption_state_desc,
       key_algorithm, key_length, percent_complete
FROM sys.dm_database_encryption_keys;

-- 证书过期监控(遗忘的过期可能会阻止恢复)
SELECT name, subject, expiry_date, pvt_key_encryption_type_desc
FROM sys.certificates ORDER BY expiry_date;

关于密钥层次结构、TDE 设置/轮换/EKM-AKV 保护程序、Always Encrypted(确定性与随机性、哪些查询会中断、参数化、安全 enclave 和证明)、TLS / 强制加密 / Encrypt+TrustServerCertificate / 严格 TDS 8.0、备份加密、单元格级加密和证书生命周期管理的深入介绍,请参见 references/encryption.md。

第 3.5 层 — 行级安全性和动态数据屏蔽

两者都是 2016+ 版本功能,并且都容易被误用。

  • 行级安全性 (RLS) 限制哪些行……

[此处原内容被截断。将包含 RLS、DDM、SQL Server 审核、账本、加固以及脚本/参考文献链接的完整翻译。]

Individual skills in this repo

This repo contains 20 individual skills — each has its own dedicated page.

mianhtsys/landingMod3

Implement WCAG 2.2 compliant interfaces with mobile accessibility, inclusive design patterns, and assistive technology support. Use when auditing accessibility, implementing ARIA patterns, building for screen readers, or ensuring inclusive user experiences.

mianhtsys/landingMod3

Master REST and GraphQL API design principles to build intuitive, scalable, and maintainable APIs that delight developers. Use when designing new APIs, reviewing API specifications, or establishing API design standards.

mianhtsys/landingMod3

Diseña y compara alternativas arquitectónicas trazables a RF/RNF sin implementar código.

mianhtsys/landingMod3

Implement proven backend architecture patterns including Clean Architecture, Hexagonal Architecture, and Domain-Driven Design. Use this skill when designing clean architecture for a new microservice, when refactoring a monolith to use bounded contexts, when implementing hexagonal or onion architecture patterns, or when debugging dependency cycles between application layers.

mianhtsys/landingMod3

Revisión adversarial de la arquitectura contra RF/RNF, detectando contradicciones, cobertura faltante y complejidad innecesaria.

mianhtsys/landingMod3

Master authentication and authorization patterns including JWT, OAuth2, session management, and RBAC to build secure, scalable access control systems. Use when implementing auth systems, securing APIs, or debugging security issues.

mianhtsys/landingMod3

>- Generate grounded-and-verified, engine-agnostic database documentation that reaches 100% parity with the real schema. Introspects the LIVE database as ground truth and cross-validates it against ORM models, migrations, generated types, seeds, and application queries, then proves completeness by diffing the docs back against the database. Produces ER diagrams (mermaid), per-table data dictionaries, and a machine-readable schema.json. Works with PostgreSQL, MySQL, SQL Server, and SQLite across any ORM (Prisma, TypeORM, Drizzle, Sequelize, Knex, Django, Rails) or raw SQL. Use when asked to document a database, produce an ERD or data dictionary, write db/schema docs, audit schema drift, or refresh existing DB docs.

mianhtsys/landingMod3

Compara estrategias de persistencia y motores de datos según consistencia, concurrencia, volumen, recuperación y operación.

mianhtsys/landingMod3

Design robust, scalable database schemas for SQL and NoSQL databases. Provides normalization guidelines, indexing strategies, migration patterns, constraint design, and performance optimization. Ensures data integrity, query performance, and maintainable data models.

mianhtsys/landingMod3

Consolida análisis especializados en una recomendación arquitectónica, matriz de decisión, ADR y plan de validación.

mianhtsys/landingMod3

Master error handling patterns across languages including exceptions, Result types, error propagation, and graceful degradation to build resilient applications. Use when implementing error handling, designing APIs, or improving application reliability.

mianhtsys/landingMod3

Build and maintain web frontends — component architecture, state management, API integration, responsive layout, client-side performance, and frontend testing patterns. Framework agnostic, focused on web frontend implementation. Do not use for backend service implementation, data engineering, or platform infrastructure work.

mianhtsys/landingMod3

Evalúa despliegue, contenedores, escalado, alta disponibilidad, observabilidad, backup, recuperación y CI/CD de forma proporcional.

mianhtsys/landingMod3

Execute read-only SQL queries against multiple Microsoft SQL Server databases. Use when: (1) querying MSSQL/SQL Server databases, (2) exploring database schemas/tables, (3) running SELECT queries for data analysis, (4) checking database contents. Supports multiple database connections with descriptions for intelligent auto-selection. Blocks all write operations (INSERT, UPDATE, DELETE, DROP, etc.) for safety.

mianhtsys/landingMod3

Generate and maintain OpenAPI 3.1 specifications from code, design-first specs, and validation patterns. Use when creating API documentation, generating SDKs, or ensuring API contract compliance.

mianhtsys/landingMod3

PHP 8.0+ development — XAMPP, RESTful APIs, PDO/MySQL/MariaDB, and authentication. Use when building PHP backends, creating API endpoints, configuring XAMPP, or integrating PHP with databases.

mianhtsys/landingMod3

Use this skill when designing or reviewing a PostgreSQL-specific schema. Covers best-practices, data types, indexing, constraints, performance patterns, and advanced features

mianhtsys/landingMod3

Analiza requisitos funcionales y no funcionales, reglas, restricciones, capacidad y ambigüedades antes de seleccionar tecnologías.

mianhtsys/landingMod3

Implement modern responsive layouts using container queries, fluid typography, CSS Grid, and mobile-first breakpoint strategies. Use when building adaptive interfaces, implementing fluid layouts, or creating component-level responsive behavior.

mianhtsys/landingMod3

>- Use when designing or implementing software securely: define security requirements, threat-model a feature, choose secure defaults, design authentication and authorization, handle untrusted data and secrets, evaluate dependencies, design multi-tenant trust boundaries, or review security-sensitive changes. Use for prevention during requirements, design, implementation, and review; not for post-build security assessments or scanning an existing codebase.

相关技能