Compare commits

...

12 commits

Author SHA1 Message Date
fc090a010c Alpine 3.17.1
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2023-01-15 18:00:36 -03:00
37ad9e62a2 nftables
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2022-11-17 22:50:56 -03:00
e9edb55a47 data: Sobreescribir si ya existe
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-11-17 22:38:39 -03:00
962493f352 Alpine 3.16.3
Some checks failed
ci/woodpecker/push/woodpecker Pipeline failed
2022-11-17 22:29:10 -03:00
986a5cc1ee qemu.sh: quiet 2022-11-17 22:28:55 -03:00
4622625570 runit: poweroff/reboot scripts 2022-11-17 22:28:32 -03:00
88e9406963 runit: Arreglar reboot 2022-11-17 22:28:19 -03:00
320e94b40d runit: Iniciar tty en serial 2022-11-17 22:25:55 -03:00
95a43f2c8b ntpsec
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
2022-09-26 19:32:55 -03:00
76d0f675b8 qemu.sh: No confirmar el wipe de tmp.ext4 2022-09-26 19:32:31 -03:00
11c685fbaf runit: Explicitar 2022-09-26 19:32:26 -03:00
f595076479 qemu.sh: Arreglar/aclarar formatos
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful
tmp.qcow2 nunca se usaba como qcow2 porque se convertía en ext4 como si fuese un archivo raw
2022-09-12 13:42:18 -03:00
7 changed files with 160 additions and 9 deletions

2
.gitignore vendored
View file

@ -3,4 +3,4 @@ v00001/
boot/
image.squashfs
cache/
tmp.qcow2
tmp.ext4

View file

@ -31,7 +31,7 @@ mount '{{path}}' '{{mountpoint}}' -o bind,umask=100,uid={{uid}},gid={{gid}} || e
local link = links[i]
string = string .. t([[
mkdir -p '{{dirname}}' || exit 1
ln -s '{{target}}' '{{path}}' || exit 1
ln -sf '{{target}}' '{{path}}' || exit 1
]],
{ dirname = utils.dirname(link.path),
target = link.target, path = link.path }

95
modules/nftables.lua Normal file
View file

@ -0,0 +1,95 @@
modules.nftables = {}
add_packages({ "nftables" })
add_file("/etc/nftables.nft", [[
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain input {
type filter hook input priority 0; policy drop;
iifname lo accept \
comment "Accept any localhost traffic"
ct state { established, related } accept \
comment "Accept traffic originated from us"
ct state invalid drop \
comment "Drop invalid connections"
tcp dport 113 reject with icmpx type port-unreachable \
comment "Reject AUTH to make it fail fast"
ip protocol icmp icmp type {
echo-reply, # type 0
destination-unreachable, # type 3
echo-request, # type 8
time-exceeded, # type 11
parameter-problem, # type 12
} accept \
comment "Accept ICMP"
ip6 nexthdr icmpv6 icmpv6 type {
destination-unreachable, # type 1
packet-too-big, # type 2
time-exceeded, # type 3
parameter-problem, # type 4
echo-request, # type 128
echo-reply, # type 129
} accept \
comment "Accept basic IPv6 functionality"
ip6 nexthdr icmpv6 icmpv6 type {
nd-router-solicit, # type 133
nd-router-advert, # type 134
nd-neighbor-solicit, # type 135
nd-neighbor-advert, # type 136
} ip6 hoplimit 255 accept \
comment "Allow IPv6 SLAAC"
ip6 nexthdr icmpv6 icmpv6 type {
mld-listener-query, # type 130
mld-listener-report, # type 131
mld-listener-reduction, # type 132
mld2-listener-report, # type 143
} ip6 saddr fe80::/10 accept \
comment "Allow IPv6 multicast listener discovery on link-local"
ip6 saddr fe80::/10 udp sport 547 udp dport 546 accept \
comment "Accept DHCPv6 replies from IPv6 link-local addresses"
tcp dport 80 counter accept \
comment "Allow HTTP"
}
chain forward {
type filter hook forward priority 0; policy drop;
}
chain output {
type filter hook output priority 0; policy accept;
}
}
# The state of stateful objects saved on the nftables service stop.
include "/var/lib/nftables/*.nft"
]])
modules.runit.add_service("nftables", [[#!/bin/sh
if [ ! -r /etc/nftables.nft ]; then
echo "No config, dropping everything"
nft -f /dev/stdin <<-EOF
flush ruleset
table inet filter {
chain input { type filter hook input priority 0; policy drop; }
chain forward { type filter hook forward priority 0; policy drop; }
chain output { type filter hook output priority 0; policy drop; }
}
EOF
exit 1
fi
nft -f /etc/nftables.nft
exec sleep infinity
]])

42
modules/ntpsec.lua Normal file
View file

@ -0,0 +1,42 @@
add_packages({ "ntpsec" })
-- In the ntpsec-doc package, open in browser:
-- file:///usr/share/doc/ntpsec/quick.html
-- file:///usr/share/doc/ntpsec/NTS-QuickStart.html
add_file("/etc/ntp.conf", [[
driftfile /var/lib/ntp/ntp.drift
restrict default kod limited nomodify nopeer noquery
restrict 127.0.0.1
restrict ::1
# https://gist.github.com/jauderho/2ad0d441760fc5ed69d8d4e2d6b35f8d
server time.cloudflare.com nts iburst
server nts.ntp.se nts iburst
# https://nts.time.nl/
server ntppool1.time.nl nts iburst
server ntppool2.time.nl nts iburst
# https://system76.com/time/
server paris.time.system76.com nts iburst
server brazil.time.system76.com nts iburst
# https://www.netnod.se/netnod-time/how-to-use-nts
server sth1.nts.netnod.se nts iburst
server sth2.nts.netnod.se nts iburst
# https://ntp.br/guia/linux/
server a.st1.ntp.br nts iburst
server b.st1.ntp.br nts iburst
server c.st1.ntp.br nts iburst
server d.st1.ntp.br nts iburst
server gps.ntp.br nts iburst
]])
modules.runit.add_service("ntpsec", [[#!/bin/sh
exec ntpd --nice --nofork --panicgate
]])

View file

@ -2,6 +2,7 @@ mkdir("/etc/runit/runsvdir/default")
add_symlink("/etc/runit/runsvdir/current", "/etc/runit/runsvdir/default")
add_symlink("/etc/service", "/etc/runit/runsvdir/current")
add_symlink("/etc/runit/stopit", "/run/runit/stopit")
add_symlink("/etc/runit/reboot", "/run/runit/reboot")
local t = require "../utils/templater"
local function add_executable(path, script)
@ -26,6 +27,7 @@ exec logger -p daemon.info -t {{name}}]], params))
)
end
add_executable(run_script_path, script)
-- Activar servicio
add_symlink("/etc/runit/runsvdir/default/"..name, "/etc/sv/"..name)
add_symlink(
t("/etc/sv/{{name}}/supervise", params),
@ -360,9 +362,17 @@ if [ -z "$VIRTUALIZATION" ]; then
fi
]])
-- https://wiki.gentoo.org/wiki/Runit#Reboot_and_shutdown
add_executable("/usr/local/sbin/rpoweroff", [[#!/bin/sh
runit-init 0]])
add_executable("/usr/local/sbin/rreboot", [[#!/bin/sh
runit-init 6]])
add_packages({ "runit", "eudev" })
modules.runit.add_service("getty-tty1", [[#!/bin/sh
exec chpst -P getty 38400 tty1 linux]], false)
modules.runit.add_service("getty-tty2", [[#!/bin/sh
exec chpst -P getty 38400 tty2 linux]], false)
modules.runit.add_service("getty-ttyS0", [[#!/bin/sh
exec chpst -P getty 38400 ttyS0 linux]], false)

12
qemu.sh
View file

@ -5,12 +5,14 @@ if test "$NOGRAPHIC" = true; then
qemuappend="-nographic"
fi
qemu-img create -f qcow2 tmp.qcow2 1G
mkfs.ext4 tmp.qcow2
fallocate --length 1G tmp.ext4
mkfs.ext4 -F tmp.ext4
sudo chown root:$(id -u) -R boot/ && sudo chmod g+rw -R boot/
qemu-system-x86_64 -enable-kvm -m 2048 \
-drive file=image.squashfs,media=disk \
-drive file=tmp.qcow2,media=disk \
-drive file=image.squashfs,media=disk,format=raw \
-drive file=tmp.ext4,media=disk,format=raw \
-net nic,model=virtio-net-pci \
-net user,hostfwd=tcp:10.69.0.2:8080-:80 \
-kernel boot/vmlinuz-virt -initrd boot/initramfs-virt \
-append "root=/dev/sda rootfstype=squashfs modules=ext4 init=/sbin/runit-init $append" $qemuappend
-append "root=/dev/sda rootfstype=squashfs modules=ext4 quiet init=/sbin/runit-init $append" $qemuappend

View file

@ -1,8 +1,8 @@
local utils = require("utils")
local alpine = require("alpine")
local alpine_base_version = "3.16"
local alpine_version = alpine_base_version..".0"
local alpine_base_version = "3.17"
local alpine_version = alpine_base_version..".1"
local packages = {
"alpine-baselayout",
-- "alpine-conf",
@ -47,7 +47,9 @@ module "runit"
module "socklog"
module "hostname"
module "dhcpcd"
module "ntpsec"
module "nginx"
module "nftables"
print("=> Installing and upgrading packages...")
utils.expect_nil(alpine.make_world(root, packages))