Extension:中央认证

This page is a translated version of the page Extension:CentralAuth and the translation is 30% complete.
MediaWiki扩展手册
CentralAuth
发行状态: 稳定版
实现 用户身份 , 数据库 , 特殊页面 , API
描述 可将許多帐户合并為全域帐户
作者 Brooke Vibber留言
兼容性政策 快照跟随MediaWiki发布。 master分支不向后兼容。
MediaWiki >= 1.42
数据库更改
globalnames
localnames
globaluser
localuser
global_user_groups
global_group_permissions
wikiset
global_group_restrictions
renameuser_status
renameuser_queue
users_to_rename
global_edit_count
global_user_autocreate_serial
许可协议 GNU通用公眾授權條款2.0或更新版本
下載
  • $wgCentralAuthAutoLoginWikis
  • $wgCentralAuthCookies
  • $wgCentralAuthIpoidDenyAccountCreationTunnelTypes
  • $wgCentralAuthIpoidCheckAtAccountCreationLogOnly
  • $wgCentralAuthEnableGlobalRenameRequest
  • $wgCentralAuthIpoidRequestTimeoutSeconds
  • $wgCentralAuthCookiePath
  • $wgCentralAuthRC
  • $wgCentralAuthIpoidCheckAtAccountCreation
  • $wgCentralAuthGlobalBlockInterwikiPrefix
  • $wgCentralAuthAutoMigrateNonGlobalAccounts
  • $wgCentralAuthIpoidUrl
  • $wgCentralAuthDatabase
  • $wgCentralAuthDryRun
  • $wgCentralAuthAutoMigrate
  • $wgCentralAuthTokenSessionTimeout
  • $wgCentralAuthSessionCacheType
  • $wgGlobalRenameDenylist
  • $wgCentralAuthOldNameAntiSpoofWiki
  • $wgCentralAuthLoginIcon
  • $wgCentralAuthStrict
  • $wgCentralAuthReadOnly
  • $wgCentralAuthLoginWiki
  • $wgCentralAuthIpoidDenyAccountCreationRiskTypes
  • $wgCentralAuthGlobalPasswordPolicies
  • $wgCentralAuthWikisPerSuppressJob
  • $wgCentralAuthCookieDomain
  • $wgCentralAuthPrefsForUIReload
  • $wgCentralAuthAutoCreateWikis
  • $wgCentralAuthCookiePrefix
  • centralauth-createlocal
  • centralauth-merge
  • centralauth-unmerge
  • centralauth-lock
  • centralauth-suppress
  • globalgrouppermissions
  • globalgroupmembership
  • centralauth-rename
季度下載量 49 (Ranked 92nd)
前往translatewiki.net翻譯CentralAuth扩展
問題 开启的任务 · 报告错误

CentralAuth可将现有的几个分開的账户系统合并为一个全域账户系统。

警告 警告:

CentralAuth是专门为维基媒体项目而设计的,该项目已经具有数百万个需要合并到全域表中的帐户。 如果你正要从头开始建立一个新的维基农场,而並沒有将现有帐户合并到全域表中的需求,则使用$wgSharedDB 來设置全域帐户比CentralAuth要容易得多。[1][2]

然而,$wgSharedDB只对防止用户名建立冲突有效,它并不处理例如全域登录(用户要分别登入各个维基)或跨集群账户权限和管理之类的事。 该扩展以付出了复杂性的代价提供上述的功能。

如果你最终在第三方维基上使用了这个扩展,很可能最终不得不对复杂的问题进行故障排除,而这些问题可能需要深入到源代码中才能解决。

我已经警告过你了。

安裝

有关使用CentralAuth的先决条件,请参见下面的配置部分。 當你已經准备好激活CentralAuth时,请按照以下说明进行操作:

  1. 請安装扩展:AntiSpoof ,因为它是一个必需的依赖项。
  2. 下载最新快照并解压到您的extensions目录中。
  3. 选择一個数据库然後创建CentralAuth数据库表。 您可以使用现有的数据库或创建一个新的数据库;默认情况下,扩展名使用名为centralauth的数据库(请参见下面的$wgCentralAuthDatabase)。 使用这个数据库,然后运行tables-generated.sql
    • 如果你使用扩展:AntiSpoof ,你將需要创建一个全域的spoofuser表(以阻挡那些看起来和任何维基中已有用户名相似的新用户名)。 一种方法是从本地维基数据库中转储spoofuser表,然后将其导入新的$wgCentralAuthDatabase表。
  4. 为您的每个维基的LocalSettings.php 添加wfLoadExtension( 'CentralAuth' );,或在您的每个维基的LocalSettings.php中包含的另一个PHP文件中添加wfLoadExtension( 'CentralAuth' );
  5. 该扩展现在应该处于活跃状态。

创建一個新的数据库

Here are sample shell and SQL commands to create the centralauth database, copy the spoofuser table to it, and migrate existing user data to it. Replace $wgDBname and $wgDBuser with the values for your own wiki installation.

Create the new database (Remember this step is optional, you can instead use one of your existing databases, in which case skip to the create tables step):

$ cd extensions/CentralAuth
$ mysql -u root -p
(enter password for root SQL user)
CREATE DATABASE centralauth;
USE centralauth;
GRANT all on centralauth.* to '$wgDBuser'@'localhost';
quit

Run maintenance scripts

The following assumes your present working directory is your MediaWiki installation (not your CentralAuth directory). Create the central auth tables (using sql.php is preferred).

php maintenance/run.php sql --wikidb centralauth extensions/CentralAuth/schema/<数据库类型>/tables-generated.sql

如果已安装AntiSpoof,则通过以下方式创建表格(如果想保留以前的入口,也可以复制现有的AntiSpoof表格):

php maintenance/run.php sql --wikidb centralauth extensions/AntiSpoof/sql/<数据库类型>/tables-generated.sql

运行用户迁移脚本

$ php maintenance/run.php CentralAuth:migratePass0.php
$ php maintenance/run.php CentralAuth:migratePass1.php

升级

CentralAuth是专为手动运行数据库更新的大型维基站点设计,以实现零停机升级。 出于此原因,CentralAuth数据库将不会以常规升级進程更新。 第三方用户应遵循CentralAuth的开发流程,並以手动套用数据库迁移。

设置

  警告: 如果您想在不同的主域之间实现通用登录(即如果您的维基不在同一域的子域之下),则需要一个中央登录维基。 详细信息,请参见下方

First, you'll need to configure your wiki family using $wgConf , or CentralAuth can't be used for your wiki family. This includes setting $wgLocalDatabases and assigning it to $wgConf->wikis, and $wgConf->settings (minimum is $wgCanonicalServer , $wgServer and $wgArticlePath ). Follow the examples carefully. If you are creating a new wiki family, bear in mind that it may be easier if the databases for the wikis in each group have the same suffix (e.g. hypothetical databases enwiki, dewiki, frwiki, etc., pertaining to wikis belonging to the same group, all have the suffix "wiki").

After installing the extension, you have to gather some data in the CentralAuth database. In order to retroactively set up global accounts, you will have to run the migratePass0.php and migratePass1.php scripts. The first one stores information about your wikis in the CentralAuth database, while the second one uses automatic migration heuristics to generate global accounts. 用户可以通过Special:MergeAccount手工合并其帐户。 Dry runs can be used for testing purposes.

To enable global groups, you will have to make an entry into the global_group_permissions table in your CentralAuth database, with ggp_group='steward' and (for access to the group management interface) ggp_permission=globalgrouppermissions. A sample query that is recommended to use is:

INSERT INTO global_group_permissions (ggp_group,ggp_permission) VALUES ('steward','globalgrouppermissions'), ('steward','globalgroupmembership');

Then, promote some users into stewards:

INSERT IGNORE INTO global_user_groups (gug_user, gug_group) VALUES ((SELECT gu_id FROM globaluser WHERE gu_name='Admin'), 'steward');

There are various settings you may wish to modify (e.g. whether to provide single sign-on across a whole domain) listed in CentralAuth.php. In particular, you will want to override the default value of $wgCentralAuthDatabase if your CentralAuth database is named something other than 'centralauth'. Make sure you put such settings after the wfLoadExtension line in LocalSettings.php, e.g.:

wfLoadExtension( 'CentralAuth' );
$wgCentralAuthDatabase = 'mycentralauthdatabase';

“SUL2”行为

  警告: As all logged in users will have a session in the central login wiki, you are recommended to set up a new wiki with as few extensions installed as possible (not using an existing wiki for this purpose). This will reduce the risk for XSS vulnerabilities.
  警告: Universal sign-on may be broken in newer Google Chrome versions due to SameSite cookie policy. 为了修复此问题,你需要添加:
$wgCookieSameSite = "None";
$wgUseSameSiteLegacyCookies = true;

In addition, you should run your site under HTTPS.

In July 2013 WMF changed its approach to logging users into multiple wikis. When configured for this new approach, after successful login and account creation CentralAuth redirects to Special:CentralLogin/start?token=somevalue on a "central login wiki", which sets cookies on that wiki and then redirects back to the logged-into wiki. It omits the "login/account creation success" page, instead redirecting back to the "returnto" page that the user was originally on. It places 1x1 pixel images in the footer of that page, in place of the icons formerly used on the "login/account creation success" page.

The settings for this are, roughly,

# General CentralAuth configuration
$wgCentralAuthCookies = true;
$wgCentralAuthDatabase = 'centralauthDatabaseName'; // default is 'centralauth'
$wgCentralAuthAutoMigrate = true;
#$wgCentralAuthCookieDomain = '.example.org';
$wgCentralAuthAutoLoginWikis = array(
    # Mapping from domain name to wiki id for other wikis to automatically login into
);

# Activates the redirect to the "central login wiki"
$wgCentralAuthLoginWiki = 'WikiIdOfLoginWiki';

$wgCentralAuthLoginWiki is the id (usually the database-name) of the wiki to which CentralAuth will redirect on login and create account.

缓存问题

For best results, it is recommended to use memcached. If you have only a single server, accelerator caches (CACHE_ACCEL) like APCu can also work, but do not use them if you have multiple servers. If you have no cache set up (i.e. CACHE_NONE) for $wgMainCacheType, or are using CACHE_DB, then you need to make sure all your wikis use the same caching table.

By default, each wiki in your wiki farm will use the objectcache table in its own database (with its own db prefix) when $wgMainCacheType is set to CACHE_NONE or CACHE_DB. To make this work with CentralAuth, we need to tell the wikis to use a central cache table.

If you want to make a central caching table in the centralauth database (and assuming one of your existing wikis has a database name of enwiki), run code like the following to copy the table to your other database:

CREATE TABLE centralauth.objectcache LIKE enwiki.objectcache

Then add the following config to all wikis to tell them to use the central table instead of their own table:

$wgSharedDB     = 'centralauth'; // or whatever database you use for central data
$wgSharedTables = array( 'objectcache' ); // remember to copy the table structure's to the central database first
$wgCentralAuthSessionCacheType = CACHE_DB; // Tell mediawiki to use objectcache database for central auth.

HTTP and HTTPS

Since 2023, CentralAuth does not support mixed-protocol HTTP/HTTPS wikis, only pure-HTTPS wikis (with $wgForceHTTPS set to true) and pure-HTTP wikis (primarily for local testing).phab:T348852

配置

CentralAuth.php中的配置设置
参数 默认 评论
$wgCentralAuthDatabase 'centralauth' Database name you keep central auth data in.

If this is not on the primary database connection, don't forget to also set up $wgDBservers to have an entry with a groupLoads setting for the 'CentralAuth' group. Alternatively you can use $wgLBFactoryConf to set up an LBFactoryMulti object.

To use a database with a table prefix, set this variable to "{$database}-{$prefix}".

$wgCentralAuthAutoMigrate false If true, existing unattached accounts will be automatically migrated if possible at first login.

Any new account creations will be required to attach.

If false, unattached accounts will not be harassed unless the individual account has opted in to migration.

$wgCentralAuthAutoMigrateNonGlobalAccounts false If true, existing unattached accounts where no global account exists will be compared to see if a merge can be made based on passwords and emails with no clashes (all accounts merge).

This was formerly controlled by $wgCentralAuthAutoMigrate

$wgCentralAuthStrict false If true, remaining accounts which have not been attached will be forbidden from logging in until they are resolved.
$wgCentralAuthDryRun false If true, merging won't actually be possible through the Special:MergeAccount interface.
$wgCentralAuthCookies false If true, global session and token cookies will be set alongside the per-wiki session and login tokens when users log in with a global account.

This allows other wikis on the same domain to transparently log them in.

$wgCentralAuthLoginWiki false Database name of a central login wiki. This is an alternative to directly setting cross-domain cookies for each wiki in $wgCentralAuthAutoLoginWikis. If set, a single login wiki will use a session/cookie to handle unified login sessions across wikis.

On login, users will be redirected to the login wiki's Special:CentralLogin/login page and then redirected to Special:CentralLogin back on the originating wiki. In the process, the central login wiki cookie and session will be set. As the user accesses other wikis, the login wiki will be checked via JavaScript to check login status and set the local session and cookies.

This requires $wgCentralAuthCookies.

$wgCentralAuthCookieDomain '' Domain to set global cookies for.

For instance, '.wikipedia.org' to work on all wikipedia.org subdomains instead of just the current one. Leave blank to set the cookie for the current domain only, such as if all your wikis are hosted on the same subdomain.

$wgCentralAuthCookiePrefix 'centralauth_' Prefix for CentralAuth global authentication cookies.
$wgCentralAuthCookiePath '/' Path for CentralAuth global authentication cookies. Set this variable if you want to restrict cookies to a certain path within the domain specified by $wgCentralAuthCookieDomain.
$wgCentralAuthAutoLoginWikis [] List of wiki IDs which should be called on login to try to set third-party cookies for the global session state.

The wiki ID is typically the database name, except when table prefixes are used, in which case it is the database name, a hyphen separator, and then the table prefix.

This allows a farm with multiple second-level domains to set up a global session on all of them by hitting one wiki from each domain (en.wikipedia.org, en.wikinews.org, etc.).

Done by accessing Special:CentralAutoLogin/start on each wiki.

If empty, no other wikis will be hit.

The key should be set to the cookie domain name.

$wgCentralAuthAutoCreateWikis [] List of wiki IDs on which an attached local account should be created automatically when the global account is created.

The wiki ID is typically the database name, except when table prefixes are used, in which case it is the database name, a hyphen separator, and then the table prefix.

$wgCentralAuthLoginIcon false Local filesystem path to the icon returned by Special:CentralAutoLogin should be a 20x20px PNG.
$wgCentralAuthPrefsForUIReload [ 'skin', 'language', 'thumbsize', 'underline', 'stubthreshold', 'showhiddencats', 'justify', 'numberheadings', 'editondblclick', 'editsection', 'editsectiononrightclick', 'usenewrc', 'extendwatchlist' ] User preferences for which we should recommend reloading the page after a successful central login query.

If you need to do something more complicated than just $userOptionsLookup->getOption( $user, $pref ) !== $userOptionsLookup->getDefaultOption( $pref ), use the hook CentralAuthIsUIReloadRecommended.

$wgCentralAuthRC [] Array of settings for sending the CentralAuth events to the RC Feeds.

@example $wgRCFeeds['example'] = array( 'uri' => "udp://localhost:1336", );

$wgCentralAuthWikisPerSuppressJob 10 Size of wikis handled in one suppress user job. Keep in mind that one wiki requires ~10 queries.
$wgCentralAuthReadOnly false Like $wgReadOnly, used to set extension to database read only mode.

@var bool

$wgCentralAuthEnableGlobalRenameRequest false Feature flag for Special:GlobalRenameRequest.

@var bool

$wgCentralAuthGlobalPasswordPolicies [] Global password policies. These are applied like local password policies, the strongest policy applicable to a user is used. Policies can apply to either a local group (if the user is a member of that group on any wiki, the policy will apply to that user) or global group.

@var array

$wgGlobalRenameDenylist null A list of users who won't be allowed to create new global rename requests through Special:GlobalRenameRequest.

There are two ways to set it:

  • Using a wiki-page: use a Title object to have a wiki-page (MediaWiki:GlobalRenameDenylist for example) as the banned-list. The wiki-page must be a list with one item per line, and must exist otherwise Special:GlobalRenameRequest will throw a MWException.
    Example: $wgGlobalRenameDenylist = Title::makeTitle( NS_MEDIAWIKI, 'GlobalRenameDenylist' );.
  • Using a URL: put a complete URL which must return, using HTTP, a plain-text list of the banned users (and nothing else).
    For example, with a URL pointing to a wiki page: $wgGlobalRenameDenylist = "https://yourwiki/yourpath/index.php?title=MediaWiki:GlobalRenameDenylist&action=raw";

You can use the exact names or regular expressions.

@var Title|string|null

$wgCentralAuthGlobalBlockInterwikiPrefix "global" When globally suppressing a user, a block against this user is inserted in all wikis. CentralAuth will set the author of theses blocks as $wgCentralAuthGlobalBlockInterwikiPrefix>(user-who-made-the-suppression's nickname). For example, if $wgCentralAuthGlobalBlockInterwikiPrefix = "Admins";, and Joe suppresses John, all wikis will show in BlockList a block against John made by Admins>Joe.

@var string

使用

Allows for a single-user login (SUL) system using MediaWiki's AuthPlugin system. User creation and login is done globally using one central user table across all wikis. Note that local user accounts are automatically created on account creation/login however.

This extension also implements global user groups, to which global accounts can belong to.

用户权限

CentralAuth defines several new user rights:

用户权限 能力 默认用户组 状态
centralauth-createlocal Forcibly create a local account for a global account 监管员与管理员 Active in MW 1.36+
centralauth-lock Prevent users from logging in on any wiki 监管员 Active
centralauth-suppress Suppress or unhide global accounts 监管员 Active
centralauth-rename Rename global accounts 监管员 Active
centralauth-unmerge Unmerge global accounts from a local account Stewards Active
centralauth-merge Merge all CentralAuth accounts globally All users Active; usually automatic
globalgrouppermissions Manage permissions of global groups Global Stewards Active; not assigned to local stewards by default
globalgroupmembership Edit membership to global groups 监管员 Active; not assigned to local stewards by default

函数

单用户登录(SUL)

A user with an account on more than one wiki may use Special:MergeAccount to create their global user account, which can then be used on any wiki. Users with the centralauth-unmerge permission (given to stewards by default) can undo a merging of a global account, where the passwords are all reset back to the pre-merge setting. User accounts can now also be renamed globally.

封锁和隐藏全域用户

 
Screenshot of Special:CentralAuth interface on Meta-Wiki, showing lock/hide interface.

A global account can be locked or hidden by a user with the centralauth-lock and centralauth-suppress permissions, respectively, given to the local group 'stewards' by default. A locked global account will be immediately logged out of any session on any wiki it is currently logged in to. A hidden global account's username is not visible in any logs except the global account log.

维基集

A wiki set is a group of wikis specified by a user with the globalgrouppermissions right. Sets can be opt-in (wikis are not in it by default) or opt-out (wikis are in it unless opted out).

全域用戶组

Once you have enabled global user groups as described in the installation section, a migrated steward can use the Special:GlobalGroupPermissions interface to configure global user groups, and their rights. A global user group is active on all wikis (the users in it have its rights on all the wikis) by default, unless the group has been specified to only be active on a specific wiki set (the users in the group only have the rights if they are on a wiki in the set). Global group permissions are not listed at Special:ListUsers, but instead Special:GlobalUsers. They are assigned by a user with the globalgroupmembership permission (by default the global group stewards), and give the specified rights to the user even if the local rights defined by $wgGroupPermissions do not do so.

许可和下载

The extension is available under the GNU General Public License 2.0 or later, and can be downloaded from Git, or accessed via the web-based viewer.

The software is provided as-is. Updates will be made according to the needs of Wikimedia wikis; or where critical vulnerabilities are discovered.

API

参见Extension:CentralAuth/API

參考資料

参见