Commit graph

87 commits

Author SHA1 Message Date
Simon Ser 6d0f7330e3 Remove RLIMIT_NOFILE bump
Starting with Go 1.19 [0] the file limit is increased by default.

[0]: 8427429c59
2024-05-09 09:02:16 +02:00
Egor eb524bfea4 Add unix domain socket listeners for HTTP and WS 2024-04-15 12:04:50 +02:00
Alex McGrath 6b89b99784 fileupload: add CORS header fields 2024-02-13 18:54:35 +01:00
Moritz Poldrack 3b1cf73165 Fix crash on start when file-upload is disabled
When started without specifying a fileupload backend, soju crashes
because of a nil-pointer deref.

	panic: runtime error: invalid memory address or nil pointer dereference
	[signal SIGSEGV: segmentation violation code=0x1 addr=0x8 pc=0x9484bd]

	goroutine 1 [running]:
	main.loadConfig()
		git.sr.ht/~emersion/soju/cmd/soju/main.go:94 +0x51d
	main.main()
		git.sr.ht/~emersion/soju/cmd/soju/main.go:127 +0x165
	panic: runtime error: invalid memory address or nil pointer dereference

Add a guardclause preventing that crash.

Signed-off-by: Moritz Poldrack <git@moritz.sh>
2024-01-28 11:46:40 +01:00
Simon Ser fd4aa892b2 Add http-ingress config directive
Co-authored-by: delthas <delthas@dille.cc>
2024-01-24 23:32:24 +01:00
Simon Ser b76cb6d5e6 Add support for file uploads
Co-authored-by: delthas <delthas@dille.cc>
2024-01-24 23:32:07 +01:00
Simon Ser 866845ea95 cmd/soju: add withDefaultPort helper 2024-01-08 18:22:39 +01:00
Simon Ser 4c818d28cc Add https:// and http+insecure:// listeners
Same as wss:// and ws+insecure://, except we'll be able to add more
endpoints for future features (e.g. file uploads).
2024-01-08 17:49:02 +01:00
Simon Ser edaae4d06b cmd/sojudb: use User.SetPassword 2023-11-01 00:05:03 +01:00
Simon Ser 4f7b577734 database: add NewUser 2023-11-01 00:04:57 +01:00
Simon Ser 9b9fc60f62 Rename Config.Log{Driver,Path} to MsgStore 2023-05-23 11:23:38 +02:00
Simon Ser 4c8e955946 Move DefaultUnixAdminPath to config package
We can drop the soju package import. This shrinks down sojuctl's
size significantly (18M to 3M).
2023-03-15 17:47:47 +01:00
Simon Ser 5a1cbc425f Remove legacy Go build comments 2023-02-23 10:33:48 +01:00
delthas 1ccc7ce6d2 Add a database store for messages
This adds a new config option, `logs db`, which enables storing chat
logs in the soju database.

Regular store options, CHATHISTORY options, and SEARCH operations are
supported, like the fs logs backend.

Messages are stored in a new table, Message. In order to track the list
of targets we have messages for in an optimized manner, another database
is used: MessageTarget.

All new requests are backend by indexes so should be fast even with
hundreds of thousands of messages.

A contrib script is provided for migrating existing logs fs chat logs to
the database. It can be run with eg:

  go run ./contrib/migrate-logs/ logs/ sqlite3:soju.db

Co-authored-by: Simon Ser <contact@emersion.fr>
2023-02-17 14:13:43 +01:00
Simon Ser bf931709db Drop permissions on Unix admin socket 2023-02-07 10:10:05 +01:00
delthas f57492af56 Add cmd/sojuctl
This new command enables communicating with the unix administrative
endpoint (unix+admin) that can be enabled on soju.

The syntax is just that of BouncerServ.

Examples:
    sojuctl -config soju.config help
    sojuctl -config soju.config user status
2023-02-06 15:15:09 +01:00
delthas 2713bcba34 Add administrative unix listen endpoint
This adds support for listening on a Unix socket for administrative
connections, that then use a simple protocol for communicating with
the service (BouncerServ) as an administrator with a global context.

The wire format used by the Unix socket is IRC, but without
registration or overheads.

Example session:

    >>> BOUNCERSERV
    <<< 461 * BOUNCERSERV :Not enough parameters
    >>> BOUNCERSERV :n s
    <<< :gensou FAIL BOUNCERSERV :this command must be run as a user
    >>> BOUNCERSERV :u s
    <<< :gensou PRIVMSG * :marisa: 2 networks
    <<< :gensou PRIVMSG * :alice: 1 networks
    <<< :gensou BOUNCERSERV OK
2023-02-06 15:15:09 +01:00
delthas ab235f0099 sojuctl: rename to sojudb
sojuctl will be used to control the soju deamon directly.

sojudb is a better name because it operates on the database file only.
2023-02-06 15:15:09 +01:00
Simon Ser c031e08d71 Add a default path for the config file 2023-02-06 13:16:55 +01:00
Simon Ser 63ca247354 Add infrastructure for external authentication 2023-01-30 11:53:01 +01:00
Simon Ser db49bc120f Add enable-user-on-auth config directive 2023-01-26 19:51:35 +01:00
Simon Ser 9df9880301 Add disable-inactive-user config option
This can be used to automatically disable users if they don't
actively use the bouncer for a while.
2023-01-26 19:42:29 +01:00
Simon Ser d7d9d45b45 Add a flag to disable users
Add a new flag to disable users. This can be useful to temporarily
deactivate an account without erasing data.

The user goroutine is kept alive for simplicity's sake. Most of the
infrastructure assumes that each user always has a running goroutine.
A disabled user's goroutine is responsible for sending back an error
to downstream connections, and listening for potential events to
re-enable the account.
2023-01-26 18:33:55 +01:00
Simon Ser dde4ee9518 config: drop multi-upstream-mode 2022-09-26 16:57:05 +02:00
Simon Ser 027a89a0b0 server: log when waiting for user goroutines on shutdown
Useful for debugging.
2022-09-18 21:43:31 +02:00
Simon Ser d27880e03e config: use structs to group DB/MsgAuth 2022-09-11 13:50:34 +02:00
Simon Ser e2e232fa9c config: add message-store memory
The old way to do this was `message-store fs ""`, which is
misleading.
2022-05-09 16:59:27 +02:00
Simon Ser 95db42e645 Move identd to separate package 2022-05-09 16:36:54 +02:00
Simon Ser 3a7dee8128 Introduce a database package 2022-05-09 15:08:04 +02:00
delthas 9647711921 Fix build on systems without syscall.Rlimit
On some systems (namely Windows), syscall.Rlimit is not defined, and
makes the build fail.

This fixes the build by making the rlimit calls only run on archs where
it is defined, defaulting to a stub on other systems.

See: 8427429c59
2022-03-21 09:39:54 +01:00
Simon Ser 8b926be817 Warn about non-FQDN hostnames
References: https://github.com/ircdocs/modern-irc/pull/148
2022-03-15 20:45:23 +01:00
Simon Ser dac003960c db: allow registering multiple metrics collectors 2022-03-08 10:36:59 +01:00
Simon Ser f2a03cf7a1 Fix incorrect listen addr in error message
The various server goroutines would always capture the last listen
addr in the loop.
2022-01-19 22:38:13 +01:00
Simon Ser d829d2ab12 Add Logger.Debugf
Makes it easy to print debugging messages which aren't targeted at
the user. See [1] for motivation.

[1]: https://dave.cheney.net/2015/11/05/lets-talk-about-logging
2021-12-06 18:35:49 +01:00
Simon Ser d722f56000 Add pprof HTTP server
This enables production debugging of the bouncer.

Closes: https://todo.sr.ht/~emersion/soju/155
2021-11-17 16:18:52 +01:00
Simon Ser ea98ac042e Add Prometheus instrumentation for the database 2021-11-17 15:58:19 +01:00
Simon Ser 8f8d7aab0e Add basic Prometheus metrics exporter
This only exports the default metrics for now.

References: https://todo.sr.ht/~emersion/soju/142
2021-11-17 15:58:18 +01:00
Simon Ser 55840312b4 Add per-user IP addresses
The new upstream-user-ip directive allows bouncer operators to
assign one IP address per user.
2021-11-17 15:07:58 +01:00
Simon Ser 0c5aa8cbff sojuctl: use background context 2021-11-17 11:54:28 +01:00
Simon Ser 3941f67380 Add config option to globally disable multi-upstream mode
Closes: https://todo.sr.ht/~emersion/soju/122
2021-11-17 11:41:11 +01:00
Simon Ser 73295e4fa7 Allow most config options to be reloaded
Closes: https://todo.sr.ht/~emersion/soju/42
2021-11-16 00:38:04 +01:00
Simon Ser 4397cd7fc2 cmd/soju: bump max number of opened files
The bouncer process may be dealing with many opened FDs. The default
on Linux is 1024. To support bouncers with a lot of users, bump
RLIMIT_NOFILE to the max as advised in [1].

[1]: http://0pointer.net/blog/file-descriptor-limits.html
2021-11-15 21:22:43 +01:00
Simon Ser 07c962018d Add title config option
Closes: https://todo.sr.ht/~emersion/soju/146
2021-11-02 22:38:07 +01:00
Simon Ser 9ec1f1a5b0 Add context args to Database interface
This is a mecanical change, which just lifts up the context.TODO()
calls from inside the DB implementations to the callers.

Future work involves properly wiring up the contexts when it makes
sense.
2021-10-18 19:15:15 +02:00
Simon Ser 2ed4491c17 Don't strip spaces at start of MOTD
This breaks ASCII art. Instead, just drop the final newline if any.
2021-10-13 12:53:43 +02:00
Simon Ser a9a066faac Add bouncer MOTD
Closes: https://todo.sr.ht/~emersion/soju/137
2021-10-13 10:58:34 +02:00
Hubert Hirtz 6e06663615 PostgreSQL support 2021-10-11 15:21:04 +02:00
Simon Ser 94dbfff11d Add max-user-networks config option 2021-10-07 20:43:10 +02:00
Chris Smith c607fd5a58 Set a higher timeout for proxyproto listeners
go-proxyproto added support for a read timeout in 0.6.0[1] and
defaulted it to 200ms. After this time if no data is read on
the socket, it is closed.

This is _really_ low if the underlying connection is a TLS
one as no data pops out the other end until the handshake is
done. It effectively limits you to TLS connections within
a 50ms RTT of your bouncer with clients that are fast enough
at responding.

It appears that HexChat on Arch is somehow slow enough at
TLS connections thant it consistently takes longer than
200ms even over localhost, meaning it outright can't connect
to soju any longer.

To make this a lot less painful, have soju pass in a read
timeout of 5 seconds. This feels like a reasonable tradeoff
between keeping (possibly malicious) connections open and
accepting the realities of network connections.

[1]: https://github.com/pires/go-proxyproto/issues/65
2021-09-19 17:00:40 +02:00
Rafael Castillo d1181b3e7a Check for TLS config in wss listeners
Previously http.Server.ListenAndServeTLS would return a not very helpful
error about a failed open. This adds a check similar to the one in the
ircs case that should make it clearer to operators what the error is.
2021-09-09 10:06:31 +02:00