Files
zitadel/internal/denylist/denylist.go
T
Marco A.andGitHub b2532e9666 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`
2026-02-25 06:33:28 +01:00

48 lines
1.0 KiB
Go

package denylist
import (
"net"
"reflect"
"github.com/mitchellh/mapstructure"
)
type AddressChecker interface {
IsDenied([]net.IP, string) error
}
func ParseDenyList(inputList []string) ([]AddressChecker, error) {
var toReturn []AddressChecker
for _, input := range inputList {
parsed, parseErr := NewHostChecker(input)
if parseErr != nil {
return nil, parseErr
}
if parsed != nil {
toReturn = append(toReturn, parsed)
}
}
return toReturn, nil
}
func DenyListDecodeHook(from, to reflect.Value) (interface{}, error) {
if to.Type() != reflect.TypeFor[[]AddressChecker]() {
return from.Interface(), nil
}
var inputDenyList []string
decoder, err := mapstructure.NewDecoder(&mapstructure.DecoderConfig{
DecodeHook: mapstructure.ComposeDecodeHookFunc(
mapstructure.StringToSliceHookFunc(","),
),
WeaklyTypedInput: true,
Result: &inputDenyList,
})
if err != nil {
return nil, err
}
if err = decoder.Decode(from.Interface()); err != nil {
return nil, err
}
return ParseDenyList(inputDenyList)
}