Skip to content

Commit 08a1752

Browse files
committed
Add more sensitive protection and testing
1 parent c73a37b commit 08a1752

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed

manifests/server/role.pp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@
8282
}
8383

8484
postgresql_psql { "CREATE ROLE ${username} ENCRYPTED PASSWORD ****":
85-
command => "CREATE ROLE \"${username}\" ${password_sql} ${login_sql} ${createrole_sql} ${createdb_sql} ${superuser_sql} ${replication_sql} CONNECTION LIMIT ${connection_limit}",
85+
command => Sensitive("CREATE ROLE \"${username}\" ${password_sql} ${login_sql} ${createrole_sql} ${createdb_sql} ${superuser_sql} ${replication_sql} CONNECTION LIMIT ${connection_limit}"),
8686
unless => "SELECT 1 FROM pg_roles WHERE rolname = '${username}'",
8787
require => undef,
8888
sensitive => true,
@@ -132,8 +132,8 @@
132132
$pwd_hash_sql = "md5${pwd_md5}"
133133
}
134134
postgresql_psql { "ALTER ROLE ${username} ENCRYPTED PASSWORD ****":
135-
command => "ALTER ROLE \"${username}\" ${password_sql}",
136-
unless => "SELECT 1 FROM pg_shadow WHERE usename = '${username}' AND passwd = '${pwd_hash_sql}'",
135+
command => Sensitive("ALTER ROLE \"${username}\" ${password_sql}"),
136+
unless => Sensitive("SELECT 1 FROM pg_shadow WHERE usename = '${username}' AND passwd = '${pwd_hash_sql}'"),
137137
sensitive => true,
138138
}
139139
}

spec/unit/defines/server/role_spec.rb

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,16 +33,16 @@
3333
it { is_expected.to contain_postgresql__server__role('test') }
3434
it 'has create role for "test" user with password as ****' do
3535
is_expected.to contain_postgresql_psql('CREATE ROLE test ENCRYPTED PASSWORD ****')
36-
.with('command' => "CREATE ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER CONNECTION LIMIT -1",
37-
'environment' => 'NEWPGPASSWD=new-pa$s',
36+
.with('command' => 'Sensitive [value redacted]',
37+
'sensitive' => 'true',
3838
'unless' => "SELECT 1 FROM pg_roles WHERE rolname = 'test'",
3939
'port' => '5432')
4040
end
4141
it 'has alter role for "test" user with password as ****' do
4242
is_expected.to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****')
43-
.with('command' => "ALTER ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD'",
44-
'environment' => 'NEWPGPASSWD=new-pa$s',
45-
'unless' => "SELECT 1 FROM pg_shadow WHERE usename = 'test' AND passwd = 'md5b6f7fcbbabb4befde4588a26c1cfd2fa'",
43+
.with('command' => 'Sensitive [value redacted]',
44+
'sensitive' => 'true',
45+
'unless' => 'Sensitive [value redacted]',
4646
'port' => '5432')
4747
end
4848

@@ -64,17 +64,17 @@
6464
it { is_expected.to contain_postgresql__server__role('test') }
6565
it 'has create role for "test" user with password as ****' do
6666
is_expected.to contain_postgresql_psql('CREATE ROLE test ENCRYPTED PASSWORD ****')
67-
.with_command("CREATE ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER CONNECTION LIMIT -1")
68-
.with_environment('NEWPGPASSWD=new-pa$s')
67+
.with_command('Sensitive [value redacted]')
68+
.with_sensitive('true')
6969
.with_unless("SELECT 1 FROM pg_roles WHERE rolname = 'test'")
7070
.with_port(5432)
7171
.with_connect_settings('PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1', 'PGUSER' => 'login-user', 'PGPASSWORD' => 'login-pass')
7272
.that_requires('Class[postgresql::server::service]')
7373
end
7474
it 'has alter role for "test" user with password as ****' do
7575
is_expected.to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****')
76-
.with('command' => "ALTER ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD'", 'environment' => 'NEWPGPASSWD=new-pa$s',
77-
'unless' => "SELECT 1 FROM pg_shadow WHERE usename = 'test' AND passwd = 'md5b6f7fcbbabb4befde4588a26c1cfd2fa'", 'port' => '5432',
76+
.with('command' => 'Sensitive [value redacted]', 'sensitive' => 'true',
77+
'unless' => 'Sensitive [value redacted]', 'port' => '5432',
7878
'connect_settings' => { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1',
7979
'PGUSER' => 'login-user', 'PGPASSWORD' => 'login-pass' })
8080
end
@@ -99,15 +99,15 @@
9999
it { is_expected.to contain_postgresql__server__role('test') }
100100
it 'has create role for "test" user with password as ****' do
101101
is_expected.to contain_postgresql_psql('CREATE ROLE test ENCRYPTED PASSWORD ****')
102-
.with('command' => "CREATE ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD' LOGIN NOCREATEROLE NOCREATEDB NOSUPERUSER CONNECTION LIMIT -1",
103-
'environment' => 'NEWPGPASSWD=new-pa$s', 'unless' => "SELECT 1 FROM pg_roles WHERE rolname = 'test'",
104-
'connect_settings' => { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1',
105-
'PGPORT' => '1234', 'PGUSER' => 'login-user', 'PGPASSWORD' => 'login-pass' })
102+
.with('command' => 'Sensitive [value redacted]',
103+
'sensitive' => 'true', 'unless' => "SELECT 1 FROM pg_roles WHERE rolname = 'test'",
104+
'connect_settings' => { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1',
105+
'PGPORT' => '1234', 'PGUSER' => 'login-user', 'PGPASSWORD' => 'login-pass' })
106106
end
107107
it 'has alter role for "test" user with password as ****' do
108108
is_expected.to contain_postgresql_psql('ALTER ROLE test ENCRYPTED PASSWORD ****')
109-
.with('command' => "ALTER ROLE \"test\" ENCRYPTED PASSWORD '$NEWPGPASSWD'", 'environment' => 'NEWPGPASSWD=new-pa$s',
110-
'unless' => "SELECT 1 FROM pg_shadow WHERE usename = 'test' AND passwd = 'md5b6f7fcbbabb4befde4588a26c1cfd2fa'",
109+
.with('command' => 'Sensitive [value redacted]', 'sensitive' => 'true',
110+
'unless' => 'Sensitive [value redacted]',
111111
'connect_settings' => { 'PGHOST' => 'postgres-db-server', 'DBVERSION' => '9.1',
112112
'PGPORT' => '1234', 'PGUSER' => 'login-user', 'PGPASSWORD' => 'login-pass' })
113113
end

0 commit comments

Comments
 (0)