Commit Graph

35 Commits

Author SHA1 Message Date
Joris Vink 833ca646e7 i forgot, it's 2022. 2022-01-31 22:02:06 +01:00
Joris Vink efc7b3d9a6 Improve how the parent handles workers.
- Make sure we drain the worker log channel if it dies
  so we can flush out any lingering log messages.

- Get rid of the raise() in the parent to signal ourselves
  we should terminate. Instead depend on the new kore_quit.

- Always attempt to reap children one way or the other.
2021-11-03 17:23:05 +01:00
Joris Vink 9f6043bbde Remove dead assignment. 2021-09-17 19:52:52 +02:00
Joris Vink 2576427dc0 Simplify if a worker needs to be added to msg.
Just look if the kore_worker data structure its ps member is non NULL.
If it is, it was started by the parent process at some point.
2021-09-14 15:45:34 +02:00
Joris Vink 1af0772ebe Don't add acme to msg framework if not needed. 2021-09-07 22:27:02 +02:00
Joris Vink cef5ac4003 bump copyright year. 2021-01-11 23:46:08 +01:00
Joris Vink 30e9b642a0 Skip ACME worker process if ACME isnt built-in. 2020-06-05 14:21:39 +02:00
Joris Vink 6ba56bb8f6 adjust copyright years 2020-02-10 15:35:41 +01:00
Joris Vink 9d0aef0079 bump copyright 2020-02-10 14:47:33 +01:00
Joris Vink 6f31e14e83 sprinkle kore_quiet around 2020-01-17 22:25:52 +01:00
Joris Vink c78535aa5d Add acmev2 (RFC8555) support to Kore.
A new acme process is created that communicates with the acme servers.

This process does not hold any of your private keys (no account keys,
no domain keys etc).

Whenever the acme process requires a signed payload it will ask the keymgr
process to do the signing with the relevant keys.

This process is also sandboxed with pledge+unveil on OpenBSD and seccomp
syscall filtering on Linux.

The implementation only supports the tls-alpn-01 challenge. This means that
you do not need to open additional ports on your machine.

http-01 and dns-01 are currently not supported (no wildcard support).

A new configuration option "acme_provider" is available and can be set
to the acme server its directory. By default this will point to the
live letsencrypt environment:
    https://acme-v02.api.letsencrypt.org/directory

The acme process can be controlled via the following config options:
  - acme_root (where the acme process will chroot/chdir into).
  - acme_runas (the user the acme process will run as).

  If none are set, the values from 'root' and 'runas' are taken.

If you want to turn on acme for domains you do it as follows:

domain kore.io {
	acme yes
}

You do not need to specify certkey/certfile anymore, if they are present
still
they will be overwritten by the acme system.

The keymgr will store all certificates and keys under its root
(keymgr_root), the account key is stored as "/account-key.pem" and all
obtained certificates go under "certificates/<domain>/fullchain.pem" while
keys go under "certificates/<domain>/key.pem".

Kore will automatically renew certificates if they will expire in 7 days
or less.
2019-11-06 19:43:48 +01:00
Joris Vink cdc3347120 Add kore.sendmsg(object, worker=None) to the python api.
This allows you to send Python objects that can be run through pickle
to other worker processes.

If your application implements koreapp.onmsg() you will be able to receive
these objects.
2019-10-16 12:05:27 +02:00
Joris Vink 0eb11794f5 Do not add keymgr its msg fd if not started.
Reshuffles the keymgr_active flag to keymgr.c and let it be figured out
from inside kore_server_start() instead of the worker init code.
2019-10-07 10:31:35 +02:00
Joris Vink eb9b7f7b14 explicitly include sys/types.h
some smaller libc variants do not include this from sys/param.h.
2019-03-06 09:29:46 +01:00
Joris Vink bf1e8e5ffb bump copyright to 2019 2019-02-22 16:57:28 +01:00
Joris Vink 9aa0e95643 Rework accesslog handling.
Move away from the parent constantly hitting the disk for every
accesslog the workers are sending.

The workers will now write their own accesslogs to shared
memory before the parent will pick those up. The parent
will flush them to disk once every second or if they grow
larger then 1MB.

This removes the heavy penalty for having access logs
turned on when you are dealing with a large volume
of requests.
2018-12-22 09:25:00 +01:00
Joris Vink baafa4897e Add -q flag.
If specified Kore will run quietly and only log important messages.
2018-11-15 16:01:37 +01:00
Joris Vink c463ecb3cb Changes to the event loop inside of Kore.
Now anyone can schedule events and get a callback to work as long
as the user data structure that is added for the event begins
with a kore_event data structure.

All event state is now kept in that kore_event structure and renamed
CONN_[READ|WRITE]_POSSIBLE to KORE_EVENT_[READ|WRITE].
2018-10-09 19:34:40 +02:00
Joris Vink b0074ba45e Add fatalx().
If a worker process dies it automatically gets respawned by the
parent process, but sometimes you want the entire server to go down
if a worker encounters an error. This is what fatalx() does.

Calling fatalx() from a worker process will initiate a full shutdown
of the kore server you are running under.
2018-08-13 09:53:49 +02:00
Joris Vink cffb7ec379 Allow on-the-fly reloading of certificates/keys.
This commit introduces the ability for the keymgr process
to reload the certificates/keys for domains when receiving
a SIGUSR1 signal.

The keymgr receives 2 new configuration options:
	- keymgr_root_path
		The root path where the keymgr will live.
		If -n is not specified when the application starts the
		keymgr process will chroot into here.

	- keymgr_runas_user
		The user the keymgr will drop privileges towards if
		-r was not specified.

All certfile and certkey configuration options are now relative to the
keymgr_root_path configuration setting.

The keymgr process will now also load the certificate for the domain
(rather then the workers) and submit these to the worker processes so
they can be reloaded when required.

Worker processes will refuse connections until the TLS configuration
for a given domain is completed (aka: the workers receive the certificate
for that domain).

Other changes:
	- client_certificates renamed to client_verify.
	- the chroot configuration option is now called root.
	- kore is a little more verbose if privsep options are missing.
	- filemaps are now relative to the root configuration option.
2018-07-11 09:44:29 +02:00
Joris Vink 3a283cd05c let KORE_MSG_WORKER_ALL include sender. 2018-04-24 20:11:48 +02:00
Joris Vink dd2dff2318 Rework HTTP and worker processes.
The HTTP layer used to make a copy of each incoming header and its
value for a request. Stop doing that and make HTTP headers zero-copy
all across the board.

This change comes with some api function changes, notably the
http_request_header() function which now takes a const char ** rather
than a char ** out pointer.

This commit also constifies several members of http_request, beware.

Additional rework how the worker processes deal with the accept lock.

Before:
	if a worker held the accept lock and it accepted a new connection
	it would release the lock for others and back off for 500ms before
	attempting to grab the lock again.

	This approach worked but under high load this starts becoming obvious.

Now:
	- workers not holding the accept lock and not having any connections
	  will wait less long before returning from kore_platform_event_wait().

	- workers not holding the accept lock will no longer blindly wait
	  an arbitrary amount in kore_platform_event_wait() but will look
	  at how long until the next lock grab is and base their timeout
	  on that.

	- if a worker its next_lock timeout is up and failed to grab the
	  lock it will try again in half the time again.

	- the worker process holding the lock will when releasing the lock
	  double check if it still has space for newer connections, if it does
	  it will keep the lock until it is full. This prevents the lock from
	  bouncing between several non busy worker processes all the time.

Additional fixes:

- Reduce the number of times we check the timeout list, only do it twice
  per second rather then every event tick.
- Fix solo worker count for TLS (we actually hold two processes, not one).
- Make sure we don't accidentally miscalculate the idle time causing new
  connections under heavy load to instantly drop.
- Swap from gettimeofday() to clock_gettime() now that MacOS caught up.
2018-02-14 13:48:49 +01:00
Joris Vink 548348f553 2018 2018-01-20 22:51:06 +01:00
Joris Vink 60a3f60a92 Allow MSG framework to pass 0 byte messages. 2017-02-27 21:27:50 -08:00
Yorick de Wid 86d85dd10b Message shutdown request (#168)
* Set server version

* Message shutdown request

* Update messaging example

* Set server verion in generic example

* Allow shutdown with NOHTTP=1
2017-01-17 18:18:01 +01:00
Joris Vink c4b1206ae3 Bump copyright to 2016. 2016-01-04 12:58:51 +01:00
Joris Vink 8a6f4a935e Set handle function pointer for message callbacks. 2015-12-10 09:26:24 +01:00
Joris Vink 769c78a6e8 Introduce NOHTTP=1 build option.
This basically turns off the HTTP layer for Kore. It does not
compile in anything for HTTP.

This allows Kore to be used as a network application platform as well.
Added an example for this called nohttp.

Other changes that sneaked in while hacking on this:
* Use calloc(), kill pendantic malloc option.
* Killed off SPDY/3.1 support completely, will be superseded by http2

Note that comes with massive changes to a lot of the core API
functions provided by Kore, these might break your application.
2015-11-27 16:22:50 +01:00
Joris Vink 1003cbcd50 Just point hldr_extra to kw->id.
Not sure what state of crazy my mind was in for writing
the previous code like that.
2015-07-07 16:11:40 +02:00
Joris Vink 0281fb7b99 Update the msg->dst member accordingly when sending.
This way the worker will always receive a message with
the correct destination set instead of KORE_MSG_WORKER_ALL.
2015-07-06 21:16:22 +02:00
Joris Vink 064f2095b0 Update message framework with src/dst for workers.
One can now send messages to specific workers and
receiving workers can see the origin of the messages.
2015-07-06 21:08:36 +02:00
Joris Vink a64808c6b0 Improvements to our message framework.
Change the callback prototypes to:
	void callback(struct kore_msg *msg, const void *data);

This allows the callbacks to receive the full kore_msg data structure
as sent over the wire (including length and id). Useful for future
additions to the kore_msg structure (such as worker origin).

Several other improvements:
	* Accesslog now uses the msg framework as well.
	* Websocket WEBSOCKET_BROADCAST_GLOBAL now works.

Small websocket improvement in this commit:
	* Build the frame to be sent only once when broadcasting
	 instead of per connection we are broadcasting towards.
2015-06-23 18:17:14 +02:00
Joris Vink c322bbd3c8 Kill the websocket message type. We're not there yet. 2015-06-22 22:20:42 +02:00
Joris Vink 7100ab0dd3 Remove useless log message. 2015-06-22 21:21:03 +02:00
Joris Vink 49ca95f390 Add our messaging framework.
With this framework apps can now send messages between worker processes.

A new API function exists:
	int kore_msg_register(u_int8_t id, void (*cb)(const void *, u_int32_t);

This API call allows your app to register a new message callback for a given ID.

You can then send messages on this ID to other workers using:
	void kore_msg_send(u_int8_t id, void *data, u_int32_t length);

This framework will interally be used for a few things such as allowing
websocket data to broadcasted between all workers, adding unified caching
and hopefully eventually moving the access log to this as well.

Some internals have changed with this commit:
	* worker_clients has been called connections.
	* the parent now initializes the net, and event subsystems.
	* kore_worker_websocket_broadcast() is dead.
2015-06-22 21:13:32 +02:00