-
-
Notifications
You must be signed in to change notification settings - Fork 999
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
root: check remote IP for proxy protocol same as HTTP/etc (cherry-pick …
…#12094) (#12097) root: check remote IP for proxy protocol same as HTTP/etc (#12094) Signed-off-by: Jens Langhammer <jens@goauthentik.io> Co-authored-by: Jens L. <jens@goauthentik.io>
- Loading branch information
1 parent
f535a23
commit 05f4e73
Showing
6 changed files
with
41 additions
and
6 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,34 @@ | ||
package utils | ||
|
||
import ( | ||
"net" | ||
|
||
"github.com/pires/go-proxyproto" | ||
log "github.com/sirupsen/logrus" | ||
"goauthentik.io/internal/config" | ||
) | ||
|
||
func GetProxyConnectionPolicy() proxyproto.ConnPolicyFunc { | ||
nets := []*net.IPNet{} | ||
for _, rn := range config.Get().Listen.TrustedProxyCIDRs { | ||
_, cidr, err := net.ParseCIDR(rn) | ||
if err != nil { | ||
continue | ||
} | ||
nets = append(nets, cidr) | ||
} | ||
return func(connPolicyOptions proxyproto.ConnPolicyOptions) (proxyproto.Policy, error) { | ||
host, _, err := net.SplitHostPort(connPolicyOptions.Upstream.String()) | ||
if err == nil { | ||
// remoteAddr will be nil if the IP cannot be parsed | ||
remoteAddr := net.ParseIP(host) | ||
for _, allowedCidr := range nets { | ||
if remoteAddr != nil && allowedCidr.Contains(remoteAddr) { | ||
log.WithField("remoteAddr", remoteAddr).WithField("cidr", allowedCidr.String()).Trace("Using remote IP from proxy protocol") | ||
return proxyproto.USE, nil | ||
} | ||
} | ||
} | ||
return proxyproto.SKIP, nil | ||
} | ||
} |
This file contains 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 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