-
Notifications
You must be signed in to change notification settings - Fork 21
(CONT-567) allow deferred function for password #436
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,13 @@ | ||
# frozen_string_literal: true | ||
|
||
# This function exists for usage of a role password that is a deferred function | ||
Puppet::Functions.create_function(:'sqlserver::password') do | ||
dispatch :password do | ||
optional_param 'Any', :pass | ||
return_type 'Any' | ||
end | ||
|
||
def password(pass) | ||
pass | ||
end | ||
end |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,8 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'spec_helper' | ||
|
||
describe 'sqlserver::password' do | ||
it { is_expected.to run.with_params('password').and_return('password') } | ||
it { is_expected.to run.with_params(nil).and_return(nil) } | ||
end |
This file contains hidden or 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,58 @@ | ||
DECLARE | ||
@is_disabled as tinyint = <%= if $disabled {1} else {0} %>, | ||
@login_type as varchar(255) = NULL; | ||
|
||
SET @login_type = (SELECT [type] FROM sys.server_principals where name = '<%= $login %>') | ||
IF (@login_type IS NULL) | ||
BEGIN | ||
-- Create the login | ||
CREATE LOGIN [<%= $login %>] | ||
<% if $login_type !~ /WINDOWS_LOGIN/ { -%> | ||
WITH | ||
PASSWORD = '<%= $password %>', | ||
CHECK_EXPIRATION = <% if $check_expiration { %>ON<% } else { %>OFF<% } %>, | ||
CHECK_POLICY = <% if $check_policy { %>ON<% } else { %>OFF<% } %>, | ||
<% } else { -%> | ||
FROM WINDOWS WITH | ||
<% } -%> | ||
DEFAULT_LANGUAGE = [<%= $default_language %>], | ||
DEFAULT_DATABASE = [<%= $default_database %>]; | ||
-- Fetch the login type | ||
SET @login_type = (SELECT [type] FROM sys.server_principals where name = '<%= $login %>') | ||
END | ||
|
||
IF (@login_type = 'G') | ||
BEGIN | ||
-- Windows Group type logins can only be granted/denied connection | ||
IF @is_disabled = 0 GRANT CONNECT SQL TO [<%= $login %>] | ||
ELSE DENY CONNECT SQL TO [<%= $login %>] | ||
END | ||
ELSE | ||
BEGIN | ||
IF @is_disabled = 0 ALTER LOGIN [<%= $login %>] ENABLE | ||
ELSE ALTER LOGIN [<%= $login %>] DISABLE | ||
END | ||
|
||
ALTER LOGIN [<%= $login %>] WITH | ||
<% if $login_type != 'WINDOWS_LOGIN' { -%> | ||
CHECK_EXPIRATION = <% if $check_expiration { %>ON<% } else { %>OFF<% } %>, | ||
CHECK_POLICY = <% if $check_policy { %>ON<% } else { %>OFF<% } %>, | ||
<% } -%> | ||
DEFAULT_LANGUAGE = [<%= $default_language %>], | ||
DEFAULT_DATABASE = [<%= $default_database %>]; | ||
|
||
<% $svrroles.each |String $role, Any $enable_bit| { -%> | ||
IF (SELECT COUNT(me.role_principal_id) from sys.server_role_members me | ||
JOIN sys.server_principals rol ON me.role_principal_id = rol.principal_id | ||
JOIN sys.server_principals pri ON me.member_principal_id = pri.principal_id | ||
WHERE rol.type_desc = 'SERVER_ROLE' | ||
AND rol.name = '<%= $role %>' | ||
AND pri.name = '<%= $login %>') != <%= $enable_bit %> | ||
BEGIN | ||
<% if ($enable_bit == '1') or ($enable_bit == 1) { -%> | ||
ALTER SERVER ROLE [<%= $role %>] ADD MEMBER [<%= $login %>]; | ||
<% } else { -%> | ||
ALTER SERVER ROLE [<%= $role %>] DROP MEMBER [<%= $login %>]; | ||
<% } -%> | ||
END | ||
<% } -%> |
This file was deleted.
Oops, something went wrong.
This file contains hidden or 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,18 @@ | ||
USE [<%= $database %>]; | ||
<% if $password { %> | ||
IF EXISTS(select containment from sys.databases WHERE name = '<%= $database %>' AND containment = 0) | ||
THROW 51000, 'Database must be contained in order to use passwords', 10 | ||
<% } %> | ||
CREATE USER [<%= $user %>] | ||
<% if $login { -%> | ||
FROM LOGIN [<%= $login %>] | ||
<% } else { -%> | ||
<% if $password { -%> | ||
WITH PASSWORD = '<%= $password %>' | ||
<% } -%> | ||
<% } -%> | ||
<% if $default_schema { -%> | ||
<% if $password { -%>,<% } else { -%> | ||
WITH <% } -%> | ||
DEFAULT_SCHEMA = <%= $default_schema %> | ||
<% } -%> |
This file was deleted.
Oops, something went wrong.
4 changes: 2 additions & 2 deletions
4
templates/delete/login.sql.erb → templates/delete/login.sql.epp
This file contains hidden or 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,7 +1,7 @@ | ||
USE master; | ||
IF exists(select * from sys.server_principals where name = '<%= @login %>') | ||
IF exists(select * from sys.server_principals where name = '<%= $login %>') | ||
BEGIN | ||
-- need to add logic to kill all possible connections if any exists, | ||
-- possible force flag to prevent from happening during transaction if user would prefer to wait | ||
DROP LOGIN [<%= @login %>] | ||
DROP LOGIN [<%= $login %>] | ||
END |
This file contains hidden or 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,4 @@ | ||
USE [<%= $database %>]; | ||
DROP USER [<%= $user %>]; | ||
IF EXISTS(SELECT name FROM sys.database_principals WHERE name = '<%= $user %>') | ||
THROW 51000, 'Failed to drop user <%= $user %>', 10 |
This file was deleted.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interested in the types here.
I wonder if we should be more prescriptive? For example, would
String
be a better choice?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chelnak the password is not mandetory field here so restricting with String will lead to make it mandetory. That's why I have added to any type.
Ref : https://github.com/puppetlabs/puppetlabs-sqlserver/blob/main/manifests/login.pp#L59
Please let me know if we wanted to make it required field.