Problem/Motivation

The original request was to restrict access by country using an IP database such as MaxMind, because entering every range for a country by hand is not practical.

Rather than integrating any particular database, this module should provide an extension point so other modules can supply or adjust IP ranges from whatever source they like: settings.php, an external list, or a country database.

Proposed resolution

Add hook_restrict_by_ip_ranges_alter(), plus type-specific variants, letting modules alter each allow list before it is applied:

  • the global login ranges,
  • each user's ranges,
  • each role's ranges, including roles with no ranges configured.

The allow/deny decision itself stays in this module: after altering, an empty list means the context is unrestricted, and a non-empty list means the request IP must match one of the ranges.

Country-level restriction is possible by implementing the hook in a module that maintains country ranges from an IP database. A point-lookup integration (querying a geo service per request) is out of scope here and better suited to a dedicated module.

API changes

New hooks: hook_restrict_by_ip_ranges_alter(), hook_restrict_by_ip_login_global_ranges_alter(), hook_restrict_by_ip_login_user_ranges_alter(), hook_restrict_by_ip_role_ranges_alter(). Documented in restrict_by_ip.api.php.

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

rex.barkdoll created an issue. See original summary.

anybody’s picture

I guess defining the white-listed IPs should be possible through settings.php, which could then retrieve the IPs from outside? Alternatively maybe a service could be used?

darvanen’s picture

Status: Active » Closed (duplicate)

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

darvanen’s picture

Version: 8.x-4.x-dev » 9.x-dev
Status: Closed (duplicate) » Active

On second thoughts, #3283846: Store per user IP range in database instead of config is different. Reopening this ticket as the place to handle providing extension points for this kind of request.

darvanen’s picture

Assigned: Unassigned » darvanen
darvanen’s picture

Issue summary: View changes

darvanen’s picture

Status: Active » Needs review
darvanen’s picture

Assigned: darvanen » Unassigned
darvanen’s picture

Status: Needs review » Reviewed & tested by the community

Came back with fresh eyes and had a read, happy with this.

  • darvanen committed 0ea6b8c4 on 9.x
    feat: #3419590 Option for including a IP Database
    
    By: rex.barkdoll
    By:...
darvanen’s picture

Status: Reviewed & tested by the community » Fixed

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.