Skip to content

Commit 68f5556

Browse files
author
Félix Piédallu
committed
Revamp LDAP :
* Move ldap config to json file * enable all extensions * rename options
1 parent 52b49fd commit 68f5556

File tree

6 files changed

+137
-63
lines changed

6 files changed

+137
-63
lines changed

conf/LocalSettings.php

Lines changed: 40 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -135,59 +135,54 @@
135135
# End of automatically generated settings.
136136
# Add more configuration options below.
137137

138-
# Enabled extensions. Most of the extensions are enabled by adding
139-
# wfLoadExtensions('ExtensionName');
140-
# to LocalSettings.php. Check specific extension documentation for more details.
138+
# LDAP Settings
139+
# See https://www.mediawiki.org/wiki/Manual:Active_Directory_Integration
141140

142-
# LDAPProvider
143-
# https://www.mediawiki.org/wiki/Extension:LDAPProvider
141+
# wfLoadExtension( 'LDAPAuthorization' );
142+
wfLoadExtension( 'LDAPAuthentication2' );
143+
wfLoadExtension( 'LDAPGroups' );
144144
wfLoadExtension( 'LDAPProvider' );
145-
146-
# PluggableAuth
147-
# https://www.mediawiki.org/wiki/Extension:PluggableAuth
145+
wfLoadExtension( 'LDAPUserInfo' );
148146
wfLoadExtension( 'PluggableAuth' );
147+
wfLoadExtension( 'Auth_remoteuser' );
149148

150-
$wgPluggableAuth_EnableLocalLogin = true;
149+
# Yunohost configuration values for config_panel
150+
$public_wiki = __PUBLIC_WIKI__;
151+
$local_accounts = __LOCAL_ACCOUNTS__;
152+
$yunohost_accounts = __YUNOHOST_ACCOUNTS__;
153+
154+
# Configuration of the generic PluggableAuth extension
155+
$wgPluggableAuth_EnableLocalLogin = $local_accounts;
151156
$wgPluggableAuth_EnableLocalProperties = true;
157+
$wgPluggableAuth_EnableFastLogout = true;
158+
# $wgPluggableAuth_ButtonLabel = "Log In";
152159

153-
# LDAPAuthentication2
154-
# https://www.mediawiki.org/wiki/Extension:LDAPAuthentication2
155-
wfLoadExtension( 'LDAPAuthentication2' );
160+
# Configuration of the Yunohost LDAP+SSO
161+
if ($yunohost_accounts) {
162+
$LDAPProviderDomainConfigs = "$IP/ldapproviders.json";
163+
$LDAPProviderDefaultDomain = "yunohost.local";
156164

157-
# Note(decentral1se): leaving here in case we need them one day
158-
# LDAPGroups
159-
# https://www.mediawiki.org/wiki/Extension:LDAPGroups
160-
# wfLoadExtension( 'LDAPGroups' );
165+
$wgPluggableAuth_Config["Log In with Yunohost"] = [
166+
"plugin" => "LDAPAuthentication2",
167+
"data" => [ "domain" => "yunohost.local" ]
168+
];
161169

162-
# Note(decentral1se): leaving here in case we need them one day
163-
# LDAPUserInfo
164-
# https://www.mediawiki.org/wiki/Extension:LDAPUserInfo
165-
# wfLoadExtension( 'LDAPUserInfo' );
170+
$wgAuthRemoteuserUserUrls = [
171+
'logout' => 'https://__DOMAIN__/yunohost/sso/?action=logout'
172+
];
173+
}
166174

167-
# Note(decentral1se): leaving here in case we need them one day
168-
# LDAPAuthorization
169-
# https://www.mediawiki.org/wiki/Extension:LDAPAuthorization
170-
# wfLoadExtension( 'LDAPAuthorization' );
175+
# Auth_remoteuser will read the REMOTE_USER http header (for Yunohost SSO)
176+
$wgAuthRemoteuserUserName = [
177+
getenv('REMOTE_USER'),
178+
];
171179

172-
# LDAP configuration
173-
$LDAPProviderDomainConfigProvider = function() {
174-
$config = [
175-
"LDAP" => [
176-
"connection" => [
177-
"server" => "localhost",
178-
"port" => "389",
179-
"basedn" => "dc=yunohost,dc=org",
180-
"groupbasedn" => "ou=users,dc=yunohost,dc=org",
181-
"userbasedn" => "ou=groups,dc=yunohost,dc=org",
182-
"searchattribute" => "uid",
183-
"usernameattribute" => "uid",
184-
"realnameattribute" => "cn",
185-
"emailattribute" => "mail"
186-
]
187-
]
188-
];
180+
# Allow users to login as other than SSO logged in user
181+
$wgAuthRemoteuserAllowUserSwitch = true;
189182

190-
return new \MediaWiki\Extension\LDAPProvider\DomainConfigProvider\InlinePHPArray( $config );
191-
};
192-
$createaccount = __CREATE_ACCOUNT__;
193-
$wgGroupPermissions['*']['createaccount'] = $createaccount;
183+
# $wgEmailConfirmToEdit = false;
184+
$wgGroupPermissions['*']['edit'] = $public_wiki;
185+
$wgGroupPermissions['*']['read'] = $public_wiki;
186+
$wgGroupPermissions['*']['createaccount'] = $local_accounts;
187+
$wgGroupPermissions['*']['autocreateaccount'] = true;
188+
$wgBlockDisablesLogin = true;

conf/ldapproviders.json

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
{
2+
"yunohost.local": {
3+
"connection": {
4+
"server": "localhost",
5+
"port": "389",
6+
"use-tls": "false",
7+
"basedn": "dc=yunohost,dc=org",
8+
"userbasedn": "ou=users,dc=yunohost,dc=org",
9+
"groupbasedn": "ou=groups,dc=yunohost,dc=org",
10+
"searchattribute": "uid",
11+
"usernameattribute": "uid",
12+
"realnameattribute": "cn",
13+
"emailattribute": "mail",
14+
"grouprequest": "MediaWiki\\Extension\\LDAPProvider\\UserGroupsRequest\\UserMemberOf::factory",
15+
"presearchusernamemodifiers": [ "spacestounderscores", "lowercase" ]
16+
},
17+
"userinfo": [],
18+
"authorization": [],
19+
"groupsync": {
20+
"mapping": {
21+
}
22+
}
23+
}
24+
}

config_panel.toml

Lines changed: 26 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,32 @@ version = "1.0"
33
[main]
44
name = "Mediawiki configuration"
55

6-
76
[main.config]
87
name = "Configuration Options"
98

10-
[main.config.create_account]
11-
ask = "Create account"
12-
type = "boolean"
13-
yes = true
14-
no = false
15-
help = "Set to 'true' to allow account creation."
16-
bind = "createaccount:__INSTALL_DIR__/LocalSettings.php"
9+
[install.public_wiki]
10+
ask.en = "Is this Wiki public ?"
11+
ask.fr = "Ce Wiki est-il public ?"
12+
help.en = "This visibility is handled by Mediawiki, not Yunohost"
13+
help.fr = "Cette visibilité est gérée par Mediawiki, pas Yunohost"
14+
type = "boolean"
15+
default = true
16+
bind = ":__INSTALL_DIR__/LocalSettings.php"
17+
18+
[install.local_accounts]
19+
ask.en = "Allow local accounts (non-Yunohost login) ?"
20+
ask.fr = "Autoriser les comptes locaux (non connectés à Yunohost) ?"
21+
help.en = "If this is enabled, people without a Yunohost account can create an account, local to the wiki."
22+
help.fr = "Si activé, les personnes sans compte Yunohost pourront créer un compte local au wiki."
23+
type = "boolean"
24+
default = false
25+
bind = ":__INSTALL_DIR__/LocalSettings.php"
26+
27+
[install.yunohost_accounts]
28+
ask.en = "Link with Yunohost accounts"
29+
ask.fr = "Lier aux comptes Yunohost"
30+
help.en = "If this is enabled, Yunohost users will be able to login."
31+
help.fr = "Si activé, les utilisateurs Yunohost pourront s'authentifier."
32+
type = "boolean"
33+
default = true
34+
bind = ":__INSTALL_DIR__/LocalSettings.php"

manifest.toml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ ram.runtime = "50M"
3838
default = "/wiki"
3939

4040
[install.init_main_permission]
41-
help.en = "Visibility of the wiki pages"
42-
help.fr = "La visibilité des pages du wiki"
41+
help.en = "Visibility of the wiki (handled by Yunohost)"
42+
help.fr = "La visibilité du wiki (gérée par Yunohost)"
4343
type = "group"
4444
default = "visitors"
4545

@@ -64,12 +64,42 @@ ram.runtime = "50M"
6464
type = "string"
6565
default = "YunoWiki"
6666

67+
[install.public_wiki]
68+
ask.en = "Is this Wiki public ?"
69+
ask.fr = "Ce Wiki est-il public ?"
70+
help.en = "This visibility is handled by Mediawiki, not Yunohost"
71+
help.fr = "Cette visibilité est gérée par Mediawiki, pas Yunohost"
72+
type = "boolean"
73+
default = true
74+
75+
[install.local_accounts]
76+
ask.en = "Allow local accounts (non-Yunohost login) ?"
77+
ask.fr = "Autoriser les comptes locaux (non connectés à Yunohost) ?"
78+
help.en = "If this is enabled, people without a Yunohost account can create an account, local to the wiki."
79+
help.fr = "Si activé, les personnes sans compte Yunohost pourront créer un compte local au wiki."
80+
type = "boolean"
81+
default = false
82+
83+
[install.yunohost_accounts]
84+
ask.en = "Link with Yunohost accounts"
85+
ask.fr = "Lier aux comptes Yunohost"
86+
help.en = "If this is enabled, Yunohost users will be able to login."
87+
help.fr = "Si activé, les utilisateurs Yunohost pourront s'authentifier."
88+
type = "boolean"
89+
default = true
90+
91+
6792
[resources]
6893
[resources.sources]
6994
[resources.sources.main]
7095
url = "https://releases.wikimedia.org/mediawiki/1.40/mediawiki-1.40.1.tar.gz"
7196
sha256 = "e05d419de40c6ad03145aca07e08cf995d1ca1667d97793bb73970e2c11b0a04"
7297

98+
[resources.sources.auth_remoteuser]
99+
url = "https://github.com/wikimedia/mediawiki-extensions-Auth_remoteuser/archive/1a72290f4b3f35694a9a0a71d7c17258badca429.tar.gz"
100+
sha256 = "4864edde068209a8a72a97238041220d47b3d4cd4c353637dd0857f488b67904"
101+
in_subdir = true
102+
73103
[resources.sources.ldap_groups]
74104
url = "https://github.com/wikimedia/mediawiki-extensions-LDAPGroups/archive/962dcfe5f68241057d6489da2b23f202bf7490f4.tar.gz"
75105
sha256 = "cd3854f89f240675b14f3472c381a21dcf1254fb11813202879ad25816ddca2b"

scripts/install

100644100755
Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,16 @@ ynh_script_progression --message="Setting up source files..." --weight=4
2626

2727
# Download, check integrity, uncompress and patch the source from app.src
2828
ynh_setup_source --dest_dir="$install_dir"
29+
30+
# See https://www.mediawiki.org/wiki/Manual:Active_Directory_Integration
31+
ynh_setup_source --dest_dir="$install_dir/extensions/Auth_remoteuser" --source_id="auth_remoteuser"
32+
ynh_setup_source --dest_dir="$install_dir/extensions/LDAPAuthorization" --source_id="ldap_authorization"
2933
ynh_setup_source --dest_dir="$install_dir/extensions/LDAPAuthentication2" --source_id="ldap_authentication2"
34+
ynh_setup_source --dest_dir="$install_dir/extensions/LDAPGroups" --source_id="ldap_groups"
3035
ynh_setup_source --dest_dir="$install_dir/extensions/LDAPProvider" --source_id="ldap_provider"
36+
ynh_setup_source --dest_dir="$install_dir/extensions/LDAPUserInfo" --source_id="ldap_userinfo"
3137
ynh_setup_source --dest_dir="$install_dir/extensions/PluggableAuth" --source_id="pluggable_auth"
3238

33-
# ynh_setup_source --dest_dir="$install_dir/extensions/LDAPGroups" --source_id="ldap_groups"
34-
# ynh_setup_source --dest_dir="$install_dir/extensions/LDAPUserInfo" --source_id="ldap_userinfo"
35-
# ynh_setup_source --dest_dir="$install_dir/extensions/LDAPAuthorization" --source_id="ldap_authorization"
3639

3740
chmod -R o-rwx "$install_dir"
3841
chown -R $app:www-data "$install_dir"
@@ -94,6 +97,7 @@ mv "$install_dir/LocalSettings.php" "$install_dir/LocalSettings.php.orig"
9497
wiki_name_underscorified="${wiki_name//[^a-zA-Z0-9]/_}"
9598

9699
ynh_add_config --template="../conf/LocalSettings.php" --destination="$install_dir/LocalSettings.php"
100+
ynh_add_config --template="../conf/ldapproviders.json" --destination="$install_dir/ldapproviders.json"
97101

98102
# This is required to update database schemas
99103
"php$phpversion" "$install_dir/maintenance/update.php"

scripts/upgrade

100644100755
Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ then
5858

5959
# Download, check integrity, uncompress and patch the source from app.src
6060
ynh_setup_source --dest_dir="$install_dir"
61+
62+
# See https://www.mediawiki.org/wiki/Manual:Active_Directory_Integration
63+
ynh_setup_source --dest_dir="$install_dir/extensions/Auth_remoteuser" --source_id="auth_remoteuser"
64+
ynh_setup_source --dest_dir="$install_dir/extensions/LDAPAuthorization" --source_id="ldap_authorization"
6165
ynh_setup_source --dest_dir="$install_dir/extensions/LDAPAuthentication2" --source_id="ldap_authentication2"
66+
ynh_setup_source --dest_dir="$install_dir/extensions/LDAPGroups" --source_id="ldap_groups"
6267
ynh_setup_source --dest_dir="$install_dir/extensions/LDAPProvider" --source_id="ldap_provider"
68+
ynh_setup_source --dest_dir="$install_dir/extensions/LDAPUserInfo" --source_id="ldap_userinfo"
6369
ynh_setup_source --dest_dir="$install_dir/extensions/PluggableAuth" --source_id="pluggable_auth"
64-
65-
# ynh_setup_source --dest_dir="$install_dir/extensions/LDAPGroups" --source_id="ldap_groups"
66-
# ynh_setup_source --dest_dir="$install_dir/extensions/LDAPUserInfo" --source_id="ldap_userinfo"
67-
# ynh_setup_source --dest_dir="$install_dir/extensions/LDAPAuthorization" --source_id="ldap_authorization"
68-
6970
fi
7071

7172
chmod -R o-rwx "$install_dir"
@@ -115,6 +116,8 @@ if (( password_length < 10 )); then
115116
echo "\$wgPasswordPolicy['policies']['default']['MinimalPasswordLength'] = 10;" >> "$install_dir/LocalSettings.php"
116117
fi
117118

119+
ynh_add_config --template="../conf/ldapproviders.json" --destination="$install_dir/ldapproviders.json"
120+
118121
# This is required to update database schemas
119122
"php$phpversion" "$install_dir/maintenance/update.php"
120123

0 commit comments

Comments
 (0)