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

New configuration not loaded on Caddy reload #89

Closed
skixmix opened this issue Jul 17, 2023 · 7 comments
Closed

New configuration not loaded on Caddy reload #89

skixmix opened this issue Jul 17, 2023 · 7 comments

Comments

@skixmix
Copy link
Contributor

skixmix commented Jul 17, 2023

Hi,

You may have noticed that I am actively testing the module before utilizing it in production (kudos for the excellent work, by the way 😄 ). During my recent tests, I observed that in both versions 1.x and 2.x, the WAF configurations are not refreshed when I make changes to the .conf file and reload Caddy. However, if I restart the Caddy service, it functions properly (of course...).

This is associated with #11, which is closed, but reloading Caddy after modifying my configuration file, as mentioned, doesn't work.

Currently, the only method I have found is to modify the file name with an added random number, but this approach is not really "clean". Do you know if there is an alternative way to completely reload the WAF configuration for a specific site without restarting Caddy?

Thank you,
Simone

@skixmix
Copy link
Contributor Author

skixmix commented Jul 17, 2023

Ok sorry I think I found the issue.

Essentially, Caddy operates in a manner where if it does not detect any alterations in the configuration (even if we modify sections), it does not execute an actual reload and instead displays a message similar to:

{"level":"info","ts":1689607946.3474102,"msg":"config is unchanged"}
{"level":"info","ts":1689607946.3475072,"logger":"admin.api","msg":"load complete"}

This happens if for example we have a configuration like:

(1_waf) {
        coraza_waf {
			include /myconfig.conf
        }
}

and somewhere in the config we import it:

import 1_waf

By modifying it to (2_waf) and importing it with (2_waf), Caddy omits the block name and acknowledges that no modifications were made. The only option is to make an actual alteration in the current configuration, such as changing /myconfig.conf to /myconfig1.conf. Currently, instead of altering the file name, I am appending a custom header with a random value, which is a more cost-effective alternative compared to changing the file name.

Do you have other ideas?

Thank you,
Simone

@jcchavezs
Copy link
Member

jcchavezs commented Jul 17, 2023 via email

@jcchavezs
Copy link
Member

jcchavezs commented Jul 17, 2023 via email

@mholt
Copy link

mholt commented Jul 17, 2023

Caddy compares the new config with the old one when reloads occur. If the old config is 100% identical, it skips a reload because there's no need to change the config. Note that it compares the adapted JSON, not the input Caddyfile. Snippets (their names and structure) are all known only to the Caddyfile adapter; simply changing the name of a snippet doesn't constitute a change in the final JSON config.

A config reload can be forced though, using caddy reload --force (or if you're using the API, by setting the Cache-Control: must-revalidate header) even if there are no changes.

@skixmix
Copy link
Contributor Author

skixmix commented Jul 18, 2023

Hi,

Sure, I checked out this section in the Caddy documentation yesterday. I gave it a try, and it's working smoothly now, without requiring any extra steps.

Thanks! 😃

@skixmix skixmix closed this as completed Jul 18, 2023
@jcchavezs
Copy link
Member

jcchavezs commented Jul 18, 2023 via email

skixmix added a commit to skixmix/coraza-caddy that referenced this issue Jul 19, 2023
Added Throubleshooting.md following issue corazawaf#89
@skixmix
Copy link
Contributor Author

skixmix commented Jul 19, 2023

Hello,

Certainly, I submitted the PR 😄

jcchavezs pushed a commit that referenced this issue Jul 19, 2023
Added Throubleshooting.md following issue #89
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

3 participants