Repository navigation
Conversation
|
Alright, I added my changes for now. The only option which I currently have is
and I'm unsure what the cause may be. Another big change is, that there's now only @nicomem may I ask if you can try out my branch if it fixes #445342 for you? Do you get the same error as I do? |
|
Thanks, I'll try your branch and get back to you on my results. I also got this error when I was trying to make it work on my machine but I don't remember exactly what fixed it. |
nicomem
left a comment
There was a problem hiding this comment.
Some feedback from me, looking at the changes before testing it
|
After applying #446307 (comment) and #446307 (comment), the However, it does not work correctly as if I call |
|
From what I have seen, the idiomatic way to make systemd.services.crowdsec.serviceConfig = {
StateDirectory = "crowdsec";
StateDirectoryMode = "0750";
ConfigurationDirectory = "crowdsec";
ConfigurationDirectoryMode = "0750";
}; |
|
People who use impermanence might appreciate |
Hm... should I add an option where the user can enable/disable it or should I just remove the |
After skimming through systemd.exec it looks like you're right. Nice one. Thanks! |
Hmm, I admit that I wasn't aware of this context. I have just been disabling anywhere it bothered me. I'd like some other people to way in on this. The impermanence issue is a bug and will hopefully be fixed sometime in the future, so that shouldn't be the only reason to forgo |
|
Anything I can do to help here? These options seem much more reasonable than the current ones. I'd also like to mention I'm getting this error when trying to run it: This is my current configuration: https://gist.github.com/poperigby/63ef3e5b6205b6a5e4de320bcb63838a |
Aye, testing! What you already did:
Thx! I'll see when I'll get back to this |
|
just tested this and ran into the same error as @poperigby. i looked in the journal and it seems like it needed the api.server.online_client.credentials_path set if anything needs to pull from crowdsec servers (anything on the hub, and possibly acquisitions) in addition the console setup fails and is a bit non intuitive. you need to go to the console and grab just the token out of the command it gives you and paste just that in the console.tokenFile. it then fails as it tries to write the console.yaml into /nix/store, which of course fails due to RO filesystem here is my configuration repo with link pointed to my system flake and the line where the crowdsec specific bits start: https://gitlab.com/Amethyst_Nightshade/nixos-flakes/-/blob/main/nixosConfigurations/tailnerd-agh.nix#L304 |
|
Alright, I'm back!
Hm... this doesn't sound nice.
It looks like as if you've changed your repository. |
|
@SuperSandro2000 Can you review and merge this please? ;) |
|
@TornaxO7 Can we backport this to 26.05 too? |
|
nvm, I think you mean that if we could get the updated module to |
You can do that by adding the backport release-26.05 label to this pr. See https://github.com/NixOS/nixpkgs/blob/master/CONTRIBUTING.md#how-to-backport-pull-requests |
Co-authored-by: Nicolas Mémeint <[email protected]> Co-authored-by: Jarno Pelkonen <[email protected]> Co-authored-by: Yash Garg <[email protected]> Co-authored-by: Gaël James <[email protected]> Co-authored-by: Azat Bahawi <[email protected]>
|
Personally, I think we have missed the boat for a 26.05 merge. As @TornaxO7 says, the rewritten module introduces breaking changes and will require user intervention. I feel like backports are more suitable for important security updates for CVEs and smaller incremental changes. If we wanted a 26.05 merge, we should have been pushing harder for it the last couple of weeks during its merging window. I personally feel we should now have to wait for 26.11. Anyone who is keen for the changes now can just pull from this PR, as many of us are already doing (or unstable if it goes master -> unstable). But that is just my honest and humble opinion, and more than happy for others to overrule me. |
|
Alright, I rebased the changes to the latest master. Also bumped the crowdsec package from |
What are the breaking changes? Normally a backport is also possible for new and updated modules. |
Well I have always used the module from this PR on my nixos system from the start, so I am not 100% on that (I am mostly going off what @TornaxO7 said). My assumption was that, due to the complete rewrite, a user who was previously using the nixpkgs module might need to reconfigure their setup to get crowdsec working again / may run into permission issues. I don't know if this module has a migration path from the older version. If it doesn't introduce breaking changes and doesn't require manual intervention, then sure, I might be able to see a justification for trying for a 26.05 backports merge. On the other hand, that's what merge windows are for, so a complete rewrite seems to me to not be appropriate for a backports update. But like I said, just my opinion. |
@liamthexpl0rer there's no |
|
Thanks for the clarification. I'm currently on nixos-26.05 channel. If this is merged, how I can override my config to get this package from unstable? |
That's... a good question
imports = [
(unstable + "nixos/modules/services/security/crowdsec.nix")
(unstable + "nixos/modules/services/security/crowdsec-firewall-bouncer.nix")
]; |
|
You'll also want to disable the current modules from nixos stable disabledModules = [
"services/security/crowdsec.nix"
"services/security/crowdsec-firewall-bouncer.nix"
];
imports = [
"${inputs.nixpkgs-unstable}/nixos/modules/services/security/crowdsec.nix"
"${inputs.nixpkgs-unstable}/nixos/modules/services/security/crowdsec-firewall-bouncer.nix"
]; |
Thanks! I will test it out after merge (and hydra build). ;) |
|
I'm using flakes und unstable and tried it this way: inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
crowdsec-module = {
url = "github:TornaxO7/nixpkgs/crowdsec";
flake = false;
};Then I disabled the nixpkgs module for one testhost: modules = [
./hosts/host.nix
(
{ config, lib, ... }:
{
disabledModules = [
"services/security/crowdsec.nix"
];
}
)
"${crowdsec-module}/nixos/modules/services/security/crowdsec.nix"
];The build was ok, I tried Not sure if it should work with this input... crowdsec = {
enable = true;
autoUpdateService = true;
hub.collections = [
"crowdsecurity/linux"
"crowdsecurity/nginx"
];
settings = {
config.api.client.credentials_path = "${config.age.secrets.host-crowdsec-lapi-credentials.path}";
acquisitions = [
{
source = "file";
filenames = [
"/var/log/nginx/*.log"
];
labels = {
type = "nginx";
};
}
];
parsers.s02Enrich = [
{
name = "local_network_whitelist";
description = "Ignore local LAN IPs";
whitelist = {
reason = "Local network IP";
cidr = [
"192.168.190.0/24"
];
};
}
];
};
}; |
|
@Peronia the |
|
Okay, I updated my config. inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
crowdsec-module = {
url = "github:TornaxO7/nixpkgs/crowdsec";
flake = false;
};
};
host = {
modules = [
./hosts/host.nix
(
{ ... }:
{
disabledModules = [
"services/security/crowdsec.nix"
];
}
)
"${crowdsec-module}/nixos/modules/services/security/crowdsec.nix"
(
{ ... }:
{
_module.args.crowdsec-module = crowdsec-module;
}
)
];host.nix: let
crowdsecPackage = import "${crowdsec-module}/pkgs/by-name/cr/crowdsec/package.nix" {
inherit (pkgs)
lib
buildGoModule
fetchFromGitHub
installShellFiles
makeWrapper
;
};
in
...
crowdsec = {
enable = true;
package = crowdsecPackage;
... (like post before)The build works, I saw that version 1.7.8 is build, but |
liamthexpl0rer
left a comment
There was a problem hiding this comment.
Looks good to me. I have also deployed it now on one of my servers.
@TornaxO7 Big thanks for your work! I hope this get merged soon. ;)
|
@Peronia Yesterday I have setup crowdsec on my machines. If you need an example, feel free to look into my repo. ^^ |
|
Yeah, we should probably not backport this as is. Maybe the most pressing parts to get things somewhat working. |
| # Ensure the directory exists | ||
| mkdir -p "$(dirname ${apiKeyFile})" || true |
There was a problem hiding this comment.
Maybe we do this in a follow up but this should be done with tmpfiles and there we can use the nix dirname function to avoid shelling.
| if ! cscli bouncers add --output raw -- ${lib.escapeShellArg cfg.registerBouncer.bouncerName} > ${apiKeyFile} 2>&1; then | ||
| echo "Failed to register the bouncer" | ||
| cat ${apiKeyFile} || true # Show error message |
There was a problem hiding this comment.
Why do we redirect stderr to the file to than cat it? Why not just log it? This way we avoid by accident logging the api key.
| fi | ||
| fi | ||
|
|
||
| chmod 0440 ${apiKeyFile} || true |
There was a problem hiding this comment.
This must be done beforehand with umask as we otherwise have a brief moment where the permissions are wrong.
| echo "Failed to register the bouncer" | ||
| cat ${apiKeyFile} || true # Show error message | ||
| rm -f ${apiKeyFile} | ||
| exit 1 |
There was a problem hiding this comment.
| exit 1 | |
| exit 1 |
Otherwise indentation is wrong I think
| # Reason: | ||
| # https://github.com/NixOS/nixpkgs/pull/446307#issuecomment-3955091336 |
There was a problem hiding this comment.
We should copy the reason in code. Than we can also easily update it over time.
| # crowdsec needs the files from caddy | ||
| systemd.services.crowdsec.after = [ "caddy.service" ]; | ||
|
|
||
| # for interactive with non-root users | ||
| security.sudo-rs.enable = true; |
There was a problem hiding this comment.
This seems rather random. Can't we avoid this with an easy workaround?
|
|
||
| # serve local hub | ||
| virtualHosts = { | ||
| "http://${hub-addr}".extraConfig = '' |
There was a problem hiding this comment.
Why not use a simple tool or the standard nginx?
| install -D $out/bin/notification-dummy -t $out/libexec/crowdsec/plugins/ | ||
| install -D $out/bin/notification-email -t $out/libexec/crowdsec/plugins/ | ||
| install -D $out/bin/notification-file -t $out/libexec/crowdsec/plugins/ | ||
| install -D $out/bin/notification-http -t $out/libexec/crowdsec/plugins/ | ||
| install -D $out/bin/notification-sentinel -t $out/libexec/crowdsec/plugins/ | ||
| install -D $out/bin/notification-slack -t $out/libexec/crowdsec/plugins/ | ||
| install -D $out/bin/notification-splunk -t $out/libexec/crowdsec/plugins/ |
There was a problem hiding this comment.
Why copy them instead of moving them?
There was a problem hiding this comment.
We should write a script for that. Can we avoid commiting this file at all?
| SupplementaryGroups = cfg.extraGroups; | ||
|
|
||
| ExecStartPre = "${crowdsec} -t -error"; | ||
| ExecStart = "${crowdsec} -info"; |
There was a problem hiding this comment.
There should be an option to change the log level. It is currently hardcoded to info.
There was a problem hiding this comment.
I applied that in the other PR.
Co-authored-by: Sandro <[email protected]>
|
Alright, this PR continues in #535319. The newer PR solves to additional things compared to this one:
|


This PR should just refactor the
crowdsecmodule. It's almost a total rewrite. So I recommend just to look at the new file instead of the diff.Alright, so after looking a bit through the code, I've got the following suggestion:
configattribute or something similar because in my opinion it's really confusing to have to "config" attributes.The generated config file should bewrittensymlinked to the default path (/etc/crowdsec/config.yaml) which should fix nixos/crowdsec: fatal error when usingcscli explain#445337services.crowdsec.settings.capiandservices.crowdsec.settings.lapisince the user can set them throughservices.crowdsec.settings.general.Feel free to share your thoughts on my suggestions!
Closes #473707
Closes #469519
Closes #459224
Closes #458206
Closes #445342
Closes #445337
Things done
passthru.tests.nixpkgs-reviewon this PR. See nixpkgs-review usage../result/bin/.Add a 👍 reaction to pull requests you find important.