Add setting to specify transit node rules

This commit is contained in:
Daniel
2023-08-22 16:31:17 +02:00
parent a44312d516
commit 96a6d6229a
4 changed files with 84 additions and 17 deletions

View File

@@ -14,12 +14,13 @@ import (
var ( var (
cfgLock sync.RWMutex cfgLock sync.RWMutex
cfgDefaultAction uint8 cfgDefaultAction uint8
cfgEndpoints endpoints.Endpoints cfgEndpoints endpoints.Endpoints
cfgServiceEndpoints endpoints.Endpoints cfgServiceEndpoints endpoints.Endpoints
cfgSPNUsagePolicy endpoints.Endpoints cfgSPNUsagePolicy endpoints.Endpoints
cfgSPNExitHubPolicy endpoints.Endpoints cfgSPNTransitHubPolicy endpoints.Endpoints
cfgFilterLists []string cfgSPNExitHubPolicy endpoints.Endpoints
cfgFilterLists []string
) )
func registerConfigUpdater() error { func registerConfigUpdater() error {
@@ -83,6 +84,13 @@ func updateGlobalConfigProfile(ctx context.Context, task *modules.Task) error {
lastErr = err lastErr = err
} }
list = cfgOptionTransitHubPolicy()
cfgSPNTransitHubPolicy, err = endpoints.ParseEndpoints(list)
if err != nil {
// TODO: module error?
lastErr = err
}
list = cfgOptionExitHubPolicy() list = cfgOptionExitHubPolicy()
cfgSPNExitHubPolicy, err = endpoints.ParseEndpoints(list) cfgSPNExitHubPolicy, err = endpoints.ParseEndpoints(list)
if err != nil { if err != nil {

View File

@@ -132,11 +132,15 @@ var (
// Setting "Home Node Rules" at order 145. // Setting "Home Node Rules" at order 145.
CfgOptionTransitHubPolicyKey = "spn/transitHubPolicy"
cfgOptionTransitHubPolicy config.StringArrayOption
cfgOptionTransitHubPolicyOrder = 146
CfgOptionExitHubPolicyKey = "spn/exitHubPolicy" CfgOptionExitHubPolicyKey = "spn/exitHubPolicy"
cfgOptionExitHubPolicy config.StringArrayOption cfgOptionExitHubPolicy config.StringArrayOption
cfgOptionExitHubPolicyOrder = 146 cfgOptionExitHubPolicyOrder = 147
// Setting "DNS Exit Node Rules" at order 147. // Setting "DNS Exit Node Rules" at order 148.
) )
// A list of all security level settings. // A list of all security level settings.
@@ -720,6 +724,34 @@ Please note that if you are using the system resolver, bypass attempts might be
cfgOptionSPNUsagePolicy = config.Concurrent.GetAsStringArray(CfgOptionSPNUsagePolicyKey, []string{}) cfgOptionSPNUsagePolicy = config.Concurrent.GetAsStringArray(CfgOptionSPNUsagePolicyKey, []string{})
cfgStringArrayOptions[CfgOptionSPNUsagePolicyKey] = cfgOptionSPNUsagePolicy cfgStringArrayOptions[CfgOptionSPNUsagePolicyKey] = cfgOptionSPNUsagePolicy
// Transit Node Rules
err = config.Register(&config.Option{
Name: "Transit Node Rules",
Key: CfgOptionTransitHubPolicyKey,
Description: `Customize which countries should or should not be used as Transit Nodes. Transit Nodes are used to transit the SPN from your Home to your Exit Node.`,
Help: SPNRulesHelp,
Sensitive: true,
OptType: config.OptTypeStringArray,
ExpertiseLevel: config.ExpertiseLevelExpert,
ReleaseLevel: config.ReleaseLevelBeta,
DefaultValue: []string{},
Annotations: config.Annotations{
config.StackableAnnotation: true,
config.CategoryAnnotation: "Routing",
config.DisplayOrderAnnotation: cfgOptionTransitHubPolicyOrder,
config.DisplayHintAnnotation: endpoints.DisplayHintEndpointList,
config.QuickSettingsAnnotation: SPNRulesQuickSettings,
endpoints.EndpointListVerdictNamesAnnotation: SPNRulesVerdictNames,
},
ValidationRegex: endpoints.ListEntryValidationRegex,
ValidationFunc: endpoints.ValidateEndpointListConfigOption,
})
if err != nil {
return err
}
cfgOptionTransitHubPolicy = config.Concurrent.GetAsStringArray(CfgOptionTransitHubPolicyKey, []string{})
cfgStringArrayOptions[CfgOptionTransitHubPolicyKey] = cfgOptionTransitHubPolicy
// Exit Node Rules // Exit Node Rules
err = config.Register(&config.Option{ err = config.Register(&config.Option{
Name: "Exit Node Rules", Name: "Exit Node Rules",

View File

@@ -382,6 +382,23 @@ func (lp *LayeredProfile) MatchSPNUsagePolicy(ctx context.Context, entity *intel
return cfgSPNUsagePolicy.Match(ctx, entity) return cfgSPNUsagePolicy.Match(ctx, entity)
} }
// StackedTransitHubPolicies returns all transit hub policies of the layered profile, including the global one.
func (lp *LayeredProfile) StackedTransitHubPolicies() []endpoints.Endpoints {
policies := make([]endpoints.Endpoints, 0, len(lp.layers)+3) // +1 for global policy, +2 for intel policies
for _, layer := range lp.layers {
if layer.spnTransitHubPolicy.IsSet() {
policies = append(policies, layer.spnTransitHubPolicy)
}
}
cfgLock.RLock()
defer cfgLock.RUnlock()
policies = append(policies, cfgSPNTransitHubPolicy)
return policies
}
// StackedExitHubPolicies returns all exit hub policies of the layered profile, including the global one. // StackedExitHubPolicies returns all exit hub policies of the layered profile, including the global one.
func (lp *LayeredProfile) StackedExitHubPolicies() []endpoints.Endpoints { func (lp *LayeredProfile) StackedExitHubPolicies() []endpoints.Endpoints {
policies := make([]endpoints.Endpoints, 0, len(lp.layers)+3) // +1 for global policy, +2 for intel policies policies := make([]endpoints.Endpoints, 0, len(lp.layers)+3) // +1 for global policy, +2 for intel policies

View File

@@ -127,15 +127,16 @@ type Profile struct { //nolint:maligned // not worth the effort
layeredProfile *LayeredProfile layeredProfile *LayeredProfile
// Interpreted Data // Interpreted Data
configPerspective *config.Perspective configPerspective *config.Perspective
dataParsed bool dataParsed bool
defaultAction uint8 defaultAction uint8
endpoints endpoints.Endpoints endpoints endpoints.Endpoints
serviceEndpoints endpoints.Endpoints serviceEndpoints endpoints.Endpoints
filterListsSet bool filterListsSet bool
filterListIDs []string filterListIDs []string
spnUsagePolicy endpoints.Endpoints spnUsagePolicy endpoints.Endpoints
spnExitHubPolicy endpoints.Endpoints spnTransitHubPolicy endpoints.Endpoints
spnExitHubPolicy endpoints.Endpoints
// Lifecycle Management // Lifecycle Management
outdated *abool.AtomicBool outdated *abool.AtomicBool
@@ -224,6 +225,15 @@ func (profile *Profile) parseConfig() error {
} }
} }
list, ok = profile.configPerspective.GetAsStringArray(CfgOptionTransitHubPolicyKey)
profile.spnTransitHubPolicy = nil
if ok {
profile.spnTransitHubPolicy, err = endpoints.ParseEndpoints(list)
if err != nil {
lastErr = err
}
}
list, ok = profile.configPerspective.GetAsStringArray(CfgOptionExitHubPolicyKey) list, ok = profile.configPerspective.GetAsStringArray(CfgOptionExitHubPolicyKey)
profile.spnExitHubPolicy = nil profile.spnExitHubPolicy = nil
if ok { if ok {