Multisite Compatibility #12
Replies: 8 comments 12 replies
-
Multisite is best-effort support right now - meaning we don't have a dedicated multisite test suite (yet). But this looks easy to fix, and I don't think there is much more to it. But first of all, how would you expect this to work on a conceptual level? Should each site have its session/totp/etc. table(s) ? Should each site have unique fortress secrets? Or should they all use the same secrets? What about all the WP-CLI commands? Should users be expected to always pass the --url flag? |
Beta Was this translation helpful? Give feedback.
-
WP Multisite assumes the users database is shared across all the sites, for example there is only 1 usermeta table. 1 Users table So I'd also assume that all user related tables in Fortress would follow that logic, 1 sessions table, etc. May be different sites, but the username/database/etc is always shared. If the password is set and reset globally for the entire network regardless of domain, shouldn't the session, 2fa, etc all also be shared? Session I could see being separate, but 2fa definitely should be defined globally not per site. |
Beta Was this translation helpful? Give feedback.
-
Internal reference: We'd need to add the Super Admin to the privileged user roles. |
Beta Was this translation helpful? Give feedback.
-
I finally got around to take a deep dive into this. Please let me know what you think. Multisite ConfigurationWe need a per-site cache and log directory. Before Fortress boots: $fortress_var_dir = '/tmp/fortress/var';
$site_id = get_current_blog_id();
mkdir(
$current_site_cache_dir = "$fortress_var_dir/site_$site_id/cache",
0755,
true
);
mkdir(
$current_site_log_dir = "$fortress_var_dir/site_$site_id/log",
0755,
true
);
$_SERVER['SNICCO_FORTRESS_CACHE_DIR'] = $current_site_cache_dir
$_SERVER['SNICCO_FORTRESS_LOG_DIR'] = $current_site_log_dir Optionally, we can use a per-site config file and a baseline config file. // This configuration is used for all sites.
$_SERVER['SNICCO_FORTRESS_SERVER_CONFIG_FILE'] = "/path/to/config/fortress-baseline.json"
// And can be merged with configuration per-site.
// The file SNICCO_FORTRESS_SITE_CONFIG_FILE does NOT have to exist.
$site_id = get_current_blog_id();
$_SERVER['SNICCO_FORTRESS_SITE_CONFIG_FILE'] = "/path/to/config/fortress-site-$site_id.json" TablesAll (current) tables are global. Reasoning:
CookiesWe only use two custom cookies currently:
We'll mimic what WordPress does with auth cookies and use the COOKIE_DOMAIN constant to determine access level. Config TestConfiguration should definitely be tested for ALL sites like so: See: https://danielbachhuber.com/tip/run-wp-cli-command-wordpress-multisite/ wp site list --field=url | xargs -n1 -I % wp --url=% snicco/fortress shared config:test CLI Commands--url should be appended for all CLI commands as a default, especially if per-site configuration is used. |
Beta Was this translation helpful? Give feedback.
-
Other considerationsSuper Admins
Oddly, there is no role slug for super admins. Instead, they are fetched from get_super_admins:
All configuration options that accept user roles will probably not work correctly with super admins. Unless This is also risky from a security perspective, IMO. Any unrestricted site option update can make a subscriber a super admin. Vaults and Pillars don't work for site options either. So, I'd recommend adding the following code in a mu-plugin:
Options that accept capabilitiesuser_can will always return true for super admins, regardless of the capability. That means that if any per-capability settings are used, the first setting in the array must be a capability that only super admins have, such as manage_network Otherwise, the super admins will inherit settings for other caps. {
"session": {
"idle_timeout_per_cap" : {
"manage_network": 1800,
"subscriber" : 10000
}
}
} |
Beta Was this translation helpful? Give feedback.
-
Roles & CapabilitiesRoles and capabilities are weird on multisite. I created a new admin on a subsite (user ID 2).
And the new user has no roles&caps on the main site - not even after adding him as a super admin. This means, that for example password reset restrictions could be bypassed if the action is performed through the main site. Because roles are stored in a usermeta key that depends on the blogid. Hence on the main blog all other users have no roles&caps. I'll need to think about how this can be handled. |
Beta Was this translation helpful? Give feedback.
-
Initial "it will not blow up support" is released on beta.27 I've spun up a subdomain MS and have not had any problems from a functionality perspective. What's unclear/undecided still is mainly related to cross-site access. Stuff like:
This are not mainly code related questions but more so "What is the expected behaviour here" |
Beta Was this translation helpful? Give feedback.
-
Application permission checks (2FA edit for another user currently) have been changed from "manage_options" to "edit_user" which is more logical and also MS compatible. |
Beta Was this translation helpful? Give feedback.
-
First attempt putting Fortress on Multisite lead to
One possible fix...
Using
base_prefix
instead ofprefix
will get you global tables instead of the single subsite tables.Example
/snicco-fortress/src/Session/SessionModule.php:142
This code...
becomes this code...
Looks like there are four uses of
$wpdb->prefix
based on a search of the code./snicco-fortress/src/Session/SessionModule.php:142
/snicco-fortress/src/Shared/SharedModule.php:220
/snicco-fortress/src/Auth/AuthModule.php:209
/snicco-fortress/src/FortressModule.php:121
I did test this on a non-multisite site, and it seemed to work just fine in my 2 minutes of testing..
Beta Was this translation helpful? Give feedback.
All reactions