aboutsummaryrefslogtreecommitdiff
path: root/doc/auth_backends.md
blob: 4075b08833cfcf73b8182f0a710e9213d95f56e8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# Authentication backends

## Supported backends

All backends prefixed with `mt` are implementations of the upstream backends.
They store ban information in `ipban.txt` in the Minetest format.

### files

This is the default authentication backend unless specified otherwise
in the [config](https://github.com/HimbeerserverDE/mt-multiserver-proxy/blob/main/doc/config.md).
It creates a directory named `auth` in the proxy directory.
It contains subdirectories for each user.
These are home to several files (created on demand):

* `salt`: The binary SRP salt of the user.
* `verifier`: The binary SRP verifier of the user.
* `timestamp`: An empty file whose access timestamps are used to keep track of reads or writes to the user's authentication entry.
* `last_server`: The name of the last server the user was connected to.

There's also a `ban` directory that holds files named after banned IP addresses
containing the username that was banned.

One of the main advantages of this format is that it is custom,
allowing the proxy to store anything it needs
and providing future expandibility. It's also very simple and easily readable
for humans or shell scripts.

### mtsqlite3

This backend is partially compatible with regular Minetest `auth.sqlite` DBs.
The proxy is able to run using this backend and the authentication information
can be converted by [mt-auth-convert](#mt-auth-convert).
However storing a player's last server is not supported with this backend
and no conversions involving it will ever output server information.

### mtpostgresql

This backend provides partial compatibility with regular Minetest PostgreSQL
databases. The proxy is able to run using this backend and the authentication
information can be converted by [mt-auth-convert](#mt-auth-convert).
However storing a player's last server is not supported with this backend
and no conversions involving it will ever output server information.

Postgres connection strings are required to use this backend.
The proxy uses a configuration value for this
while the converter gets them from command-line arguments.

## Dealing with existing Minetest databases

If possible you should always convert your existing database
to the `files` format. An alternative is to reconfigure the proxy
to use the existing format directly at the cost of reduced functionality.
This method currently does not support storing the last server
a user was connected to, for example.

## mt-auth-convert

There's a tool that is able to convert between the supported backends.

### Installation

If you didn't install all tools using the command in [README.md](https://github.com/HimbeerserverDE/mt-multiserver-proxy#readme),
manually run the following command to install `mt-auth-convert`:

```
go install github.com/HimbeerserverDE/mt-multiserver-proxy/cmd/mt-auth-convert@latest
```

Please specify the version explicitly if @latest differs from your proxy version.

### Usage

1. Move the binary to the directory the proxy binary is located in.
The same rules apply regarding symlinks (see [README.md](https://github.com/HimbeerserverDE/mt-multiserver-proxy#readme)).
2. Move or copy the source database to the directory.
3. Stop the proxy.
4. Run the conversion tool.
5. (optional) Reconfigure the proxy to use the new backend.
6. Start the proxy.
7. (optional) Check if everything is working.

Unused Postgres connection strings should be set to nil,
though any other value should work as well.

Example (converting Minetest's auth.sqlite to the `files` backend):

```
mt-auth-convert mtsqlite3 files nil nil
```

Example (converting Minetest's PostgreSQL database to the `files` backend):

```
mt-auth-convert mtpostgresql files 'host=localhost user=mt dbname=mtauth sslmode=disable' nil
```

## Implementing custom authentication backends

Plugins can implement their own authentication backends and register them
using the [RegisterAuthBackend](https://pkg.go.dev/github.com/HimbeerserverDE/mt-multiserver-proxy#RegisterAuthBackend)
function. These plugins can then be enabled by setting the `AuthBackend`
config option. Configuration for them is provided through a plugin-specific
configuration mechanism if needed.

This makes it possible to integrate with custom environments, especially those
that share a database with other services such as a forum.

Note that the network protocol is always SRP and the credentials are always SRP
verifiers and salts. This is a protocol limitation and should not be an issue.

When implementing an authentication backend, make sure you follow the
[interface documentation](https://pkg.go.dev/github.com/HimbeerserverDE/mt-multiserver-proxy#AuthBackend)
carefully. The active authentication backend can be accessed using the
[DefaultAuth](https://pkg.go.dev/github.com/HimbeerserverDE/mt-multiserver-proxy#DefaultAuth)
function *after initialization time*.
Other backends can be accessed using the
[Auth](https://pkg.go.dev/github.com/HimbeerserverDE/mt-multiserver-proxy#Auth)
function *after initialization time*.

Custom backends can be handled by the [mt-auth-convert](#mt-auth-convert) tool
as long as it is able to load the relevant plugin(s).