Skip to content

Commit 08e9b2d

Browse files
shane-bordenShane Borden
andauthored
feat(mssql): add digital signed cert instructions (#478)
* feat: add directions how to digitially sign powershell scripts using self signed cert * fix: address possible permission error with Azure SQL Database --------- Co-authored-by: Shane Borden <[email protected]>
1 parent a40e1f2 commit 08e9b2d

File tree

3 files changed

+117
-15
lines changed

3 files changed

+117
-15
lines changed

docs/user_guide/sqlserver/collection_scripts.md

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,9 +294,52 @@ This is recommended if you plan to upload the results to the Migration Center.
294294

295295
!!! IMPORTANT Do not modify the name or the contents of the zip file without consultation from Google.
296296

297+
## Digitially Signing Powershell Scripts (Optional / Only if Necessary)
298+
299+
Occasionally, organizational security policies require that Powershell scripts be digitally signed before they can be executed. Google will not provide a certificate to do this, however, the customer can create a self-signed certificate and then sign the scripts on their own using the following steps:
300+
301+
- Create directory to store the certificates
302+
- $PSScriptRoot\_Certs\
303+
304+
- Assign directories to variables
305+
- $certExport = "C:\$PSScriptRoot\_Certs\"
306+
- $ScriptRepo = "C:\$PSScriptRoot"
307+
308+
- Create variable params with relevant information to create the self signed certificate
309+
$params = @{
310+
Subject = 'Google DMA Self Signed PS Code Signing'
311+
DnsName = '[email protected]'
312+
FriendlyName = 'Google DMA Self Signed PS Code Signing'
313+
NotAfter = (Get-Date).AddYears(5)
314+
Type = 'CodeSigning'
315+
CertStoreLocation = 'cert:\CurrentUser\My'
316+
KeyUsage = 'DigitalSignature'
317+
KeyAlgorithm = 'RSA'
318+
KeyLength = 2048
319+
HashAlgorithm = 'sha256'
320+
}
321+
322+
- Create a new self-signed certificate based on the above parameters and send the details to 'newCodeSigningCert' variable for reference later.
323+
- New-SelfSignedCertificate @params -OutVariable newCodeSigningCert
324+
325+
- Export the public key to the file system.
326+
- Export-Certificate -Cert "cert:\CurrentUser\My\$($newCodeSigningCert.Thumbprint)" -FilePath "$($certExport)\CodeSigning.cer"
327+
328+
- Re-import certificate into Trusted Root otherwise it's not possible to validate any signed scripts.
329+
- Import-Certificate -FilePath "$($certExport)\CodeSigning.cer" -Cert Cert:\LocalMachine\root
330+
331+
- Sign all DMA Scripts
332+
- Set-AuthenticodeSignature $ScriptRepo\instanceReview.ps1 -Certificate (Get-ChildItem "cert:\CurrentUser\My\$($newCodeSigningCert.Thumbprint)" -CodeSigningCert)
333+
- Set-AuthenticodeSignature $ScriptRepo\createUserWithSQLAuth.ps1 -Certificate (Get-ChildItem "cert:\CurrentUser\My\$($newCodeSigningCert.Thumbprint)" -CodeSigningCert)
334+
- Set-AuthenticodeSignature $ScriptRepo\createUserWithWindowsAuth.ps1 -Certificate (Get-ChildItem "cert:\CurrentUser\My\$($newCodeSigningCert.Thumbprint)" -CodeSigningCert)
335+
- Set-AuthenticodeSignature $ScriptRepo\dmaCollectorCommonFunctions.psm1 -Certificate (Get-ChildItem "cert:\CurrentUser\My\$($newCodeSigningCert.Thumbprint)" -CodeSigningCert)
336+
- Set-AuthenticodeSignature $ScriptRepo\dmaSQLServerCorrectPerfmonDataset.ps1 -Certificate (Get-ChildItem "cert:\CurrentUser\My\$($newCodeSigningCert.Thumbprint)" -CodeSigningCert)
337+
- Set-AuthenticodeSignature $ScriptRepo\dmaSQLServerHWSpecs.ps1 -Certificate (Get-ChildItem "cert:\CurrentUser\My\$($newCodeSigningCert.Thumbprint)" -CodeSigningCert)
338+
- Set-AuthenticodeSignature $ScriptRepo\dmaSQLServerPerfmonDataset.ps1 -Certificate (Get-ChildItem "cert:\CurrentUser\My\$($newCodeSigningCert.Thumbprint)" -CodeSigningCert)
339+
297340
## License
298341

299-
Copyright 2024 Google LLC
342+
Copyright 2025 Google LLC
300343

301344
Licensed under the Apache License, Version 2.0 (the "License");
302345
you may not use this file except in compliance with the License.

scripts/collector/sqlserver/README.txt

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,58 @@ Operating System Versions:
264264

265265
!!! IMPORTANT Do not modify the name or the contents of the zip file without consultation from Google.
266266

267-
5. License
267+
5. Digitially Signing Powershell Scripts (If Necessary)
268268
------------
269-
Copyright 2024 Google LLC
269+
270+
#### Signing Scripts (Optional)
271+
272+
Occasionally, organizational security policies require that Powershell scripts be digitally signed
273+
before they can be executed. Google will not provide a certificate to do this, however, the customer
274+
can create a self-signed certificate and then sign the scripts on their own using the following steps:
275+
276+
- Create directory to store the certificates
277+
- $PSScriptRoot\_Certs\
278+
279+
- Assign directories to variables
280+
- $certExport = "C:\dma-mssql\_Certs\"
281+
- $ScriptRepo = "C:\dma-mssql"
282+
283+
- Create variable params with relevant information to create the self signed certificate
284+
$params = @{
285+
Subject = 'Google DMA Self Signed PS Code Signing'
286+
DnsName = '[email protected]'
287+
FriendlyName = 'Google DMA Self Signed PS Code Signing'
288+
NotAfter = (Get-Date).AddYears(5)
289+
Type = 'CodeSigning'
290+
CertStoreLocation = 'cert:\CurrentUser\My'
291+
KeyUsage = 'DigitalSignature'
292+
KeyAlgorithm = 'RSA'
293+
KeyLength = 2048
294+
HashAlgorithm = 'sha256'
295+
}
296+
297+
- Create a new self-signed certificate based on the above parameters and send the details to 'newCodeSigningCert' variable for reference later.
298+
- New-SelfSignedCertificate @params -OutVariable newCodeSigningCert
299+
300+
- Export the public key to the file system.
301+
- Export-Certificate -Cert "cert:\CurrentUser\My\$($newCodeSigningCert.Thumbprint)" -FilePath "$($certExport)\CodeSigning.cer"
302+
303+
- Re-import certificate into Trusted Root otherwise it's not possible to validate any signed scripts.
304+
- Import-Certificate -FilePath "$($certExport)\CodeSigning.cer" -Cert Cert:\LocalMachine\root
305+
306+
- Sign all DMA Scripts
307+
- Set-AuthenticodeSignature $ScriptRepo\instanceReview.ps1 -Certificate (Get-ChildItem "cert:\CurrentUser\My\$($newCodeSigningCert.Thumbprint)" -CodeSigningCert)
308+
- Set-AuthenticodeSignature $ScriptRepo\createUserWithSQLAuth.ps1 -Certificate (Get-ChildItem "cert:\CurrentUser\My\$($newCodeSigningCert.Thumbprint)" -CodeSigningCert)
309+
- Set-AuthenticodeSignature $ScriptRepo\createUserWithWindowsAuth.ps1 -Certificate (Get-ChildItem "cert:\CurrentUser\My\$($newCodeSigningCert.Thumbprint)" -CodeSigningCert)
310+
- Set-AuthenticodeSignature $ScriptRepo\dmaCollectorCommonFunctions.psm1 -Certificate (Get-ChildItem "cert:\CurrentUser\My\$($newCodeSigningCert.Thumbprint)" -CodeSigningCert)
311+
- Set-AuthenticodeSignature $ScriptRepo\dmaSQLServerCorrectPerfmonDataset.ps1 -Certificate (Get-ChildItem "cert:\CurrentUser\My\$($newCodeSigningCert.Thumbprint)" -CodeSigningCert)
312+
- Set-AuthenticodeSignature $ScriptRepo\dmaSQLServerHWSpecs.ps1 -Certificate (Get-ChildItem "cert:\CurrentUser\My\$($newCodeSigningCert.Thumbprint)" -CodeSigningCert)
313+
- Set-AuthenticodeSignature $ScriptRepo\dmaSQLServerPerfmonDataset.ps1 -Certificate (Get-ChildItem "cert:\CurrentUser\My\$($newCodeSigningCert.Thumbprint)" -CodeSigningCert)
314+
315+
316+
6. License
317+
------------
318+
Copyright 2025 Google LLC
270319

271320
Licensed under the Apache License, Version 2.0 (the "License");
272321
you may not use this file except in compliance with the License.

scripts/collector/sqlserver/sql/dbServerFeatures.sql

Lines changed: 22 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ DECLARE @TABLE_PERMISSION_COUNT AS INTEGER
2525
DECLARE @ROW_COUNT_VAR AS INTEGER
2626
DECLARE @DMA_SOURCE_ID AS VARCHAR(256)
2727
DECLARE @DMA_MANUAL_ID AS VARCHAR(256)
28+
DECLARE @ERROR_NUMBER AS INT
2829

2930
SELECT @PKEY = N'$(pkey)';
3031
SELECT @CLOUDTYPE = 'NONE';
@@ -149,18 +150,27 @@ BEGIN
149150
from dqs_service');
150151
END TRY
151152
BEGIN CATCH
152-
exec('
153-
WITH dqs_service as (
154-
select count(*) as dqs_count from sys.sql_logins where name like ''##MS_dqs%'')
155-
INSERT INTO #FeaturesEnabled
156-
SELECT
157-
''DATA QUALITY SERVICES'' as Features,
158-
CASE
159-
WHEN dqs_count > 0 THEN 1
160-
ELSE 0
161-
END AS Is_EnabledOrUsed,
162-
dqs_count as Count
163-
from dqs_service');
153+
SELECT @ERROR_NUMBER = ERROR_NUMBER()
154+
IF @ERROR_NUMBER = 229
155+
exec('
156+
INSERT INTO #FeaturesEnabled
157+
SELECT
158+
''DATA QUALITY SERVICES'' as Features,
159+
''0'' as Is_EnabledOrUsed,
160+
''0'' as Count');
161+
ELSE
162+
exec('
163+
WITH dqs_service as (
164+
select count(*) as dqs_count from sys.sql_logins where name like ''##MS_dqs%'')
165+
INSERT INTO #FeaturesEnabled
166+
SELECT
167+
''DATA QUALITY SERVICES'' as Features,
168+
CASE
169+
WHEN dqs_count > 0 THEN 1
170+
ELSE 0
171+
END AS Is_EnabledOrUsed,
172+
dqs_count as Count
173+
from dqs_service');
164174
END CATCH
165175
END;
166176

0 commit comments

Comments
 (0)