Skip to content

Commit c179f67

Browse files
committed
(CAT-1417) Nested require support for authz_core mod
1 parent abb8410 commit c179f67

File tree

10 files changed

+3000
-2676
lines changed

10 files changed

+3000
-2676
lines changed

.rubocop_todo.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,3 +156,8 @@ RSpec/RepeatedExampleGroupDescription:
156156
RSpec/StubbedMock:
157157
Exclude:
158158
- 'spec/util/apache_mod_platform_compatibility_spec.rb'
159+
160+
# Offense count: 1
161+
Metrics/BlockLength:
162+
Exclude:
163+
- 'lib/puppet/functions/apache/authz_core_config.rb'

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
[`apache::mod::auth_mellon`]: https://forge.puppet.com/modules/puppetlabs/apache/reference#apachemodauth_mellon
4040
[`apache::mod::authn_dbd`]: https://forge.puppet.com/modules/puppetlabs/apache/reference#apachemodauthn_dbd
4141
[`apache::mod::authnz_ldap`]: https://forge.puppet.com/modules/puppetlabs/apache/reference#apachemodauthnz_ldap
42+
[`apache::mod::authz_core`]: https://forge.puppet.com/modules/puppetlabs/apache/reference#apachemodauthz_core
4243
[`apache::mod::cluster`]: https://forge.puppet.com/modules/puppetlabs/apache/reference#apachemodcluster
4344
[`apache::mod::data]: https://forge.puppet.com/modules/puppetlabs/apache/reference#apachemoddata
4445
[`apache::mod::disk_cache`]: https://forge.puppet.com/modules/puppetlabs/apache/reference#apachemoddisk_cache
@@ -157,6 +158,7 @@
157158
[`mod_authnz_external`]: https://github.com/phokz/mod-auth-external
158159
[`mod_auth_dbd`]: http://httpd.apache.org/docs/current/mod/mod_authn_dbd.html
159160
[`mod_auth_mellon`]: https://github.com/UNINETT/mod_auth_mellon
161+
[`mod_authz_core`]: https://httpd.apache.org/docs/current/mod/mod_authz_core.html
160162
[`mod_dbd`]: http://httpd.apache.org/docs/current/mod/mod_dbd.html
161163
[`mod_disk_cache`]: https://httpd.apache.org/docs/2.2/mod/mod_disk_cache.html
162164
[`mod_dumpio`]: https://httpd.apache.org/docs/2.4/mod/mod_dumpio.html

REFERENCE.md

Lines changed: 2818 additions & 2667 deletions
Large diffs are not rendered by default.
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
# frozen_string_literal: true
2+
3+
# @summary
4+
# Function to generate the authz_core configuration directives.
5+
#
6+
Puppet::Functions.create_function(:'apache::authz_core_config') do
7+
# @param config
8+
# The input as JSON format.
9+
#
10+
# @return
11+
# Returns the authz_core config directives in array.
12+
#
13+
# @example
14+
#
15+
# arg = {
16+
# require_all => {
17+
# 'require_any' => {
18+
# 'require' => ['user superadmin'],
19+
# 'require_all' => {
20+
# 'require' => ['group admins'],
21+
# },
22+
# },
23+
# 'require_none' => {
24+
# 'require' => ['group temps']
25+
# }
26+
# }
27+
# }
28+
#
29+
# apache::bool2httpd(arg)
30+
# returns :
31+
# [
32+
# " <RequireAll>",
33+
# " <RequireAny>",
34+
# " Require user superadmin",
35+
# " <RequireAll>",
36+
# " Require group admins",
37+
# " Require ldap-group \"cn=Administrators,o=Airius\"",
38+
# " </RequireAll>",
39+
# " </RequireAny>",
40+
# " <RequireNone>",
41+
# " Require group temps",
42+
# " Require ldap-group \"cn=Temporary Employees,o=Airius\"",
43+
# " </RequireNone>",
44+
# " </RequireAll>"
45+
# ]
46+
#
47+
dispatch :authz_core_config do
48+
param 'Hash', :config
49+
return_type 'Array'
50+
end
51+
52+
private
53+
54+
def build_directive(value)
55+
value.split('_').map(&:capitalize).join
56+
end
57+
58+
def authz_core_config(config, count = 1)
59+
result_string = []
60+
config.map do |key, value|
61+
directive = build_directive(key)
62+
if value.is_a?(Hash)
63+
result_string << spacing("<#{directive}>", count)
64+
result_string << authz_core_config(value, count + 1)
65+
result_string << spacing("</#{directive}>", count)
66+
else
67+
value.map do |v|
68+
result_string << spacing("#{directive} #{v}", count)
69+
end
70+
end
71+
end
72+
result_string.flatten
73+
end
74+
75+
def spacing(string, count)
76+
(' ' * count) + string
77+
end
78+
end

manifests/default_mods.pp

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -131,9 +131,7 @@
131131
include apache::mod::filter
132132

133133
# authz_core is needed for 'Require' directive
134-
::apache::mod { 'authz_core':
135-
id => 'authz_core_module',
136-
}
134+
include apache::mod::authz_core
137135

138136
# lots of stuff seems to break without access_compat
139137
::apache::mod { 'access_compat': }
@@ -145,17 +143,13 @@
145143
::apache::default_mods::load { $mods: }
146144

147145
# authz_core is needed for 'Require' directive
148-
::apache::mod { 'authz_core':
149-
id => 'authz_core_module',
150-
}
146+
include apache::mod::authz_core
151147

152148
# filter is needed by mod_deflate
153149
include apache::mod::filter
154150
} else {
155151
# authz_core is needed for 'Require' directive
156-
::apache::mod { 'authz_core':
157-
id => 'authz_core_module',
158-
}
152+
include apache::mod::authz_core
159153

160154
# filter is needed by mod_deflate
161155
include apache::mod::filter

manifests/mod/authz_core.pp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# @summary
2+
# Installs `mod_authz_core`.
3+
#
4+
# @see https://httpd.apache.org/docs/current/mod/mod_authz_core.html for additional documentation.
5+
#
6+
class apache::mod::authz_core {
7+
apache::mod { 'authz_core': }
8+
}

manifests/vhost.pp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,6 +1455,33 @@
14551455
# }
14561456
# ```
14571457
#
1458+
# lint:ignore:parameter_documentation
1459+
# @param authz_core
1460+
# lint:endignore
1461+
# Specifies mod_authz_core parameters for particular directories in a virtual host directory
1462+
# ```puppet
1463+
# apache::vhost { 'sample.example.net':
1464+
# docroot => '/path/to/directory',
1465+
# directories => [
1466+
# { path => '/path/to/different/dir',
1467+
# authz_core => {
1468+
# require_all => {
1469+
# 'require_any' => {
1470+
# 'require' => ['user superadmin'],
1471+
# 'require_all' => {
1472+
# 'require' => ['group admins', 'ldap-group "cn=Administrators,o=Airius"'],
1473+
# },
1474+
# },
1475+
# 'require_none' => {
1476+
# 'require' => ['group temps', 'ldap-group "cn=Temporary Employees,o=Airius"']
1477+
# }
1478+
# }
1479+
# }
1480+
# },
1481+
# ],
1482+
# }
1483+
# ```
1484+
#
14581485
# @param ssl
14591486
# Enables SSL for the virtual host. SSL virtual hosts only respond to HTTPS queries.
14601487
#
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper'
4+
5+
describe 'apache::authz_core_config' do
6+
let(:input1) do
7+
{
8+
'Require' => [
9+
'user foo',
10+
'user bar',
11+
]
12+
}
13+
end
14+
15+
let(:input2) do
16+
{
17+
'require_all' => {
18+
'require_any' => {
19+
'require' => ['user superadmin'],
20+
'require_all' => {
21+
'require' => ['group admins', 'ldap-group "cn=Administrators,o=Airius"']
22+
}
23+
},
24+
'require_none' => {
25+
'require' => ['group temps', 'ldap-group "cn=Temporary Employees,o=Airius"']
26+
}
27+
}
28+
}
29+
end
30+
let(:output2) do
31+
[
32+
' <RequireAll>',
33+
' <RequireAny>',
34+
' Require user superadmin',
35+
' <RequireAll>',
36+
' Require group admins',
37+
' Require ldap-group "cn=Administrators,o=Airius"',
38+
' </RequireAll>',
39+
' </RequireAny>',
40+
' <RequireNone>',
41+
' Require group temps',
42+
' Require ldap-group "cn=Temporary Employees,o=Airius"',
43+
' </RequireNone>',
44+
' </RequireAll>',
45+
]
46+
end
47+
48+
it { is_expected.to run.with_params(nil).and_raise_error(StandardError) }
49+
it { is_expected.to run.with_params([]).and_raise_error(StandardError) }
50+
it { is_expected.to run.with_params({}).and_return([]) }
51+
it { is_expected.to run.with_params(input1).and_return([' Require user foo', ' Require user bar']) }
52+
it { is_expected.to run.with_params(input2).and_return(output2) }
53+
end

templates/vhost/_authz_core.epp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<% $authz_core_config.each |$line| { -%>
2+
<%= $line %>
3+
<%- } -%>

templates/vhost/_directories.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -544,6 +544,9 @@
544544
<%- if directory['custom_fragment'] -%>
545545
<%= directory['custom_fragment'] %>
546546
<%- end -%>
547+
<%- if directory['authz_core'] -%>
548+
<%= scope.call_function('epp',["apache/vhost/_authz_core.epp", 'authz_core_config' => scope.call_function('apache::authz_core_config', directory['authz_core'])]) -%>
549+
<%- end -%>
547550
<%- if directory['gssapi'] -%>
548551
<%= scope.call_function('epp',["apache/vhost/_gssapi.epp", directory['gssapi']]) -%>
549552
<%- end -%>

0 commit comments

Comments
 (0)