Merge commit from fork

* Inject DenyList from config to `StartCommands()`

* Implementation draft

* Move address checker to separate package

* Migrate usages of actions.AddressChecker to denylist.AddressChecker

* Rename denylist package files

* Pass []denylist.AddressChecker to StartCommand

* Add DenyList to defaults.yaml and add custom config parser

* net: add HostnameToIPList function

* denylist: Add IsHostBlocked()

* actions: use denylist.IsHostBlocked()

* command: Inject ip lookup function + extend add target validationt test

* command: Unexport ChangeTarget.IsValid()

* command: Add denyList check on ChangeTarget validation

* command: Export ActionsV2DenyList and IPLookupFunction params

* Lint fix

* Check denylist during action execution

* Fix integration tests

* Apply suggestions

* Add `mapstructure.StringToSliceHookFunc()` to decode `HTTPConfigDecodeHook`
This commit is contained in:
Marco A.
2026-02-25 06:33:28 +01:00
committed by GitHub
parent bac224c56d
commit b2532e9666
38 changed files with 823 additions and 292 deletions
+30
View File
@@ -0,0 +1,30 @@
package net
import (
builtin_net "net"
"github.com/zitadel/zitadel/internal/zerrors"
)
type IPLookupFunc func(string) ([]builtin_net.IP, error)
// HostnameToIPList converts the input URL to a list [net.IP].
//
// Returns an internal error if the lookup fails.
// Returns an invalid argument if the lookup function is nil
func HostnameToIPList(hostname string, lookupFunc IPLookupFunc) ([]builtin_net.IP, error) {
ip := builtin_net.ParseIP(hostname)
ips := []builtin_net.IP{ip}
if ip != nil {
return ips, nil
}
// if the hostname is a domain, we need to check resolve the ip(s), since it might be denied
if lookupFunc == nil {
return nil, zerrors.ThrowInvalidArgument(nil, "NET-naSn77", "lookup function must not be nil")
}
ips, err := lookupFunc(hostname)
if err != nil {
return nil, zerrors.ThrowInternal(err, "NET-4m9s2", "lookup failed")
}
return ips, nil
}
+78
View File
@@ -0,0 +1,78 @@
package net
import (
builtin_net "net"
"testing"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"github.com/zitadel/zitadel/internal/zerrors"
)
func TestHostnameToIPList(t *testing.T) {
t.Parallel()
addrErr := &builtin_net.AddrError{Addr: "invalid.local", Err: "Invalid address"}
tests := []struct {
name string
hostname string
lookupFunc IPLookupFunc
want []builtin_net.IP
expectedErr error
}{
{
name: "valid IP address",
hostname: "192.168.1.1",
lookupFunc: nil,
want: []builtin_net.IP{builtin_net.ParseIP("192.168.1.1")},
},
{
name: "domain with lookup function",
hostname: "example.com",
lookupFunc: func(s string) ([]builtin_net.IP, error) {
return []builtin_net.IP{builtin_net.ParseIP("127.0.0.1")}, nil
},
want: []builtin_net.IP{builtin_net.ParseIP("127.0.0.1")},
},
{
name: "domain without lookup function",
hostname: "example.com",
lookupFunc: nil,
want: nil,
expectedErr: zerrors.ThrowInvalidArgument(nil, "NET-naSn77", "lookup function must not be nil"),
},
{
name: "domain with lookup error",
hostname: "invalid.local",
lookupFunc: func(s string) ([]builtin_net.IP, error) {
return nil, addrErr
},
want: nil,
expectedErr: zerrors.ThrowInternal(addrErr, "NET-4m9s2", "lookup failed"),
},
{
name: "domain with multiple IPs",
hostname: "multi.example.com",
lookupFunc: func(s string) ([]builtin_net.IP, error) {
return []builtin_net.IP{
builtin_net.ParseIP("127.0.0.1"),
builtin_net.ParseIP("127.0.0.2"),
}, nil
},
want: []builtin_net.IP{
builtin_net.ParseIP("127.0.0.1"),
builtin_net.ParseIP("127.0.0.2"),
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got, err := HostnameToIPList(tt.hostname, tt.lookupFunc)
require.ErrorIs(t, err, tt.expectedErr)
assert.ElementsMatch(t, got, tt.want)
})
}
}