Documentation
¶
Overview ¶
contract.go: Wires the geofence plugin into the forge-dashboard contract surface via plugin.ContractContributor.
Package geofence provides country-based access control for authentication. It allows/blocks authentication based on the geographic location of the request IP, using GeoIP data from the geoip plugin.
Index ¶
- Variables
- type Config
- 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
Constants ¶
This section is empty.
Variables ¶
var ( // SettingDefaultPolicy is the default access policy when no country rules match. SettingDefaultPolicy = settings.Define("geofence.default_policy", "allow_all", settings.WithDisplayName("Default Policy"), settings.WithDescription("Default access policy when no country rules match"), settings.WithCategory("Geofencing"), settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp), settings.WithEnforceable(), settings.WithHelpText("Default access policy when no country rules match"), settings.WithOrder(10), settings.WithInputType(formconfig.FieldSelect), settings.WithOptions( formconfig.SelectOption{Label: "Allow All", Value: "allow_all"}, formconfig.SelectOption{Label: "Block All", Value: "block_all"}, ), ) // SettingAllowedCountries is the list of ISO 3166-1 alpha-2 country codes allowed. SettingAllowedCountries = settings.Define("geofence.allowed_countries", []string{}, settings.WithDisplayName("Allowed Countries"), settings.WithDescription("ISO 3166-1 alpha-2 country codes allowed"), settings.WithCategory("Geofencing"), settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp), settings.WithHelpText("ISO 3166-1 alpha-2 country codes allowed. Empty means all allowed."), settings.WithOrder(20), settings.WithPlaceholder("US, GB, DE"), ) // SettingBlockedCountries is the list of ISO 3166-1 alpha-2 country codes blocked. SettingBlockedCountries = settings.Define("geofence.blocked_countries", []string{}, settings.WithDisplayName("Blocked Countries"), settings.WithDescription("ISO 3166-1 alpha-2 country codes blocked"), settings.WithCategory("Geofencing"), settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp), settings.WithHelpText("ISO 3166-1 alpha-2 country codes blocked."), settings.WithOrder(30), settings.WithPlaceholder("CN, RU"), ) // SettingBlockMessage is the error message shown when access is denied. SettingBlockMessage = settings.Define("geofence.block_message", "access denied based on location", settings.WithDisplayName("Block Message"), settings.WithDescription("Error message shown when access is denied by geofence rules"), settings.WithCategory("Geofencing"), settings.WithScopes(settings.ScopeGlobal, settings.ScopeApp), settings.WithHelpText("Error message shown when access is denied by geofence rules"), settings.WithOrder(40), ) )
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// DefaultPolicy is the default action when no rules match.
// "allow_all" (default) or "deny_all".
DefaultPolicy string
// AllowedCountries is a whitelist of ISO 3166-1 alpha-2 country codes.
// When non-empty, only these countries are allowed.
AllowedCountries []string
// BlockedCountries is a blacklist of ISO 3166-1 alpha-2 country codes.
// Requests from these countries are blocked.
BlockedCountries []string
// BlockMessage is the error message returned when blocked (default: "access denied from your location").
BlockMessage string
}
Config configures the geofence plugin.
type Plugin ¶
type Plugin struct {
// contains filtered or unexported fields
}
Plugin implements country-based geofencing for auth events.
func (*Plugin) DeclareSettings ¶
DeclareSettings implements plugin.SettingsProvider. It registers all geofence-related configurable settings.
func (*Plugin) OnBeforePrincipalAuth ¶
OnBeforePrincipalAuth checks whether a machine caller's IP is allowed by geofence rules.
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 worked from any country regardless of geofence policy.
func (*Plugin) OnBeforeSignIn ¶
OnBeforeSignIn checks if the sign-in IP is allowed by geofence rules.
func (*Plugin) OnBeforeSignUp ¶
OnBeforeSignUp checks if the sign-up IP is allowed by geofence rules.
func (*Plugin) RegisterContract ¶
func (p *Plugin) RegisterContract( d *dispatcher.Dispatcher, reg contract.Registry, wreg contract.WardenRegistry, engine plugin.Engine, ) error