// packages/iac_fleet/examples/demo.vk // Self-contained verification suite & runnable example for `iac_fleet`. use [ fs iac = iac_fleet ] assert-true = fn [cond bool, label str] enum [ if not cond [ println (str/join ['[FAIL] ' label] '') os/exit 1 ] println (str/join ['[PASS] ' label] '') .ok ] index-of-id = fn [ordered block, target_id str] i64 [ mut i = 0 while i < (len ordered) [ if ordered[i].id == target_id [ return i ] i = i + 1 ] -1 ] // --- 1. Compile Homoiconic `quote [...]` Production Server Stack (All 8 Resource Kinds) --- // Declared intentionally out-of-order (`exec_check` and `systemd_service` before `file`/`dir`/`user`/`pkg`) // to exercise Kahn topological DAG sorting! prod_stack = iac/compile-stack 'veko-prod-edge' (quote [ .exec_check 'edge-readiness' [ check_cmd = 'curl -fsS http://127.0.0.1:8443/healthz' apply_cmd = 'systemctl restart veko-edge' needs = ['systemd_service:veko-edge'] ] .systemd_service 'veko-edge' [ description = 'Veko Production TLS Edge Service' user = 'veko' working_dir = '/var/lib/veko' exec_start = '/usr/local/bin/veko-edge --config /etc/veko/edge.conf' env = [ 'VEKO_ENV' = 'production', 'VEKO_LOG' = 'info' ] secret_env = [ 'DB_PASSWORD' = 'VekoProdDbSecret!2026#99' 'API_HMAC_KEY' = 'HmacSuperSecretKey!887766' ] harden = true needs = ['user:veko' 'file:/etc/veko/edge.conf' 'sysctl:net.ipv4.tcp_fastopen' 'ufw_rule:https-8443'] ] .file '/etc/veko/edge.conf' [ owner = 'veko' group = 'veko' mode = '0640' content = 'listen = 0.0.0.0:8443\nworkers = 4\n' secrets = [ 'INLINE_TOK' = 'InlineSecretToken!5544' ] needs = ['dir:/etc/veko' 'pkg:ca-certificates'] ] .dir '/etc/veko' [ owner = 'veko' group = 'veko' mode = '0750' needs = ['user:veko'] ] .user 'veko' [ uid = 990 shell = '/usr/sbin/nologin' home = '/var/lib/veko' system = true ] .pkg 'ca-certificates' [ state = 'present' ] .sysctl 'net.ipv4.tcp_fastopen' [ value = '3' ] .ufw_rule 'https-8443' [ port = 8443 proto = 'tcp' action = 'allow' ] ]) ordered = iac/sort-dag prod_stack pos_user = index-of-id ordered 'user:veko' pos_pkg = index-of-id ordered 'pkg:ca-certificates' pos_dir = index-of-id ordered 'dir:/etc/veko' pos_file = index-of-id ordered 'file:/etc/veko/edge.conf' pos_sys = index-of-id ordered 'sysctl:net.ipv4.tcp_fastopen' pos_ufw = index-of-id ordered 'ufw_rule:https-8443' pos_svc = index-of-id ordered 'systemd_service:veko-edge' pos_chk = index-of-id ordered 'exec_check:edge-readiness' dag_ok = (len ordered) == 8 and pos_user < pos_dir and pos_dir < pos_file and pos_pkg < pos_file and pos_file < pos_svc and pos_sys < pos_svc and pos_ufw < pos_svc and pos_svc < pos_chk _ = assert-true dag_ok 'compile-stack (all 8 resource kinds) and Kahn sort-dag topological ordering' // --- 2. Cycle Detection Naming Exact Cycle Participants --- cyclic_stack = iac/compile-stack 'cyclic-test' (quote [ .dir '/etc/app' [ needs = ['systemd_service:app'] ] .file '/etc/app/app.conf' [ needs = ['dir:/etc/app'] ] .systemd_service 'app' [ exec_start = '/usr/bin/app' needs = ['file:/etc/app/app.conf'] ] ]) cycle_err = iac/sort-dag/or cyclic_stack [e -> msg = mold e if (str/contains? msg 'cycle') and (str/contains? msg 'dir:/etc/app') and (str/contains? msg 'systemd_service:app') [ [ iac/Resource { id = '__cycle_caught__', kind = .dir, kind_name = 'dir', name = '/etc/app' } ] ] else [ [] ] ] _ = assert-true ((len cycle_err) == 1 and cycle_err[0].id == '__cycle_caught__') 'sort-dag detects dependency cycles and names cycle nodes cleanly' // --- 3. Deterministic `plan-changes` (Create, Update with Unified Diff, Delete) & Idempotency --- mut initial_facts = iac/new-host-facts 'edge-01.prod.veko' // Pre-populate 1 outdated resource (`sysctl` has `value = '1'` instead of `'3'`) // and 1 orphan legacy resource (`file:/etc/veko/legacy.conf` to be deleted) _ = iac/record-fact mut initial_facts 'sysctl:net.ipv4.tcp_fastopen' { key = 'net.ipv4.tcp_fastopen' persist_file = '/etc/sysctl.d/99-veko.conf' value = '1' } _ = iac/record-fact mut initial_facts 'file:/etc/veko/legacy.conf' { path = '/etc/veko/legacy.conf' content = 'deprecated = true\n' } plan1 = iac/plan-changes prod_stack initial_facts // Locate the `.update` action on `sysctl:net.ipv4.tcp_fastopen` to inspect its unified diff mut sysctl_diff = '' mut ai = 0 while ai < (len plan1.actions) [ act = plan1.actions[ai] if act.resource_id == 'sysctl:net.ipv4.tcp_fastopen' and act.op == .update [ sysctl_diff = act.diff_text ] ai = ai + 1 ] plan1_ok = plan1.has_changes and plan1.creates == 7 and plan1.updates == 1 and plan1.deletes == 1 and plan1.noops == 0 and (str/contains? sysctl_diff '-value = \'1\'') and (str/contains? sysctl_diff '+value = \'3\'') _ = assert-true plan1_ok 'plan-changes computes .create (7), .update with unified diff (1), and .delete (1)' // Converge host state and re-run `plan-changes` -> MUST yield 0 changes and 8 `.noop` actions! converged_facts = iac/apply-plan-facts initial_facts plan1 plan2 = iac/plan-changes prod_stack converged_facts idemp_ok = (not plan2.has_changes) and plan2.creates == 0 and plan2.updates == 0 and plan2.deletes == 0 and plan2.noops == 8 _ = assert-true idemp_ok 'idempotency verified: second plan-changes against converged HostFacts yields 0 changes (all .noop)' // --- 4. Hardened `systemd` Unit Generation & Secret Redaction Proof --- svc_res = map/get prod_stack.by_id 'systemd_service:veko-edge' unit_safe = iac/render-systemd-unit svc_res script_sh = iac/render-plan-script plan1 tmp_dir = str/join [(os/temp-dir) '/veko_iac_fleet_demo_' (mold (time/unix))] '' _ = fs/mkdir-all tmp_dir defer [ _ = fs/remove-all tmp_dir ] script_path = str/join [tmp_dir '/converge.sh'] '' _ = fs/write-atomic script_path (bytes/from-str script_sh) disk_script = os/read-file script_path systemd_ok = (str/contains? unit_safe '[Unit]') and (str/contains? unit_safe 'ExecStart=/usr/local/bin/veko-edge --config /etc/veko/edge.conf') and (str/contains? unit_safe 'NoNewPrivileges=yes') and (str/contains? unit_safe 'ProtectSystem=strict') and (str/contains? unit_safe 'PrivateTmp=yes') _ = assert-true systemd_ok 'render-systemd-unit emits hardened sandboxing directives and service configuration' // Verify ZERO leakage of raw secret values across audit logs, systemd previews, and rendered shell scripts! no_leak_audit = (not (str/contains? plan1.audit_log 'VekoProdDbSecret!2026#99')) and (not (str/contains? plan1.audit_log 'HmacSuperSecretKey!887766')) and (not (str/contains? plan1.audit_log 'InlineSecretToken!5544')) no_leak_unit = (not (str/contains? unit_safe 'VekoProdDbSecret!2026#99')) and (str/contains? unit_safe 'Environment="DB_PASSWORD="') no_leak_script = (not (str/contains? disk_script 'VekoProdDbSecret!2026#99')) and (not (str/contains? disk_script 'HmacSuperSecretKey!887766')) and (str/contains? disk_script 'install -d -m') // Also verify rotating a secret triggers `.update` without exposing either old or new secret value in `diff_text`! rotated_stack = iac/compile-stack 'veko-prod-edge' (quote [ .exec_check 'edge-readiness' [ check_cmd = 'curl -fsS http://127.0.0.1:8443/healthz' apply_cmd = 'systemctl restart veko-edge' needs = ['systemd_service:veko-edge'] ] .systemd_service 'veko-edge' [ description = 'Veko Production TLS Edge Service' user = 'veko' working_dir = '/var/lib/veko' exec_start = '/usr/local/bin/veko-edge --config /etc/veko/edge.conf' env = [ 'VEKO_ENV' = 'production', 'VEKO_LOG' = 'info' ] secret_env = [ 'DB_PASSWORD' = 'RotatedDbSecret!2027#NEW' 'API_HMAC_KEY' = 'HmacSuperSecretKey!887766' ] harden = true needs = ['user:veko' 'file:/etc/veko/edge.conf' 'sysctl:net.ipv4.tcp_fastopen' 'ufw_rule:https-8443'] ] .file '/etc/veko/edge.conf' [ owner = 'veko' group = 'veko' mode = '0640' content = 'listen = 0.0.0.0:8443\nworkers = 4\n' secrets = [ 'INLINE_TOK' = 'InlineSecretToken!5544' ] needs = ['dir:/etc/veko' 'pkg:ca-certificates'] ] .dir '/etc/veko' [ owner = 'veko' group = 'veko' mode = '0750' needs = ['user:veko'] ] .user 'veko' [ uid = 990 shell = '/usr/sbin/nologin' home = '/var/lib/veko' system = true ] .pkg 'ca-certificates' [ state = 'present' ] .sysctl 'net.ipv4.tcp_fastopen' [ value = '3' ] .ufw_rule 'https-8443' [ port = 8443, proto = 'tcp', action = 'allow' ] ]) plan_rot = iac/plan-changes rotated_stack converged_facts mut rot_diff = '' mut ri = 0 while ri < (len plan_rot.actions) [ ra = plan_rot.actions[ri] if ra.resource_id == 'systemd_service:veko-edge' and ra.op == .update [ rot_diff = ra.diff_text ] ri = ri + 1 ] no_leak_rot = plan_rot.updates == 1 and (not (str/contains? rot_diff 'RotatedDbSecret!2027#NEW')) and (not (str/contains? rot_diff 'VekoProdDbSecret!2026#99')) and (str/contains? rot_diff 'secret.DB_PASSWORD') _ = assert-true (no_leak_audit and no_leak_unit and no_leak_script and no_leak_rot) 'secret values are strictly redacted across audit logs, systemd previews, shell scripts, and rotation diffs' println 'iac_fleet: all verification checks passed'