nixos/services/crowdsec: add data sources option

This commit is contained in:
Gabriel Arazas 2024-09-18 09:49:03 +08:00
parent 30a39a2fd8
commit c5eac6f3f9
No known key found for this signature in database
GPG Key ID: 62104B43D00AA360

View File

@ -16,7 +16,7 @@ let
default = pluginsConfigDrv; default = pluginsConfigDrv;
defaultText = '' defaultText = ''
All of the compiled configuration files from All of the compiled configuration files from
{option}`services.crowdsec.plugins.settings`. {option}`services.crowdsec.plugins.<name>.settings`.
''; '';
example = "./config/crowdsec/plugins"; example = "./config/crowdsec/plugins";
}; };
@ -29,28 +29,56 @@ let
default = pluginsDir; default = pluginsDir;
defaultText = '' defaultText = ''
All of the compiled plugins from All of the compiled plugins from
{options}`services.crowdsec.plugins.package`. {options}`services.crowdsec.plugins.<name>.package`.
''; '';
}; };
}; };
options.crowdsec_service = {
acqusition_dir = lib.mkOption {
type = lib.types.path;
description = ''
Directory containing acqusition configurations.
'';
default = acqusitionsDir;
defaultText = ''
All of the compiled configuration from
{options}`services.crowdsec.acqusitions.<name>.settings`.
'';
example = "./config/crowdsec/acqusitions";
};
};
}; };
pluginsDir = pkgs.symlinkJoin { pluginsDir = pkgs.symlinkJoin {
name = "crowdsec-system-plugins"; name = "crowdsec-system-plugins";
paths = lib.mapAttrsToList (n: v: "${v.package}/share/crowdsec") cfg.plugins; paths =
let
plugins = lib.filterAttrs (n: v: v.package != null) cfg.plugins;
in
lib.mapAttrsToList (n: v: "${v.package}/share/crowdsec") plugins;
}; };
pluginsConfigDrv = let pluginsConfigDrv = let
pluginsConfigs = pluginsConfigs =
lib.mapAttrsToList lib.mapAttrsToList
(n: v: (n: v: settingsFormat.generate "crowdsec-system-plugin-config-${n}" v.settings)
pkgs.writeTextDir "/notifications/${n}.yaml" (lib.generators.toYAML { } v.settings))
cfg.plugins; cfg.plugins;
in pkgs.symlinkJoin { in pkgs.symlinkJoin {
name = "crowdsec-system-plugins-configs"; name = "crowdsec-system-plugins-configs";
paths = pluginsConfigs; paths = pluginsConfigs;
}; };
acqusitionsDir = let
acqusitionConfigs =
lib.mapAttrsToList
(n: v: settingsFormat.generate "crowdsec-system-acqusition-config-${n}" v.settings)
cfg.dataSources;
in pkgs.symlinkJoin {
name = "crowdsec-system-acqusitions-configs";
paths = acqusitionConfigs;
};
crowdsecPluginsModule = { name, config, ... }: { crowdsecPluginsModule = { name, config, ... }: {
options = { options = {
settings = lib.mkOption { settings = lib.mkOption {
@ -82,6 +110,22 @@ let
}; };
}; };
acqusitionsSubmodule = { name, config, ... }: {
options.settings = lib.mkOption {
type = settingsFormat.type;
description = ''
Configuration associated with each data source.
'';
default = { };
example = {
source = "journalctl";
journalctl_filter = [
"_SYSTEMD_UNIT=ssh.service"
];
};
};
};
configFile = settingsFormat.generate "crowdsec-config" cfg.settings; configFile = settingsFormat.generate "crowdsec-config" cfg.settings;
in in
{ {
@ -140,6 +184,31 @@ in
} }
''; '';
}; };
dataSources = lib.mkOption {
type = with lib.types; attrsOf (submodule acqusitionsSubmodule);
description = ''
Set of data sources where logs are to be analyzed from.
::: {.caution}
This is to be included as part of the default acqusition configuration
directory.
If {option}`services.crowdsec.settings.crowdsec_agent.acqusition_dir`
is set by the user, this option is effectively ignored.
:::
'';
default = { };
example = {
ssh = {
source = "journalctl";
journalctl_filter = [
"_SYSTEMD_UNIT=ssh.service"
];
labels.type = "syslog";
};
};
};
}; };
config = lib.mkIf cfg.enable { config = lib.mkIf cfg.enable {