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

Add config validate functionality without starting the server #110

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

DavidProdinger
Copy link

@DavidProdinger DavidProdinger commented Sep 27, 2024

New CLI-Flag

I have added the CLI flag -validate which checks the configuration and exits before starting the SPOA server.
Example call:

$ coraza-spoa -validate -config /etc/coraza-spoa/coraza.yaml
Loading 1 applications
Configuration is valid

Why?

When modifying rules, there can happen errors like wrong syntax or duplicate ids.
If they are unnoticed and you restart the coraza-spoa it will crash and the WAF isn't handling any requests anymore.
This flag enables you to check the configuration before running into such troubles.

This feature isn't solving the restart without downtime as in #19, but it minimizes the risk of bigger downtimes.

Other fixes

I fixed the systemd unit file with the wrong syntax InaccessiblePaths=-/bin/find
Fixes #102

David Prodinger added 4 commits September 27, 2024 15:09
Added a flag to validate the configuration without restarting the server
@@ -61,6 +63,11 @@ func main() {
globalLogger.Fatal().Err(err).Msg("Failed creating applications")
}

if validateConfig == true {
globalLogger.Info().Bool("valid", true).Msg("Configuration is valid")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Printing valid=true implies that a invalid config would print false. Instead it would return with exit 1 and another error message. We should probably rework this to return false and not fatal when in check mode.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also this should be added to the CI/E2E test

@@ -28,6 +28,13 @@ coraza-spoa -f /etc/coraza-spoa/coraza-spoa.yaml

You will also want to download & extract the [OWASP Core Ruleset]( https://github.com/coreruleset/coreruleset/releases) (version 4+ supported) to the `/etc/coraza-spoa` directory.

### Validate Configuration
To validate the configuration, you can pass the `-validate` flag, which just loads the configuration and exits.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like our current flag names but because renaming would be a breaking change I left them as they are. I would really like to use haproxy like flags e.g. -c for check mode and supplying the config file as first argument to the process. What do you think about this?

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

Successfully merging this pull request may close these issues.

Systemd service failed
2 participants