Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[HAPROXY] use $SOURCEIP instead of $PROXIED_SRCIP #361

Merged

Conversation

bazsi
Copy link
Member

@bazsi bazsi commented Nov 2, 2024

This is a large refactor of the HAProxy support, and preparations for protocol auto detection. It also changes the HAProxy support to use the standard source/destination addresses in LogMessage, instead of a proxy specific values e.g. $SOURCEIP instead of $PROXIED_SRCIP.

Short summary of the patches:

  • small refactors and cleanups (first 5 patches)
  • simplify TLS compression setup code, previously this crossed a lot of layers, whereas it can be a lot simpler
  • LogTransportTLS is becoming an adapter, e.g. instead of going directly to file descriptors, go through another layer of the LogTransport interface. This prepares for protocol auto detection.
  • introduces LogTransportStack level aux data, making it possible to enrich messages from the any of the Transports
  • adds the $SOURCEPORT macro
  • LogTransportHAProxy is changed so it invokes a log_transport_stack_switch() instead of doing this internally
  • has a big refactor of TransportMapperInet, as its various settings and options were becoming too difficult to read. This patch also adds a large light testcase to cover all possible transport() cases
  • contains an alternative fix for afsocket/transport-mapper: fix auto transport with tls #482 (although pretty similar)
  • and few smaller patches

@bazsi bazsi force-pushed the haproxy-use-sourceip-instead-of-proxied-srcip branch 2 times, most recently from cdfd3b6 to c2c1e8f Compare November 2, 2024 21:09
@bazsi bazsi force-pushed the haproxy-use-sourceip-instead-of-proxied-srcip branch 4 times, most recently from 58f020f to dff7494 Compare November 11, 2024 19:51
@bazsi bazsi force-pushed the haproxy-use-sourceip-instead-of-proxied-srcip branch 2 times, most recently from 672e0c2 to 1c9e896 Compare December 3, 2024 17:30
@bazsi bazsi force-pushed the haproxy-use-sourceip-instead-of-proxied-srcip branch from 1c9e896 to 5ee3ffd Compare January 27, 2025 08:55
@bazsi bazsi force-pushed the haproxy-use-sourceip-instead-of-proxied-srcip branch 6 times, most recently from b3b5bc7 to e8322f7 Compare February 2, 2025 16:21
@bazsi bazsi requested a review from MrAnno February 2, 2025 17:04
@bazsi
Copy link
Member Author

bazsi commented Feb 2, 2025

This is now ready for review and I think would be a better solution than #482 with the same fix.

@bazsi
Copy link
Member Author

bazsi commented Feb 3, 2025

@OverOrion @MrAnno could you re-review this, so we can merge this instead of #482?

@MrAnno MrAnno requested a review from OverOrion February 3, 2025 12:46
@MrAnno
Copy link
Member

MrAnno commented Feb 3, 2025

I'm reviewing it.

lib/transport/transport-tls.c Outdated Show resolved Hide resolved
lib/transport/transport-tls.c Show resolved Hide resolved
lib/transport/transport-aux-data.h Show resolved Hide resolved
modules/afsocket/transport-mapper-inet.h Show resolved Hide resolved
modules/afsocket/transport-mapper-inet.c Show resolved Hide resolved
@MrAnno MrAnno self-requested a review February 3, 2025 16:21
bazsi added 5 commits February 4, 2025 13:08
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
…ransportStack

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
bazsi added 17 commits February 4, 2025 13:08
Previously TLS compression was enabled using an overly complicated mechanism
crossing a number of layers (TransportMapperInet -> TransportFactoryTLS ->
TLSSession -> SSL). This can be a lot simpler, which this patch
implements.

NOTE: compression will not work in most cases due to OpenSSL security
levels and this patch adds a warning about it.

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Instead of going to the fd directly, wrap the lower-level LogTransport
instance into a BIO and use that. This implements proper stacking
for LogTransportTLS.

This adds the use of OpenSSL BIOs to wrap the lower level LogTransport
instance.

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
…rtStack level

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
…sages

The "auto" protocol can be applied to both syslog() and network(), so
it's not strictly RFC6587 related and it does not add too much information
anyway.

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Instead of using proxy protocol specific name value pairs, set the
addresses in the message's saddr/daddr members.

This should be a lot faster and a lot easier to use.

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
…resses

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
…e_index

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
…e message

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
This reworks the various boolean members in TransportMapperInet that
control which logproto/transport we apply to a specific connection.

With these renames, it's much easier to follow what happens and why.

NOTE: there's a followup bugfix that fixes the same bug as axoflow#482.

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
"auto" has originally been planned to auto-detect TLS as well as framing
format, but at this point it does not do TLS auto-detection.

But this means that transport(auto) with tls() options set will start reading
data without SSL, e.g. the encrypted stuff will make it into the
messages received.

This patch fixes that for both the syslog() and the network() driver. The
only change is that delegate_tls_start_to_logproto is FALSE for the "auto"
case. This will be changed once the TLS auto detection feature is also
in.

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
… transports

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Instead of just exercising the proxyprotocol try all valid transports, including
the "auto" variants.

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
@bazsi bazsi force-pushed the haproxy-use-sourceip-instead-of-proxied-srcip branch from e8322f7 to 6344ea8 Compare February 4, 2025 12:22
Copy link
Member

@MrAnno MrAnno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've started manual-testing the generic- and TLS-related transport changes (I think we need thorough testing since this touches core functionality).

lib/transport/transport-tls.c Outdated Show resolved Hide resolved
lib/transport/transport-tls.c Show resolved Hide resolved
@MrAnno
Copy link
Member

MrAnno commented Feb 5, 2025

I've tested the TLS-related changes on a real network connection through multiple hops, it works as expected.

bazsi added 2 commits February 6, 2025 14:04
Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
This was a one-off allocation, but it's better if it is freed.

Signed-off-by: Balazs Scheidler <balazs.scheidler@axoflow.com>
@bazsi bazsi force-pushed the haproxy-use-sourceip-instead-of-proxied-srcip branch from d05bb69 to 704ded6 Compare February 6, 2025 13:29
@bazsi
Copy link
Member Author

bazsi commented Feb 6, 2025

@MrAnno I've resolved the memory leak and did not add BIO_set_nbio() call and resolved your comments. Let me know if you agree. Thanks

@MrAnno MrAnno merged commit fe2fdf9 into axoflow:main Feb 7, 2025
22 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants