Skip to content

Commit

Permalink
feat: add systemd
Browse files Browse the repository at this point in the history
  • Loading branch information
GTrunSec committed Dec 13, 2023
1 parent 0cff035 commit baaec4d
Show file tree
Hide file tree
Showing 8 changed files with 106 additions and 17 deletions.
9 changes: 9 additions & 0 deletions nix/src/pops/lego.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
omnibus,
projectDir,
inputs,
}:
omnibus.pops.load {
src = projectDir + /units/lego;
inputs = {};
}
23 changes: 13 additions & 10 deletions nix/src/pops/nixosProfiles.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@
};
};
};
nixos = eachSystem (system: omnibus.pops.nixosProfiles.addLoadExtender {
load = {
src = projectDir + /units/nixosProfiles;
type = "nixosProfilesOmnibus";
inputs = {
inherit system;
inputs = inputs // {
inherit ((omnibus.flake.setSystem system).inputs) nixos-23_11;
nixos = eachSystem (
system:
omnibus.pops.nixosProfiles.addLoadExtender {
load = {
src = projectDir + /units/nixosProfiles;
type = "nixosProfilesOmnibus";
inputs = {
inherit system;
inputs = inputs // {
inherit ((omnibus.flake.setSystem system).inputs) nixos-23_11;
};
};
};
};
});
}
);
}
6 changes: 4 additions & 2 deletions nix/std/cells/repo/nixago.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,10 @@ in

nginx = inputs.std.lib.dev.mkNixago {
data = {
ansible-collection-hardening = inputs.lego-hardening.units.ansible-collection-hardening.${nixpkgs.system}.nginx.argument_specs;
nixos = inputs.lego-hardening.units.nixosProfiles.nixos.${nixpkgs.system}.options.nginxNixosOptionsDocJson;
ansible-collection-hardening =
inputs.lego-hardening.units.ansible-collection-hardening.${nixpkgs.system}.nginx.argument_specs;
nixos =
inputs.lego-hardening.units.nixosProfiles.nixos.${nixpkgs.system}.options.nginxNixosOptionsDocJson;
};
output = "compare/nginx.yml";
format = "yaml";
Expand Down
10 changes: 7 additions & 3 deletions nix/std/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,13 @@
{std, call-flake, ...}@inputs:
std.growOn
{
inputs = inputs // (call-flake ../lock).inputs // (call-flake ../..).inputs // {
lego-hardening = call-flake ../..;
};
inputs =
inputs
// (call-flake ../lock).inputs
// (call-flake ../..).inputs
// {
lego-hardening = call-flake ../..;
};
cellsFrom = ./cells;

cellBlocks = with std.blockTypes; [
Expand Down
3 changes: 2 additions & 1 deletion units/dev-sec/ansible-collection-hardening/nginx.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
{ansibleCollectionHardeningSrc}:
let
defaults = ansibleCollectionHardeningSrc.roles.nginx_hardening.defaults.main;
argument_specs = ansibleCollectionHardeningSrc.roles.nginx_hardening.meta.argument_specs;
argument_specs =
ansibleCollectionHardeningSrc.roles.nginx_hardening.meta.argument_specs;
in
{
inherit defaults argument_specs;
Expand Down
11 changes: 11 additions & 0 deletions units/lego/os/sysctl.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
default = [
{
keywords = ["sysctl"];
knowlaedges = [
" https://madaidans-insecurities.github.io/guides/linux-hardening.html#sysctl"
];
profiles = [];
}
];
}
55 changes: 55 additions & 0 deletions units/lego/os/systemd.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{self}:
{
isolate = {
CapabilityBoundingSet = "";
DeviceAllow = "";
IPAddressDeny = "any";
KeyringMode = "private";
LockPersonality = true;
MemoryDenyWriteExecute = true;
NoNewPrivileges = true;
NotifyAccess = "none";
ProcSubset = "pid";
RemoveIPC = true;

PrivateDevices = true;
PrivateMounts = true;
PrivateNetwork = true;
PrivateTmp = true;
PrivateUsers = true;

ProtectClock = true;
ProtectControlGroups = true;
ProtectHome = true;
ProtectKernelLogs = true;
ProtectKernelModules = true;
ProtectKernelTunables = true;
ProtectHostname = true;
ProtectProc = "invisible";
ProtectSystem = "strict";
RestrictAddressFamilies = "";
RestrictNamespaces = true;
RestrictRealtime = true;
RestrictSUIDSGID = true;
};
cap = {
AmbientCapabilities = [
"CAP_NET_BIND_SERVICE"
"CAP_NET_RAW"
];
CapabilityBoundingSet = ["CAP_NET_BIND_SERVICE"];
};

networked = self.isolate // {
IPAddressDeny = [""];
PrivateNetwork = false;
RestrictAddressFamilies = [
"AF_INET"
"AF_INET6"
];
};

socketed = self.isolate // {
RestrictAddressFamilies = ["AF_UNIX"];
};
}
6 changes: 5 additions & 1 deletion units/nixosProfiles/options.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,9 @@
nginxNixosOptionsDoc = inputs.nixos-23_11.legacyPackages.nixosOptionsDoc {
options = self.nginx.options.services.nginx;
};
nginxNixosOptionsDocJson = builtins.fromJSON (builtins.readFile (self.nginxNixosOptionsDoc.optionsJSON + "/share/doc/nixos/options.json"));
nginxNixosOptionsDocJson = builtins.fromJSON (
builtins.readFile (
self.nginxNixosOptionsDoc.optionsJSON + "/share/doc/nixos/options.json"
)
);
}

0 comments on commit baaec4d

Please sign in to comment.