13 Commits

37 changed files with 1393 additions and 362 deletions

View File

@ -1,3 +1,9 @@
Dockerfile Dockerfile
tmp/**/* tmp/**/*
dist/* dist/*
go.work
go.work.sum
modd.*conf
test-initrd*
test-initrd/**/*
target

3
.gitignore vendored
View File

@ -3,3 +3,6 @@
/qemu.pid /qemu.pid
/test-initrd.cpio /test-initrd.cpio
/tmp /tmp
/go.work
/go.work.sum
/target

569
Cargo.lock generated Normal file
View File

@ -0,0 +1,569 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "addr2line"
version = "0.22.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678"
dependencies = [
"gimli",
]
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]]
name = "aho-corasick"
version = "1.1.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e60d3430d3a69478ad0993f19238d2df97c507009a52b3c10addcd7f6bcb916"
dependencies = [
"memchr",
]
[[package]]
name = "anstream"
version = "0.6.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "418c75fa768af9c03be99d17643f93f79bbba589895012a80e3452a19ddda15b"
dependencies = [
"anstyle",
"anstyle-parse",
"anstyle-query",
"anstyle-wincon",
"colorchoice",
"is_terminal_polyfill",
"utf8parse",
]
[[package]]
name = "anstyle"
version = "1.0.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "038dfcf04a5feb68e9c60b21c9625a54c2c0616e79b72b0fd87075a056ae1d1b"
[[package]]
name = "anstyle-parse"
version = "0.2.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c03a11a9034d92058ceb6ee011ce58af4a9bf61491aa7e1e59ecd24bd40d22d4"
dependencies = [
"utf8parse",
]
[[package]]
name = "anstyle-query"
version = "1.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a64c907d4e79225ac72e2a354c9ce84d50ebb4586dee56c82b3ee73004f537f5"
dependencies = [
"windows-sys 0.52.0",
]
[[package]]
name = "anstyle-wincon"
version = "3.0.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "61a38449feb7068f52bb06c12759005cf459ee52bb4adc1d5a7c4322d716fb19"
dependencies = [
"anstyle",
"windows-sys 0.52.0",
]
[[package]]
name = "anyhow"
version = "1.0.86"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b3d1d046238990b9cf5bcde22a3fb3584ee5cf65fb2765f454ed428c7a0063da"
[[package]]
name = "backtrace"
version = "0.3.73"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a"
dependencies = [
"addr2line",
"cc",
"cfg-if",
"libc",
"miniz_oxide",
"object",
"rustc-demangle",
]
[[package]]
name = "bytes"
version = "1.6.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "514de17de45fdb8dc022b1a7975556c53c86f9f0aa5f534b98977b171857c2c9"
[[package]]
name = "cc"
version = "1.0.101"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ac367972e516d45567c7eafc73d24e1c193dcf200a8d94e9db7b3d38b349572d"
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "colorchoice"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b6a852b24ab71dffc585bcb46eaf7959d175cb865a7152e35b348d1b2960422"
[[package]]
name = "env_filter"
version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a009aa4810eb158359dda09d0c87378e4bbb89b5a801f016885a4707ba24f7ea"
dependencies = [
"log",
"regex",
]
[[package]]
name = "env_logger"
version = "0.11.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "38b35839ba51819680ba087cd351788c9a3c476841207e0b8cee0b04722343b9"
dependencies = [
"anstream",
"anstyle",
"env_filter",
"humantime",
"log",
]
[[package]]
name = "equivalent"
version = "1.0.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5"
[[package]]
name = "gimli"
version = "0.29.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd"
[[package]]
name = "hashbrown"
version = "0.14.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e5274423e17b7c9fc20b6e7e208532f9b19825d82dfd615708b70edd83df41f1"
[[package]]
name = "humantime"
version = "2.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a3a5bfb195931eeb336b2a7b4d761daec841b97f947d34394601737a7bba5e4"
[[package]]
name = "indexmap"
version = "2.2.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "168fb715dda47215e360912c096649d23d58bf392ac62f73919e831745e40f26"
dependencies = [
"equivalent",
"hashbrown",
]
[[package]]
name = "init"
version = "0.1.0"
dependencies = [
"anyhow",
"env_logger",
"log",
"serde",
"serde_json",
"serde_yaml",
"tokio",
]
[[package]]
name = "is_terminal_polyfill"
version = "1.70.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f8478577c03552c21db0e2724ffb8986a5ce7af88107e6be5d2ee6e158c12800"
[[package]]
name = "itoa"
version = "1.0.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "49f1f14873335454500d59611f1cf4a4b0f786f9ac11f4312a78e4cf2566695b"
[[package]]
name = "libc"
version = "0.2.155"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "97b3888a4aecf77e811145cadf6eef5901f4782c53886191b2f693f24761847c"
[[package]]
name = "log"
version = "0.4.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "90ed8c1e510134f979dbc4f070f87d4313098b704861a105fe34231c70a3901c"
[[package]]
name = "memchr"
version = "2.7.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
[[package]]
name = "miniz_oxide"
version = "0.7.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08"
dependencies = [
"adler",
]
[[package]]
name = "mio"
version = "0.8.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a4a650543ca06a924e8b371db273b2756685faae30f8487da1b56505a8f78b0c"
dependencies = [
"libc",
"wasi",
"windows-sys 0.48.0",
]
[[package]]
name = "object"
version = "0.36.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434"
dependencies = [
"memchr",
]
[[package]]
name = "pin-project-lite"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02"
[[package]]
name = "proc-macro2"
version = "1.0.81"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3d1597b0c024618f09a9c3b8655b7e430397a36d23fdafec26d6965e9eec3eba"
dependencies = [
"unicode-ident",
]
[[package]]
name = "quote"
version = "1.0.36"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fa76aaf39101c457836aec0ce2316dbdc3ab723cdda1c6bd4e6ad4208acaca7"
dependencies = [
"proc-macro2",
]
[[package]]
name = "regex"
version = "1.10.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c117dbdfde9c8308975b6a18d71f3f385c89461f7b3fb054288ecf2a2058ba4c"
dependencies = [
"aho-corasick",
"memchr",
"regex-automata",
"regex-syntax",
]
[[package]]
name = "regex-automata"
version = "0.4.6"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "86b83b8b9847f9bf95ef68afb0b8e6cdb80f498442f5179a29fad448fcc1eaea"
dependencies = [
"aho-corasick",
"memchr",
"regex-syntax",
]
[[package]]
name = "regex-syntax"
version = "0.8.3"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "adad44e29e4c806119491a7f06f03de4d1af22c3a680dd47f1e6e179439d1f56"
[[package]]
name = "rustc-demangle"
version = "0.1.24"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
[[package]]
name = "ryu"
version = "1.0.17"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e86697c916019a8588c99b5fac3cead74ec0b4b819707a682fd4d23fa0ce1ba1"
[[package]]
name = "serde"
version = "1.0.199"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0c9f6e76df036c77cd94996771fb40db98187f096dd0b9af39c6c6e452ba966a"
dependencies = [
"serde_derive",
]
[[package]]
name = "serde_derive"
version = "1.0.199"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "11bd257a6541e141e42ca6d24ae26f7714887b47e89aa739099104c7e4d3b7fc"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "serde_json"
version = "1.0.116"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3e17db7126d17feb94eb3fad46bf1a96b034e8aacbc2e775fe81505f8b0b2813"
dependencies = [
"itoa",
"ryu",
"serde",
]
[[package]]
name = "serde_yaml"
version = "0.9.34+deprecated"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47"
dependencies = [
"indexmap",
"itoa",
"ryu",
"serde",
"unsafe-libyaml",
]
[[package]]
name = "signal-hook-registry"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
dependencies = [
"libc",
]
[[package]]
name = "syn"
version = "2.0.60"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "909518bc7b1c9b779f1bbf07f2929d35af9f0f37e47c6e9ef7f9dddc1e1821f3"
dependencies = [
"proc-macro2",
"quote",
"unicode-ident",
]
[[package]]
name = "tokio"
version = "1.38.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ba4f4a02a7a80d6f274636f0aa95c7e383b912d41fe721a31f29e29698585a4a"
dependencies = [
"backtrace",
"bytes",
"libc",
"mio",
"pin-project-lite",
"signal-hook-registry",
"tokio-macros",
"windows-sys 0.48.0",
]
[[package]]
name = "tokio-macros"
version = "2.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5f5ae998a069d4b5aba8ee9dad856af7d520c3699e6159b185c2acd48155d39a"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "unicode-ident"
version = "1.0.12"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "3354b9ac3fae1ff6755cb6db53683adb661634f67557942dea4facebec0fee4b"
[[package]]
name = "unsafe-libyaml"
version = "0.2.11"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "673aac59facbab8a9007c7f6108d11f63b603f7cabff99fabf650fea5c32b861"
[[package]]
name = "utf8parse"
version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "711b9620af191e0cdc7468a8d14e709c3dcdb115b36f838e601583af800a370a"
[[package]]
name = "wasi"
version = "0.11.0+wasi-snapshot-preview1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423"
[[package]]
name = "windows-sys"
version = "0.48.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "677d2418bec65e3338edb076e806bc1ec15693c5d0104683f2efe857f61056a9"
dependencies = [
"windows-targets 0.48.5",
]
[[package]]
name = "windows-sys"
version = "0.52.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d"
dependencies = [
"windows-targets 0.52.5",
]
[[package]]
name = "windows-targets"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a2fa6e2155d7247be68c096456083145c183cbbbc2764150dda45a87197940c"
dependencies = [
"windows_aarch64_gnullvm 0.48.5",
"windows_aarch64_msvc 0.48.5",
"windows_i686_gnu 0.48.5",
"windows_i686_msvc 0.48.5",
"windows_x86_64_gnu 0.48.5",
"windows_x86_64_gnullvm 0.48.5",
"windows_x86_64_msvc 0.48.5",
]
[[package]]
name = "windows-targets"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "6f0713a46559409d202e70e28227288446bf7841d3211583a4b53e3f6d96e7eb"
dependencies = [
"windows_aarch64_gnullvm 0.52.5",
"windows_aarch64_msvc 0.52.5",
"windows_i686_gnu 0.52.5",
"windows_i686_gnullvm",
"windows_i686_msvc 0.52.5",
"windows_x86_64_gnu 0.52.5",
"windows_x86_64_gnullvm 0.52.5",
"windows_x86_64_msvc 0.52.5",
]
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "2b38e32f0abccf9987a4e3079dfb67dcd799fb61361e53e2882c3cbaf0d905d8"
[[package]]
name = "windows_aarch64_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7088eed71e8b8dda258ecc8bac5fb1153c5cffaf2578fc8ff5d61e23578d3263"
[[package]]
name = "windows_aarch64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "dc35310971f3b2dbbf3f0690a219f40e2d9afcf64f9ab7cc1be722937c26b4bc"
[[package]]
name = "windows_aarch64_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9985fd1504e250c615ca5f281c3f7a6da76213ebd5ccc9561496568a2752afb6"
[[package]]
name = "windows_i686_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a75915e7def60c94dcef72200b9a8e58e5091744960da64ec734a6c6e9b3743e"
[[package]]
name = "windows_i686_gnu"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "88ba073cf16d5372720ec942a8ccbf61626074c6d4dd2e745299726ce8b89670"
[[package]]
name = "windows_i686_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "87f4261229030a858f36b459e748ae97545d6f1ec60e5e0d6a3d32e0dc232ee9"
[[package]]
name = "windows_i686_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8f55c233f70c4b27f66c523580f78f1004e8b5a8b659e05a4eb49d4166cca406"
[[package]]
name = "windows_i686_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "db3c2bf3d13d5b658be73463284eaf12830ac9a26a90c717b7f771dfe97487bf"
[[package]]
name = "windows_x86_64_gnu"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "53d40abd2583d23e4718fddf1ebec84dbff8381c07cae67ff7768bbf19c6718e"
[[package]]
name = "windows_x86_64_gnu"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4e4246f76bdeff09eb48875a0fd3e2af6aada79d409d33011886d3e1581517d9"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0b7b52767868a23d5bab768e390dc5f5c55825b6d30b86c844ff2dc7414044cc"
[[package]]
name = "windows_x86_64_gnullvm"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "852298e482cd67c356ddd9570386e2862b5673c85bd5f88df9ab6802b334c596"
[[package]]
name = "windows_x86_64_msvc"
version = "0.48.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "ed94fce61571a4006852b7389a063ab983c02eb1bb37b47f8272ce92d06d9538"
[[package]]
name = "windows_x86_64_msvc"
version = "0.52.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bec47e5bfd1bff0eeaf6d8b485cc1074891a197ab4225d504cb7a1ab88b02bf0"

15
Cargo.toml Normal file
View File

@ -0,0 +1,15 @@
[package]
name = "init"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
anyhow = "1.0.86"
env_logger = "0.11.3"
log = "0.4.21"
serde = { version = "1.0.198", features = ["derive"] }
serde_json = "1.0.116"
serde_yaml = "0.9.34"
tokio = { version = "1.38.0", features = ["rt", "signal", "process", "macros"] }

View File

@ -1,25 +1,49 @@
from golang:1.21.4-alpine3.18 as build # ------------------------------------------------------------------------
from rust:1.79.0-alpine3.20 as rust
run apk add --no-cache musl-dev # pkgconfig cryptsetup-dev lvm2-dev clang-dev clang-static
workdir /src workdir /src
copy go.mod go.sum . copy Cargo.* .
run go mod download copy src src
run --mount=type=cache,id=novit-rs,target=/usr/local/cargo/registry \
copy . . --mount=type=cache,id=novit-rs-target,sharing=private,target=/src/target \
run go test ./... cargo build --release && cp target/release/init /
run go build -o /go/bin/init -trimpath .
# ------------------------------------------------------------------------ # ------------------------------------------------------------------------
from alpine:3.18.4 from golang:1.22.4-alpine3.20 as build
workdir /src
copy . .
run \
--mount=type=cache,id=gomod,target=/go/pkg/mod \
--mount=type=cache,id=gobuild,target=/root/.cache/go-build \
go test ./... \
&& go build -o /go/bin/init -trimpath .
# ------------------------------------------------------------------------
from alpine:3.20.0 as initrd
run apk add --no-cache xz
workdir /layer workdir /layer
run wget -O- https://dl-cdn.alpinelinux.org/alpine/v3.18/releases/x86_64/alpine-minirootfs-3.18.4-x86_64.tar.gz |tar zxv run . /etc/os-release \
&& wget -O- https://dl-cdn.alpinelinux.org/alpine/v${VERSION_ID%.*}/releases/x86_64/alpine-minirootfs-${VERSION_ID}-x86_64.tar.gz |tar zxv
run apk add --no-cache -p . musl lvm2 lvm2-dmeventd udev cryptsetup e2fsprogs btrfs-progs lsblk run apk add --no-cache -p . musl lvm2 lvm2-extra lvm2-dmeventd udev cryptsetup e2fsprogs btrfs-progs lsblk
run rm -rf usr/share/apk var/cache/apk run rm -rf usr/share/apk var/cache/apk
copy --from=build /go/bin/init . #copy --from=build /go/bin/init .
copy --from=rust /init .
# check viability # check viability
run chroot /layer /init hello run chroot . /init hello
entrypoint ["sh","-c","find |cpio -H newc -o |base64"] run find |cpio -H newc -o >/initrd
# ------------------------------------------------------------------------
from alpine:3.20.0
copy --from=initrd /initrd /
entrypoint ["base64","/initrd"]

5
Dockerfile.build Normal file
View File

@ -0,0 +1,5 @@
from rust:1.77.1-alpine as rust
run apk add --no-cache musl-dev
run apk add --no-cache musl lvm2 lvm2-extra lvm2-dmeventd udev cryptsetup e2fsprogs btrfs-progs lsblk

2
Dockerfile.test Normal file
View File

@ -0,0 +1,2 @@
from alpine:3.19.0
run apk add --no-cache musl lvm2 lvm2-extra lvm2-dmeventd udev cryptsetup e2fsprogs btrfs-progs lsblk

View File

@ -1,7 +1,6 @@
package main package main
import ( import (
"log"
"os" "os"
"path/filepath" "path/filepath"
"strconv" "strconv"
@ -9,53 +8,14 @@ import (
"syscall" "syscall"
"time" "time"
"github.com/rs/zerolog/log"
yaml "gopkg.in/yaml.v2" yaml "gopkg.in/yaml.v2"
"novit.tech/direktil/pkg/sysfs"
"novit.tech/direktil/pkg/config/apply"
) )
var loopOffset = 0 var loopOffset = 0
func bootV1() {
log.Print("-- boot v1 --")
// find and mount /boot
bootMatch := param("boot", "")
bootMounted := false
if bootMatch != "" {
bootFS := param("boot.fs", "vfat")
for i := 0; ; i++ {
devNames := sysfs.DeviceByProperty("block", bootMatch)
if len(devNames) == 0 {
if i > 30 {
fatal("boot partition not found after 30s")
}
log.Print("boot partition not found, retrying")
time.Sleep(1 * time.Second)
continue
}
devFile := filepath.Join("/dev", devNames[0])
log.Print("boot partition found: ", devFile)
mount(devFile, "/boot", bootFS, bootMountFlags, "")
bootMounted = true
break
}
} else {
log.Print("Assuming /boot is already populated.")
}
// load config
cfgPath := param("config", "/boot/config.yaml")
layersDir = filepath.Join("/boot", bootVersion, "layers")
applyConfig(cfgPath, bootMounted)
finalizeBoot()
}
func applyConfig(cfgPath string, bootMounted bool) (cfg *configV1) { func applyConfig(cfgPath string, bootMounted bool) (cfg *configV1) {
cfgBytes, err := os.ReadFile(cfgPath) cfgBytes, err := os.ReadFile(cfgPath)
if err != nil { if err != nil {
@ -72,10 +32,10 @@ func applyConfig(cfgPath string, bootMounted bool) (cfg *configV1) {
fatal("no layers configured!") fatal("no layers configured!")
} }
log.Printf("wanted layers: %q", cfg.Layers)
layersInMemory := paramBool("layers-in-mem", false) layersInMemory := paramBool("layers-in-mem", false)
log.Info().Strs("layers", cfg.Layers).Bool("in-memory", layersInMemory).Msg("mounting layers")
const layersInMemDir = "/layers-in-mem" const layersInMemDir = "/layers-in-mem"
if layersInMemory { if layersInMemory {
mkdir(layersInMemDir, 0700) mkdir(layersInMemDir, 0700)
@ -84,6 +44,8 @@ func applyConfig(cfgPath string, bootMounted bool) (cfg *configV1) {
lowers := make([]string, len(cfg.Layers)) lowers := make([]string, len(cfg.Layers))
for i, layer := range cfg.Layers { for i, layer := range cfg.Layers {
log := log.With().Str("layer", layer).Logger()
path := layerPath(layer) path := layerPath(layer)
info, err := os.Stat(path) info, err := os.Stat(path)
@ -91,10 +53,10 @@ func applyConfig(cfgPath string, bootMounted bool) (cfg *configV1) {
fatal(err) fatal(err)
} }
log.Printf("layer %s found (%d bytes)", layer, info.Size()) log.Info().Int64("size", info.Size()).Msg("layer found")
if layersInMemory { if layersInMemory {
log.Print(" copying to memory...") log.Info().Msg("copying to memory")
targetPath := filepath.Join(layersInMemDir, layer) targetPath := filepath.Join(layersInMemDir, layer)
cp(path, targetPath) cp(path, targetPath)
path = targetPath path = targetPath
@ -126,7 +88,7 @@ func applyConfig(cfgPath string, bootMounted bool) (cfg *configV1) {
if bootMounted { if bootMounted {
if layersInMemory { if layersInMemory {
if err := syscall.Unmount("/boot", 0); err != nil { if err := syscall.Unmount("/boot", 0); err != nil {
log.Print("WARNING: failed to unmount /boot: ", err) log.Warn().Err(err).Msg("failed to unmount /boot")
time.Sleep(2 * time.Second) time.Sleep(2 * time.Second)
} }
@ -135,74 +97,44 @@ func applyConfig(cfgPath string, bootMounted bool) (cfg *configV1) {
} }
} }
// - write configuration
log.Print("writing /config.yaml")
if err := os.WriteFile("/system/config.yaml", cfgBytes, 0600); err != nil {
fatal("failed: ", err)
}
// - write files // - write files
for _, fileDef := range cfg.Files { apply.Files(cfg.Files, "/system")
log.Print("writing ", fileDef.Path)
filePath := filepath.Join("/system", fileDef.Path)
if err := os.MkdirAll(filepath.Dir(filePath), 0755); err != nil {
log.Printf("failed to create dir %s: %v", filepath.Dir(fileDef.Path), err)
}
mode := fileDef.Mode
if mode == 0 {
mode = 0644
}
err = os.WriteFile(filePath, []byte(fileDef.Content), mode)
if err != nil {
fatalf("failed to write %s: %v", fileDef.Path, err)
}
}
// - groups // - groups
for _, group := range cfg.Groups { for _, group := range cfg.Groups {
log.Print("creating group ", group.Name) logEvt := log.Info().Str("group", group.Name)
opts := make([]string, 0) opts := make([]string, 0)
opts = append(opts /* chroot */, "/system", "groupadd", "-r") opts = append(opts /* chroot */, "/system", "groupadd", "-r")
if group.Gid != 0 { if group.Gid != 0 {
opts = append(opts, "-g", strconv.Itoa(group.Gid)) opts = append(opts, "-g", strconv.Itoa(group.Gid))
logEvt.Int("gid", group.Gid)
} }
opts = append(opts, group.Name) opts = append(opts, group.Name)
logEvt.Msg("creating group")
run("chroot", opts...) run("chroot", opts...)
} }
// - user // - user
for _, user := range cfg.Users { for _, user := range cfg.Users {
log.Print("creating user ", user.Name) logEvt := log.Info().Str("user", user.Name)
opts := make([]string, 0) opts := make([]string, 0)
opts = append(opts /* chroot */, "/system", "useradd", "-r") opts = append(opts /* chroot */, "/system", "useradd", "-r")
if user.Gid != 0 { if user.Gid != 0 {
opts = append(opts, "-g", strconv.Itoa(user.Gid)) opts = append(opts, "-g", strconv.Itoa(user.Gid))
logEvt.Int("gid", user.Gid)
} }
if user.Uid != 0 { if user.Uid != 0 {
opts = append(opts, "-u", strconv.Itoa(user.Uid)) opts = append(opts, "-u", strconv.Itoa(user.Uid))
logEvt.Int("uid", user.Uid)
} }
opts = append(opts, user.Name) opts = append(opts, user.Name)
logEvt.Msg("creating user")
run("chroot", opts...) run("chroot", opts...)
} }
return return
} }
func finalizeBoot() {
// clean zombies
cleanZombies()
// switch root
log.Print("switching root")
err := syscall.Exec("/sbin/switch_root", []string{"switch_root",
"-c", "/dev/console", "/system", "/sbin/init"}, os.Environ())
fatal("switch_root failed: ", err)
}

View File

@ -6,41 +6,51 @@ import (
"fmt" "fmt"
"io" "io"
"os" "os"
"sync"
"sync/atomic"
) )
func askSecret(prompt string) []byte { var (
stdinTTY.EchoOff() inputTTYs = new(sync.Map)
askingSecret atomic.Bool
)
var ( func registerInput(in *tty) { inputTTYs.Store(in, in) }
in io.Reader = stdin func unregiterInput(in *tty) { inputTTYs.Delete(in) }
out io.Writer = stdout
)
if stdin == nil { func askSecret(prompt string) (s []byte) {
in = os.Stdin err := func() (err error) {
out = os.Stdout askingSecret.Store(true)
} defer askingSecret.Store(false)
out.Write([]byte(prompt + ": ")) inputTTYs.Range(func(k, v any) (con bool) { v.(*tty).EchoOff(); return true })
defer inputTTYs.Range(func(k, v any) (con bool) { v.(*tty).Restore(); return true })
if stdin != nil { var (
stdout.HideInput() in io.Reader = stdin
} out io.Writer = stdout
)
s, err := bufio.NewReader(in).ReadBytes('\n') if stdin == nil {
in = os.Stdin
out = os.Stdout
}
if stdin != nil { out.Write([]byte(prompt + ": "))
stdout.ShowInput()
}
stdinTTY.Restore() s, err = bufio.NewReader(in).ReadBytes('\n')
if err != nil {
return
}
fmt.Println()
s = bytes.TrimRight(s, "\r\n")
return
}()
if err != nil { if err != nil {
fatalf("failed to read from stdin: %v", err) fatalf("failed to read from stdin: %v", err)
} }
fmt.Println() return
s = bytes.TrimRight(s, "\r\n")
return s
} }

View File

@ -3,8 +3,8 @@ package main
import ( import (
"bytes" "bytes"
"errors" "errors"
"log"
"github.com/rs/zerolog/log"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
config "novit.tech/direktil/pkg/bootstrapconfig" config "novit.tech/direktil/pkg/bootstrapconfig"
@ -23,7 +23,7 @@ func localAuth() bool {
} }
if config.CheckPassword(auth.Password, sec) { if config.CheckPassword(auth.Password, sec) {
log.Printf("login with auth %q", auth.Name) log.Info().Msgf("login with auth %q", auth.Name)
return true return true
} }
} }
@ -41,12 +41,12 @@ func sshCheckPubkey(conn ssh.ConnMetadata, key ssh.PublicKey) (*ssh.Permissions,
allowedKey, _, _, _, err := ssh.ParseAuthorizedKey([]byte(auth.SSHKey)) allowedKey, _, _, _, err := ssh.ParseAuthorizedKey([]byte(auth.SSHKey))
if err != nil { if err != nil {
log.Printf("SSH pubkey for %q invalid: %v", auth.Name, auth.SSHKey) log.Warn().Err(err).Str("user", auth.Name).Str("key", auth.SSHKey).Msg("SSH public key is invalid")
return nil, err return nil, err
} }
if bytes.Equal(allowedKey.Marshal(), keyBytes) { if bytes.Equal(allowedKey.Marshal(), keyBytes) {
log.Print("ssh: accepting public key for ", auth.Name) log.Info().Str("user", auth.Name).Msg("ssh: accepting public key")
return &ssh.Permissions{ return &ssh.Permissions{
Extensions: map[string]string{ Extensions: map[string]string{
"pubkey-fp": ssh.FingerprintSHA256(key), "pubkey-fp": ssh.FingerprintSHA256(key),

View File

@ -1,20 +1,21 @@
package main package main
import ( import (
"log"
"os" "os"
"os/exec" "os/exec"
"syscall"
"github.com/rs/zerolog/log"
"gopkg.in/yaml.v3" "gopkg.in/yaml.v3"
config "novit.tech/direktil/pkg/bootstrapconfig" config "novit.tech/direktil/pkg/bootstrapconfig"
) )
func bootV2() { func bootV2() {
log.Print("-- boot v2 --") log.Info().Msg("-- boot v2 --")
kernelVersion := unameRelease() kernelVersion := unameRelease()
log.Print("Linux version ", kernelVersion) log.Info().Str("version", kernelVersion).Msg("Linux")
cfg := &config.Config{} cfg := &config.Config{}
@ -32,15 +33,19 @@ func bootV2() {
} }
} }
log.Print("config loaded") log.Info().Msg("config loaded")
log.Printf("anti-phishing code: %q", cfg.AntiPhishingCode)
if cfg.AntiPhishingCode != "" {
log.Info().Str("anti-phishing-code", cfg.AntiPhishingCode).Send()
}
auths = cfg.Auths auths = cfg.Auths
// mount kernel modules // mount kernel modules
if cfg.Modules == "" { if cfg.Modules == "" {
log.Print("NOT mounting modules (nothing specified)") log.Warn().Msg("NOT mounting modules (\"modules:\" not specified)")
} else { } else {
log.Info().Str("from", cfg.Modules).Msg("mounting modules")
mountSquahfs(cfg.Modules, "/modules") mountSquahfs(cfg.Modules, "/modules")
modulesSourcePath := "/modules/lib/modules/" + kernelVersion modulesSourcePath := "/modules/lib/modules/" + kernelVersion
@ -55,19 +60,23 @@ func bootV2() {
} }
// load basic modules // load basic modules
run("modprobe", "unix") for _, module := range []string{"unix"} {
log.Info().Str("module", module).Msg("loading module")
run("modprobe", module)
}
// devices init // devices init
log.Info().Msg("starting udevd")
err := exec.Command("udevd").Start() err := exec.Command("udevd").Start()
if err != nil { if err != nil {
fatal("failed to start udevd: ", err) fatal("failed to start udevd: ", err)
} }
log.Print("udevadm triggers") log.Info().Msg("udevadm triggers")
run("udevadm", "trigger", "-c", "add", "-t", "devices") run("udevadm", "trigger", "-c", "add", "-t", "devices")
run("udevadm", "trigger", "-c", "add", "-t", "subsystems") run("udevadm", "trigger", "-c", "add", "-t", "subsystems")
log.Print("udevadm settle") log.Info().Msg("udevadm settle")
run("udevadm", "settle") run("udevadm", "settle")
// networks // networks
@ -79,6 +88,9 @@ func bootV2() {
// SSH service // SSH service
startSSH(cfg) startSSH(cfg)
// dmcrypt blockdevs
setupCrypt(cfg.PreLVMCrypt, map[string]string{})
// LVM // LVM
setupLVM(cfg) setupLVM(cfg)
@ -88,3 +100,11 @@ func bootV2() {
// finalize // finalize
finalizeBoot() finalizeBoot()
} }
func finalizeBoot() {
// switch root
log.Info().Msg("switching root")
err := syscall.Exec("/sbin/switch_root", []string{"switch_root",
"-c", "/dev/console", "/system", "/sbin/init"}, os.Environ())
fatal("switch_root failed: ", err)
}

View File

@ -4,12 +4,13 @@ import (
"bytes" "bytes"
"fmt" "fmt"
"io" "io"
"log"
"net/http" "net/http"
"os" "os"
"path/filepath" "path/filepath"
"strings" "strings"
"github.com/rs/zerolog/log"
config "novit.tech/direktil/pkg/bootstrapconfig" config "novit.tech/direktil/pkg/bootstrapconfig"
) )
@ -27,14 +28,14 @@ func bootstrap(cfg *config.Config) {
sysCfgPath := filepath.Join(baseDir, "config.yaml") sysCfgPath := filepath.Join(baseDir, "config.yaml")
if _, err := os.Stat(sysCfgPath); os.IsNotExist(err) { if _, err := os.Stat(sysCfgPath); os.IsNotExist(err) {
log.Printf("bootstrap %q does not exist", bootVersion) log.Warn().Msgf("bootstrap %q does not exist", bootVersion)
seed := cfg.Bootstrap.Seed seed := cfg.Bootstrap.Seed
if seed == "" { if seed == "" {
fatalf("boostrap seed not defined, admin required") fatalf("boostrap seed not defined, admin required")
} }
log.Printf("seeding bootstrap from %s", seed) log.Info().Str("from", seed).Msgf("seeding bootstrap")
err = os.MkdirAll(baseDir, 0700) err = os.MkdirAll(baseDir, 0700)
if err != nil { if err != nil {
@ -72,7 +73,7 @@ func bootstrap(cfg *config.Config) {
fatalf("seeding failed: %v", err) fatalf("seeding failed: %v", err)
} }
log.Print("unpacking bootstrap file") log.Info().Msg("unpacking bootstrap file")
run("tar", "xvf", bootstrapFile, "-C", baseDir) run("tar", "xvf", bootstrapFile, "-C", baseDir)
} }
@ -80,6 +81,13 @@ func bootstrap(cfg *config.Config) {
layersOverride["modules"] = "/modules.sqfs" layersOverride["modules"] = "/modules.sqfs"
sysCfg := applyConfig(sysCfgPath, false) sysCfg := applyConfig(sysCfgPath, false)
// load requested modules
for _, mod := range sysCfg.Modules {
log.Info().Str("module", mod).Msg("loading module")
run("modprobe", mod)
}
// localy-generated assets dir
localGenDir := filepath.Join(bsDir, "local-gen") localGenDir := filepath.Join(bsDir, "local-gen")
// vpns are v2+ // vpns are v2+
@ -89,7 +97,7 @@ func bootstrap(cfg *config.Config) {
// mounts are v2+ // mounts are v2+
for _, mount := range sysCfg.Mounts { for _, mount := range sysCfg.Mounts {
log.Print("mount ", mount.Dev, " to system's ", mount.Path) log.Info().Str("source", mount.Dev).Str("target", mount.Path).Msg("mount")
path := filepath.Join("/system", mount.Path) path := filepath.Join("/system", mount.Path)
@ -108,13 +116,17 @@ func bootstrap(cfg *config.Config) {
// setup root user // setup root user
if ph := sysCfg.RootUser.PasswordHash; ph != "" { if ph := sysCfg.RootUser.PasswordHash; ph != "" {
log.Print("setting root's password") log.Info().Msg("setting root's password")
setUserPass("root", ph) setUserPass("root", ph)
} }
if ak := sysCfg.RootUser.AuthorizedKeys; len(ak) != 0 { if ak := sysCfg.RootUser.AuthorizedKeys; len(ak) != 0 {
log.Print("setting root's authorized keys") log.Info().Msg("setting root's authorized keys")
setAuthorizedKeys(ak) setAuthorizedKeys(ak)
} }
// update-ca-certificates
log.Info().Msg("updating CA certificates")
run("chroot", "/system", "update-ca-certificates")
} }
func setUserPass(user, passwordHash string) { func setUserPass(user, passwordHash string) {
@ -133,6 +145,7 @@ func setUserPass(user, passwordHash string) {
p := strings.Split(line, ":") p := strings.Split(line, ":")
if len(p) < 2 || p[0] != user { if len(p) < 2 || p[0] != user {
buf.WriteString(line) buf.WriteString(line)
buf.WriteByte('\n')
continue continue
} }

27
build-init Executable file
View File

@ -0,0 +1,27 @@
set -ex
which podman &>/dev/null && docker=podman || docker=docker
mkdir -p empty
$docker build -t nv-rs-build --network=host -f Dockerfile.build empty
case $1 in
release)
opts=--release
bindir=target/release
;;
"")
bindir=target/debug
;;
*)
echo >&2 "invalid arg: $1"
exit 1
;;
esac
$docker run --rm -i --net=host --user=$UID \
nv-rs-build \
cargo build $opts
mkdir -p dist
cp $bindir/init dist/

22
go.mod
View File

@ -1,29 +1,31 @@
module novit.nc/direktil/initrd module novit.tech/direktil/initrd
require ( require (
github.com/creack/pty v1.1.21
github.com/freddierice/go-losetup/v2 v2.0.1 github.com/freddierice/go-losetup/v2 v2.0.1
github.com/kr/pty v1.1.8
github.com/pkg/term v1.1.0 github.com/pkg/term v1.1.0
golang.org/x/crypto v0.16.0 github.com/rs/zerolog v1.31.0
golang.org/x/sys v0.15.0 golang.org/x/crypto v0.18.0
golang.org/x/term v0.15.0 golang.org/x/sys v0.16.0
golang.org/x/term v0.16.0
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6 golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6
gopkg.in/yaml.v2 v2.4.0 gopkg.in/yaml.v2 v2.4.0
gopkg.in/yaml.v3 v3.0.1 gopkg.in/yaml.v3 v3.0.1
novit.tech/direktil/pkg v0.0.0-20230201224712-5e39572dc50e novit.tech/direktil/pkg v0.0.0-20240120172717-8498a102796f
) )
require ( require (
github.com/cavaliergopher/cpio v1.0.1 // indirect github.com/cavaliergopher/cpio v1.0.1 // indirect
github.com/creack/pty v1.1.21 // indirect
github.com/google/go-cmp v0.6.0 // indirect github.com/google/go-cmp v0.6.0 // indirect
github.com/josharian/native v1.1.0 // indirect github.com/josharian/native v1.1.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mdlayher/genetlink v1.3.2 // indirect github.com/mdlayher/genetlink v1.3.2 // indirect
github.com/mdlayher/netlink v1.7.2 // indirect github.com/mdlayher/netlink v1.7.2 // indirect
github.com/mdlayher/socket v0.5.0 // indirect github.com/mdlayher/socket v0.5.0 // indirect
golang.org/x/net v0.19.0 // indirect golang.org/x/net v0.20.0 // indirect
golang.org/x/sync v0.5.0 // indirect golang.org/x/sync v0.6.0 // indirect
golang.zx2c4.com/wireguard v0.0.0-20231022001213-2e0774f246fb // indirect golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173 // indirect
) )
go 1.21 go 1.21

115
go.sum
View File

@ -1,87 +1,94 @@
github.com/cavaliergopher/cpio v1.0.1 h1:KQFSeKmZhv0cr+kawA3a0xTQCU4QxXF1vhU7P7av2KM= github.com/cavaliergopher/cpio v1.0.1 h1:KQFSeKmZhv0cr+kawA3a0xTQCU4QxXF1vhU7P7av2KM=
github.com/cavaliergopher/cpio v1.0.1/go.mod h1:pBdaqQjnvXxdS/6CvNDwIANIFSP0xRKI16PX4xejRQc= github.com/cavaliergopher/cpio v1.0.1/go.mod h1:pBdaqQjnvXxdS/6CvNDwIANIFSP0xRKI16PX4xejRQc=
github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc=
github.com/creack/pty v1.1.18 h1:n56/Zwd5o6whRC5PMGretI4IdRLlmBXYNjScPaBgsbY=
github.com/creack/pty v1.1.18/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0= github.com/creack/pty v1.1.21 h1:1/QdRyBaHHJP61QkWMXlOIBfsgdDeeKfK8SYVUWJKf0=
github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4= github.com/creack/pty v1.1.21/go.mod h1:MOBLtS5ELjhRRrroQr9kyvTxUAFNvYEK993ew/Vr4O4=
github.com/freddierice/go-losetup/v2 v2.0.1 h1:wPDx/Elu9nDV8y/CvIbEDz5Xi5Zo80y4h7MKbi3XaAI= github.com/freddierice/go-losetup/v2 v2.0.1 h1:wPDx/Elu9nDV8y/CvIbEDz5Xi5Zo80y4h7MKbi3XaAI=
github.com/freddierice/go-losetup/v2 v2.0.1/go.mod h1:TEyBrvlOelsPEhfWD5rutNXDmUszBXuFnwT1kIQF4J8= github.com/freddierice/go-losetup/v2 v2.0.1/go.mod h1:TEyBrvlOelsPEhfWD5rutNXDmUszBXuFnwT1kIQF4J8=
github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI=
github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY=
github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA= github.com/josharian/native v1.1.0 h1:uuaP0hAbW7Y4l0ZRQ6C9zfb7Mg1mbFKry/xzDAfmtLA=
github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w= github.com/josharian/native v1.1.0/go.mod h1:7X/raswPFr05uY3HiLlYeyQntB6OO7E/d2Cu7qoaN2w=
github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA=
github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg=
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM=
github.com/kr/pty v1.1.8 h1:AkaSdXYQOWeaO3neb8EM634ahkXXe3jYbVh/F9lq+GI= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/kr/pty v1.1.8/go.mod h1:O1sed60cT9XZ5uDucP5qwvh+TE3NnUj51EiZO/lmSfw= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY=
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y=
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
github.com/mdlayher/genetlink v1.3.1 h1:roBiPnual+eqtRkKX2Jb8UQN5ZPWnhDCGj/wR6Jlz2w=
github.com/mdlayher/genetlink v1.3.1/go.mod h1:uaIPxkWmGk753VVIzDtROxQ8+T+dkHqOI0vB1NA9S/Q=
github.com/mdlayher/genetlink v1.3.2 h1:KdrNKe+CTu+IbZnm/GVUMXSqBBLqcGpRDa0xkQy56gw= github.com/mdlayher/genetlink v1.3.2 h1:KdrNKe+CTu+IbZnm/GVUMXSqBBLqcGpRDa0xkQy56gw=
github.com/mdlayher/genetlink v1.3.2/go.mod h1:tcC3pkCrPUGIKKsCsp0B3AdaaKuHtaxoJRz3cc+528o= github.com/mdlayher/genetlink v1.3.2/go.mod h1:tcC3pkCrPUGIKKsCsp0B3AdaaKuHtaxoJRz3cc+528o=
github.com/mdlayher/netlink v1.7.1 h1:FdUaT/e33HjEXagwELR8R3/KL1Fq5x3G5jgHLp/BTmg=
github.com/mdlayher/netlink v1.7.1/go.mod h1:nKO5CSjE/DJjVhk/TNp6vCE1ktVxEA8VEh8drhZzxsQ=
github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/g= github.com/mdlayher/netlink v1.7.2 h1:/UtM3ofJap7Vl4QWCPDGXY8d3GIY2UGSDbK+QWmY8/g=
github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw= github.com/mdlayher/netlink v1.7.2/go.mod h1:xraEF7uJbxLhc5fpHL4cPe221LI2bdttWlU+ZGLfQSw=
github.com/mdlayher/socket v0.4.0 h1:280wsy40IC9M9q1uPGcLBwXpcTQDtoGwVt+BNoITxIw=
github.com/mdlayher/socket v0.4.0/go.mod h1:xxFqz5GRCUN3UEOm9CZqEJsAbe1C8OwSK46NlmWuVoc=
github.com/mdlayher/socket v0.5.0 h1:ilICZmJcQz70vrWVes1MFera4jGiWNocSkykwwoy3XI= github.com/mdlayher/socket v0.5.0 h1:ilICZmJcQz70vrWVes1MFera4jGiWNocSkykwwoy3XI=
github.com/mdlayher/socket v0.5.0/go.mod h1:WkcBFfvyG8QENs5+hfQPl1X6Jpd2yeLIYgrGFmJiJxI= github.com/mdlayher/socket v0.5.0/go.mod h1:WkcBFfvyG8QENs5+hfQPl1X6Jpd2yeLIYgrGFmJiJxI=
github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721 h1:RlZweED6sbSArvlE924+mUcZuXKLBHA35U7LN621Bws= github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721 h1:RlZweED6sbSArvlE924+mUcZuXKLBHA35U7LN621Bws=
github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721/go.mod h1:Ickgr2WtCLZ2MDGd4Gr0geeCH5HybhRJbonOgQpvSxc= github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721/go.mod h1:Ickgr2WtCLZ2MDGd4Gr0geeCH5HybhRJbonOgQpvSxc=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/term v1.1.0 h1:xIAAdCMh3QIAy+5FrE8Ad8XoDhEU4ufwbaSozViP9kk= github.com/pkg/term v1.1.0 h1:xIAAdCMh3QIAy+5FrE8Ad8XoDhEU4ufwbaSozViP9kk=
github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw= github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw=
github.com/ulikunitz/xz v0.5.6/go.mod h1:2bypXElzHzzJZwzH67Y6wb67pO62Rzfn7BSiF4ABRW8= github.com/rs/xid v1.5.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
golang.org/x/crypto v0.0.0-20220321153916-2c7772ba3064/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= github.com/rs/zerolog v1.31.0 h1:FcTR3NnLWW+NnTwwhFWiJSZr4ECLpqCm6QsEnyvbV4A=
golang.org/x/crypto v0.5.0 h1:U/0M97KRkSFvyD/3FSmdP5W5swImpNgle/EHFhOsQPE= github.com/rs/zerolog v1.31.0/go.mod h1:/7mN4D5sKwJLZQ2b/znpjC3/GQWY/xaDXUM0kKWRHss=
golang.org/x/crypto v0.5.0/go.mod h1:NK/OQwhpMQP3MwtdjgLlYHnH9ebylxKWv3e0fK+mkQU= github.com/ulikunitz/xz v0.5.11/go.mod h1:nbz6k7qbPmH4IRqmfOplQw/tblSgqTqBwxkY0oWt/14=
golang.org/x/crypto v0.16.0 h1:mMMrFzRSCF0GvB7Ne27XVtVAaXLrPmgPC7/v0tkwHaY= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
golang.org/x/crypto v0.16.0/go.mod h1:gCAAfMLgwOJRpTjQ2zCCt2OcSfYMTeZVSRtQlPC7Nq4= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc=
golang.org/x/net v0.5.0 h1:GyT4nK/YDHSqa1c4753ouYCDajOYKTja9Xb/OHtgvSw= golang.org/x/crypto v0.18.0 h1:PGVlW0xEltQnzFZ55hkuX5+KLyrMYhHld1YHO4AKcdc=
golang.org/x/net v0.5.0/go.mod h1:DivGGAXEgPSlEBzxGzZI+ZLohi+xUj054jfeKui00ws= golang.org/x/crypto v0.18.0/go.mod h1:R0j02AL6hcrfOiy9T4ZYp/rcWeMxM3L6QYxlOuEG1mg=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c= golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U= golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c=
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
golang.org/x/net v0.20.0 h1:aCL9BSgETF1k+blQaYUBx9hJ9LOGP3gAVemcZlf1Kpo=
golang.org/x/net v0.20.0/go.mod h1:z8BVo6PvndSri0LbOE3hAn0apkU+1YvI6E70E9jsnvY=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.5.0 h1:60k92dhOjHxJkrqnwsfl8KuaHbn/5dl0lUPUklKo3qE= golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
golang.org/x/sync v0.5.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0 h1:Zr2JFtRQNX3BCZ8YtxRE9hNJYC8J6I1MVbMg6owUp18= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.4.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0 h1:h48lPFYpsTvQJZF4EKyI4aLHaev3CxivZmv7yZig9pc= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.15.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.16.0 h1:xWw16ngr6ZMtmxDyKyIgsE93KNKz5HKmMa3b8ALHidU=
golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/term v0.4.0 h1:O7UWfv5+A2qiuulQk30kVinPoMtoIPeVaKLEgLpVkvg= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8=
golang.org/x/term v0.4.0/go.mod h1:9P2UbLfCdcvo3p/nzKvsmas4TnlujnuoV9hGgYzW1lQ= golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k=
golang.org/x/term v0.15.0 h1:y/Oo/a/q3IXu26lQgl04j/gjuBDOBlx7X6Om1j2CPW4= golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo=
golang.org/x/term v0.15.0/go.mod h1:BDl952bC7+uMoWR75FIrCDx79TPU9oHkTZ9yRbYOrX0= golang.org/x/term v0.16.0 h1:m+B6fahuftsE9qjo0VWp2FW0mB3MTJvR0BaMQrq0pmE=
golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/term v0.16.0/go.mod h1:yn7UURbUtPyrVJPGPq404EukNFxcm/foM+bV/bfcDsY=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ=
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.zx2c4.com/wireguard v0.0.0-20220920152132-bb719d3a6e2c h1:Okh6a1xpnJslG9Mn84pId1Mn+Q8cvpo4HCeeFWHo0cA= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.zx2c4.com/wireguard v0.0.0-20220920152132-bb719d3a6e2c/go.mod h1:enML0deDxY1ux+B6ANGiwtg0yAJi1rctkTpcHNAVPyg= golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.zx2c4.com/wireguard v0.0.0-20231022001213-2e0774f246fb h1:c5tyN8sSp8jSDxdCCDXVOpJwYXXhmTkNMt+g0zTSOic= golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.zx2c4.com/wireguard v0.0.0-20231022001213-2e0774f246fb/go.mod h1:tkCQ4FQXmpAgYVh++1cq16/dH4QJtmvpRv19DWGAHSA= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20221104135756-97bc4ad4a1cb h1:9aqVcYEDHmSNb0uOWukxV5lHV09WqiSiCuhEgWNETLY= golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173 h1:/jFs0duh4rdb8uIfPMv78iAJGcPKDeqAFnaLBropIC4=
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20221104135756-97bc4ad4a1cb/go.mod h1:mQqgjkW8GQQcJQsbBvK890TKqUK1DfKWkuBGbOkuMHQ= golang.zx2c4.com/wireguard v0.0.0-20231211153847-12269c276173/go.mod h1:tkCQ4FQXmpAgYVh++1cq16/dH4QJtmvpRv19DWGAHSA=
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6 h1:CawjfCvYQH2OU3/TnxLx97WDSUDRABfT18pCOYwc2GE= golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6 h1:CawjfCvYQH2OU3/TnxLx97WDSUDRABfT18pCOYwc2GE=
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6/go.mod h1:3rxYc4HtVcSG9gVaTs2GEBdehh+sYPOwKtyUWEOTb80= golang.zx2c4.com/wireguard/wgctrl v0.0.0-20230429144221-925a1e7659e6/go.mod h1:3rxYc4HtVcSG9gVaTs2GEBdehh+sYPOwKtyUWEOTb80=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY=
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
novit.nc/direktil/pkg v0.0.0-20220221171542-fd3ce3a1491b/go.mod h1:zwTVO6U0tXFEaga73megQIBK7yVIKZJVePaIh/UtdfU= novit.tech/direktil/pkg v0.0.0-20240120172717-8498a102796f h1:7y11nLhChrrsLQwRaW7wn/9x+Xn2gEVtzj75VkOpJ+o=
novit.tech/direktil/pkg v0.0.0-20230201224712-5e39572dc50e h1:eQFbzcuB4wOSrnOhkcN30hFDCIack40VkIoqVRbWnWc= novit.tech/direktil/pkg v0.0.0-20240120172717-8498a102796f/go.mod h1:zjezU6tELE880oYHs/WAauGBupKIEQQ7KqWTB69RW10=
novit.tech/direktil/pkg v0.0.0-20230201224712-5e39572dc50e/go.mod h1:2Mir5x1eT/e295WeFGzzXa4siunKX4z+rmNPfVsXS0k=

1
init-rs Symbolic link
View File

@ -0,0 +1 @@
target/debug/init

52
lvm.go
View File

@ -3,15 +3,17 @@ package main
import ( import (
"bytes" "bytes"
"io/fs" "io/fs"
"log"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
"sort" "sort"
"strconv" "strconv"
"novit.nc/direktil/initrd/lvm" "github.com/rs/zerolog/log"
config "novit.tech/direktil/pkg/bootstrapconfig" config "novit.tech/direktil/pkg/bootstrapconfig"
"novit.tech/direktil/initrd/lvm"
) )
func sortedKeys[T any](m map[string]T) (keys []string) { func sortedKeys[T any](m map[string]T) (keys []string) {
@ -25,7 +27,7 @@ func sortedKeys[T any](m map[string]T) (keys []string) {
func setupLVM(cfg *config.Config) { func setupLVM(cfg *config.Config) {
if len(cfg.LVM) == 0 { if len(cfg.LVM) == 0 {
log.Print("no LVM VG configured.") log.Info().Msg("no LVM VG configured.")
return return
} }
@ -75,15 +77,17 @@ func setupVG(vg config.LvmVG) {
} }
} }
log := log.With().Str("vg", vg.VG).Logger()
if devNeeded <= 0 { if devNeeded <= 0 {
log.Print("LVM VG ", vg.VG, " has all its devices") log.Info().Msg("LVM VG has all its devices")
return return
} }
if vgExists { if vgExists {
log.Printf("LVM VG %s misses %d devices", vg.VG, devNeeded) log.Info().Msgf("LVM VG misses %d devices", devNeeded)
} else { } else {
log.Printf("LVM VG %s does not exists, creating", vg.VG) log.Info().Msg("LVM VG does not exists, creating")
} }
devNames := make([]string, 0) devNames := make([]string, 0)
@ -108,20 +112,16 @@ func setupVG(vg config.LvmVG) {
m := regexpSelectN(vg.PVs.N, vg.PVs.Regexps, devNames) m := regexpSelectN(vg.PVs.N, vg.PVs.Regexps, devNames)
if len(m) == 0 { if len(m) == 0 {
log.Printf("no devices match the regexps %v", vg.PVs.Regexps) log.Error().Strs("regexps", vg.PVs.Regexps).Msg("no device match the regexps")
for _, d := range devNames {
log.Print("- ", d)
}
fatalf("failed to setup VG %s", vg.VG) fatalf("failed to setup VG %s", vg.VG)
} }
if vgExists { if vgExists {
log.Print("- extending vg to ", m) log.Info().Strs("devices", m).Msg("LVM VG: extending")
run("vgextend", append([]string{vg.VG}, m...)...) run("vgextend", append([]string{vg.VG}, m...)...)
devNeeded -= len(m) devNeeded -= len(m)
} else { } else {
log.Print("- creating vg with devices ", m) log.Info().Strs("devices", m).Msg("LVM VG: creating")
run("vgcreate", append([]string{vg.VG}, m...)...) run("vgcreate", append([]string{vg.VG}, m...)...)
devNeeded -= len(m) devNeeded -= len(m)
} }
@ -142,17 +142,17 @@ func setupLVs(vg config.LvmVG, createdDevs map[string]string) {
defaults := vg.Defaults defaults := vg.Defaults
for _, lv := range vg.LVs { for idx, lv := range vg.LVs {
lvKey := vg.VG + "/" + lv.Name log := log.With().Str("vg", vg.VG).Str("lv", lv.Name).Logger()
if contains(lvs, func(v lvm.LV) bool { if contains(lvs, func(v lvm.LV) bool {
return v.VGName == vg.VG && v.Name == lv.Name return v.VGName == vg.VG && v.Name == lv.Name
}) { }) {
log.Printf("LV %s exists", lvKey) log.Info().Msg("LV exists")
continue continue
} }
log.Printf("creating LV %s", lvKey) log.Info().Msg("LV does not exist")
if lv.Raid == nil { if lv.Raid == nil {
lv.Raid = defaults.Raid lv.Raid = defaults.Raid
@ -161,7 +161,7 @@ func setupLVs(vg config.LvmVG, createdDevs map[string]string) {
args := make([]string, 0) args := make([]string, 0)
if lv.Name == "" { if lv.Name == "" {
fatalf("LV has no name") fatalf("LV[%d] has no name", idx)
} }
args = append(args, vg.VG, "--name", lv.Name) args = append(args, vg.VG, "--name", lv.Name)
@ -184,7 +184,7 @@ func setupLVs(vg config.LvmVG, createdDevs map[string]string) {
} }
} }
log.Print("lvcreate args: ", args) log.Info().Strs("args", args).Msg("LV: creating")
run("lvcreate", args...) run("lvcreate", args...)
dev := "/dev/" + vg.VG + "/" + lv.Name dev := "/dev/" + vg.VG + "/" + lv.Name
@ -212,6 +212,8 @@ func zeroDevStart(dev string) {
} }
} }
var cryptDevs = map[string]bool{}
func setupCrypt(devSpecs []config.CryptDev, createdDevs map[string]string) { func setupCrypt(devSpecs []config.CryptDev, createdDevs map[string]string) {
var password []byte var password []byte
passwordVerified := false passwordVerified := false
@ -245,8 +247,6 @@ func setupCrypt(devSpecs []config.CryptDev, createdDevs map[string]string) {
} }
} }
cryptDevs := map[string]bool{}
for _, devName := range devNames { for _, devName := range devNames {
name, dev := devName.Name, devName.Dev name, dev := devName.Name, devName.Dev
@ -286,12 +286,12 @@ func setupCrypt(devSpecs []config.CryptDev, createdDevs map[string]string) {
} }
if !eq { if !eq {
log.Print("passwords don't match") log.Error().Msg("passwords don't match")
goto retry goto retry
} }
} }
log.Print("formatting encrypted device ", dev) log.Info().Str("dev", dev).Msg("formatting encrypted device")
cmd := exec.Command("cryptsetup", "luksFormat", dev, "--key-file=-") cmd := exec.Command("cryptsetup", "luksFormat", dev, "--key-file=-")
cmd.Stdin = bytes.NewBuffer(password) cmd.Stdin = bytes.NewBuffer(password)
cmd.Stdout = stdout cmd.Stdout = stdout
@ -312,7 +312,7 @@ func setupCrypt(devSpecs []config.CryptDev, createdDevs map[string]string) {
} }
} }
log.Print("openning encrypted device ", name, " from ", dev) log.Info().Str("name", name).Str("dev", dev).Msg("openning encrypted device")
cmd := exec.Command("cryptsetup", "open", dev, name, "--key-file=-") cmd := exec.Command("cryptsetup", "open", dev, name, "--key-file=-")
cmd.Stdin = bytes.NewBuffer(password) cmd.Stdin = bytes.NewBuffer(password)
cmd.Stdout = stdout cmd.Stdout = stdout
@ -364,7 +364,7 @@ func devInitialized(dev string) bool {
func setupFS(dev, fs string) { func setupFS(dev, fs string) {
if devInitialized(dev) { if devInitialized(dev) {
log.Print("device ", dev, " already formatted") log.Info().Str("dev", dev).Msg("device already formatted")
return return
} }
@ -372,7 +372,7 @@ func setupFS(dev, fs string) {
fs = "ext4" fs = "ext4"
} }
log.Print("formatting ", dev, " (", fs, ")") log.Info().Str("dev", dev).Str("fs", fs).Msg("formatting device")
args := make([]string, 0) args := make([]string, 0)
switch fs { switch fs {

56
main.go
View File

@ -3,7 +3,6 @@ package main
import ( import (
"fmt" "fmt"
"io" "io"
"log"
"os" "os"
"os/exec" "os/exec"
"path/filepath" "path/filepath"
@ -12,10 +11,12 @@ import (
"time" "time"
"github.com/pkg/term/termios" "github.com/pkg/term/termios"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"golang.org/x/term" "golang.org/x/term"
"novit.nc/direktil/initrd/colorio" "novit.tech/direktil/initrd/colorio"
"novit.nc/direktil/initrd/shio" "novit.tech/direktil/initrd/shio"
) )
const ( const (
@ -41,11 +42,15 @@ func newPipe() (io.ReadCloser, io.WriteCloser) {
} }
func main() { func main() {
log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
registerInput(newTTY(os.Stdin.Fd()))
switch baseName := filepath.Base(os.Args[0]); baseName { switch baseName := filepath.Base(os.Args[0]); baseName {
case "init": case "init":
runInit() runInit()
default: default:
log.Fatal("unknown sub-command: ", baseName) log.Fatal().Msgf("unknown sub-command: %q", baseName)
} }
} }
@ -57,18 +62,19 @@ func runInit() {
runtime.LockOSThread() runtime.LockOSThread()
if pid := os.Getpid(); pid != 1 {
log.Fatal("init must be PID 1, not ", pid)
}
// move log to shio // move log to shio
go io.Copy(os.Stdout, stdout.NewReader()) go io.Copy(os.Stdout, stdout.NewReader())
log.SetOutput(stderr) log.Logger = log.Output(zerolog.ConsoleWriter{Out: stderr})
// check the PID is 1
if pid := os.Getpid(); pid != 1 {
log.Fatal().Int("pid", pid).Msg("init must be PID 1")
}
// copy os.Stdin to my stdin pipe // copy os.Stdin to my stdin pipe
go io.Copy(stdinPipe, os.Stdin) go io.Copy(stdinPipe, os.Stdin)
log.Print("Welcome to ", VERSION) log.Info().Msg("Welcome to " + VERSION)
// essential mounts // essential mounts
mount("none", "/proc", "proc", 0, "") mount("none", "/proc", "proc", 0, "")
@ -78,17 +84,14 @@ func runInit() {
// get the "boot version" // get the "boot version"
bootVersion = param("version", "current") bootVersion = param("version", "current")
log.Printf("booting system %q", bootVersion) log.Info().Msgf("booting system %q", bootVersion)
os.Setenv("PATH", "/usr/bin:/bin:/usr/sbin:/sbin") os.Setenv("PATH", "/usr/bin:/bin:/usr/sbin:/sbin")
_, err := os.Stat("/config.yaml") _, err := os.Stat("/config.yaml")
if err != nil { if err != nil {
if os.IsNotExist(err) { log.Error().Err(err).Msg("config not found")
bootV1() fatal()
return
}
fatal("stat failed: ", err)
} }
bootV2() bootV2()
@ -107,19 +110,20 @@ func layerPath(name string) string {
} }
func fatal(v ...interface{}) { func fatal(v ...interface{}) {
log.Print("*** FATAL ***") log.Error().Msg("*** FATAL ***")
log.Print(v...) log.Error().Msg(fmt.Sprint(v...))
die() die()
} }
func fatalf(pattern string, v ...interface{}) { func fatalf(pattern string, v ...interface{}) {
log.Print("*** FATAL ***") log.Error().Msg("*** FATAL ***")
log.Printf(pattern, v...) log.Error().Msgf(pattern, v...)
die() die()
} }
func die() { func die() {
log.SetOutput(os.Stderr) log.Logger = log.Output(zerolog.ConsoleWriter{Out: os.Stderr})
stdout.Close() stdout.Close()
stdin.Close() stdin.Close()
stdinPipe.Close() stdinPipe.Close()
@ -138,13 +142,13 @@ mainLoop:
deadline := time.Now().Add(time.Minute) deadline := time.Now().Add(time.Minute)
os.Stdin.SetReadDeadline(deadline) os.Stdin.SetReadDeadline(deadline)
termios.Tcflush(os.Stdin.Fd(), termios.TCIFLUSH)
term.MakeRaw(int(os.Stdin.Fd())) term.MakeRaw(int(os.Stdin.Fd()))
termios.Tcflush(os.Stdin.Fd(), termios.TCIFLUSH)
b := make([]byte, 1) b := make([]byte, 1)
_, err := os.Stdin.Read(b) _, err := os.Stdin.Read(b)
if err != nil { if err != nil {
log.Print("failed to read from stdin: ", err) log.Error().Err(err).Msg("failed to read from stdin")
time.Sleep(5 * time.Second) time.Sleep(5 * time.Second)
syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART) syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART)
} }
@ -184,10 +188,10 @@ mainLoop:
} }
continue mainLoop continue mainLoop
} }
log.Print("failed to find a shell!") log.Error().Msg("failed to find a shell!")
default: default:
log.Printf("unknown choice: %q", string(b)) log.Error().Msgf("unknown choice: %q", string(b))
} }
} }
} }
@ -212,7 +216,7 @@ func mount(source, target, fstype string, flags uintptr, data string) {
if err := syscall.Mount(source, target, fstype, flags, data); err != nil { if err := syscall.Mount(source, target, fstype, flags, data); err != nil {
fatalf("mount %q %q -t %q -o %q failed: %v", source, target, fstype, data, err) fatalf("mount %q %q -t %q -o %q failed: %v", source, target, fstype, data, err)
} }
log.Printf("mounted %q", target) log.Info().Str("target", target).Msg("mounted")
} }
func cp(srcPath, dstPath string) { func cp(srcPath, dstPath string) {

View File

@ -3,11 +3,19 @@ modd.conf {}
go.??? **/*.go { go.??? **/*.go {
prep: go test ./... prep: go test ./...
prep: mkdir -p dist prep: mkdir -p dist
prep: go build -o dist/init .
prep: go build -o dist/ ./tools/... prep: go build -o dist/ ./tools/...
} }
dist/init Dockerfile { **/*.rs Cargo.* {
prep: docker build -t novit-initrd-gen . prep: cargo test
prep: docker run novit-initrd-gen |base64 -d >dist/initrd.new #prep: cargo build
prep: mv dist/initrd.new dist/initrd prep: docker build --network host -t novit-initrd-gen .
prep: docker run --net=host --rm novit-initrd-gen |base64 -d >dist/initrd.new
} }
#dist/init Dockerfile {
# prep: docker build --network host -t novit-initrd-gen .
# prep: docker run --net=host --rm novit-initrd-gen |base64 -d >dist/initrd.new
# prep: mv dist/initrd.new dist/initrd
#}

View File

@ -1,8 +1,10 @@
modd.test.conf {} modd.test.conf {}
dist/initrd dist/cpiocat test-initrd/* { dist/initrd dist/cpiocat dist/testconf test-initrd/**/* {
prep: dist/testconf test-initrd/config.yaml
prep: cp -f dist/initrd test-initrd.cpio prep: cp -f dist/initrd test-initrd.cpio
prep: cd test-initrd && ../dist/cpiocat <../dist/initrd >../test-initrd.cpio * prep: cd test-initrd && cat ../dist/initrd | ../dist/cpiocat * |lz4 -l9v >../test-initrd.cpio.new
prep: if cpio -t -F test-initrd.cpio 2>&1 |grep bytes.of.junk; then echo "bad cpio archive"; exit 1; fi prep: mv test-initrd.cpio.new test-initrd.cpio
prep: if lz4cat test-initrd.cpio | cpio -t 2>&1 |grep bytes.of.junk; then echo "bad cpio archive"; exit 1; fi
prep: kill $(<qemu.pid) prep: kill $(<qemu.pid)
} }

View File

@ -1,17 +1,18 @@
package main package main
import ( import (
"log"
"net" "net"
"os/exec" "os/exec"
"strings" "strings"
"github.com/rs/zerolog/log"
config "novit.tech/direktil/pkg/bootstrapconfig" config "novit.tech/direktil/pkg/bootstrapconfig"
) )
func setupNetworks(cfg *config.Config) { func setupNetworks(cfg *config.Config) {
if len(cfg.Networks) == 0 { if len(cfg.Networks) == 0 {
log.Print("no networks configured.") log.Info().Msg("no networks configured.")
return return
} }
@ -29,7 +30,8 @@ func setupNetworks(cfg *config.Config) {
assigned := map[string]bool{} assigned := map[string]bool{}
for _, network := range cfg.Networks { for _, network := range cfg.Networks {
log.Print("setting up network ", network.Name) log := log.With().Str("network", network.Name).Logger()
log.Info().Msg("setting up network")
// compute available names // compute available names
if len(assigned) != 0 { if len(assigned) != 0 {
@ -60,10 +62,11 @@ func setupNetworks(cfg *config.Config) {
assigned[m] = true assigned[m] = true
} }
log.Print("- ", envvar)
envvars = append(envvars, envvar.String()) envvars = append(envvars, envvar.String())
} }
log.Info().Strs("env", envvars).Msg("running script")
cmd := exec.Command("/bin/sh", "-c", network.Script) cmd := exec.Command("/bin/sh", "-c", network.Script)
cmd.Env = envvars cmd.Env = envvars
cmd.Stdout = stdout cmd.Stdout = stdout

View File

@ -1,8 +1,9 @@
package main package main
import ( import (
"log"
"regexp" "regexp"
"github.com/rs/zerolog/log"
) )
func regexpSelectN(n int, regexps []string, names []string) (matches []string) { func regexpSelectN(n int, regexps []string, names []string) (matches []string) {
@ -16,7 +17,7 @@ func regexpSelectN(n int, regexps []string, names []string) (matches []string) {
for _, reStr := range regexps { for _, reStr := range regexps {
re, err := regexp.Compile(reStr) re, err := regexp.Compile(reStr)
if err != nil { if err != nil {
log.Printf("warning: invalid regexp ignored: %q: %v", reStr, err) log.Warn().Err(err).Str("regexp", reStr).Msg("invalid regexp, ignored")
continue continue
} }
res = append(res, re) res = append(res, re)

2
run-docker Executable file
View File

@ -0,0 +1,2 @@
docker build -t nv-initrd-test -f Dockerfile.test empty
docker run -d --name nv-initrd-test -it --privileged -v $PWD:/src --workdir /src/test-initrd nv-initrd-test

View File

@ -5,7 +5,7 @@ import (
"io" "io"
"sync" "sync"
"novit.nc/direktil/initrd/colorio" "novit.tech/direktil/initrd/colorio"
) )
type ShIO struct { type ShIO struct {

1
src/bootstrap.rs Normal file
View File

@ -0,0 +1 @@
pub mod config;

145
src/bootstrap/config.rs Normal file
View File

@ -0,0 +1,145 @@
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Config {
anti_phishing_code: String,
keymap: Option<String>,
modules: String,
auths: Vec<Auth>,
networks: Vec<Network>,
#[serde(default)]
ssh: SSHServer,
#[serde(default)]
pre_lvm_crypt: Vec<CryptDev>,
#[serde(default)]
lvm: Vec<LvmVG>,
#[serde(default)]
crypt: Vec<CryptDev>,
bootstrap: Bootstrap,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Auth {
name: String,
#[serde(rename = "sshKey")]
ssh_key: String,
password: String,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Network {
name: String,
interfaces: Vec<NetworkInterface>,
script: String,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct NetworkInterface {
pub var: String,
pub n: i16,
pub regexps: Vec<String>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct SSHServer {
listen: String,
keys: SSHKeys,
}
impl Default for SSHServer {
fn default() -> Self {
Self {
listen: "[::]:22".to_string(),
keys: SSHKeys::default(),
}
}
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct SSHKeys {
dsa: String,
rsa: String,
ecdsa: String,
ed25519: String,
}
impl Default for SSHKeys {
fn default() -> Self {
Self {
dsa: "id_dsa".to_string(),
rsa: "id_rsa".to_string(),
ecdsa: "id_ecdsa".to_string(),
ed25519: "id_ed25519".to_string(),
}
}
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct LvmVG {
vg: String,
pvs: LvmPV,
#[serde(default)]
defaults: LvmLVDefaults,
lvs: Vec<LvmLV>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct LvmLVDefaults {
#[serde(default = "default_fs")]
fs: String,
raid: Option<Raid>,
}
impl Default for LvmLVDefaults {
fn default() -> Self {
Self {
fs: default_fs(),
raid: None,
}
}
}
fn default_fs() -> String {
"ext4".to_string()
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct LvmLV {
name: String,
#[serde(skip_serializing_if = "Option::is_none")]
fs: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
raid: Option<Raid>,
#[serde(skip_serializing_if = "Option::is_none")]
size: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
extents: Option<String>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct LvmPV {
n: i16,
regexps: Vec<String>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct CryptDev {
name: String,
dev: Option<String>,
prefix: Option<String>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Raid {
mirrors: Option<u8>,
stripes: Option<u8>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Bootstrap {
dev: String,
seed: String,
}

27
src/lsblk.rs Normal file
View File

@ -0,0 +1,27 @@
use std::io;
use std::process::Command;
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct Report {
pub blockdevices: Vec<BlockDev>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
pub struct BlockDev {
pub name: String,
#[serde(rename = "maj:min")]
pub maj_min: String,
pub rm: bool,
pub size: String,
pub ro: bool,
#[serde(rename = "type")]
pub dev_type: String,
pub mountpoints: Vec<Option<String>>,
#[serde(default)]
pub children: Vec<BlockDev>,
}
pub fn report() -> io::Result<Report> {
let output = Command::new("lsblk").arg("--json").output()?;
Ok(serde_json::from_slice(output.stdout.as_slice()).unwrap())
}

84
src/lvm.rs Normal file
View File

@ -0,0 +1,84 @@
use std::io;
use std::process::Command;
#[derive(Debug, serde::Deserialize, serde::Serialize)]
struct Report {
report: Vec<ReportObj>,
}
#[derive(Debug, serde::Deserialize, serde::Serialize)]
#[serde(untagged)]
enum ReportObj {
PV { pv: Vec<PV> },
VG { vg: Vec<VG> },
LV { lv: Vec<LV> },
}
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct PV {
pub pv_name: String,
pub vg_name: String,
pub pv_fmt: String,
pub pv_attr: String,
pub pv_size: String,
pub pv_free: String,
}
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct VG {
pub vg_name: String,
pub pv_count: String,
pub lv_count: String,
pub snap_count: String,
pub vg_attr: String,
pub vg_size: String,
pub vg_free: String,
}
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct LV {
lv_name: String,
vg_name: String,
lv_attr: String,
lv_size: String,
pool_lv: String,
origin: String,
data_percent: String,
metadata_percent: String,
move_pv: String,
mirror_log: String,
copy_percent: String,
convert_lv: String,
}
pub fn pvs() -> io::Result<Vec<PV>> {
report_cmd("pvs", |o| match o {
ReportObj::PV { pv } => Some(pv),
_ => None,
})
}
pub fn vgs() -> io::Result<Vec<VG>> {
report_cmd("vgs", |o| match o {
ReportObj::VG { vg } => Some(vg),
_ => None,
})
}
pub fn lvs() -> io::Result<Vec<LV>> {
report_cmd("lvs", |o| match o {
ReportObj::LV { lv } => Some(lv),
_ => None,
})
}
fn report_cmd<T>(cmd: &str, find: fn(ReportObj) -> Option<Vec<T>>) -> io::Result<Vec<T>> {
let output = Command::new(cmd).arg("--reportformat=json").output()?;
let report: Report = serde_json::from_slice(output.stdout.as_slice()).unwrap();
Ok(report
.report
.into_iter()
.filter_map(find)
.flatten()
.collect())
}

51
src/main.rs Normal file
View File

@ -0,0 +1,51 @@
mod bootstrap;
mod lsblk;
mod lvm;
use anyhow::format_err;
use log::error;
use std::io::{self, Read, Write};
use std::process::exit;
use std::{env, fs};
#[tokio::main(flavor = "current_thread")]
async fn main() -> anyhow::Result<()> {
if let None = env::var_os("RUST_LOG") {
env::set_var("RUST_LOG", "info");
}
env_logger::init();
if let Some(arg) = env::args().into_iter().nth(1) {
match arg.as_str() {
"hello" => println!("hello"),
_ => {
error!("invalid arg: {arg}");
exit(1);
}
};
exit(0);
}
let cfg = fs::read("config.yaml").map_err(|e| format_err!("failed to read config: {e}"))?;
let cfg: bootstrap::config::Config = serde_yaml::from_slice(cfg.as_slice())
.map_err(|e| format_err!("failed to parse config: {e}"))?;
serde_yaml::to_writer(io::stdout(), &cfg)?;
for pv in lvm::pvs().unwrap() {
println!("pv: {pv:?}");
}
for vg in lvm::vgs().unwrap() {
println!("vg: {vg:?}");
}
for lv in lvm::lvs().unwrap() {
println!("lv: {lv:?}");
}
println!("lsblk: {:?}", lsblk::report());
// TODO
Ok(())
}

105
ssh.go
View File

@ -4,15 +4,16 @@ import (
"encoding/binary" "encoding/binary"
"fmt" "fmt"
"io" "io"
"log"
"net" "net"
"os" "os"
"os/exec" "os/exec"
"sync" "sync"
"syscall" "syscall"
"time"
"unsafe" "unsafe"
"github.com/kr/pty" "github.com/creack/pty"
"github.com/rs/zerolog/log"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
config "novit.tech/direktil/pkg/bootstrapconfig" config "novit.tech/direktil/pkg/bootstrapconfig"
@ -23,31 +24,46 @@ func startSSH(cfg *config.Config) {
PublicKeyCallback: sshCheckPubkey, PublicKeyCallback: sshCheckPubkey,
} }
pkBytes, err := os.ReadFile("/id_rsa") // TODO configurable hostKeyLoaded := false
if err != nil {
fatalf("ssh: failed to load private key: %v", err) for _, format := range []string{"rsa", "dsa", "ecdsa", "ed25519"} {
log := log.With().Str("format", format).Logger()
pkBytes, err := os.ReadFile("/id_" + format)
if err != nil {
log.Error().Err(err).Msg("ssh: failed to load host key")
continue
}
pk, err := ssh.ParsePrivateKey(pkBytes)
if err != nil {
log.Error().Err(err).Msg("ssh: failed to parse host key")
continue
}
sshConfig.AddHostKey(pk)
hostKeyLoaded = true
log.Info().Msg("ssh: loaded host key")
} }
pk, err := ssh.ParsePrivateKey(pkBytes) if !hostKeyLoaded {
if err != nil { fatalf("ssh: failed to load any host key")
fatalf("ssh: failed to parse private key: %v", err)
} }
sshConfig.AddHostKey(pk)
sshBind := ":22" // TODO configurable sshBind := ":22" // TODO configurable
listener, err := net.Listen("tcp", sshBind) listener, err := net.Listen("tcp", sshBind)
if err != nil { if err != nil {
fatalf("ssh: failed to listen on %s: %v", sshBind, err) fatalf("ssh: failed to listen on %s: %v", sshBind, err)
} }
log.Print("SSH server listening on ", sshBind) log.Info().Str("bind-address", sshBind).Msg("SSH server listening")
go func() { go func() {
for { for {
conn, err := listener.Accept() conn, err := listener.Accept()
if err != nil { if err != nil {
log.Print("ssh: accept conn failed: ", err) log.Info().Err(err).Msg("ssh: accept conn failed")
continue continue
} }
@ -60,12 +76,12 @@ func sshHandleConn(conn net.Conn, sshConfig *ssh.ServerConfig) {
sshConn, chans, reqs, err := ssh.NewServerConn(conn, sshConfig) sshConn, chans, reqs, err := ssh.NewServerConn(conn, sshConfig)
if err != nil { if err != nil {
log.Print("ssh: handshake failed: ", err) log.Error().Err(err).Msg("ssh: handshake failed")
return return
} }
remoteAddr := sshConn.User() + "@" + sshConn.RemoteAddr().String() remoteAddr := sshConn.User() + "@" + sshConn.RemoteAddr().String()
log.Print("ssh: new connection from ", remoteAddr) log.Info().Str("remote", remoteAddr).Msg("ssh: new connection")
go sshHandleReqs(reqs) go sshHandleReqs(reqs)
go sshHandleChannels(remoteAddr, chans) go sshHandleChannels(remoteAddr, chans)
@ -78,7 +94,7 @@ func sshHandleReqs(reqs <-chan *ssh.Request) {
req.Reply(true, nil) req.Reply(true, nil)
default: default:
log.Printf("ssh: discarding req: %+v", req) log.Info().Str("type", req.Type).Msg("ssh: discarding request")
req.Reply(false, nil) req.Reply(false, nil)
} }
} }
@ -93,7 +109,7 @@ func sshHandleChannels(remoteAddr string, chans <-chan ssh.NewChannel) {
channel, requests, err := newChannel.Accept() channel, requests, err := newChannel.Accept()
if err != nil { if err != nil {
log.Print("ssh: failed to accept channel: ", err) log.Error().Err(err).Msg("ssh: failed to accept channel")
continue continue
} }
@ -127,14 +143,35 @@ func sshHandleChannel(remoteAddr string, channel ssh.Channel, requests <-chan *s
command := string(req.Payload[4 : req.Payload[3]+4]) command := string(req.Payload[4 : req.Payload[3]+4])
switch command { switch command {
case "init": case "init":
go func() { if ptyF == nil {
io.Copy(channel, stdout.NewReader()) go func() {
once.Do(closeCh) channel.Stderr().Write([]byte("\033[5m\033[31;1m\n\nWARNING: no TTY requested, passwords will be echoed!\n\n\033[0m"))
}() time.Sleep(3 * time.Second)
go func() { io.Copy(channel, stdout.NewReader())
io.Copy(stdinPipe, channel) once.Do(closeCh)
once.Do(closeCh) }()
}() go func() {
io.Copy(stdinPipe, channel)
once.Do(closeCh)
}()
} else {
stdinTTY := newTTY(ptyF.Fd())
if askingSecret.Load() {
stdinTTY.EchoOff()
}
registerInput(stdinTTY)
defer unregiterInput(stdinTTY)
go func() {
io.Copy(ttyF, stdout.NewReader())
once.Do(closeCh)
}()
go func() {
io.Copy(stdinPipe, ttyF)
once.Do(closeCh)
}()
}
req.Reply(true, nil) req.Reply(true, nil)
@ -180,15 +217,6 @@ func sshHandleChannel(remoteAddr string, channel ssh.Channel, requests <-chan *s
ttyF = nil ttyF = nil
}() }()
go func() {
io.Copy(channel, ptyF)
once.Do(closeCh)
}()
go func() {
io.Copy(ptyF, channel)
once.Do(closeCh)
}()
req.Reply(true, nil) req.Reply(true, nil)
case "pty-req": case "pty-req":
@ -200,7 +228,7 @@ func sshHandleChannel(remoteAddr string, channel ssh.Channel, requests <-chan *s
var err error var err error
ptyF, ttyF, err = pty.Open() ptyF, ttyF, err = pty.Open()
if err != nil { if err != nil {
log.Print("PTY err: ", err) log.Error().Err(err).Msg("ssh: PTY open failed")
req.Reply(false, nil) req.Reply(false, nil)
continue continue
} }
@ -212,6 +240,15 @@ func sshHandleChannel(remoteAddr string, channel ssh.Channel, requests <-chan *s
req.Reply(true, nil) req.Reply(true, nil)
go func() {
io.Copy(channel, ptyF)
once.Do(closeCh)
}()
go func() {
io.Copy(ptyF, channel)
once.Do(closeCh)
}()
case "window-change": case "window-change":
w, h := sshParseDims(req.Payload) w, h := sshParseDims(req.Payload)
sshSetWinsize(ptyF.Fd(), w, h) sshSetWinsize(ptyF.Fd(), w, h)

View File

@ -26,20 +26,27 @@ networks:
- eno.* - eno.*
- enp.* - enp.*
script: | script: |
ip a add 2001:41d0:306:168f::1337:2eed/64 dev $iface
ip li set $iface up ip li set $iface up
#udhcpc $iface udhcpc -i $iface -b -t1 -T1 -A5 ||
ip a add 2001:41d0:306:168f::1337:2eed/64 dev $iface
pre_lvm_crypt:
- dev: /dev/vda
name: sys0
- dev: /dev/vdb
name: sys1
lvm: lvm:
- vg: storage - vg: storage
pvs: pvs:
n: 2 n: 2
regexps: regexps:
- /dev/mapper/sys[01]
# to match full disks # to match full disks
- /dev/nvme[0-9]+n[0-9]+ #- /dev/nvme[0-9]+n[0-9]+
- /dev/vd[a-z]+ #- /dev/vd[a-z]+
- /dev/sd[a-z]+ #- /dev/sd[a-z]+
- /dev/hd[a-z]+ #- /dev/hd[a-z]+
# to match partitions: # to match partitions:
#- /dev/nvme[0-9]+n[0-9]+p[0-9]+ #- /dev/nvme[0-9]+n[0-9]+p[0-9]+
#- /dev/vd[a-z]+[0-9]+ #- /dev/vd[a-z]+[0-9]+
@ -67,12 +74,13 @@ lvm:
extents: 100%FREE extents: 100%FREE
# size: 10g # size: 10g
crypt: #crypt:
- dev: /dev/storage/bootstrap #- dev: /dev/storage/bootstrap
- dev: /dev/storage/dls #- dev: /dev/storage/dls
bootstrap: bootstrap:
dev: /dev/mapper/bootstrap #dev: /dev/mapper/bootstrap
dev: /dev/storage/bootstrap
# TODO seed: https://direktil.novit.io/bootstraps/dls-crypt # TODO seed: https://direktil.novit.io/bootstraps/dls-crypt
seed: http://192.168.10.254:7606/hosts/m1/bootstrap.tar seed: http://192.168.10.254:7606/hosts/m1/bootstrap.tar
# TODO seed_sign_key: "..." # TODO seed_sign_key: "..."

1
test-initrd/init Symbolic link
View File

@ -0,0 +1 @@
../dist/init

View File

@ -2,7 +2,7 @@ package main
import ( import (
"flag" "flag"
"log" "fmt"
"os" "os"
"novit.tech/direktil/pkg/cpiocat" "novit.tech/direktil/pkg/cpiocat"
@ -13,6 +13,7 @@ func main() {
err := cpiocat.Append(os.Stdout, os.Stdin, flag.Args()) err := cpiocat.Append(os.Stdout, os.Stdin, flag.Args())
if err != nil { if err != nil {
log.Fatal(err) fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
} }
} }

37
tools/testconf/main.go Normal file
View File

@ -0,0 +1,37 @@
package main
import (
"bytes"
"flag"
"fmt"
"os"
"gopkg.in/yaml.v3"
config "novit.tech/direktil/pkg/bootstrapconfig"
)
func main() {
flag.Parse()
for _, arg := range flag.Args() {
fmt.Println("testing", arg)
cfgBytes, err := os.ReadFile(arg)
fail(err)
cfg := config.Config{}
dec := yaml.NewDecoder(bytes.NewBuffer(cfgBytes))
dec.KnownFields(true)
err = dec.Decode(&cfg)
fail(err)
}
}
func fail(err error) {
if err != nil {
fmt.Fprintln(os.Stderr, err.Error())
os.Exit(1)
}
}

25
tty.go
View File

@ -1,29 +1,25 @@
package main package main
import ( import (
"os"
"golang.org/x/sys/unix" "golang.org/x/sys/unix"
) )
var (
stdinTTY = &tty{int(os.Stdin.Fd()), nil}
)
type tty struct { type tty struct {
fd int fd int
termios *unix.Termios termios *unix.Termios
} }
func newTTY(fd uintptr) *tty {
termios, _ := unix.IoctlGetTermios(int(fd), unix.TCGETS)
return &tty{int(fd), termios}
}
func (t *tty) EchoOff() { func (t *tty) EchoOff() {
termios, err := unix.IoctlGetTermios(t.fd, unix.TCGETS) if t.termios == nil {
if err != nil {
return return
} }
t.termios = termios newState := *t.termios
newState := *termios
newState.Lflag &^= unix.ECHO newState.Lflag &^= unix.ECHO
newState.Lflag |= unix.ICANON | unix.ISIG newState.Lflag |= unix.ICANON | unix.ISIG
newState.Iflag |= unix.ICRNL newState.Iflag |= unix.ICRNL
@ -31,8 +27,9 @@ func (t *tty) EchoOff() {
} }
func (t *tty) Restore() { func (t *tty) Restore() {
if t.termios != nil { if t.termios == nil {
unix.IoctlSetTermios(t.fd, unix.TCSETS, t.termios) return
t.termios = nil
} }
unix.IoctlSetTermios(t.fd, unix.TCSETS, t.termios)
} }

20
vpn.go
View File

@ -1,11 +1,11 @@
package main package main
import ( import (
"log"
"net" "net"
"os" "os"
"path/filepath" "path/filepath"
"github.com/rs/zerolog/log"
"golang.zx2c4.com/wireguard/wgctrl" "golang.zx2c4.com/wireguard/wgctrl"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes" "golang.zx2c4.com/wireguard/wgctrl/wgtypes"
@ -13,11 +13,18 @@ import (
) )
func setupVPN(vpn config.VPNDef, localGenDir string) { func setupVPN(vpn config.VPNDef, localGenDir string) {
log.Printf("setting up VPN %s", vpn.Name) log := log.With().Str("vpn", vpn.Name).Logger()
log.Info().Msg("VPN: setting up")
vpnDir := filepath.Join(localGenDir, vpn.Name) vpnDir := filepath.Join(localGenDir, vpn.Name)
os.MkdirAll(vpnDir, 0750) os.MkdirAll(vpnDir, 0750)
logMsg := log.Info()
if vpn.ListenPort != nil {
logMsg.Int("ListenPort", *vpn.ListenPort)
}
// public/private key // public/private key
keyFile := filepath.Join(vpnDir, "key") keyFile := filepath.Join(vpnDir, "key")
keyBytes, err := os.ReadFile(keyFile) keyBytes, err := os.ReadFile(keyFile)
@ -39,7 +46,7 @@ func setupVPN(vpn config.VPNDef, localGenDir string) {
fatalf("bad VPN key: %v", err) fatalf("bad VPN key: %v", err)
} }
log.Printf("VPN %s public key is %s", vpn.Name, key.PublicKey().String()) logMsg.Stringer("PublicKey", key.PublicKey())
// pre-shared key // pre-shared key
pskeyFile := filepath.Join(vpnDir, "pskey") pskeyFile := filepath.Join(vpnDir, "pskey")
@ -62,7 +69,10 @@ func setupVPN(vpn config.VPNDef, localGenDir string) {
fatalf("bad VPN pre-shared key: %v", err) fatalf("bad VPN pre-shared key: %v", err)
} }
log.Printf("VPN %s pre-shared key is %s", vpn.Name, key.String()) {
keyStr := key.String()
logMsg.Str("PresharedKey", keyStr[0:4]+"..."+keyStr[len(keyStr)-4:])
}
// setup interface // setup interface
cfg := wgtypes.Config{ cfg := wgtypes.Config{
@ -110,12 +120,14 @@ func setupVPN(vpn config.VPNDef, localGenDir string) {
} }
defer wg.Close() defer wg.Close()
log.Info().Strs("ips", vpn.IPs).Msg("VPN: creating interface")
run("ip", "link", "add", vpn.Name, "type", "wireguard") run("ip", "link", "add", vpn.Name, "type", "wireguard")
for _, ip := range vpn.IPs { for _, ip := range vpn.IPs {
run("ip", "addr", "add", ip, "dev", vpn.Name) run("ip", "addr", "add", ip, "dev", vpn.Name)
} }
logMsg.Msg("VPN: configuring interface")
err = wg.ConfigureDevice(vpn.Name, cfg) err = wg.ConfigureDevice(vpn.Name, cfg)
if err != nil { if err != nil {
fatalf("failed to setup VPN %s: %v", vpn.Name, err) fatalf("failed to setup VPN %s: %v", vpn.Name, err)

View File

@ -1,26 +0,0 @@
package main
import (
"log"
"syscall"
)
func cleanZombies() {
return // FIXME noop... udhcpc is a daemon staying alive so we never finish
var wstatus syscall.WaitStatus
for {
pid, err := syscall.Wait4(-1, &wstatus, 0, nil)
switch err {
case nil:
log.Printf("collected PID %v", pid)
case syscall.ECHILD:
return
default:
log.Printf("unknown error: %v", err)
}
}
}