From: Max Carrara <m.carrara@proxmox.com>
To: Wolfgang Bumiller <w.bumiller@proxmox.com>
Cc: pbs-devel@lists.proxmox.com
Subject: Re: [pbs-devel] [PATCH proxmox 1/3] rest-server: Add `BiAcceptBuilder`
Date: Tue, 18 Jul 2023 07:46:28 +0200 [thread overview]
Message-ID: <0f5792c2-282f-ea1a-0fd3-2fd1b7c5c6ad@proxmox.com> (raw)
In-Reply-To: <v2kbs2jmx4jfushj4p4otjjfxbpsodhezymlk4fjykogipoo5y@nllavir4lwip>
On 7/14/23 11:20, Wolfgang Bumiller wrote:
> On Thu, Jun 22, 2023 at 11:15:24AM +0200, Max Carrara wrote:
>> This builder is similar to `AcceptBuilder`, but is also able to differ
>> between plain TCP streams and TCP streams running TLS.
>>
>> It does so by peeking into the stream's buffer and checking whether
>> the client is initiating a TLS handshake.
>>
>> Newly accepted plain TCP streams are sent along via a separate channel
>> in order to clearly distinguish between "secure" and "insecure"
>> connections.
>>
>> Signed-off-by: Max Carrara <m.carrara@proxmox.com>
>> ---
>> proxmox-rest-server/src/connection.rs | 327 ++++++++++++++++++++++++++
>> 1 file changed, 327 insertions(+)
>>
>> diff --git a/proxmox-rest-server/src/connection.rs b/proxmox-rest-server/src/connection.rs
>> index 7681f00..937b5d7 100644
>> --- a/proxmox-rest-server/src/connection.rs
>> +++ b/proxmox-rest-server/src/connection.rs
>> @@ -302,3 +302,330 @@ impl AcceptBuilder {
>> }
>> }
>> }
>> +
>> +#[cfg(feature = "rate-limited-stream")]
>> +type InsecureClientStreamResult = Pin<Box<RateLimitedStream<TcpStream>>>;
>> +#[cfg(not(feature = "rate-limited-stream"))]
>> +type InsecureClientStreamResult = Pin<Box<TcpStream>>;
>
> ^ You can drop one set of `#[cfg]`s by using `Pin<Box<ClientStream>>` ;-)
>
>> +
>> +#[cfg(feature = "rate-limited-stream")]
>> +type ClientStream = RateLimitedStream<TcpStream>;
>> +
>> +#[cfg(not(feature = "rate-limited-stream"))]
>> +type ClientStream = TcpStream;
>> +
>> +pub struct BiAcceptBuilder {
>> + acceptor: Option<Arc<Mutex<SslAcceptor>>>,
>> + debug: bool,
>> + tcp_keepalive_time: u32,
>> + max_pending_accepts: usize,
>> +
>> + #[cfg(feature = "rate-limited-stream")]
>> + lookup_rate_limiter: Option<Arc<LookupRateLimiter>>,
>> +}
>
> 90% of this whole thing is a copy of `AcceptBuilder`.
> I'd argue that we should be able to instead add this version's
> `accept()` method to the regular `AcceptBuilder` as another variant with
> a different name, eg. `accept_with_tls_optional()`.
>
> The `accept_connections()` task AFAICT is also just the original split
> in 2 with the tls check in between. It should be fine to just change the
> original to this with the tls check covered by whether an
> `Option<Sender<Insecure...>>` is `Some`.
>
> Otherwise we're just duplicating too much.
>
I had realized this while writing this series; I decided to go for a
separate type because I wasn't sure whether I'd be breaking an API or
not (but as you had already mentioned off list, this isn't the case here).
> The only other change is that the tls acceptor is now optional.
> Do we even have a use case for where we need potentially-rate-limited
> non-tls streams?
> If so, this could also be another accept method.
>
> In fact, given the point where the acceptor is actually used, perhaps we
> should drop it from the struct entirely and instead pass it along to the
> `accept()` methods:
> - accept_tls(acceptor) -> stream
> - accept_optional_tls(acceptor) -> (tls stream, insecure stream)
> - accept_direct(acceptor) -> nontls-stream
>
> ^ dropping the original `accept` on purpose ensure all crate users get
> updated accordingly
Good point actually! This seems like the right way to go.
next prev parent reply other threads:[~2023-07-18 5:47 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-22 9:15 [pbs-devel] [PATCH proxmox, proxmox-backup 0/3] Add support for HTTP to HTTPS redirection Max Carrara
2023-06-22 9:15 ` [pbs-devel] [PATCH proxmox 1/3] rest-server: Add `BiAcceptBuilder` Max Carrara
2023-07-14 9:20 ` Wolfgang Bumiller
2023-07-18 5:46 ` Max Carrara [this message]
2023-06-22 9:15 ` [pbs-devel] [PATCH proxmox 2/3] rest-server: Add `Redirector` Max Carrara
2023-07-14 9:24 ` Wolfgang Bumiller
2023-07-18 5:59 ` Max Carrara
2023-06-22 9:15 ` [pbs-devel] [PATCH proxmox-backup 3/3] proxy: redirect HTTP requests to HTTPS Max Carrara
2023-06-23 10:15 ` [pbs-devel] [PATCH proxmox, proxmox-backup 0/3] Add support for HTTP to HTTPS redirection Max Carrara
2023-06-23 10:55 ` Thomas Lamprecht
2023-06-27 9:39 ` Max Carrara
2023-06-23 11:40 ` Lukas Wagner
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=0f5792c2-282f-ea1a-0fd3-2fd1b7c5c6ad@proxmox.com \
--to=m.carrara@proxmox.com \
--cc=pbs-devel@lists.proxmox.com \
--cc=w.bumiller@proxmox.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox