-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: updates to MSSQL user create process (#295)
* bug: 299460067 fix user ddl + add drop method * bug: fix syntax for user creation * chore: bump version to 4.3.18 --------- Co-authored-by: Shane Borden <shaneborden@google.com>
- Loading branch information
1 parent
4a42a4d
commit 9d1110a
Showing
9 changed files
with
168 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
[bumpversion] | ||
current_version = 4.3.17 | ||
current_version = 4.3.18 | ||
commit = False | ||
tag = False | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 75 additions & 0 deletions
75
scripts/collector/sqlserver/sql/addCollectionUserPermissions.sql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
/* | ||
Copyright 2023 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
SET NOCOUNT ON; | ||
SET LANGUAGE us_english; | ||
|
||
DECLARE @dbname VARCHAR(50); | ||
DECLARE @COLLECTION_USER VARCHAR(256); | ||
DECLARE @PRODUCT_VERSION AS INTEGER | ||
|
||
DECLARE db_cursor CURSOR FOR | ||
SELECT name | ||
FROM MASTER.sys.databases | ||
WHERE name NOT IN ('model','msdb','distribution','reportserver', 'reportservertempdb','resource','rdsadmin') | ||
AND state = 0; | ||
|
||
SELECT @PRODUCT_VERSION = CONVERT(INTEGER, PARSENAME(CONVERT(nvarchar, SERVERPROPERTY('productversion')), 4)); | ||
SELECT @COLLECTION_USER = N'$(collectionUser)' | ||
|
||
BEGIN | ||
IF EXISTS | ||
(SELECT name | ||
FROM master.sys.server_principals | ||
WHERE name = @COLLECTION_USER) | ||
BEGIN | ||
exec('GRANT VIEW SERVER STATE TO [' + @COLLECTION_USER + ']'); | ||
exec('GRANT SELECT ALL USER SECURABLES TO [' + @COLLECTION_USER + ']'); | ||
exec('GRANT VIEW ANY DATABASE TO [' + @COLLECTION_USER + ']'); | ||
exec('GRANT VIEW ANY DEFINITION TO [' + @COLLECTION_USER + ']'); | ||
exec('GRANT VIEW SERVER STATE TO [' + @COLLECTION_USER + ']'); | ||
IF @PRODUCT_VERSION > 15 | ||
BEGIN | ||
exec('GRANT VIEW SERVER PERFORMANCE STATE TO [' + @COLLECTION_USER + ']'); | ||
exec('GRANT VIEW SERVER SECURITY STATE TO [' + @COLLECTION_USER + ']'); | ||
exec('GRANT VIEW ANY PERFORMANCE DEFINITION TO [' + @COLLECTION_USER + ']'); | ||
exec('GRANT VIEW ANY SECURITY DEFINITION TO [' + @COLLECTION_USER + ']'); | ||
END; | ||
END; | ||
END; | ||
|
||
OPEN db_cursor | ||
FETCH NEXT FROM db_cursor INTO @dbname | ||
|
||
WHILE @@FETCH_STATUS = 0 | ||
BEGIN | ||
BEGIN | ||
exec (' | ||
use [' + @dbname + ']; | ||
IF EXISTS (SELECT [name] | ||
FROM [sys].[database_principals] | ||
WHERE [type] = N''S'' AND [name] = N''' + @COLLECTION_USER + ''') | ||
BEGIN | ||
GRANT VIEW DATABASE STATE TO [' + @COLLECTION_USER + ']; | ||
END'); | ||
END; | ||
|
||
FETCH NEXT FROM db_cursor INTO @dbname; | ||
END; | ||
|
||
CLOSE db_cursor | ||
DEALLOCATE db_cursor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
Copyright 2023 Google LLC | ||
Licensed under the Apache License, Version 2.0 (the "License"); | ||
you may not use this file except in compliance with the License. | ||
You may obtain a copy of the License at | ||
https://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
*/ | ||
|
||
SET NOCOUNT ON; | ||
SET LANGUAGE us_english; | ||
|
||
DECLARE @dbname VARCHAR(50); | ||
DECLARE @COLLECTION_USER VARCHAR(256); | ||
|
||
DECLARE db_cursor CURSOR FOR | ||
SELECT name | ||
FROM MASTER.sys.databases | ||
WHERE name NOT IN ('model','msdb','distribution','reportserver', 'reportservertempdb','resource','rdsadmin') | ||
AND state = 0; | ||
|
||
SELECT @COLLECTION_USER = N'$(collectionUser)' | ||
|
||
OPEN db_cursor | ||
FETCH NEXT FROM db_cursor INTO @dbname | ||
|
||
WHILE @@FETCH_STATUS = 0 | ||
BEGIN | ||
BEGIN | ||
exec (' | ||
use [' + @dbname + ']; | ||
IF EXISTS (SELECT [name] | ||
FROM [sys].[database_principals] | ||
WHERE [type] = N''S'' AND [name] = N''' + @COLLECTION_USER + ''') | ||
BEGIN | ||
DROP USER [' + @COLLECTION_USER + ']; | ||
END; | ||
'); | ||
END; | ||
|
||
FETCH NEXT FROM db_cursor INTO @dbname; | ||
END; | ||
|
||
CLOSE db_cursor | ||
DEALLOCATE db_cursor | ||
|
||
use [master]; | ||
IF EXISTS | ||
(SELECT name | ||
FROM master.sys.server_principals | ||
WHERE name = @COLLECTION_USER) | ||
BEGIN | ||
exec ('DROP LOGIN [' + @COLLECTION_USER + ']'); | ||
END; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters