Moving from an execute as owner approach to a signed procedure approach

The following can be used as a template for signing procedures which removes the need for executing as owner and database chaining

–create a test login
CREATE LOGIN test WITH PASSWORD =’abc’, CHECK_POLICY = OFF

GO

–create a test proc

CREATE PROC test_proc
AS
SELECT * FROM sys.dm_exec_query_memory_grants

GO

GRANT EXEC ON test_proc TO PUBLIC

CREATE CERTIFICATE [CodeSigningCertificate]
ENCRYPTION BY PASSWORD = ‘Password123!’
WITH EXPIRY_DATE = ‘2099-01-01’,
SUBJECT = ‘Code Signing Cert’

CREATE LOGIN [CodeSigningLogin] FROM CERTIFICATE [CodeSigningCertificate]

GRANT VIEW SERVER STATE TO [CodeSigningLogin]
ADD SIGNATURE TO test_proc
BY CERTIFICATE [CodeSigningCertificate]
WITH PASSWORD = ‘Password123!’;

–Clean Up

/*
DROP PROC dbo.test_proc
DROP LOGIN [CodeSigningLogin]
DROP CERTIFICATE [CodeSigningCertificate]
DROP LOGIN test
*/

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s


%d bloggers like this: