Commit Graph

169 Commits

Author SHA1 Message Date
Thomas Lamprecht
61cf96bed7 bump version to 4.1-1
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-01-13 13:32:47 +01:00
Fabian Grünbichler
e902248507 fix #3789: allow disabling TLS v1.2/v1.3
SSL 2 and 3 are already disabled by default by us, and TLS 1.1 and below
are disabled by default on Debian systems.

requires corresponding patch in pve-manager to have an effect.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Tested-by: Stoiko Ivanov <s.ivanov@proxmox.com>
Reviewed-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2022-01-13 13:30:20 +01:00
Fabian Grünbichler
d93700f182 fix #3745: allow overriding TLS key location
when using a custom pveproxy certificate. actual handling is done in
pve-manager.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Tested-by: Stoiko Ivanov <s.ivanov@proxmox.com>
Reviewed-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2022-01-13 13:30:14 +01:00
Fabian Grünbichler
95fde1f73d fix #3790: allow setting TLS 1.3 cipher suites
like the TLS <= 1.2 cipher list, but needs a different option since the
format and values are incompatible. AnyEvent doesn't yet handle this
directly like the cipher list, so set it directly on the context.

requires corresponding patch in pve-manager (which reads the config, and
passes relevant parts back to the API server).

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Tested-by: Stoiko Ivanov <s.ivanov@proxmox.com>
Reviewed-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2022-01-13 13:30:10 +01:00
Fabian Grünbichler
e12e46c979 fix #3807: don't attempt response on closed handle
if a client closes the connection while the API server is
waiting/stalling here, the handle will disappear, and sending a response
is no longer possible.

(this issue is only cosmetic, but if such clients are a regular
occurrence it might get quite noisy in the logs)

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2022-01-13 13:10:26 +01:00
Thomas Lamprecht
baf8c8dc0d small indentation and code cleanup
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-01-13 13:10:17 +01:00
Thomas Lamprecht
d9b3838f27 avoid warning if request params do not exists
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2022-01-13 13:10:17 +01:00
Fabian Grünbichler
6277311e71 WS: guard disconnect block check properly
if the WS gets disconnected without any data having been sent first,
wbuf (and thus `length $wbuf`) is undef. the actual length of the buffer
is not relevant here anyway, just the fact that it's non-empty - so
avoid the undef warning by dropping the unnecessary comparison.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-12-17 11:05:03 +01:00
Thomas Lamprecht
d298a22cc2 bump version to 4.0-4
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-11-24 18:14:57 +01:00
Thomas Lamprecht
5cef57dee9 http: split and sort use statements
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-11-24 18:13:14 +01:00
Dominik Csapak
127dbe7c7d download-stream: allow the api call to set the content-encoding
this is useful if we want to pipe the output of a program e.g. through gzip

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-11-24 18:09:37 +01:00
Thomas Lamprecht
7599c47894 constructor: split TLS flags to separate lines
easier to grasp what's actually being set..

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-11-16 07:34:11 +01:00
Stoiko Ivanov
a0434e126e fix #3724: disable TLS renegotiation
The issue is probably not critical and best addressed by not running
the perl API servers in an exposed environment or when this needs to
be done by installing a reverse proxy in front of them.

The DOS potential of the perl daemons is limited more by the limited
number of parallel workers (and the memory constraints of starting
more of them), than by the CPU cycles wasted on TLS renegotiation.

Still disabling TLS renegotiation should show very little downside:
* it was removed in TLS 1.3 for security reasons
* it was the way nginx addressed this issue [1].
* we do not use client certificate authentication

Tested by running `openssl s_client -no_tls1_3 -connect 192.0.2.1:8006`
and issuing a `HEAD / HTTP/1.1\nR\n`
with and without the patch.

[1] 70bd187c4c386d82d6e4d180e0db84f361d1be02 at
    https://github.com/nginx/nginx (although that code adapted to
    the various changes in openssl API over the years)
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2021-11-16 07:07:40 +01:00
Fabian Grünbichler
b1364a3c98 webproxy: handle unflushed write buffer
for proxied requests, we usually tear down the proxy connection
immediately when closing the source connection. this is not the correct
course of action for bulk one-way data streams that are proxied, where
the source connection might be closed, but the proxy connection might
still have data in the write buffer that needs to be written out.

push_shutdown already handles this case (closing the socket/FH after it
has been fully drained).

one example for such a proxied data stream is the 'migrate' data for a
remote migration, which gets proxied over a websocket connection.
terminating the proxied connection early makes the target VM crash for
obvious reasons.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-11-11 17:01:12 +01:00
Thomas Lamprecht
46b962f6b1 buildsys: change upload dist to bullseye
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-10-04 10:21:12 +02:00
Thomas Lamprecht
a545da70da bump version to 4.0-3
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-10-04 10:18:38 +02:00
Thomas Lamprecht
9a826d0ce9 d/control: wrap-and-sort -tkn
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-10-04 10:13:57 +02:00
Thomas Lamprecht
515633c801 d/control: break libpve-storage-perl (<< 7.0-11)
as only newer version cleanup temp files on their own.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-10-04 10:13:23 +02:00
Lorenz Stechauner
7fb356b79e anyevent: move unlink from http-server to endpoint
any uploaded file has to be deleted by the corrosponding
endpoint. the file upload was only used by the 'upload to
storage' feature in pve.

this change allows the endpoint to delete the file itself,
making the old and racey`sleep 1` (waiting until the worker
has opened the file) obsolete.

this change breaks all pve-manager versions, in which the
worker does not unlink the temp file itself.

Signed-off-by: Lorenz Stechauner <l.stechauner@proxmox.com>
2021-10-04 10:00:23 +02:00
Fabian Grünbichler
28a4b9a424 bump version to 4.0-2
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-05-18 10:24:39 +02:00
Fabian Grünbichler
1d7da93655 websocket: add note about compat removal
this major release still needs to have an incompatible client, the next
one can drop setting a protocol client-side, and the one after that can
remove the protocol handling on the server side.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2021-05-18 09:25:33 +02:00
Dominik Csapak
e7eb716588 AnyEvent/websocket_proxy: drop handling of websocket subprotocols
We do not support any, and we only ever send binary frames, so drop
trying to parse the header.

For compatibility with current clients (novnc, pve-xtermjs), we have
to reply with the protocols it sent.

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2021-05-18 09:24:16 +02:00
Dominik Csapak
1201435994 AnyEvent/websocket_proxy: remove 'base64' handling
novnc does not support this anymore since 2015, and neither does
our xtermjs client. it is also not listed in IANAs list of websocket
protocols [0].

so simply drop it and only send out binary frames and don't decode text frames

0: https://www.iana.org/assignments/websocket/websocket.xml#subprotocol-name

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2021-05-18 09:24:16 +02:00
Thomas Lamprecht
a7f937b2d0 bump version to 4.0-1
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-05-14 16:38:26 +02:00
Thomas Lamprecht
f8f97c8d26 buildsys: split packaging and source build-systems
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-05-14 16:37:17 +02:00
Thomas Lamprecht
ec08ad30f5 d/control: drop unzip from build depends
is actually not required since quite a bit, i.e., commit
88628fd141 from my last bootstrapping
effort in 2019.

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-05-14 15:13:08 +02:00
Thomas Lamprecht
e69542b4c9 d/control: improve package description
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-05-14 15:12:05 +02:00
Thomas Lamprecht
a008f818b4 d/control: bump compat level to 12
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-05-14 15:11:46 +02:00
Thomas Lamprecht
0527add069 d/copyright: update years
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-05-14 15:11:22 +02:00
Thomas Lamprecht
dacfcf3a3c bump version to 3.2-2
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-05-07 17:50:07 +02:00
Stoiko Ivanov
9494318e18 access control: also include ipv6 in 'all'
Net::IP objects are bound to a version - 0/0 is treated as ipv4 only.
If 'all' is present in the allow_from/deny_from list we should also
add ::/0 for matching all ipv6 addresses.

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2021-05-07 17:47:46 +02:00
Stoiko Ivanov
c6de5b3f2d access control: correctly match v4-mapped-v6 addresses
With recent changes to the listening socket code in pve-manager
the proxy daemons now usually bind to '::' and ipv4 clients are
read as v4-mapped-v6 addresses [0] from ::ffff:0:0/96.

This caused the allow_from/deny_from matching to break.

This patch addresses the issue by normalizing addresses from
::ffff:0:0/96 using Net::IP::ip_get_embedded_ipv4
(which roughly splits on ':' and checks if the last part looks like an
ipv4 address).

Issue was originally reported in our community forum [1]

[0] https://en.wikipedia.org/wiki/IPv6_address
[1] https://forum.proxmox.com/threads/my-pveproxy-file-doesnt-work.83228/

Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2021-05-07 17:47:46 +02:00
Thomas Lamprecht
6d42e63792 bump version to 3.2-1
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2021-04-23 13:54:14 +02:00
Stefan Reiter
51841e98fa allow stream download from path and over pvedaemon-proxy
Allow specifying a filepath for stream=1 instead of either a path or fh
with stream=1.

With this in place, we can also just return the path to the proxy in
case we want to stream a response back, and let it read from the file
itself. This way, the pvedaemon is cut out of the transfer pipe.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
2021-04-22 18:18:50 +02:00
Stefan Reiter
389ad881f9 support streaming data form fh to client
Use an explicit AnyEvent::Handle similar to websocket proxying.

Needs some special care to make sure we apply backpressure correctly to
avoid caching too much data. Note that because of AnyEvent restrictions,
specifying a "fh" to point to a file or a packet-based socket may result
in unwanted behaviour[0].

[0]: https://metacpan.org/pod/AnyEvent::Handle#DESCRIPTION

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
2021-04-22 18:18:50 +02:00
Oguz Bektas
9afe1e89ea utils: add LISTEN_IP option in /etc/default/pveproxy
to allow setting arbitrary IP address to listen on

Signed-off-by: Oguz Bektas <o.bektas@proxmox.com>
Tested-by: Dylan Whyte <d.whyte@proxmox.com>
Reviewed-by: Dylan Whyte <d.whyte@proxmox.com>
2021-04-21 17:44:03 +02:00
Stefan Reiter
6d832dbced allow 'download' to be passed from API handler
PVE::HTTPServer in pve-manager wraps the API return value in a 'data'
element, look for a 'download' element there too to allow an API call to
instruct the HTTP server to return a file via path or filehandle.

Signed-off-by: Stefan Reiter <s.reiter@proxmox.com>
2021-04-21 17:42:01 +02:00
Thomas Lamprecht
e22eccff31 bump version to 3.1-1
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-12-11 08:41:44 +01:00
Stoiko Ivanov
1e1692429a add debug log for problems during accept
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2020-12-10 20:23:38 +01:00
Stoiko Ivanov
ebcaaf4606 accept-phase: shutdown socket on early error
if an error happens before AnyEvent::Handle registers the cleanup
callback, we should shutdown/close the socket, when handling it.

Using close, instead of shutdown($sock, SHUT_WR) here, since we are in
an error-state, and would not read from the socket anyways.
(Additionally close sends just on packet (RST,ACK), vs shutdown
(FIN,ACK+RST,ACK) in its use here).

Co-Authored-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2020-12-10 20:23:38 +01:00
Stoiko Ivanov
c82d1707ed accept-phase: fix conn_count "leak"
When handling new connections in 'accept_connections' the number of
active connections (conn_count) got increased before the callback, which
would eventually decrease it got registered in AnyEvent::Handle->new.

Any error/die before registering the callback would skip the
decrement, and leave the process in an endless loop upon exiting in
wait_end_loop.

This can happen e.g. when the call to getpeername fails, or if the
connection is denied by the ALLOW_FROM/DENY_FROM settings in
'/etc/default/pveproxy' (which is also a simple reproducer for that).

Additionally it can cause a denial of service, by attempting to
connect from a denied ip until the connection count exeeds the maximum
connections of all child-processes.

This patch addresses the issue by incrementing the connection count
before attempting to create the handle, and decrementing it again, if
handle creation fails.

A warning is logged if 'conn_count' turns negative when decrementing
during cleanup on error/eof. In case creating a new handle during
initial accept_connection fails, a warning is logged as well, but
'conn_count' is not decremented.

Reported via our community-forum:
https://forum.proxmox.com/threads/pveproxy-eats-available-ram.79617/

Co-Authored-by: Dominik Csapak <d.csapak@proxmox.com>
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2020-12-10 20:23:38 +01:00
Stoiko Ivanov
26e73e6b9e add debug print helper
and uniformly use it

Suggested-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Signed-off-by: Stoiko Ivanov <s.ivanov@proxmox.com>
2020-12-10 20:23:38 +01:00
Thomas Lamprecht
a420cb361a bump version to 3.0-6
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-07-02 09:44:16 +02:00
Thomas Lamprecht
e7ee5e3f75 increase max headers to 64 to cope with modern browsers + proxy combinations
This is mostly a "do not allow infinity headers" limit in the sense
of "it's good to have limits". With modern browsers and users behind
proxies we may actually get over 30 headers, so increase it for now
to 64 - hopefully enough for another decade ;)

Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
Reported-by: Victor Hooi <victorhooi@yahoo.com>
2020-07-02 07:58:45 +02:00
Dominik Csapak
abef317256 fix post if variable declaration
Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-06-05 09:07:29 +02:00
Dominik Csapak
3e05f16607 fix #2766: allow application/json as content-type for post/put requests
this makes creating an api client much nicer

Signed-off-by: Dominik Csapak <d.csapak@proxmox.com>
2020-06-05 09:07:29 +02:00
Thomas Lamprecht
779306a757 bump version to 3.0-5
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-03-09 16:12:51 +01:00
Fabian Grünbichler
f1b41d8405 websocket_proxy: fix indentation
Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-03-07 20:19:03 +01:00
Fabian Grünbichler
e6cb79b52c websocket_proxy: implement ping/pong support
needed to keep tunnel connections alive.

> The Ping frame contains an opcode of 0x9.
> [...]
> The Pong frame contains an opcode of 0xA.
-- Section 5.5.2 cf. https://tools.ietf.org/html/rfc6455#section-5.5.2

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
Signed-off-by: Thomas Lamprecht <t.lamprecht@proxmox.com>
2020-03-07 20:17:41 +01:00
Fabian Grünbichler
c3bd22ec46 websocket_proxy: pull out encoding into helper sub
to allow adding other types of frames.

Signed-off-by: Fabian Grünbichler <f.gruenbichler@proxmox.com>
2020-03-07 20:11:12 +01:00