Skip to content

Conversation

cnlangzi
Copy link
Member

@cnlangzi cnlangzi commented Feb 11, 2025

Changed

Fixed

Added

  • feat(proxyproto): support serve http(s) server through proxy servers and load balancers.
  • added cookie, hsts and proxyproto sections on README.md

Tests

Tasks to complete before merging PR:

  • Ensure unit tests are passing. If not run make unit-test to check for any regressions 📋
  • Ensure lint tests are passing. if not run make lint to check for any issues
  • Ensure codecov/patch is passing for changes.

Summary by Sourcery

New Features:

  • Added support for the PROXY protocol, enabling the application to receive client connection information passed through proxy servers and load balancers.

Copy link

sourcery-ai bot commented Feb 11, 2025

Reviewer's Guide by Sourcery

This pull request introduces proxy protocol support for HTTP(S) servers enabling them to operate behind proxy servers and load balancers. The changes include documentation updates, dependency bumps, and a new proxyproto package that provides utilities to parse both v1 and v2 of the proxy protocol, wrap network connections and listeners, and integrate proxy protocol handling in server startup functions.

Class diagram for the proxyproto package

classDiagram
    class Header {
      +net.Addr LocalAddr
      +net.Addr RemoteAddr
      +int Version
      +Command Command
      +Protocol Protocol
      +[]byte RawTLVs
    }

    class conn {
      -net.Conn Conn
      -*bufio.Reader r
      -*Header h
      -bool isLoaded
      -sync.Once once
      +Read(b []byte) int
      +LocalAddr() net.Addr
      +RemoteAddr() net.Addr
      -tryUseProxy()
    }

    class listener {
      -net.Listener Listener
      +Accept() net.Conn
    }

    %% Relationships
    conn ..> Header : uses
    listener ..> conn : wraps

    %% Global functions
    class NewConn {
      <<function>>
    }
    class NewListener {
      <<function>>
    }
    class ListenAndServe {
      <<function>>
    }
    class ListenAndServeTLS {
      <<function>>
    }

    %% Functions are not methods of any class, so they are shown as standalone elements
Loading

File-Level Changes

Change Details Files
Documentation and Example Updates
  • Updated README.md with new code examples demonstrating the usage of proxyproto.ListenAndServe and proxyproto.ListenAndServeTLS.
  • Added sections on cookie handling and HSTS configuration.
  • Included security notes advising on the proper use of the PROXY protocol.
README.md
Dependency and Module Updates
  • Bumped version of golang.org/x/crypto from v0.32.0 to v0.33.0.
  • Updated indirect dependencies in go.mod for golang.org/x/net, golang.org/x/sys, and golang.org/x/text.
  • Updated go.sum accordingly.
go.mod
go.sum
Introduction of Proxy Protocol Header Parsing
  • Implemented header parsing for both PROXY protocol v1 and v2 in a new file.
  • Validated addresses and ports for IPv4, IPv6 and Unix sockets.
  • Handled TLVs (Type-Length-Value entries) for v2 protocol.
ext/proxyproto/header.go
ext/proxyproto/header_test.go
Proxy-enabled Connection Wrapping
  • Created a new connection wrapper to intercept and parse incoming connections for PROXY protocol headers.
  • Extended net.Conn interface methods such as LocalAddr() and RemoteAddr() to return correct addresses from the header if present.
ext/proxyproto/conn.go
ext/proxyproto/conn_test.go
Proxy Protocol Listener and Server Integration
  • Developed a new listener wrapper that creates proxy-aware connections on Accept.
  • Added helper functions ListenAndServe and ListenAndServeTLS to integrate proxy protocol with HTTP servers.
ext/proxyproto/listener.go
ext/proxyproto/serve.go

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link

deepsource-io bot commented Feb 11, 2025

Here's the code health analysis summary for commits 34263b4..94237f7. View details on DeepSource ↗.

Analysis Summary

AnalyzerStatusSummaryLink
DeepSource Go LogoGo✅ SuccessView Check ↗

💡 If you’re a repository administrator, you can configure the quality gates from the settings.

Copy link

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @cnlangzi - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Detected hardcoded secret key for cookie signing. (link)
  • Detected hardcoded secret key for cookie verification. (link)

Overall Comments:

  • Consider adding a benchmark to conn_test.go to measure the performance impact of using proxyproto.Conn.
Here's what I looked at during the review
  • 🟡 General issues: 4 issues found
  • 🔴 Security: 2 blocking issues
  • 🟡 Testing: 2 issues found
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Copy link

codecov bot commented Feb 11, 2025

Codecov Report

Attention: Patch coverage is 92.72727% with 16 lines in your changes missing coverage. Please review.

Project coverage is 92.10%. Comparing base (34263b4) to head (94237f7).
Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
ext/proxyproto/header.go 88.96% 13 Missing and 3 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main      #40      +/-   ##
==========================================
+ Coverage   92.01%   92.10%   +0.09%     
==========================================
  Files          38       43       +5     
  Lines        1427     1647     +220     
==========================================
+ Hits         1313     1517     +204     
- Misses         78       91      +13     
- Partials       36       39       +3     
Flag Coverage Δ
Unit-Tests 92.10% <92.72%> (+0.09%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@cnlangzi cnlangzi merged commit 7b7455d into main Feb 11, 2025
7 checks passed
@cnlangzi cnlangzi deleted the feat/proxyproto branch February 11, 2025 12:01
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.

1 participant