{"id":25005417,"url":"https://github.com/jonasschubert/traefik-allow-countries","last_synced_at":"2025-04-12T14:33:08.088Z","repository":{"id":207974874,"uuid":"720522514","full_name":"JonasSchubert/traefik-allow-countries","owner":"JonasSchubert","description":"A Traefik plugin to allow only certain countries and block everything else.","archived":false,"fork":false,"pushed_at":"2025-04-09T11:20:14.000Z","size":286,"stargazers_count":7,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-09T12:27:13.134Z","etag":null,"topics":["traefik","traefik-middleware","traefik-plugin"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JonasSchubert.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-11-18T18:40:09.000Z","updated_at":"2025-04-09T11:20:10.000Z","dependencies_parsed_at":"2024-12-09T19:27:37.201Z","dependency_job_id":"f1303c92-7470-413d-8f5b-a2861275acec","html_url":"https://github.com/JonasSchubert/traefik-allow-countries","commit_stats":null,"previous_names":["jonasschubert/traefik-allow-countries"],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonasSchubert%2Ftraefik-allow-countries","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonasSchubert%2Ftraefik-allow-countries/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonasSchubert%2Ftraefik-allow-countries/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JonasSchubert%2Ftraefik-allow-countries/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JonasSchubert","download_url":"https://codeload.github.com/JonasSchubert/traefik-allow-countries/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248581356,"owners_count":21128155,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["traefik","traefik-middleware","traefik-plugin"],"created_at":"2025-02-05T00:31:30.016Z","updated_at":"2025-04-12T14:33:08.069Z","avatar_url":"https://github.com/JonasSchubert.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Traefik Allow Countries\n\nA [Traefik](https://github.com/containous/traefik) plugin to allow only certain countries and block everything else. Uses the hourly updated country IP blocks from [here](https://github.com/herrbischoff/country-ip-blocks).\n\n## Configuration\n\nSample configuration in Traefik.\n\n### Configuration as local plugin\n\ntraefik.yml\n\n```yaml\nlog:\n  level: INFO\nexperimental:\n  localPlugins:\n    allow-countries:\n      moduleName: github.com/JonasSchubert/traefik-allow-countries\n```\n\ndynamic-configuration.yml\n\n```yaml\nhttp:\n  middlewares:\n    allow-countries-de:\n      plugin:\n        allow-countries:\n          addCountryHeader: true\n          allowLocalRequests: true\n          cidrFileFolder: /usr/traefik/plugins/cidr\n          cidrFileUpdate: true\n          countries:\n            - DE\n          fileExtension: 'cidr'\n          logAllowedRequests: false\n          logDetails: true\n          logLocalRequests: false\n          silentStartUp: true\n```\n\ndocker-compose.yml\n\n```yaml\nservices:\n  traefik:\n    image: traefik\n    volumes:\n      - /var/run/docker.sock:/var/run/docker.sock\n      - /docker/config/traefik/traefik.yml:/etc/traefik/traefik.yml\n      - /docker/config/traefik/dynamic-configuration.yml:/etc/traefik/dynamic-configuration.yml\n      - /plugin/allow-countries:/plugins-local/src/github.com/JonasSchubert/traefik-allow-countries/\n    ports:\n      - \"80:80\"\n  hello:\n    image: containous/whoami\n    labels:\n      - traefik.enable=true\n      - traefik.http.routers.hello.entrypoints=http\n      - traefik.http.routers.hello.rule=Host(`hello.localhost`)\n      - traefik.http.services.hello.loadbalancer.server.port=80\n      - traefik.http.routers.hello.middlewares=my-plugin@file\n```\n\n## Sample configuration\n\n- `addCountryHeader`:  If set to `true`, adds the X-IPCountry header to the HTTP request header. The header contains the two letter country code returned by cache or API request.\n- `allowLocalRequests`: If set to true, will not block request from [Private IP Ranges](https://de.wikipedia.org/wiki/Private_IP-Adresse)\n- `countries`: list of allowed countries\n- `logLocalRequests`: If set to true, will log every connection from any IP in the private IP range\n\n```yaml\nmy-allow-countries:\n  plugin:\n    allow-countries:\n      addCountryHeader: true\n      allowLocalRequests: true\n      cidrFileFolder: /usr/traefik/plugins/cidr\n      cidrFileUpdate: true\n      countries:\n        - AF # Afghanistan\n        - AL # Albania\n        - DZ # Algeria\n        - AS # American Samoa\n        - AD # Andorra\n        - AO # Angola\n        - AI # Anguilla\n        - AQ # Antarctica\n        - AG # Antigua and Barbuda\n        - AR # Argentina\n        - AM # Armenia\n        - AW # Aruba\n        - AU # Australia\n        - AT # Austria\n        - AZ # Azerbaijan\n        - BS # Bahamas (the)\n        - BH # Bahrain\n        - BD # Bangladesh\n        - BB # Barbados\n        - BY # Belarus\n        - BE # Belgium\n        - BZ # Belize\n        - BJ # Benin\n        - BM # Bermuda\n        - BT # Bhutan\n        - BO # Bolivia (Plurinational State of)\n        - BQ # Bonaire, Sint Eustatius and Saba\n        - BA # Bosnia and Herzegovina\n        - BW # Botswana\n        - BV # Bouvet Island\n        - BR # Brazil\n        - IO # British Indian Ocean Territory (the)\n        - BN # Brunei Darussalam\n        - BG # Bulgaria\n        - BF # Burkina Faso\n        - BI # Burundi\n        - CV # Cabo Verde\n        - KH # Cambodia\n        - CM # Cameroon\n        - CA # Canada\n        - KY # Cayman Islands (the)\n        - CF # Central African Republic (the)\n        - TD # Chad\n        - CL # Chile\n        - CN # China\n        - CX # Christmas Island\n        - CC # Cocos (Keeling) Islands (the)\n        - CO # Colombia\n        - KM # Comoros (the)\n        - CD # Congo (the Democratic Republic of the)\n        - CG # Congo (the)\n        - CK # Cook Islands (the)\n        - CR # Costa Rica\n        - HR # Croatia\n        - CU # Cuba\n        - CW # Curaçao\n        - CY # Cyprus\n        - CZ # Czechia\n        - CI # Côte d'Ivoire\n        - DK # Denmark\n        - DJ # Djibouti\n        - DM # Dominica\n        - DO # Dominican Republic (the)\n        - EC # Ecuador\n        - EG # Egypt\n        - SV # El Salvador\n        - GQ # Equatorial Guinea\n        - ER # Eritrea\n        - EE # Estonia\n        - SZ # Eswatini\n        - ET # Ethiopia\n        - FK # Falkland Islands (the) [Malvinas]\n        - FO # Faroe Islands (the)\n        - FJ # Fiji\n        - FI # Finland\n        - FR # France\n        - GF # French Guiana\n        - PF # French Polynesia\n        - TF # French Southern Territories (the)\n        - GA # Gabon\n        - GM # Gambia (the)\n        - GE # Georgia\n        - DE # Germany\n        - GH # Ghana\n        - GI # Gibraltar\n        - GR # Greece\n        - GL # Greenland\n        - GD # Grenada\n        - GP # Guadeloupe\n        - GU # Guam\n        - GT # Guatemala\n        - GG # Guernsey\n        - GN # Guinea\n        - GW # Guinea-Bissau\n        - GY # Guyana\n        - HT # Haiti\n        - HM # Heard Island and McDonald Islands\n        - VA # Holy See (the)\n        - HN # Honduras\n        - HK # Hong Kong\n        - HU # Hungary\n        - IS # Iceland\n        - IN # India\n        - ID # Indonesia\n        - IR # Iran (Islamic Republic of)\n        - IQ # Iraq\n        - IE # Ireland\n        - IM # Isle of Man\n        - IL # Israel\n        - IT # Italy\n        - JM # Jamaica\n        - JP # Japan\n        - JE # Jersey\n        - JO # Jordan\n        - KZ # Kazakhstan\n        - KE # Kenya\n        - KI # Kiribati\n        - KP # Korea (the Democratic People's Republic of)\n        - KR # Korea (the Republic of)\n        - KW # Kuwait\n        - KG # Kyrgyzstan\n        - LA # Lao People's Democratic Republic (the)\n        - LV # Latvia\n        - LB # Lebanon\n        - LS # Lesotho\n        - LR # Liberia\n        - LY # Libya\n        - LI # Liechtenstein\n        - LT # Lithuania\n        - LU # Luxembourg\n        - MO # Macao\n        - MG # Madagascar\n        - MW # Malawi\n        - MY # Malaysia\n        - MV # Maldives\n        - ML # Mali\n        - MT # Malta\n        - MH # Marshall Islands (the)\n        - MQ # Martinique\n        - MR # Mauritania\n        - MU # Mauritius\n        - YT # Mayotte\n        - MX # Mexico\n        - FM # Micronesia (Federated States of)\n        - MD # Moldova (the Republic of)\n        - MC # Monaco\n        - MN # Mongolia\n        - ME # Montenegro\n        - MS # Montserrat\n        - MA # Morocco\n        - MZ # Mozambique\n        - MM # Myanmar\n        - NA # Namibia\n        - NR # Nauru\n        - NP # Nepal\n        - NL # Netherlands (the)\n        - NC # New Caledonia\n        - NZ # New Zealand\n        - NI # Nicaragua\n        - NE # Niger (the)\n        - NG # Nigeria\n        - NU # Niue\n        - NF # Norfolk Island\n        - MP # Northern Mariana Islands (the)\n        - NO # Norway\n        - OM # Oman\n        - PK # Pakistan\n        - PW # Palau\n        - PS # Palestine, State of\n        - PA # Panama\n        - PG # Papua New Guinea\n        - PY # Paraguay\n        - PE # Peru\n        - PH # Philippines (the)\n        - PN # Pitcairn\n        - PL # Poland\n        - PT # Portugal\n        - PR # Puerto Rico\n        - QA # Qatar\n        - MK # Republic of North Macedonia\n        - RO # Romania\n        - RU # Russian Federation (the)\n        - RW # Rwanda\n        - RE # Réunion\n        - BL # Saint Barthélemy\n        - SH # Saint Helena, Ascension and Tristan da Cunha\n        - KN # Saint Kitts and Nevis\n        - LC # Saint Lucia\n        - MF # Saint Martin (French part)\n        - PM # Saint Pierre and Miquelon\n        - VC # Saint Vincent and the Grenadines\n        - WS # Samoa\n        - SM # San Marino\n        - ST # Sao Tome and Principe\n        - SA # Saudi Arabia\n        - SN # Senegal\n        - RS # Serbia\n        - SC # Seychelles\n        - SL # Sierra Leone\n        - SG # Singapore\n        - SX # Sint Maarten (Dutch part)\n        - SK # Slovakia\n        - SI # Slovenia\n        - SB # Solomon Islands\n        - SO # Somalia\n        - ZA # South Africa\n        - GS # South Georgia and the South Sandwich Islands\n        - SS # South Sudan\n        - ES # Spain\n        - LK # Sri Lanka\n        - SD # Sudan (the)\n        - SR # Suriname\n        - SJ # Svalbard and Jan Mayen\n        - SE # Sweden\n        - CH # Switzerland\n        - SY # Syrian Arab Republic\n        - TW # Taiwan (Province of China)\n        - TJ # Tajikistan\n        - TZ # Tanzania, United Republic of\n        - TH # Thailand\n        - TL # Timor-Leste\n        - TG # Togo\n        - TK # Tokelau\n        - TO # Tonga\n        - TT # Trinidad and Tobago\n        - TN # Tunisia\n        - TR # Turkey\n        - TM # Turkmenistan\n        - TC # Turks and Caicos Islands (the)\n        - TV # Tuvalu\n        - UG # Uganda\n        - UA # Ukraine\n        - AE # United Arab Emirates (the)\n        - GB # United Kingdom of Great Britain and Northern Ireland (the)\n        - UM # United States Minor Outlying Islands (the)\n        - US # United States of America (the)\n        - UY # Uruguay\n        - UZ # Uzbekistan\n        - VU # Vanuatu\n        - VE # Venezuela (Bolivarian Republic of)\n        - VN # Viet Nam\n        - VG # Virgin Islands (British)\n        - VI # Virgin Islands (U.S.)\n        - WF # Wallis and Futuna\n        - EH # Western Sahara\n        - YE # Yemen\n        - ZM # Zambia\n        - ZW # Zimbabwe\n        - AX # Åland Islands\n      fileExtension: 'cidr'\n      logAllowedRequests: false\n      logDetails: true\n      logLocalRequests: true\n      silentStartUp: false\n```\n\n## Configuration options\n\n### Allow local requests: `allowLocalRequests`\n\nIf set to true, will not block request from [Private IP Ranges](https://en.wikipedia.org/wiki/Private_network).\n\nDefaults to `false`.\n\n### CIDR file folder `cidrFileFolder`\n\nThe (mounted) folder with the sub folders `ipv4` and `ipv6` containing the `CIDR` files for each country.\n\nRecommandation is to clone [this project](https://github.com/herrbischoff/country-ip-blocks) and mount it as well as update it in a cron job.\n\n### CIDR file update `cidrFileUpdate`\n\nEnables the hourly update for the CIDR files. Recommended to set to `true`.\n\nDefaults to `true`.\n\n### Countries `countries`\n\nA list of country codes from which connections to the service should be allowed.\n\n### File extension `fileExtension`\n\nThe file extension to use. Defaults to `cidr`. If you use i.e. the [alternative project](https://git.herrbischoff.com/country-ip-blocks-alternative), you should set it to `netset`.\n\n### Log allowed requests `logAllowedRequests`\n\nIf set to true, will show a log message with the IP and the country of origin if a request is allowed.\n\nDefaults to `false`.\n\n### Log details `logDetails`\n\nIf set to true, will show a log message with method calls and more.\n\nDefaults to `true`.\n\n### Log local requests: `logLocalRequests`\n\nIf set to true, will show a log message when some one accesses the service over a private ip address.\n\nDefaults to `true`.\n\n## Contributors\n\n| [\u003cimg alt=\"JonasSchubert\" src=\"https://secure.gravatar.com/avatar/835215bfb654d58acb595c64f107d052?s=180\u0026d=identicon\" width=\"117\"/\u003e](https://code.schubert.zone/jonas-schubert) |\n| :---------------------------------------------------------------------------------------------------------------------------------------: |\n| [Jonas Schubert](https://code.schubert.zone/jonas-schubert) |\n\n## License\n\ntraefik-allow-countries is distributed under the MIT license. [See LICENSE](LICENSE) for details.\n\n```\nMIT License\n\nCopyright (c) 2022-today Jonas Schubert\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonasschubert%2Ftraefik-allow-countries","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjonasschubert%2Ftraefik-allow-countries","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjonasschubert%2Ftraefik-allow-countries/lists"}