-
-
Notifications
You must be signed in to change notification settings - Fork 5.9k
Support Proxy protocol #12527
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
Merged
zeripath
merged 30 commits into
go-gitea:main
from
zeripath:fix-7508-support-proxy-protocol
Aug 21, 2022
+786
−73
Merged
Support Proxy protocol #12527
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
dd337e1
Support HAProxy protocol
zeripath fc0065d
oops
zeripath 2e488e8
Rename everything to UseProxyProtocol
zeripath b3be091
Merge remote-tracking branch 'origin/master' into fix-7508-support-pr…
zeripath e0f5e72
Merge remote-tracking branch 'origin/master' into fix-7508-support-pr…
zeripath d4d93a6
Merge branch 'master' into fix-7508-support-proxy-protocol
6543 e5ca3a2
Merge branch 'master' into fix-7508-support-proxy-protocol
6543 588bd55
Merge remote-tracking branch 'origin/master' into fix-7508-support-pr…
zeripath 9d117e4
Merge branch 'master' into fix-7508-support-proxy-protocol
6543 e8194a5
lint fix
zeripath b34674d
Merge branch 'fix-7508-support-proxy-protocol' of github.com:zeripath…
zeripath 6d82c15
Merge branch 'master' into fix-7508-support-proxy-protocol
6543 af2e349
fix
6543 ce969b7
Merge branch 'main' into fix-7508-support-proxy-protocol
zeripath 6c7cf4b
Merge branch 'main' into fix-7508-support-proxy-protocol
zeripath bc96c0e
Merge remote-tracking branch 'origin/main' into fix-7508-support-prox…
zeripath 8761f00
Merge remote-tracking branch 'origin/main' into fix-7508-support-prox…
zeripath 6a0cc94
Merge branch 'main' into fix-7508-support-proxy-protocol
lunny 1034070
Merge remote-tracking branch 'origin/main' into fix-7508-support-prox…
zeripath f31fa3c
Merge remote-tracking branch 'origin/main' into fix-7508-support-prox…
zeripath 1f242a3
Merge remote-tracking branch 'origin/main' into fix-7508-support-prox…
zeripath d5bc6eb
Update custom/conf/app.example.ini
zeripath 95e0f03
Update modules/setting/setting.go
zeripath e718469
placate the linter
zeripath 9c2d512
as per silverwind
zeripath bd1302d
Merge remote-tracking branch 'origin/main' into fix-7508-support-prox…
zeripath cc2be6f
Merge branch 'main' into fix-7508-support-proxy-protocol
6543 c81db21
Merge branch 'main' into fix-7508-support-proxy-protocol
zeripath 288a7fd
Merge branch 'main' into fix-7508-support-proxy-protocol
zeripath a07e09c
Merge branch 'main' into fix-7508-support-proxy-protocol
zeripath File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package proxyprotocol | ||
|
||
import "fmt" | ||
|
||
// ErrBadHeader is an error demonstrating a bad proxy header | ||
type ErrBadHeader struct { | ||
Header []byte | ||
} | ||
|
||
func (e *ErrBadHeader) Error() string { | ||
return fmt.Sprintf("Unexpected proxy header: %v", e.Header) | ||
} | ||
|
||
// ErrBadAddressType is an error demonstrating a bad proxy header with bad Address type | ||
type ErrBadAddressType struct { | ||
Address string | ||
} | ||
|
||
func (e *ErrBadAddressType) Error() string { | ||
return fmt.Sprintf("Unexpected proxy header address type: %s", e.Address) | ||
} | ||
|
||
// ErrBadRemote is an error demonstrating a bad proxy header with bad Remote | ||
type ErrBadRemote struct { | ||
IP string | ||
Port string | ||
} | ||
|
||
func (e *ErrBadRemote) Error() string { | ||
return fmt.Sprintf("Unexpected proxy header remote IP and port: %s %s", e.IP, e.Port) | ||
} | ||
|
||
// ErrBadLocal is an error demonstrating a bad proxy header with bad Local | ||
type ErrBadLocal struct { | ||
IP string | ||
Port string | ||
} | ||
|
||
func (e *ErrBadLocal) Error() string { | ||
return fmt.Sprintf("Unexpected proxy header local IP and port: %s %s", e.IP, e.Port) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package proxyprotocol | ||
|
||
import ( | ||
"net" | ||
"time" | ||
) | ||
|
||
// Listener is used to wrap an underlying listener, | ||
// whose connections may be using the HAProxy Proxy Protocol (version 1 or 2). | ||
// If the connection is using the protocol, the RemoteAddr() will return | ||
// the correct client address. | ||
// | ||
// Optionally define ProxyHeaderTimeout to set a maximum time to | ||
// receive the Proxy Protocol Header. Zero means no timeout. | ||
type Listener struct { | ||
Listener net.Listener | ||
ProxyHeaderTimeout time.Duration | ||
AcceptUnknown bool // allow PROXY UNKNOWN | ||
} | ||
|
||
// Accept implements the Accept method in the Listener interface | ||
// it waits for the next call and returns a wrapped Conn. | ||
func (p *Listener) Accept() (net.Conn, error) { | ||
// Get the underlying connection | ||
conn, err := p.Listener.Accept() | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
newConn := NewConn(conn, p.ProxyHeaderTimeout) | ||
newConn.acceptUnknown = p.AcceptUnknown | ||
return newConn, nil | ||
} | ||
|
||
// Close closes the underlying listener. | ||
func (p *Listener) Close() error { | ||
return p.Listener.Close() | ||
} | ||
|
||
// Addr returns the underlying listener's network address. | ||
func (p *Listener) Addr() net.Addr { | ||
return p.Listener.Addr() | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package proxyprotocol | ||
|
||
import "io" | ||
|
||
var localHeader = append(v2Prefix, '\x20', '\x00', '\x00', '\x00', '\x00') | ||
|
||
// WriteLocalHeader will write the ProxyProtocol Header for a local connection to the provided writer | ||
func WriteLocalHeader(w io.Writer) error { | ||
_, err := w.Write(localHeader) | ||
return err | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.