Skip to content

A Traefik plugin to block access to certain paths using a list of regex values and return a defined status code.

License

Notifications You must be signed in to change notification settings

JonasSchubert/traefik-block-paths

Repository files navigation

Traefik Block Paths

A Traefik plugin to block access to certain paths using a list of regex values and return a defined status code.

Configuration

Sample configuration in Traefik.

Configuration as local plugin

traefik.yml

log:
  level: INFO
experimental:
  localPlugins:
    block-paths:
      moduleName: github.com/JonasSchubert/traefik-block-paths

dynamic-configuration.yml

http:
  middlewares:
    block-wp:
      plugin:
        block-paths:
          allowLocalRequests: true
          regex:
            - "^/wp(.*)"
          statusCode: 404

docker-compose.yml

services:
  traefik:
    image: traefik
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock
      - /docker/config/traefik/traefik.yml:/etc/traefik/traefik.yml
      - /docker/config/traefik/dynamic-configuration.yml:/etc/traefik/dynamic-configuration.yml
      - /plugin/block-paths:/plugins-local/src/github.com/JonasSchubert/traefik-block-paths/
    ports:
      - "80:80"
  hello:
    image: containous/whoami
    labels:
      - traefik.enable=true
      - traefik.http.routers.hello.entrypoints=http
      - traefik.http.routers.hello.rule=Host(`hello.localhost`)
      - traefik.http.services.hello.loadbalancer.server.port=80
      - traefik.http.routers.hello.middlewares=my-plugin@file

Sample configuration

  • allowLocalRequests: If set to true, will not block request from Private IP Ranges
  • regex: List of regex values to use for path blocking.
  • statusCode: Return value of the status code.
my-block-paths:
  plugin:
    block-paths:
      allowLocalRequests: true
      regex:
        - "^/wp(.*)"
      statusCode: 404

Contributors

JonasSchubert
Jonas Schubert

License

traefik-block-paths is distributed under the MIT license. See LICENSE for details.

MIT License

Copyright (c) 2023-today Jonas Schubert

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

About

A Traefik plugin to block access to certain paths using a list of regex values and return a defined status code.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages