Skip to content

Role Valid Until Date #1624

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 2 commits into from
Jan 10, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions manifests/server/role.pp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
# @param inherit Specifies whether to grant inherit capability for the new role.
# @param superuser Specifies whether to grant super user capability for the new role.
# @param replication Provides provides replication capabilities for this role if set to true.
# @param valid_until Specifies whether to set a valid until date for the role.
# @param connection_limit Specifies how many concurrent connections the role can make. Default value: '-1', meaning no limit.
# @param username Defines the username of the role to create.
# @param connect_settings Specifies a hash of environment variables used when connecting to a remote server.
Expand All @@ -35,6 +36,7 @@
Boolean $inherit = true,
Boolean $superuser = false,
Boolean $replication = false,
Optional[String[1]] $valid_until = undef,
String[1] $connection_limit = '-1',
String[1] $username = $title,
Hash $connect_settings = $postgresql::server::default_connect_settings,
Expand Down Expand Up @@ -126,6 +128,12 @@
unless => "SELECT 1 FROM pg_roles WHERE rolname = '${username}' AND rolinherit = ${inherit}",
}

if $valid_until {
postgresql_psql { "ALTER ROLE \"${username}\" VALID UNTIL '${valid_until}'":
unless => "SELECT 1 FROM pg_roles WHERE rolname = '${username}' AND rolvaliduntil = '${valid_until}'",
}
}

if(versioncmp($version, '9.1') >= 0) {
if $replication_sql == '' {
postgresql_psql { "ALTER ROLE \"${username}\" NOREPLICATION":
Expand Down
13 changes: 12 additions & 1 deletion spec/defines/server_instance_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ class { 'postgresql::server':
'app_test1': { 'login' => true },
'rep_test1': { 'replication' => true,
'login' => true },
'rou_test1': { 'login' => true }, },
'rou_test1': { 'login' => true },
'val_test1': { 'login' => true,
'valid_until' => '2030-01-01 00:00:00+00' }, },
'pg_hba_rules': { 'local all INSTANCE user': { 'type' => 'local',
'database' => 'all',
'user' => 'ins_test1',
Expand Down Expand Up @@ -214,10 +216,19 @@ class { 'postgresql::server':
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rou_test1" NOCREATEROLE') }
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rou_test1" NOREPLICATION') }
it { is_expected.to contain_postgresql_psql('ALTER ROLE "rou_test1" NOSUPERUSER') }
it { is_expected.to contain_postgresql_psql('ALTER ROLE "val_test1" CONNECTION LIMIT -1') }
it { is_expected.to contain_postgresql_psql('ALTER ROLE "val_test1" INHERIT') }
it { is_expected.to contain_postgresql_psql('ALTER ROLE "val_test1" LOGIN') }
it { is_expected.to contain_postgresql_psql('ALTER ROLE "val_test1" NOCREATEDB') }
it { is_expected.to contain_postgresql_psql('ALTER ROLE "val_test1" NOCREATEROLE') }
it { is_expected.to contain_postgresql_psql('ALTER ROLE "val_test1" NOREPLICATION') }
it { is_expected.to contain_postgresql_psql('ALTER ROLE "val_test1" NOSUPERUSER') }
it { is_expected.to contain_postgresql_psql('ALTER ROLE "val_test1" VALID UNTIL \'2030-01-01 00:00:00+00\'') }
it { is_expected.to contain_postgresql_psql('CREATE ROLE app_test1 ENCRYPTED PASSWORD ****') }
it { is_expected.to contain_postgresql_psql('CREATE ROLE dba_test1 ENCRYPTED PASSWORD ****') }
it { is_expected.to contain_postgresql_psql('CREATE ROLE ins_test1 ENCRYPTED PASSWORD ****') }
it { is_expected.to contain_postgresql_psql('CREATE ROLE rep_test1 ENCRYPTED PASSWORD ****') }
it { is_expected.to contain_postgresql_psql('CREATE ROLE rou_test1 ENCRYPTED PASSWORD ****') }
it { is_expected.to contain_postgresql_psql('CREATE ROLE val_test1 ENCRYPTED PASSWORD ****') }
end
end