Skip to content
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

Ensure limits_fragments_hiera_merge is using proper lookup function #263

Merged
merged 1 commit into from
Jul 17, 2023
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
1 change: 1 addition & 0 deletions .sync.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
spec/spec_helper.rb:
coverage_report: true
minimum_code_coverage_percentage: 100
hiera_config: spec/hiera.yaml
appveyor.yml:
delete: true
.gitlab-ci.yml:
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,26 @@ This would create `/etc/security/limits.d/custom.conf` with content
* hard cpu 1440
```
The parameter `pam::limits_fragments_hiera_merge` can be set to `true` to allow Hiera to define and merge limits from multiple locations. Example:
```yaml
# data/common.yaml
---
pam::limits_fragments_hiera_merge: true
pam::limits_fragments:
custom:
list:
- '* soft nofile 2048'
- '* hard nofile 8192'
# data/os/RedHat/8.yaml
---
pam::limits_fragments:
custom:
list:
- '* soft as 3145728'
- '* hard as 4194304'
```

#### Specifying the content of a service
Manage PAM file for specific service.

Expand Down
2 changes: 1 addition & 1 deletion manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@

if $limits_fragments {
if $limits_fragments_hiera_merge {
$limits_fragments_real = hiera_hash('pam::limits_fragments')
$limits_fragments_real = lookup('pam::limits_fragments', Hash, 'deep', {})
} else {
$limits_fragments_real = $limits_fragments
}
Expand Down
4 changes: 2 additions & 2 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@
}
],
"description": "Manages PAM, including specifying users and groups in access.conf, limits.conf, and limits fragments",
"pdk-version": "2.6.0",
"pdk-version": "3.0.0",
"template-url": "https://github.com/tailored-automation/pdk-templates#main",
"template-ref": "heads/main-0-g37b4517"
"template-ref": "heads/main-0-g53868f7"
}
19 changes: 18 additions & 1 deletion spec/classes/init_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,24 @@

it { is_expected.to contain_class('nsswitch') }
it { is_expected.to have_pam__service_resource_count(0) }
it { is_expected.to have_pam__limits__fragment_resource_count(0) }
it { is_expected.to have_pam__limits__fragment_resource_count(1) }
it do
is_expected.to contain_pam__limits__fragment('test').with(
list: ['* soft as 3145728', '* hard as 4194304'],
)
end
# Validate presence to ensure coverage stays 100%
it { is_expected.to contain_file('/etc/security/limits.d/test.conf') }

context 'when limits_fragments_hiera_merge => true' do
let(:params) { { limits_fragments_hiera_merge: true } }

it do
is_expected.to contain_pam__limits__fragment('test').with(
list: ['* soft nofile 2048', '* hard nofile 8192', '* soft as 3145728', '* hard as 4194304'],
)
end
end

context "with login_pam_access set to valid string sufficient on OS #{os}" do
let(:params) { { login_pam_access: 'sufficient' } }
Expand Down
2 changes: 2 additions & 0 deletions spec/classes/limits_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@
it { is_expected.to contain_exec('mkdir_p-/testing.d') }
it { is_expected.to contain_file('limits_d').with_path('/testing.d') }
it { is_expected.to contain_file('limits_d').that_requires('Exec[mkdir_p-/testing.d]') }
# Included by default due to unit testing Hiera adding to tests-only common.yaml
it { is_expected.to contain_file('/testing.d/test.conf') }
end

context 'with limits_d_dir_mode set to a valid string' do
Expand Down
6 changes: 6 additions & 0 deletions spec/fixtures/data/common.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
pam::limits_fragments:
test:
list:
- '* soft nofile 2048'
- '* hard nofile 8192'
6 changes: 6 additions & 0 deletions spec/fixtures/data/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
pam::limits_fragments:
test:
list:
- '* soft as 3145728'
- '* hard as 4194304'
10 changes: 10 additions & 0 deletions spec/hiera.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
version: 5
defaults:
datadir: fixtures/data
data_hash: yaml_data
hierarchy:
- name: testing
path: test.yaml
- name: common
path: common.yaml
1 change: 1 addition & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@

RSpec.configure do |c|
c.default_facts = default_facts
c.hiera_config = 'spec/hiera.yaml'
c.before :each do
# set to strictest setting for testing
# by default Puppet runs at warning level
Expand Down