PascalMinder / geoblock

Traefik middleware plugin - Deny requests based on country of origin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

White list some ranges of IP

Fratt opened this issue · comments

commented

Hello,

I would like to white-list some ranges of IP Address in a country that's normally blocked.

Is this currently possible ?

Thanks a lot

commented

If this can help someone else, I found a "workaround".
You need to have allowLocalRequestsset to true.
Edit geoblock.go and add the range in the cidr array of the method initPrivateIPBlocks

I haven't thought about it yet, since I do not need it. But it might be an interesting idea. I look into it.

commented

This would reallly be a great enhancement. I have quite a few services that I only want to be available from specific regions, but that might also need e.g. some kind of remote monitoring tool that is hosted in a different country, without opening for all traffic from that country.

Hi, sorry for the late answer. I’ll look into it as soon as I have some time at my hand.

I have added a first draft to allow defining specific IP addresses which should always be allowed. What do you think?

Pull Request: #30

testData:
  allowLocalRequests: false
  logLocalRequests: false
  logAllowedRequests: false
  logApiRequests: true
  api: "https://get.geojs.io/v1/ip/country/{ip}"
  apiTimeoutMs: 150
  cacheSize: 15
  forceMonthlyUpdate: true
  allowUnknownCountries: false
  unknownCountryApiResponse: "nil"
  countries:
    - CH
  allowedIpAddresses:
    - 8.8.8.8
    - 1.1.1.1
commented

Looks great.
The official "ipWhiteList" plugin also allows for prefixes and IPv6:

tcp:
  middlewares:
    olen-net:
      ipWhiteList:
        sourceRange: 
          - "123.234.50.66/32"               # Home
          - "2a00:00c0:2:3::567:8001/128"  # Server
          - "178.90.234.0/24"             # Work

Does this work with your code as well?

With my last commit, this should work.

commented

Looks great. Will try to test it as soon as possible.

Fixed by f923e4e

commented

Thank you very much !

You forgot to add it here though : https://github.com/PascalMinder/geoblock/blob/main/geoblock.go#L122
(not a big deal ;-)