[Bug 265255] net-mgmt/unbound_exporter rc.d script causes failure to start when ssl configuration is empty

From: <bugzilla-noreply_at_freebsd.org>
Date: Sat, 16 Jul 2022 20:56:09 UTC
https://bugs.freebsd.org/bugzilla/show_bug.cgi?id=265255

            Bug ID: 265255
           Summary: net-mgmt/unbound_exporter rc.d script causes failure
                    to start when ssl configuration is empty
           Product: Ports & Packages
           Version: Latest
          Hardware: Any
                OS: Any
            Status: New
          Severity: Affects Only Me
          Priority: ---
         Component: Individual Port(s)
          Assignee: ports-bugs@FreeBSD.org
          Reporter: joel.bohnes+freebsd@gmail.com
                CC: aduitsis@cpan.org
             Flags: maintainer-feedback?(aduitsis@cpan.org)
                CC: aduitsis@cpan.org

In our configuration we have have unbound and unbound_exporter running in the
same jail. The unbound remote-control is listening on a plain (unencrypted) tcp
socket.

Section in unbound.conf looks something like this:
--- unbound.conf ---
remote-control:
        control-enable: yes
        control-interface: 127.0.0.1
        control-use-cert: "no"
---

This configuration is supported by unbound_exporter, but it's a bit awkward
because it requires passing an empty string in the command line. The correct,
working command line looks like this:

  unbound_exporter -unbound.cert "" -unbound.ca "" <...>

If we try to use the rc.d script provided by the unbound_exporter port, we can
try using following settings:
--- /etc/rc.conf ---
unbound_exporter_enable="YES"
unbound_exporter_ca=""
unbound_exporter_cert=""
unbound_exporter_key=""
---

However this will fail with the following error:

--- /var/log/unbound_exporter.log ---
time="2022-07-16T22:12:56+02:00" level=info msg="Starting unbound_exporter"
source="unbound_exporter.go:478"
panic: open -unbound.cert: no such file or directory

goroutine 1 [running]:
main.main()
        github.com/kumina/unbound_exporter/unbound_exporter.go:481 +0x485
---

The failing command that the init script executes looks like this:
  unbound_exporter -unbound.cert -unbound.ca <...>

When using command_args in the init script, it seems a bit difficult to pass
empty strings
along (which is a feature of shellscript).

We used to following (nasty?) patch to fix the rc.d script.
---
--- /usr/local/etc/rc.d/unbound_exporter.original    2022-07-16
22:12:50.062388470 +0200
+++ /usr/local/etc/rc.d/unbound_exporter      2022-07-16 22:12:09.073708468
+0200
@@ -46,9 +46,9 @@
 command=/usr/sbin/daemon
 procname="/usr/local/bin/unbound_exporter"
 command_args="-p ${pidfile} /usr/bin/env ${procname} \
-                               -unbound.ca ${unbound_exporter_ca} \
-                               -unbound.cert ${unbound_exporter_cert} \
-                               -unbound.key ${unbound_exporter_key} \
+                               -unbound.ca '\"'${unbound_exporter_ca}'\"' \
+                               -unbound.cert '\"'${unbound_exporter_cert}'\"'
\
+                               -unbound.key '\"'${unbound_exporter_key}'\"' \
                                -web.listen-address ${unbound_exporter_bind} \
                                 ${unbound_exporter_args} >
${unbound_exporter_log_file} 2>&1"
---

-- 
You are receiving this mail because:
You are the assignee for the bug.