HomeITAdmin / nextcloud_geoblocker

GNU Affero General Public License v3.0
39 stars 2 forks source link

Nextcloud Geoblocker App

GitHub release (latest by date) GitHub Releases GitHub All Releases GitHub

This is a server side app for a Nextcloud instance. This is a front end to geo localization services, that allows blocking (beta), delaying (beta) and logging of login attempts from specified countries. Login attempts from local network IP addresses are never blocked, delayed or logged. In the current implementation the login page is normally shown to everybody independent of the country. Also login attempts with a non existing user are failing as usual independent of the country. Wrong Nextcloud configuration (especially in container) can lead to all access seems to come from local network IP address. Determination of the country from IP address is only as good as the chosen service.

You can activate the latest release version of the app in the "Apps" configuration section of your Nextcloud server when logged in as administrator.

General hints for installation

As for other blocking apps like brute force protection it is important, that the actual IP address from the client is reaching the app and not the address from something inbetween.

One commone source of problems are reverse proxys. Make sure that it is correctly configured to forward the clients IP address as header. You may have to add "trusted_proxies" and "forwarded_for_headers" setting to your Nextcloud config.

A second source of problems are container environments like Docker. Here also the right configuration for these config variables should help. It can make the configuration easier, if you make sure that the containers always have the same internal IP addresses.

I cannot login anymore

If you cannot login anymore because Geoblocker App here are some hints what to do:

How to activate the location services

There are serveral location services available. The app is only the frontend for the location service, so the services need to be installed by the administrator correctly, that the app can work correctly.

Dummy

This is just a dummy location service always returning "Country not found" for debug purposes.

Geoiplookup

Using the geoiplookup programm available on some linux distributions:

MaxMind GeoLite2

Using the MaxMind GeoLite2 PHP API:

If Geoblocker is insisting on that there is an error in the installation the following may help:

include 'geoip2.phar'; use GeoIp2\Database\Reader; $reader = new Reader('%ABSOLUT_PATH_TO_DB%'); print($reader->country('24.165.23.67')->country->isoCode);

Data from Regional Internet Registries (RIRs)

Using the information from the Regional Internet Registries (RIRs):

Fail2ban

Alternatively to the blocking in the app, you can achive some blocking by using fail2ban, relying on the logging feature. Make sure that at least the IP address is included in the logging and the logging time is correct. The following parameters should help to create the filter for fail2ban in English:

datepattern = %%Y-%%m-%%dT%%H:%%M:%%S
failregex = ^.*The user .+ logged in with IP address \\"<HOST>.+  from blocked country .+$

Defining the jail is then straight forward. For "maxretry" only 1 makes sense to be as close to a blocking of the login as possible. But the first request is maybe not blocked still.

Personal remark

Besides the hopefully helpful functionality of the app, it is a learning project for Open Source, Nextcloud App API, PHP, Javascript, HTML, CSS, Clean Coding and Github for me. All kind of feedback, constructive crtiticism and contributions are highly welcome.