Cómo configurar los servicios iniciadores para seguridad de diálogo completa (Transact-SQL)

SQL Server utiliza la seguridad de diálogo para cualquier conversación con un servicio para el que existe un enlace de servicio remoto en la base de datos que hospeda el servicio iniciador. Si la base de datos que hospeda el servicio de destino contiene un usuario que corresponde al usuario que creó el diálogo y el enlace de servicio remoto no especifica la seguridad anónima, el diálogo utiliza la seguridad completa.

Para asegurarse de que un servicio iniciador utiliza la seguridad de diálogo, puede crear un enlace de servicio remoto para el servicio. Para que SQL Server utilice la seguridad completa, el enlace de servicio remoto no debe especificar la seguridad anónima y la base de datos de destino debe estar configurada para utilizar seguridad completa para este servicio.

Para configurar un servicio iniciador para seguridad de diálogo completa

  1. Obtenga un certificado para el propietario del servicio de destino en la base de datos remota de un origen de confianza. Normalmente, esto supone enviar la certificando mediante un correo electrónico cifrado o transferir el certificado en un medio físico, como un disquete.

    Nota de seguridadNota de seguridad

    Instale solamente certificados que provengan de fuentes de confianza.

    Nota

    El certificado debe estar cifrado con la clave maestra para la base de datos. Para obtener más información, vea CREATE MASTER KEY (Transact-SQL).

  2. Cree un usuario sin inicio de sesión para el servicio remoto.

  3. Instale el certificado para el usuario del servicio remoto. El usuario creado en el paso anterior será el propietario del certificado.

  4. Cree un enlace de servicio remoto que especifique el usuario del servicio remoto y el servicio.

  5. Cree un usuario sin inicio de sesión para que sea el propietario del servicio local.

  6. Cree un certificado para el servicio local. El usuario creado en el paso anterior será el propietario del certificado.

    Nota

    El certificado debe estar cifrado con la clave maestra para la base de datos. Para obtener más información, vea CREATE MASTER KEY (Transact-SQL).

  7. Realice una copia de seguridad del certificado.

    Nota de seguridadNota de seguridad

    Realice la copia de seguridad sólo del certificado para este usuario. No realice ninguna otra copia de seguridad ni distribuya la clave privada asociada con el certificado.

  8. Proporcione el certificado y el nombre del servicio iniciador al administrador de la base de datos remota. Por ejemplo, puede intercambiar el certificado en un medio físico, como un disquete o un CD-ROM, puede colocarlo en un recurso compartido de archivos o bien enviarlo a través de un correo electrónico seguro.

    Nota

    Para que SQL Server utilice la seguridad de diálogo completa, el certificado debe instalarse en la base de datos remota y el usuario creado en el paso 7 debe ser el usuario que inicie la conversación.

Ejemplo

USE AdventureWorks2008R2 ;
GO

--------------------------------------------------------------------
-- The first part of the script configures security to allow the
-- remote service to send messages in this database. The script creates
-- a user in this database, loads the certificate for the remote service,
-- grants permission to the user, and creates a remote service binding.

-- Given a certificate for the owner of the remote target service
-- SupplierOrders, create a remote service binding for
-- the service.  The remote user will be granted permission
-- to send messages to the local service OrderParts. 
-- This example assumes that the certificate for the service 
-- is saved in the file'C:\Certificates\SupplierOrders.cer' and that
-- the initiating service already exists.


-- Create a user without a login.  For convenience,
-- the name of the user is based on the name of the
-- the remote service.

CREATE USER [SupplierOrdersUser]
    WITHOUT LOGIN ;
GO

-- Install a certificate for a user
-- in the remote database. The certificate is
-- provided by the owner of the remote service. The
-- user for the remote service owns the certificate.

CREATE CERTIFICATE [SupplierOrdersCertificate]
    AUTHORIZATION [SupplierOrdersUser]
    FROM FILE='C:\Certificates\SupplierOrders.cer' ;
GO

-- Create the remote service binding. Notice
-- that the user specified in the binding
-- does not own the binding itself.

-- Creating this binding specifies that messages from
-- this database are secured using the certificate for
-- the [SupplierOrdersUser] user.

-- When the anonymous option is omitted, anonymous is OFF.
-- Therefore, the credentials for the user that begins
-- are used in the remote database.

CREATE REMOTE SERVICE BINDING [SupplierOrdersBinding]
    TO SERVICE 'SupplierOrders'
    WITH USER = [SupplierOrdersUser] ;
GO

--------------------------------------------------------------------
-- The second part of the script creates a local user that will begin
-- conversations to the remote service. The certificate for this
-- user must be provided to the owner of the remote service.


-- Create a user without a login for the local service.

CREATE USER [OrderPartsUser]
    WITHOUT LOGIN ;
GO

-- Create a certificate for the local service.
CREATE CERTIFICATE [OrderPartsCertificate]
    AUTHORIZATION [OrderPartsUser]
    WITH SUBJECT = 'Certificate for the order service user.';
GO

-- Make this user the owner of the initiator service.

ALTER AUTHORIZATION ON SERVICE::OrderParts TO OrderPartsUser 

-- Backup the certificate for the user that initiates the
-- conversation. This example assumes that the certificate
-- is named OrderServiceCertificate.
BACKUP CERTIFICATE [OrderPartsCertificate]
    TO FILE = 'C:\Certificates\OrderParts.cer' ;
GO

-- Grant RECEIVE permissions on the queue for the service.
-- This allows the local user to begin conversations from
-- services that use the queue.

GRANT RECEIVE ON [OrderPartsQueue] TO [OrderPartsUser] ;
GO