Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion backend/internal/services/forward_preflight_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ func TestRefuseForwardTarget_LiteralPolicyForEveryClass(t *testing.T) {
"fd00:ec2::254": true,
"100.100.100.200": true,
"168.63.129.16": true,
"0.0.0.0": true,
"0.0.0.0": false, // loopback-equivalent on an ordinary port (see forwardLiteralBlocked)
"10.20.30.40": false,
"192.168.1.10": false,
"100.64.0.5": false,
Expand Down
19 changes: 17 additions & 2 deletions backend/internal/services/forward_target_policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import (

"github.com/Wikid82/charon/backend/internal/caddy"
"github.com/Wikid82/charon/backend/internal/models"
"github.com/Wikid82/charon/backend/internal/network"
"github.com/Wikid82/charon/backend/internal/orthrus"
)

Expand Down Expand Up @@ -295,7 +296,7 @@ func refuseForwardTarget(tx *gorm.DB, forwardHost string, port int, v forwardVer
}
literal := parseIPOrLegacy(host)
if literal != nil {
if v.policy.Blocked(literal) {
if forwardLiteralBlocked(v.policy, literal) {
return ErrForwardTargetAddress
}
} else if nv, ok := v.names[host]; ok && nv.err == nil {
Expand Down Expand Up @@ -351,7 +352,21 @@ func addrIP(a netip.Addr) net.IP {
func literalRefusedByPolicy(forwardHost string) bool {
host := normalizeForwardName(forwardTargetHost(forwardHost))
ip := parseIPOrLegacy(host)
return ip != nil && probePolicy().Blocked(ip)
return ip != nil && forwardLiteralBlocked(probePolicy(), ip)
}

// forwardLiteralBlocked reports whether a forward target literal is refused by
// the policy. The IPv4 unspecified address 0.0.0.0 (also in its legacy spellings)
// is judged as 127.0.0.1. On Linux a connection to it reaches this machine's
// loopback listeners, so it is accepted wherever loopback is. The policy itself
// is unchanged, so probes and dials still refuse 0.0.0.0. The IPv6 unspecified
// address `::` is not covered: the reported case is IPv4, and `::` stays refused.
// Only the forward-target paths use this helper.
func forwardLiteralBlocked(policy network.AddressPolicy, ip net.IP) bool {
if ip.Equal(net.IPv4zero) {
ip = net.IPv4(127, 0, 0, 1)
}
return policy.Blocked(ip)
}

// parseIPOrLegacy returns the address a host names when it is an IP literal in
Expand Down
54 changes: 54 additions & 0 deletions backend/internal/services/forward_target_policy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -627,3 +627,57 @@ func requireForwardRefused(t *testing.T, err error) {
assert.True(t, errors.Is(err, ErrOrthrusListenerTarget) || errors.Is(err, ErrForwardTargetAddress),
"unexpected refusal %v", err)
}

// The IPv4 unspecified literal reaches this machine's loopback listeners on Linux,
// so an ordinary port on 0.0.0.0 is accepted as a loopback target. The reserved
// port rule still applies to it, and the other blocked ranges stay refused.
func TestForwardTarget_UnspecifiedIPv4OnOrdinaryPortIsAccepted(t *testing.T) {
db := setupListenerPolicyDB(t)
seedAgentPort(t, db, "a", 2375)
useListenerSource(t, fakeListenerSource{})
noLookup(t)

for _, host := range []string{"0.0.0.0", "0", "0x0", "0.0", "::ffff:0.0.0.0"} {
t.Run(host, func(t *testing.T) {
refused, err := NewListenerTargetGuard(db).RefusesForwardTarget(host, 8080)
require.NoError(t, err)
assert.False(t, refused, "config generation keeps the host")

require.NoError(t, refuseForwardTarget(db, host, 8080, verdictsFor(t)), "save accepts the host")
})
}
}

func TestForwardTarget_UnspecifiedIPv4OnReservedPortIsRefused(t *testing.T) {
db := setupListenerPolicyDB(t)
seedAgentPort(t, db, "a", 2375)
useListenerSource(t, fakeListenerSource{})
noLookup(t)

for _, host := range []string{"0.0.0.0", "0", "0x0"} {
t.Run(host, func(t *testing.T) {
refused, err := NewListenerTargetGuard(db).RefusesForwardTarget(host, 2375)
require.NoError(t, err)
assert.True(t, refused, "config generation drops the host")

require.ErrorIs(t, refuseForwardTarget(db, host, 2375, verdictsFor(t)), ErrOrthrusListenerTarget)
})
}
}

func TestForwardTarget_BlockedRangesStayRefusedOnOrdinaryPort(t *testing.T) {
db := setupListenerPolicyDB(t)
useListenerSource(t, fakeListenerSource{})
noLookup(t)

// The unspecified IPv6 address is not part of the exception: it stays refused.
for _, host := range []string{"169.254.169.254", "169.254.1.1", "fe80::1", "::"} {
t.Run(host, func(t *testing.T) {
refused, err := NewListenerTargetGuard(db).RefusesForwardTarget(host, 8080)
require.NoError(t, err)
assert.True(t, refused, "config generation drops the host")

requireForwardRefused(t, refuseForwardTarget(db, host, 8080, verdictsFor(t)))
})
}
}
4 changes: 2 additions & 2 deletions docs/features/orthrus.md
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,11 @@ The registry check needs a note. Read-only means the proxy can't change anything

When you save a proxy host or a location, Charon checks its forward target. It refuses the save if the target is:

- A link-local address (`169.254.0.0/16` or `fe80::/10`), a cloud instance service address such as `169.254.169.254`, or another reserved address such as `0.0.0.0`, multicast or broadcast
- A link-local address (`169.254.0.0/16` or `fe80::/10`), a cloud instance service address such as `169.254.169.254`, or another reserved address such as multicast or broadcast
- This machine on a port Charon uses for itself: the agent proxy ports and the internal ports opened for connected agents, the internal admin port (2019), the bundled CrowdSec port (8085), and the emergency server port while that server is turned on. This applies to `localhost`, `127.0.0.1`, the machine's own addresses, and the Docker and Podman host names (`host.docker.internal`, `host.containers.internal`, `gateway.docker.internal`).
- The agent-name form (`orthrus:<agent>`). It is not accepted as a forward target at all.

Everything else is allowed, including private network addresses, loopback on ports Charon does not use, Tailscale-style addresses (`100.64.0.0/10`), IPv6 private addresses, and the fake-IP range `198.18.0.0/15`.
Everything else is allowed, including private network addresses, loopback on ports Charon does not use, Tailscale-style addresses (`100.64.0.0/10`), IPv6 private addresses, and the fake-IP range `198.18.0.0/15`. The IPv4 address `0.0.0.0` counts as loopback: it is allowed on ports Charon does not use and refused on the ports above, like `127.0.0.1`.

The refusal message is the same for every reason: "This forward target is not allowed." It does not say which rule applied, so compare the address with the list above.

Expand Down
Loading