Documentation
¶
Overview ¶
contract.go: Wires the ipreputation plugin into the forge-dashboard contract surface via plugin.ContractContributor.
Package ipreputation checks IP addresses against threat intelligence sources and blocks or flags high-risk IPs during authentication.
Index ¶
- Variables
- type Config
- type IPReputation
- type Plugin
- func (p *Plugin) DeclareSettings(m *settings.Manager) error
- func (p *Plugin) Name() string
- func (p *Plugin) OnBeforePrincipalAuth(ctx context.Context, a *principal.AuthAttempt) error
- func (p *Plugin) OnBeforeSignIn(ctx context.Context, req *account.SignInRequest) error
- func (p *Plugin) OnBeforeSignUp(ctx context.Context, req *account.SignUpRequest) error
- func (p *Plugin) OnInit(_ context.Context, engine plugin.Engine) error
- func (p *Plugin) RegisterContract(d *dispatcher.Dispatcher, reg contract.Registry, wreg contract.WardenRegistry, ...) error
- type Provider
Constants ¶
This section is empty.
Variables ¶
var ( // SettingBlockThreshold is the score at or above which IPs are blocked. SettingBlockThreshold = settings.Define("ipreputation.block_threshold", 80, settings.WithDisplayName("Block Threshold"), settings.WithDescription("Score at or above which IPs are blocked"), settings.WithCategory("IP Reputation"), settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp), settings.WithEnforceable(), settings.WithUIValidation(formconfig.Validation{Min: intPtr(0), Max: intPtr(100)}), settings.WithHelpText("Score at or above which IPs are blocked (0-100)"), settings.WithOrder(10), ) // SettingWarnThreshold is the score at or above which IPs are flagged with a warning. SettingWarnThreshold = settings.Define("ipreputation.warn_threshold", 50, settings.WithDisplayName("Warn Threshold"), settings.WithDescription("Score at or above which IPs are flagged with a warning"), settings.WithCategory("IP Reputation"), settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp), settings.WithUIValidation(formconfig.Validation{Min: intPtr(0), Max: intPtr(100)}), settings.WithHelpText("Score at or above which IPs are flagged with a warning (0-100)"), settings.WithOrder(20), ) // SettingCacheTTLHours is how long IP reputation results are cached, in hours. SettingCacheTTLHours = settings.Define("ipreputation.cache_ttl_hours", 6, settings.WithDisplayName("Cache TTL (Hours)"), settings.WithDescription("How long IP reputation results are cached"), settings.WithCategory("IP Reputation"), settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp), settings.WithHelpText("How long IP reputation results are cached, in hours"), settings.WithOrder(30), ) // SettingBlockMessage is the error message shown when an IP is blocked. SettingBlockMessage = settings.Define("ipreputation.block_message", "access denied due to IP reputation", settings.WithDisplayName("Block Message"), settings.WithDescription("Error message shown when an IP is blocked"), settings.WithCategory("IP Reputation"), settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp), settings.WithHelpText("Error message shown when an IP is blocked"), settings.WithOrder(40), ) )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Provider is the reputation data source.
Provider Provider
// BlockThreshold is the score at/above which IPs are blocked (default: 80).
BlockThreshold int
// WarnThreshold is the score at/above which IPs are flagged (default: 50).
WarnThreshold int
// CacheTTL is how long reputation results are cached (default: 6h).
CacheTTL time.Duration
// BlockMessage is the error message on block.
BlockMessage string
// MaxCachedIPs bounds the in-memory reputation cache; the least
// recently used address is dropped when it is full (default: 10000).
MaxCachedIPs int
}
Config configures the IP reputation plugin.
type IPReputation ¶
type IPReputation struct {
IP string `json:"ip"`
Score int `json:"score"` // 0 (clean) to 100 (malicious)
Categories []string `json:"categories,omitempty"`
ISP string `json:"isp,omitempty"`
ASN int `json:"asn,omitempty"`
IsBlacklisted bool `json:"is_blacklisted"`
Source string `json:"source"`
ExpiresAt time.Time `json:"expires_at"`
}
IPReputation represents the reputation score for an IP address.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin checks IP reputation before authentication.
func (*Plugin) DeclareSettings ¶
DeclareSettings implements plugin.SettingsProvider. It registers all IP reputation-related configurable settings.
func (*Plugin) OnBeforePrincipalAuth ¶
OnBeforePrincipalAuth checks the IP reputation of a machine caller.
The same check sign-in gets. API-key traffic reaches strategy.Authenticate and fires none of the sign-in hooks, so without this a leaked key works from any address in the world.
func (*Plugin) OnBeforeSignIn ¶
OnBeforeSignIn checks the IP reputation.
func (*Plugin) OnBeforeSignUp ¶
OnBeforeSignUp checks the IP reputation.
func (*Plugin) RegisterContract ¶
func (p *Plugin) RegisterContract( d *dispatcher.Dispatcher, reg contract.Registry, wreg contract.WardenRegistry, engine plugin.Engine, ) error