Skip to content

Commit 114ae7d

Browse files
committed
Document the new migration tool
1 parent ff06b5e commit 114ae7d

File tree

4 files changed

+125
-45
lines changed

4 files changed

+125
-45
lines changed

docs/SUMMARY.md

+1
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
- [`database`](./reference/cli/database.md)
3434
- [`manage`](./reference/cli/manage.md)
3535
- [`server`](./reference/cli/server.md)
36+
- [`syn2mas`](./reference/cli/syn2mas.md)
3637
- [`worker`](./reference/cli/worker.md)
3738
- [`templates`](./reference/cli/templates.md)
3839
- [`doctor`](./reference/cli/doctor.md)

docs/reference/cli/config.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ clients:
2626
# ...
2727
```
2828

29-
## `config generate`
29+
## `config generate [--synapse-config <synapse-config>] [--output <output>]`
3030

3131
Generate a sample configuration file.
3232
It generates random signing keys (`.secrets.keys`) and the cookie encryption secret (`.secrets.encryption`).
@@ -38,6 +38,10 @@ INFO generate:rsa: mas_config::oauth2: Done generating RSA key
3838
INFO generate:ecdsa: mas_config::oauth2: Done generating ECDSA key
3939
```
4040

41+
The `--synapse-config` option can be used to migrate over configuration options from an existing Synapse configuration.
42+
43+
The `--output` option can be used to specify the output file. If not specified, the output will be written to stdout.
44+
4145
## `config sync [--prune] [--dry-run]`
4246

4347
Synchronize the configuration with the database.
@@ -52,4 +56,4 @@ INFO cli.config.sync: Updating provider provider.id=01H3FDH2XZJS8ADKRGWM84PZTY
5256
INFO cli.config.sync: Adding provider provider.id=01H3FDH2XZJS8ADKRGWM84PZTF
5357
INFO cli.config.sync: Deleting client client.id=01GFWRB9MYE0QYK60NZP2YF905
5458
INFO cli.config.sync: Updating client client.id=01GFWRB9MYE0QYK60NZP2YF904
55-
```
59+
```

docs/reference/cli/syn2mas.md

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# `syn2mas`
2+
3+
Tool to import data from an existing Synapse homeserver into MAS.
4+
5+
Global options:
6+
- `--config <config>`: Path to the MAS configuration file.
7+
- `--help`: Print help.
8+
- `--synapse-config <synapse-config>`: Path to the Synapse configuration file.
9+
- `--synapse-database-uri <synapse-database-uri>`: Override the Synapse database URI.
10+
11+
## `syn2mas check`
12+
13+
Check the setup for potential problems before running a migration
14+
15+
```console
16+
$ mas-cli syn2mas check --config mas_config.yaml --synapse-config homeserver.yaml
17+
```
18+
19+
## `syn2mas migrate [--dry-run]`
20+
21+
Migrate data from the homeserver to MAS.
22+
23+
The `--dry-run` option will perform a dry-run of the migration, which is safe to run without stopping Synapse.
24+
It will perform a full data migration, but then empty the MAS database at the end to roll back.
25+
26+
27+
```console
28+
$ mas-cli syn2mas migrate --config mas_config.yaml --synapse-config homeserver.yaml
29+
```

docs/setup/migration.md

+89-43
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,25 @@
11
# Migrating an existing homeserver
22

3-
One of the design goals of MAS has been to allow it to be used to migrate an existing homeserver to an OIDC-based architecture.
3+
One of the design goals of MAS has been to allow it to be used to migrate an existing homeserver, specifically without requiring users to re-authenticate and ensuring that all existing clients continue to work.
44

5-
Specifically without requiring users to re-authenticate and that non-OIDC clients continue to work.
6-
7-
Features that are provided to support this include:
5+
Features that support this include:
86

97
- Ability to import existing password hashes from Synapse
108
- Ability to import existing sessions and devices
11-
- Ability to import existing access tokens linked to devices (ie not including short-lived admin puppeted access tokens)
9+
- Ability to import existing access tokens
1210
- Ability to import existing upstream IdP subject ID mappings
1311
- Provides a compatibility layer for legacy Matrix authentication
1412

15-
There will be tools to help with the migration process itself. But these aren't quite ready yet.
16-
1713
## Preparing for the migration
1814

19-
The deployment is non-trivial so it is important to read through and understand the steps involved and make a plan before starting.
15+
The deployment is non-trivial, so it is important to read through and understand the steps involved and make a plan before starting.
2016

2117
### Is your setup ready to be migrated?
2218

2319
#### SAML2 and LDAP Single Sign-On Providers are not supported
2420

25-
A deployment which requires SAML or LDAP-based authentication should use a service like [Dex](https://github.com/dexidp/dex) to bridge between the SAML provider and the authentication service.
26-
MAS is different from Synapse in that it does **not** have built-in support for SAML or LDAP-based providers.
21+
A deployment that requires SAML or LDAP-based authentication should use a service like [Dex](https://github.com/dexidp/dex) to bridge between the SAML provider and the authentication service.
22+
MAS differs from Synapse in that it does **not** have built-in support for SAML or LDAP-based providers.
2723

2824
#### Custom password providers are not supported
2925

@@ -32,28 +28,34 @@ If your Synapse homeserver currently uses a custom password provider module, ple
3228
#### SQLite databases are not supported
3329

3430
It is worth noting that MAS currently only supports PostgreSQL as a database backend.
31+
The migration tool only supports reading from PostgreSQL for the Synapse database as well.
3532

3633
### Install and configure MAS alongside your existing homeserver
3734

3835
Follow the instructions in the [installation guide](installation.md) to install MAS alongside your existing homeserver.
3936

4037
You'll need a blank PostgreSQL database for MAS to use; it does not share the database with the homeserver.
4138

42-
Set up a configuration file but don't start MAS, or create any users, yet.
39+
MAS provides a tool to generate a configuration file based on your existing Synapse configuration. This is useful for kickstarting your new configuration.
40+
41+
```sh
42+
mas-cli config generate --synapse-config homeserver.yaml --output mas_config.yaml
43+
```
44+
45+
When using this tool, be careful to examine the log output for any warnings about unsupported configuration options.
4346

4447
#### Local passwords
4548

46-
Synapse uses bcrypt as its password hashing scheme while MAS defaults to using the newer argon2id.
49+
Synapse uses bcrypt as its password hashing scheme, while MAS defaults to using the newer argon2id.
4750
You will have to configure the version 1 scheme as bcrypt for migrated passwords to work.
48-
It is also recommended that you keep argon2id as version 2 so that once users log in, their hashes will be updated to the newer recommended scheme.
49-
If you have a `pepper` set in the `password_config` section of your Synapse config, then you need to specify this `pepper` as the `secret` field for your `bcrypt` scheme.
51+
It is also recommended that you keep argon2id as version 2 so that once users log in, their hashes will be updated to the newer, recommended scheme.
5052

5153
Example passwords configuration:
5254
```yml
5355
passwords:
5456
enabled: true
5557
schemes:
56-
- version: 1 # TODO I think v:2 has to come first in this list
58+
- version: 1
5759
algorithm: bcrypt
5860
# Optional, must match the `password_config.pepper` in the Synapse config
5961
#secret: secretPepperValue
@@ -70,22 +72,59 @@ The migration checker will inform you if this has not been configured properly.
7072
If you are using an upstream SSO provider, then you will need to configure the upstream provider in MAS manually.
7173
7274
MAS does not support SAML or LDAP upstream providers.
73-
If you are using one of these, you will need to use an adapter such as Dex at this time,
74-
but we have not yet documented this procedure.
75+
If you are using one of these, you will need to use an adapter such as Dex at this time, but we have not yet documented this procedure.
7576
7677
Each upstream provider that was used by at least one user in Synapse will need to be configured in MAS.
7778
7879
Set the `synapse_idp_id` attribute on the provider to:
7980

8081
- `"oidc"` if you used an OIDC provider in Synapse's legacy `oidc_config` configuration section.
81-
- `"oidc-myprovider"` if you used an OIDC provider in Synapse's `oidc_providers` configuration list,
82-
with a `provider` of `"myprovider"`.
82+
- `"oidc-myprovider"` if you used an OIDC provider in Synapse's `oidc_providers` configuration list, with a `provider` of `"myprovider"`.
8383
(This is because Synapse prefixes the provider ID with `oidc-` internally.)
8484

85-
Without the `synapse_idp_id`s being set, syn2mas does not understand which providers
86-
in Synapse correspond to which provider in MAS.
85+
Without the `synapse_idp_id`s being set, `mas-cli syn2mas` does not understand which providers in Synapse correspond to which provider in MAS.
86+
87+
For example, if your Synapse configuration looked like this:
88+
89+
```yaml
90+
oidc_providers:
91+
- idp_id: dex
92+
idp_name: "My Dex server"
93+
issuer: "https://example.com/dex"
94+
client_id: "synapse"
95+
client_secret: "supersecret"
96+
scopes: ["openid", "profile", "email"]
97+
user_mapping_provider:
98+
config:
99+
localpart_template: "{{ user.email.split('@')[0].lower() }}"
100+
email_template: "{{ user.email }}"
101+
display_name_template: "{{ user.name|capitalize }}"
102+
```
87103

88-
!!!!!!!!! TODO add an example here
104+
Then the equivalent configuration in MAS would look like this:
105+
106+
```yaml
107+
upstream_oauth2:
108+
providers:
109+
- id: 01JSHPZHAXC50QBKH67MH33TNF
110+
synapse_idp_id: oidc-dex
111+
issuer: "https://example.com/dex"
112+
human_name: "My Dex server"
113+
client_id: "synapse"
114+
client_secret: "supersecret"
115+
token_endpoint_auth_method: client_secret_basic
116+
scope: "email openid profile"
117+
claims_imports:
118+
localpart:
119+
action: require
120+
template: "{{ user.email.split('@')[0].lower() }}"
121+
displayname:
122+
action: force
123+
template: "{{ user.name|capitalize }}"
124+
email:
125+
action: force
126+
template: "{{ user.email }}"
127+
```
89128

90129
The migration checker will inform you if a provider is missing from MAS' config.
91130

@@ -95,58 +134,65 @@ You can use the `check` command of the `syn2mas` tool to identify configuration
95134
You do not need to stop Synapse to run this command.
96135

97136
```sh
98-
mas-cli --config mas_config.yaml syn2mas --synapse-config homeserver.yaml check
137+
mas-cli syn2mas check --config mas_config.yaml --synapse-config homeserver.yaml
99138
```
100139

101-
This will either output a list of errors and warnings, or tell you that the check completed with no errors or warnings.
140+
This will output a list of errors and warnings, or tell you that the check completed with no errors or warnings.
102141

103-
If you have any errors, you must resolve these before starting the migration.
142+
If you have any errors, you must resolve them before starting the migration.
104143

105-
If you have any warnings, please read, understand and possibly resolve them.
106-
With that said, resolving them is not strictly required before starting the migration.
144+
If you have any warnings, please read and understand them, and possibly resolve them.
145+
Resolving warnings is not strictly required before starting the migration.
107146

108147
### Do a dry-run of the import to test
109148

110-
!!!!!!! TODO we don't have an exact dry-run mode exposed at the moment...
149+
MAS can perform a dry-run of the import, which is safe to run without stopping Synapse.
150+
It will perform a full data migration but then empty the MAS database at the end to roll back.
151+
152+
This means it is safe to run multiple times without worrying about resetting the MAS database.
153+
It also means the time this dry-run takes is representative of the time it will take to perform the actual migration.
154+
155+
```sh
156+
mas-cli syn2mas migrate --config mas_config.yaml --synapse-config homeserver.yaml --dry-run
157+
```
111158

112159
## Doing the migration
113160

114-
Having done the preparation, you can now proceed with the actual migration. Note that this will require downtime for the homeserver and is not easily reversible.
161+
Having completed the preparation, you can now proceed with the actual migration. Note that this will require downtime for the homeserver and is not easily reversible.
115162

116163
### Backup your data and configuration
117164

118-
As with any migration, it is important to backup your data before proceeding.
165+
As with any migration, it is important to back up your data before proceeding.
119166

120-
We also suggest making a backup copy of your homeserver's known good configuration,
121-
before making any changes to enable MAS integration.
167+
We also suggest making a backup copy of your homeserver's known good configuration before making any changes to enable MAS integration.
122168

123-
### Shutdown the homeserver
169+
### Shut down the homeserver
124170

125-
This is to ensure that no new sessions are created whilst the migration is in progress.
171+
This ensures that no new sessions are created while the migration is in progress.
126172

127173
### Configure the homeserver to enable MAS integration
128174

129175
Follow the instructions in the [homeserver configuration guide](homeserver.md) to configure the homeserver to use MAS.
130176

131177
### Do the import
132178

133-
Once the homeserver has been stopped, MAS has been configured (but is not running!)
134-
and you have a successful migration check,
135-
run `syn2mas`'s `migrate` command.
136-
137-
Other than the change of command word, the syntax is exactly the same as the `check` command.
179+
Once the homeserver has been stopped, MAS has been configured (but is not running!), and you have a successful migration check, run `syn2mas`'s `migrate` command.
138180

139181
```sh
140-
mas-cli --config mas_config.yaml syn2mas --synapse-config homeserver.yaml migrate
182+
mas-cli syn2mas migrate --config mas_config.yaml --synapse-config homeserver.yaml
141183
```
142184

143185
#### What to do if it goes wrong
144186

145187
If the migration fails with an error:
146188

147-
- You can either try to fix the error and make another attempt by re-running the command; or
148-
- you can revert your homeserver configuration (so MAS integration is disabled once more)
149-
and abort the migration for now. In this case, you should not start MAS up.
189+
- You can try to fix the error and make another attempt by re-running the command; or
190+
- You can revert your homeserver configuration (so MAS integration is disabled once more) and abort the migration for now. In this case, you should not start MAS up.
191+
192+
In *some cases*, MAS may have written to its own database during a failed migration, causing it to complain in subsequent runs.
193+
In this case, you can safely delete and recreate the MAS database, then start over.
194+
195+
In *any case*, the migration tool itself **will not** write to the Synapse database, so as long as MAS hasn't been started, it is safe to roll back the migration without restoring the Synapse database.
150196

151197
Please report migration failures to the developers.
152198

0 commit comments

Comments
 (0)