RE: Permission to view system tables in master database



After further searching I found a cleaner way to accomplish what I need to
do. See example below.

Although I am not entirely sure why this line is necessary:

-- now that we signed the procedure, we can drop the private key
alter certificate certSignCreatePrincipal remove private key;


/*
Laurentiu Cristofor's blog
SQL Server 2005: procedure signing demo
http://blogs.msdn.com/lcris/archive/2005/06/15/429631.aspx
*/

create database demo;
use demo;

CREATE LOGIN alice WITH PASSWORD = '!Pa55word!' ;
CREATE USER alice FOR LOGIN alice


-- create a procedure that selects from sys.dm_exec_connections
create procedure sp_CreatePrincipal
AS

DECLARE @ip Varchar(60)

SELECT @ip=client_net_address
FROM sys.dm_exec_connections
WHERE session_id=@@spid

PRINT @ip

go

-- now use this newly added procedure
-- to create a low privileged principal
EXEC sp_CreatePrincipal

-- we'll now want alice to be able to use the procedure and create new
principals
-- but without granting her directly the permissions
grant execute on sp_CreatePrincipal to alice;

-- verify that alice cannot create principals
execute as login = 'alice';
EXEC sp_CreatePrincipal
revert;


-- first, we'll need to create a database master key
create master key encryption by password = 'Apufe@))%';
-- create a certificate to sign the procedure
create certificate certSignCreatePrincipal with subject = 'for signing
procedure sp_CreatePrincipal';

-- sign procedure sp_CreatePrincipal
add signature to sp_CreatePrincipal by certificate certSignCreatePrincipal;
-- now that we signed the procedure, we can drop the private key
alter certificate certSignCreatePrincipal remove private key;
-- backup certificate to file; it will be used later to put the certificate
in master
backup certificate certSignCreatePrincipal to file =
'certSignCreatePrincipal.cer';

-- create and map a user to the certificate
--??? create user u_certSignCreatePrincipal from certificate
certSignCreatePrincipal;

-- create the same certificate in master now
use master;
create certificate certSignCreatePrincipal from file =
'certSignCreatePrincipal.cer';
-- create and map a login to the certificate
create login l_certSignCreatePrincipal from certificate
certSignCreatePrincipal;
GRANT VIEW SERVER STATE TO l_certSignCreatePrincipal;


-- we're done!
use demo;

-- check that the certificate in demo matches the one in master
select c.name
from sys.certificates c
JOIN master.sys.certificates mc ON c.thumbprint = mc.thumbprint;


-- verify that alice can now create principals
execute as login = 'alice';
sp_CreatePrincipal
revert;

-- cleanup
drop user u_certSignCreatePrincipal;
drop login l_certSignCreatePrincipal;
drop procedure sp_CreatePrincipal;
drop certificate certSignCreatePrincipal;
drop user alice;
drop login alice;
drop user bob;
drop login bob;
EXEC sp_configure 'xp_cmdshell', 1 ;
RECONFIGURE ;
EXEC xp_cmdshell 'del "C:\Program Files\Microsoft SQL
Server\MSSQL.1\MSSQL\Data\certSignCreatePrincipal.cer"' ;
EXEC xp_cmdshell 'DIR "C:\Program Files\Microsoft SQL
Server\MSSQL.1\MSSQL\Data\*.cer"' ;

use master;
drop certificate certSignCreatePrincipal;
drop database demo;


.



Relevant Pages

  • Re: Multi-layered PKI implementation
    ... Bob is an online retailer and Eve is a nasty ... Alice -> Bob: I want to by a shiny wotsit from you for 500 monkeys. ... my public key is 12345. ... Sure, my public key is 12345, and here is my certificate ...
    (Debian-User)
  • Re: Multi-layered PKI implementation
    ... Bob is an online retailer and Eve is a nasty ... Alice -> Bob: I want to by a shiny wotsit from you for 500 monkeys. ... my public key is 12345. ... Sure, my public key is 12345, and here is my certificate ...
    (Debian-User)
  • Re: WSJ Online: Voltage Unveils Encryption Program
    ... Alice sends Bob an encrypted, ... yet have Alice's certificate, and adds the received certificate to Bob's ... e-mail client replaces the Alice's real certificate with the fake from Eve. ...
    (sci.crypt)
  • Re: Help! Im trying to understand PKI - especially CAs role
    ... > sender's public key is sent to a CA, and the CA sends back a digital ... Then the sender send the digital certificate to the ... Alice send her public key to a CA for certification ... If Alice wants to encrypt a message to Bob she needs to get the certificate ...
    (comp.security.misc)
  • Re: Lua Cheng Eng
    ... You were drag into this argument when he bullshit about the unqualified captain. ... First of all, before anyone sign on the ship, for, the person signing on has to appear before the shipping master of the marine department in the country. ... Therefore no one without the necessary qualification can sign on and work on the ship. ... The marine department, will do the following: if it is a junior position, may just approve the person and issue an exemption certificate. ...
    (soc.culture.singapore)