Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use caddy-fail2ban for reverse proxy #1

Open
mastervol opened this issue Nov 28, 2024 · 1 comment
Open

Use caddy-fail2ban for reverse proxy #1

mastervol opened this issue Nov 28, 2024 · 1 comment

Comments

@mastervol
Copy link

mastervol commented Nov 28, 2024

Hi.

I would like to use the plugin matcher for reverse_proxy and tried the following.
Anything I missed, should this even work for reverse_proxy as well?
So the abort function seems to work.
If the ip address is in the list, I get an error, so far so good.
However if I remove the ip address I just get a blank page, so I assume I need a directive to continue if the ip is not in the list?

I added the ip to the file banned-ips:
e.g.

1.2.3.4
etc.

Caddy file contents:

a.b.org {
        log {
                format transform "{common_log}"
                output file /var/log/caddy/a.b.org.access.log {
                        roll_size 100MiB
                        roll_keep 10
                        roll_keep_for 200d
                }
        }

        reverse_proxy 192.168.1.107:13378 {

                handle_response {

                        @banned {
                                fail2ban /data/banned-ips
                        }
                        handle @banned {
                                abort

                        }
                }
         }

}

Thanks

@Javex
Copy link
Owner

Javex commented Dec 7, 2024

Hi, sorry for the delay in replying. I haven't used this inside a reverse_proxy block myself so I can't say I've tested this. However, looking at the docs for handle_response you might want to try and pull the directives outside of the block like this:

                @banned {
                        fail2ban /data/banned-ips
                }
                handle_response @banned {
                        abort
                }

I don't know if this is going to work, but it's worth a shot. The plugin should support this, although I found the docs a little confusing so I'm not sure exactly how it'll behave. If you can narrow it down and identify a bug, let me know.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants