امنیت Database، Role، Schema، User و Object در SQL Server | Pro SQL Server 2019 Administration

امنیت Database، Role، Schema، User و Object در SQL Server

توسط admin | گروه SQL Server | 1405/05/20

نظرات 0

امنیت Database، Role، Schema، User و Object در SQL Server

Chapter 10 — Database-Level and Object-Level Security

نویسنده: Peter A. Carter

زبان منبع: انگلیسی

محدوده: صفحات PDF 356 تا 367

تاریخ ترجمه: 2026-08-11

اعتبار ترجمه: ترجمه با کمک هوش مصنوعی

PAGE-356

عضویت Server Role و Database-Level Security

ALTER SERVER ROLE برای افزودن/حذف Member استفاده می‌شود. در سطح Database، Login معمولاً به User نگاشت و User در Database Role عضو می‌شود. Fixed Database Roleها مجموعه Permissionهای از پیش تعریف‌شده‌اند.

ALTER SERVER ROLE ReportingAdmins ADD MEMBER Danielle;
Table 10-2 — بازنمایی متن فنی جدول منبع
--- PDF PAGE 356 ---
341
Listing 10-7.  Adding and Removing Server Roles
--Add Danielle to the sysadmin Role
ALTER SERVER ROLE sysadmin ADD MEMBER Danielle ;
GO
--Remove Danielle from the sysadmin role
ALTER SERVER ROLE sysadmin DROP MEMBER Danielle ;
GO
Implementing Database-Level Security
We have seen how security at the instance level is managed using logins and server 
roles. Security at the level of the individual database has a similar model, consisting of 
database users and database roles. The following sections describe this functionality.
Database Roles
Just as there are server roles at the instance level that help manage permissions, there 
are also database roles at the database level that can group principals together to assign 
common permissions. There are built-in database roles, but it is also possible to define 
your own, ones that meet the requirements of your specific data-tier application.
The built-in database roles that are available in SQL Server 2019 are described in 
Table 10-2.
Table 10-2.  Database Roles
Database Role
Description
db_accessadmin
Members of this role can add and remove database users from the 
database.
db_backupoperator
The db_backupoperator role gives users the permissions they need 
to back up the database, natively. It may not work for third-party backup 
tools, such as CommVault or Backup Exec, since these tools often 
require sysadmin rights.
(continued)
Chapter 10  SQL Server Security Model

--- PDF PAGE 357 ---
342
Database Role
Description
db_datareader
Members of the db_datareader role can run SELECT statements 
against any table in the database. It is possible to override this for 
specific tables by explicitly denying a user permissions to those tables. 
DENY overrides the GRANT.
db_datawriter
Members of the db_datawriter role can perform DML (Data 
Manipulation Language) statements against any table in the database. 
It is possible to override this for specific tables by specifically denying a 
user permissions against a table. The DENY will override the GRANT.
db_denydatareader
The db_denydatareader role denies the SELECT permission against 
every table in the database.
db_denydatawriter
The db_denydatawriter role denies its members the permissions to 
perform DML statements against every table in the database.
db_ddladmin
Members of this role are given the ability to run CREATE, ALTER, 
and DROP statements against any object in the database. This 
role is rarely used, but I have seen a couple of examples or poorly 
written applications that create database objects on the fly. If you are 
responsible for administering an application such as this, then the  
ddl_admin role may be useful.
db_owner
Members of the db_owner role can perform any action within the 
database that has not been specifically denied.
db_securityadmin
Members of this role can grant, deny, and revoke a user’s permissions 
to securables. They can also add or remove role memberships, with the 
exception of the db_owner role.
Table 10-2.  (continued)
You can create your own database roles in SQL Server Management Studio by 
drilling down through Databases ➤ Your Database ➤ Security and then selecting New 
Database Role from the context menu of database roles in Object Explorer. This displays 
the General tab of the Database Role - New dialog box. Here, you should specify  
db_ReadOnlyUsers as the name of our role and state that the role will be owned by dbo. 
dbo is the system user that members of the sysadmin server role map to. We have then 
used the Add button to add Danielle to the role.
Chapter 10  SQL Server Security Model
PAGE-357
نمونه Fixed Database Roleها
Roleکارکرد
db_ownerکنترل کامل Database
db_securityadminمدیریت Role و Permission
db_accessadminمدیریت دسترسی Userها
db_backupoperatorBackup Database
db_ddladminاجرای DDL
db_datareaderخواندن همه Table/Viewهای User
db_datawriterتغییر داده در همه Tableهای User
db_denydatareaderمنع خواندن
db_denydatawriterمنع تغییر داده

Roleهای deny باید با احتیاط استفاده شوند؛ ترکیب DENY با Roleهای دیگر می‌تواند Effective Permission را پیچیده کند.

PAGE-358

تب Securables در SSMS اجازه می‌دهد Objectهای Database را جست‌وجو و Permissionهای Explicit را ببینید. برای محیط‌های بزرگ، Script و Role-based Design نسبت به تنظیم دستی تک‌تک Objectها قابل ممیزی‌تر است.

Figure 10-4 — شکل/تصویر منبع، صفحه PDF 358
PAGE-359

ساخت Database Role

CREATE ROLE SalesReaders AUTHORIZATION dbo;
GRANT SELECT ON SCHEMA::Sales TO SalesReaders;
ALTER ROLE SalesReaders ADD MEMBER [Danielle];

Role سفارشی را می‌توان متناسب با Job Function طراحی کرد. DENY زمانی مفید است که استثنا لازم باشد، اما پیچیدگی Effective Permission را افزایش می‌دهد؛ طراحی ساده با GRANT به Roleهای محدود معمولاً قابل نگهداری‌تر است.

PAGE-360

Schemas

Schema ظرف امنیتی و Namespace برای Objectهاست. جداکردن Tableها بر اساس Domain مانند Sales، HR و Finance امکان می‌دهد Permission به Schema داده شود، بدون صدها GRANT روی Object منفرد. Owner Schema مستقل از Owner Object است و طراحی صحیح Ownership Chain می‌تواند نیاز به Permission مستقیم را کاهش دهد.

PAGE-361

مدل Entity Relationship مثال کتاب Objectها را میان Schemaها تقسیم می‌کند تا نشان دهد امنیت مبتنی بر Schema چطور Boundary منطقی ایجاد می‌کند. این روش همراه با Roleهای Database معمولاً الگوی مناسبی برای Application Security است.

Figure 10-5 — شکل/تصویر منبع، صفحه PDF 361
Table 10-3 — بازنمایی متن فنی جدول منبع
--- PDF PAGE 361 ---
346
A good schema design for this example would involve three schemas, which are split 
by business responsibility—Sales, Procurement, and Accounts. Table 10-3 demonstrates 
how these tables can be split and permissions can then be assigned to the tables via 
database roles.
Figure 10-5.  Entity relationship diagram
Chapter 10  SQL Server Security Model

--- PDF PAGE 362 ---
347
The command in Listing 10-9 creates a schema called CH10 and then grants the user 
Danielle SELECT permissions on the dbo schema. This will implicitly give her SELECT 
permissions on all tables within this schema, including new tables, which are yet to be 
created.
Listing 10-9.  Granting Permissions on a Schema
CREATE SCHEMA CH10 ;
GO
GRANT SELECT ON SCHEMA::CH10 TO Danielle ;
To change a table’s schema post creation, use the ALTER SCHEMA TRANSFER 
command, as demonstrated in Listing 10-10. This script creates a table without 
specifying a schema. This means that it is automatically placed in the dbo schema.  
It is then moved to the CH10 schema.
Table 10-3.  Schema Permissions
Schema
Table
Database Role
Permissions
Sales
OrderHeader
OrderDetails
Customers
Addresses
Sales
SELECT, INSERT, UPDATE
Accounts
SELECT
Procurement
Products
Vendors
Purchasing
SELECT, INSERT, UPDATE
Sales
SELECT
Accounts
SELECT
Accounts
Invoices
CustAccountHistory
VendAccountHistory
Accounts
SELECT, INSERT, UPDATE
Chapter 10  SQL Server Security Model
PAGE-362
GRANT SELECT, INSERT, UPDATE ON SCHEMA::Sales TO SalesWriters;
GRANT SELECT ON SCHEMA::Sales TO SalesReaders;

Permission سطح Schema به Objectهای داخل آن اعمال می‌شود. باید توجه کرد CREATE/ALTER و Ownership می‌تواند مسیرهای غیرمستقیم ایجاد کند؛ بنابراین Roleهای DDL و DML جدا نگه داشته شوند.

PAGE-363

انتقال Object بین Schemaها

ALTER SCHEMA Sales TRANSFER dbo.Customers;

انتقال Object فقط Namespace و Owner Context را تغییر نمی‌دهد؛ Referenceها، Permission و وابستگی‌های Code باید بررسی شوند. نام دو بخشی Object نیز تغییر می‌کند.

PAGE-364

Contained Database و User

EXEC sp_configure 'contained database authentication', 1;
RECONFIGURE;
ALTER DATABASE Chapter10 SET CONTAINMENT = PARTIAL;

CREATE USER [MyDomain\User1] FOR LOGIN [MyDomain\User1];

Contained User می‌تواند وابستگی به Login سطح Server را کاهش دهد و جابه‌جایی Database را ساده‌تر کند. Partial Containment محدودیت‌ها و ملاحظات امنیتی خود را دارد.

PAGE-365
CREATE USER AppUser WITH PASSWORD = 'Example-Only-Password';
-- User با Authentication در سطح Database

Contained User با Password در Database نگهداری می‌شود. ساخت User تکراری/هم‌نام در Databaseهای مختلف می‌تواند SID متفاوت داشته باشد؛ در Restore/Migration باید Mapping و SIDها کنترل شوند.

PAGE-366

SID، TRUSTWORTHY و Object-Level Security

SID هویت واقعی Principal را در Mapping تعیین می‌کند. TRUSTWORTHY می‌تواند مسیر عبور Context بین Database و Server ایجاد کند و روشن‌کردن بی‌دلیل آن خطرناک است. Permissionهای Object با GRANT/REVOKE/DENY روی Table، View، Procedure و Function اعمال می‌شوند.

GRANT SELECT ON OBJECT::Sales.Customers TO SalesReaders;
PAGE-367

Column-Level Permission و آغاز Server Audit

GRANT SELECT (CustomerID, CustomerName) ON Sales.Customers TO SalesReaders;

Permission سطح Column امکان محدودکردن دسترسی درون یک Table را می‌دهد، هرچند مدیریت آن می‌تواند پیچیده شود. فصل سپس وارد Server Audit می‌شود؛ قابلیتی برای ثبت رویدادهای امنیتی در File یا Event Log.

امتیاز کاربران به این مقاله

☆☆☆☆☆

0 نفر امتیاز داده اند. میانگین: 0.0 از 5

 

0 نظر

نظر محترم شما در مورد مقاله های وب سایت برنامه نویسی و پایگاه داده

نظرات محترم شما در خدمات رسانی بهتر ما را یاری می نمایند. لطفا اگر مایل بودید یک نظر ما را مهمان فرمائید. آدرس ایمیل و وب سایت شما نمایش داده نخواهد شد.

0 / 500