Skip to content

Commit 8417c0b

Browse files
committed
Manage DNF module for mod_auth_openidc
On EL 8 mod_auth_openidc is in a DNF module that must be enabled. Otherwise the package is uninstallable. This is verified by adding an acceptance test for the class. The inheritance on apache::params is removed since it was redundant. That is only needed if a class parameter uses apache::params. $oidc_settings on apache::vhost is changed to have a default. The template expects one and With that it's impossible to miscompile. The alternative is to implement a fail() inside the code if it is empty, but this provides some safety.
1 parent 985d959 commit 8417c0b

File tree

4 files changed

+72
-9
lines changed

4 files changed

+72
-9
lines changed

manifests/mod/auth_openidc.pp

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,30 @@
11
# @summary
22
# Installs and configures `mod_auth_openidc`.
3-
#
3+
#
4+
# @param manage_dnf_module Whether to manage the DNF module
5+
# @param dnf_module_ensure The DNF module name to ensure. Only relevant if manage_dnf_module is set to true.
6+
# @param dnf_module_name The DNF module name to manage. Only relevant if manage_dnf_module is set to true.
7+
#
48
# @see https://github.com/zmartzone/mod_auth_openidc for additional documentation.
9+
# @note Unsupported platforms: OracleLinux: 6; RedHat: 6; Scientific: 6; SLES: all
510
#
6-
class apache::mod::auth_openidc inherits apache::params {
11+
class apache::mod::auth_openidc (
12+
Boolean $manage_dnf_module = $facts['os']['family'] == 'RedHat' and $facts['os']['release']['major'] == '8',
13+
String[1] $dnf_module_ensure = 'present',
14+
String[1] $dnf_module_name = 'mod_auth_openidc',
15+
) {
716
include apache
817
include apache::mod::authn_core
918
include apache::mod::authz_user
19+
1020
apache::mod { 'auth_openidc': }
21+
22+
if $manage_dnf_module {
23+
package { 'dnf-module-mod_auth_openidc':
24+
ensure => $dnf_module_ensure,
25+
name => $dnf_module_name,
26+
provider => 'dnfmodule',
27+
before => Apache::Mod['auth_openidc'],
28+
}
29+
}
1130
}

manifests/vhost.pp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1945,7 +1945,7 @@
19451945
Optional[Variant[String, Array[String]]] $comment = undef,
19461946
Hash $define = {},
19471947
Boolean $auth_oidc = false,
1948-
Optional[Apache::OIDCSettings] $oidc_settings = undef,
1948+
Apache::OIDCSettings $oidc_settings = {},
19491949
Optional[Variant[Boolean, String]] $mdomain = undef,
19501950
Optional[Variant[String[1], Array[String[1]]]] $userdir = undef,
19511951
) {
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper_acceptance'
4+
5+
describe 'apache::mod::auth_openidc', if: mod_supported_on_platform?('apache::mod::auth_openidc') do
6+
pp = <<-MANIFEST
7+
include apache
8+
apache::vhost { 'example.com':
9+
docroot => '/var/www/example.com',
10+
port => 80,
11+
auth_oidc => true,
12+
oidc_settings => {
13+
'ProviderMetadataURL' => 'https://login.example.com/.well-known/openid-configuration',
14+
'ClientID' => 'test',
15+
'RedirectURI' => 'https://login.example.com/redirect_uri',
16+
'ProviderTokenEndpointAuth' => 'client_secret_basic',
17+
'RemoteUserClaim' => 'sub',
18+
'ClientSecret' => 'aae053a9-4abf-4824-8956-e94b2af335c8',
19+
'CryptoPassphrase' => '4ad1bb46-9979-450e-ae58-c696967df3cd',
20+
},
21+
}
22+
MANIFEST
23+
24+
it 'succeeds in configuring a virtual host using mod_auth_openidc' do
25+
apply_manifest(pp, catch_failures: true)
26+
end
27+
28+
it 'is idempotent' do
29+
apply_manifest(pp, catch_changes: true)
30+
end
31+
end

spec/classes/mod/auth_openidc_spec.rb

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,43 @@
99
context 'on a Debian OS', :compile do
1010
include_examples 'Debian 11'
1111

12-
it { is_expected.to contain_class('apache::params') }
1312
it { is_expected.to contain_class('apache::mod::authn_core') }
1413
it { is_expected.to contain_class('apache::mod::authz_user') }
1514
it { is_expected.to contain_apache__mod('auth_openidc') }
1615
it { is_expected.to contain_package('libapache2-mod-auth-openidc') }
16+
it { is_expected.not_to contain_package('dnf-module-mod_auth_openidc') }
1717
end
18-
context 'on a RedHat OS', :compile do
19-
include_examples 'RedHat 6'
18+
context 'on RedHat 7', :compile do
19+
include_examples 'RedHat 7'
2020

21-
it { is_expected.to contain_class('apache::params') }
2221
it { is_expected.to contain_class('apache::mod::authn_core') }
2322
it { is_expected.to contain_class('apache::mod::authz_user') }
2423
it { is_expected.to contain_apache__mod('auth_openidc') }
2524
it { is_expected.to contain_package('mod_auth_openidc') }
25+
it { is_expected.not_to contain_package('dnf-module-mod_auth_openidc') }
26+
end
27+
context 'on RedHat 8', :compile do
28+
include_examples 'RedHat 8'
29+
30+
it { is_expected.to contain_class('apache::mod::authn_core') }
31+
it { is_expected.to contain_class('apache::mod::authz_user') }
32+
it { is_expected.to contain_apache__mod('auth_openidc') }
33+
it { is_expected.to contain_package('mod_auth_openidc') }
34+
it do
35+
is_expected.to contain_package('dnf-module-mod_auth_openidc')
36+
.with_ensure('present')
37+
.with_name('mod_auth_openidc')
38+
.that_comes_before('Package[mod_auth_openidc]')
39+
end
2640
end
2741
context 'on a FreeBSD OS', :compile do
2842
include_examples 'FreeBSD 9'
2943

30-
it { is_expected.to contain_class('apache::params') }
3144
it { is_expected.to contain_class('apache::mod::authn_core') }
3245
it { is_expected.to contain_class('apache::mod::authz_user') }
3346
it { is_expected.to contain_apache__mod('auth_openidc') }
3447
it { is_expected.to contain_package('www/mod_auth_openidc') }
48+
it { is_expected.not_to contain_package('dnf-module-mod_auth_openidc') }
3549
end
3650
end
3751
context 'overriding mod_packages' do
@@ -48,7 +62,6 @@ class { 'apache':
4862
MANIFEST
4963
end
5064

51-
it { is_expected.to contain_class('apache::params') }
5265
it { is_expected.to contain_class('apache::mod::authn_core') }
5366
it { is_expected.to contain_class('apache::mod::authz_user') }
5467
it { is_expected.to contain_apache__mod('auth_openidc') }

0 commit comments

Comments
 (0)