Repository: eclipse-bluechi/bluechi (language: python)

Issue:
manager: check if AllowedNodeNames contain value
Before starting the daemon, make sure the AllowedNodeNames is set. If users don't set the AllowedNodeNames the hirte won't communicate with other nodes.


Discussion / hints:
Also avoid the segmentation fault:

Steps:
```
1) Comment AllowedNodeNames
2) Build raw hirte and start the daemon
git clone https://github.com/containers/hirte && cd hirte
# make 
# ./builddir/src/manager/hirte -c /etc/hirte/hirte.conf
free(): invalid pointer
Aborted (core dumped)
```

The configuration file commented:
```
# cat /etc/hirte/hirte.conf
# This is the configuration file for hirte manager.
#
# All available options are described in hirte.conf man page file provided by hirte package.
#

[hirte]

#
# A comma separated list of unique hirte-agent names. Only nodes with names mentioned in the list can connect to hirte
# manager. These names are defined in the agent's configuration file under the `NodeName` option.
# (see `hirte-agent.conf(5)`).
#AllowedNodeNames=control,node1,qm-node1
#AllowedNodeNames=

#
# The port the manager listens on to establish connections with the hirte agents.
#ManagerPort=842

#
# The level used for logging. Supported values are: DEBUG, INFO, WARN and ERROR.
#LogLevel=INFO

#
# The target where logs are written to. Supported values are: journald and stderr.
#LogTarget=journald

#
# If this flag is set to true, no logs are written by hirte.
#LogIsQuiet=false
```


With the applied suggested patch:
```
root@control hirte]# ./builddir/src/manager/hirte -c /etc/hirte/hirte.conf
2023-07-16 20:31:31,415+0000 ERROR	: AllowedNodeNames must be set in the configuration file
```
Another way I found the segfault (with AllowedNodeNames empty):

**Config**
```
# cat /etc/hirte/hirte.conf
# This is the configuration file for hirte manager.
#
# All available options are described in hirte.conf man page file provided by hirte package.
#

[hirte]

#
# A comma separated list of unique hirte-agent names. Only nodes with names mentioned in the list can connect to hirte
# manager. These names are defined in the agent's configuration file under the `NodeName` option.
# (see `hirte-agent.conf(5)`).
#AllowedNodeNames=control,node1,qm-node1
AllowedNodeNames=

#
# The port the manager listens on to establish connections with the hirte agents.
#ManagerPort=842

#
# The level used for logging. Supported values are: DEBUG, INFO, WARN and ERROR.
#LogLevel=INFO

#
# The target where logs are written to. Supported values are: journald and stderr.
#LogTarget=journald

#
# If this flag is set to true, no logs are written by hirte.
#LogIsQuiet=false
```

**Cloning from GitHub, building and starting**
```
# git clone https://github.com/containers/hirte && cd hirte
# make
# ./builddir/src/manager/hirte -c /etc/hirte/hirte.conf (wait 30 sec or so)
2023-07-16 22:27:24,045+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:24,045+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:26,295+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:26,295+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:28,545+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:28,545+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:30,795+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:30,795+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:33,045+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:33,045+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:35,295+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:35,295+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:37,545+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:37,545+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:39,795+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:39,796+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:42,045+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:42,046+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:44,295+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:44,296+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:46,545+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:46,546+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:48,795+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:48,796+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:51,045+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:51,046+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:53,295+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:53,296+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:55,545+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:55,546+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:57,795+0000 INFO	: Anonymous node disconnected
2023-07-16 22:27:57,796+0000 INFO	: Anonymous node disconnected
2023-07-16 22:28:00,045+0000 INFO	: Anonymous node disconnected
2023-07-16 22:28:00,046+0000 INFO	: Anonymous node disconnected
2023-07-16 22:28:02,295+0000 INFO	: Anonymous node disconnected
2023-07-16 22:28:02,296+0000 INFO	: Anonymous node disconnected
Segmentation fault (core dumped)
```
Now, I have a question, why by the default AllowedNodeName is uncommented and empty? Even if the controller/manager agent must be set to allow communication.
> Also avoid the segmentation fault:
> 
> Steps:
> 
> ```
> 1) Comment AllowedNodeNames
> 2) Build raw hirte and start the daemon
> git clone https://github.com/containers/hirte && cd hirte
> # make 
> # ./builddir/src/manager/hirte -c /etc/hirte/hirte.conf
> free(): invalid pointer
> Aborted (core dumped)
> ```
> 

Sorry, that's not supported setup, you need to install the project correctly, you cannot just run from buildir

> > Also avoid the segmentation fault:
> > Steps:
> > ```
> > 1) Comment AllowedNodeNames
> > 2) Build raw hirte and start the daemon
> > git clone https://github.com/containers/hirte && cd hirte
> > # make 
> > # ./builddir/src/manager/hirte -c /etc/hirte/hirte.conf
> > free(): invalid pointer
> > Aborted (core dumped)
> > ```
> 
> Sorry, that's not supported setup, you need to install the project correctly, you cannot just run from buildir

I cannot follow here too:

generated the rpms
```
# ls
hirte-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
hirte-agent-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
hirte-agent-debuginfo-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
hirte-ctl-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
hirte-ctl-debuginfo-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
hirte-debuginfo-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
hirte-debugsource-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
hirte-selinux-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
python3-pyhirte-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
```

Installed the hirte via rpm
```
 hirte.service - Hirte systemd service controller manager daemon
     Loaded: loaded (/usr/lib/systemd/system/hirte.service; enabled; preset: disabled)
     Active: failed (Result: core-dump) since Tue 2023-07-18 13:45:23 UTC; 338ms ago
   Duration: 132ms
       Docs: man:hirte(1)
             man:hirte.conf(5)
    Process: 25658 ExecStart=/usr/bin/hirte (code=dumped, signal=ABRT)
   Main PID: 25658 (code=dumped, signal=ABRT)
        CPU: 3ms

Jul 18 13:45:23 control systemd[1]: hirte.service: Scheduled restart job, restart counter is at 5.
Jul 18 13:45:23 control systemd[1]: Stopped Hirte systemd service controller manager daemon.
Jul 18 13:45:23 control systemd[1]: hirte.service: Start request repeated too quickly.
Jul 18 13:45:23 control systemd[1]: hirte.service: Failed with result 'core-dump'.
Jul 18 13:45:23 control systemd[1]: Failed to start Hirte systemd service controller manager daemon.
```

Commented the AllowedNodeName in /etc/hirte/hirte.conf and /usr/share/hirte/config/hirte.conf and as you can see there are a segfault right there.

```
# systemctl start hirte
# systemctl status hirte
× hirte.service - Hirte systemd service controller manager daemon
     Loaded: loaded (/usr/lib/systemd/system/hirte.service; enabled; preset: disabled)
     Active: failed (Result: core-dump) since Tue 2023-07-18 13:45:23 UTC; 338ms ago
   Duration: 132ms
       Docs: man:hirte(1)
             man:hirte.conf(5)
    Process: 25658 ExecStart=/usr/bin/hirte (code=dumped, signal=ABRT)
   Main PID: 25658 (code=dumped, signal=ABRT)
        CPU: 3ms

Jul 18 13:45:23 control systemd[1]: hirte.service: Scheduled restart job, restart counter is at 5.
Jul 18 13:45:23 control systemd[1]: Stopped Hirte systemd service controller manager daemon.
Jul 18 13:45:23 control systemd[1]: hirte.service: Start request repeated too quickly.
Jul 18 13:45:23 control systemd[1]: hirte.service: Failed with result 'core-dump'.
Jul 18 13:45:23 control systemd[1]: Failed to start Hirte systemd service controller manager daemon.
```
> > > Also avoid the segmentation fault:
> > > Steps:
> > > ```
> > > 1) Comment AllowedNodeNames
> > > 2) Build raw hirte and start the daemon
> > > git clone https://github.com/containers/hirte && cd hirte
> > > # make 
> > > # ./builddir/src/manager/hirte -c /etc/hirte/hirte.conf
> > > free(): invalid pointer
> > > Aborted (core dumped)
> > > ```
> > 
> > 
> > Sorry, that's not supported setup, you need to install the project correctly, you cannot just run from buildir
> 
> I cannot follow here too:
> 
> generated the rpms
> 
> ```
> # ls
> hirte-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> hirte-agent-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> hirte-agent-debuginfo-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> hirte-ctl-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> hirte-ctl-debuginfo-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> hirte-debuginfo-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> hirte-debugsource-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> hirte-selinux-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> python3-pyhirte-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> ```
> 
> Installed the hirte via rpm

Ahh, so that's not what you have mentioned, you mentioned that you try to run hirte from buildir.
Of course, when hirte is installed from RPM, then this is a supported use case.

> 
> ```
>  hirte.service - Hirte systemd service controller manager daemon
>      Loaded: loaded (/usr/lib/systemd/system/hirte.service; enabled; preset: disabled)
>      Active: failed (Result: core-dump) since Tue 2023-07-18 13:45:23 UTC; 338ms ago
>    Duration: 132ms
>        Docs: man:hirte(1)
>              man:hirte.conf(5)
>     Process: 25658 ExecStart=/usr/bin/hirte (code=dumped, signal=ABRT)
>    Main PID: 25658 (code=dumped, signal=ABRT)
>         CPU: 3ms
> 
> Jul 18 13:45:23 control systemd[1]: hirte.service: Scheduled restart job, restart counter is at 5.
> Jul 18 13:45:23 control systemd[1]: Stopped Hirte systemd service controller manager daemon.
> Jul 18 13:45:23 control systemd[1]: hirte.service: Start request repeated too quickly.
> Jul 18 13:45:23 control systemd[1]: hirte.service: Failed with result 'core-dump'.
> Jul 18 13:45:23 control systemd[1]: Failed to start Hirte systemd service controller manager daemon.
> ```
> 
> Commented the AllowedNodeName in /etc/hirte/hirte.conf and /usr/share/hirte/config/hirte.conf and as you can see there are a segfault right there.

So that's the problem:
1. You can update whatever you want in `/etc/hirte/hirte.conf`, that's a user file, no issues with that
2. You should not modify `/usr/share/hirte/config/hirte.conf`, that's hirte default configuration storage and of course you mess up things a lot.

We haven't yet finished moving default configuration from `/usr/share/hirte/config/hirte.conf` to the to code as described in #301. So you have a crashdump, because when you comment out `AllowedNodeNames` from `/usr/share/hirte/config/hirte.conf` this config option doesn't exist in the configuration object even though this option should always exist (no matter if filled in or not)

So my suggestion to fix this issue is to finish the work in #301.
> > > > Also avoid the segmentation fault:
> > > > Steps:
> > > > ```
> > > > 1) Comment AllowedNodeNames
> > > > 2) Build raw hirte and start the daemon
> > > > git clone https://github.com/containers/hirte && cd hirte
> > > > # make 
> > > > # ./builddir/src/manager/hirte -c /etc/hirte/hirte.conf
> > > > free(): invalid pointer
> > > > Aborted (core dumped)
> > > > ```
> > > 
> > > 
> > > Sorry, that's not supported setup, you need to install the project correctly, you cannot just run from buildir
> > 
> > 
> > I cannot follow here too:
> > generated the rpms
> > ```
> > # ls
> > hirte-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> > hirte-agent-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> > hirte-agent-debuginfo-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> > hirte-ctl-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> > hirte-ctl-debuginfo-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> > hirte-debuginfo-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> > hirte-debugsource-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> > hirte-selinux-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> > python3-pyhirte-0.5.0-0.202307181342.git80e717d.el9.x86_64.rpm
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > Installed the hirte via rpm
> 
> Ahh, so that's not what you have mentioned, you mentioned that you try to run hirte from buildir. Of course, when hirte is installed from RPM, then this is a supported use case.
> 
> > ```
> >  hirte.service - Hirte systemd service controller manager daemon
> >      Loaded: loaded (/usr/lib/systemd/system/hirte.service; enabled; preset: disabled)
> >      Active: failed (Result: core-dump) since Tue 2023-07-18 13:45:23 UTC; 338ms ago
> >    Duration: 132ms
> >        Docs: man:hirte(1)
> >              man:hirte.conf(5)
> >     Process: 25658 ExecStart=/usr/bin/hirte (code=dumped, signal=ABRT)
> >    Main PID: 25658 (code=dumped, signal=ABRT)
> >         CPU: 3ms
> > 
> > Jul 18 13:45:23 control systemd[1]: hirte.service: Scheduled restart job, restart counter is at 5.
> > Jul 18 13:45:23 control systemd[1]: Stopped Hirte systemd service controller manager daemon.
> > Jul 18 13:45:23 control systemd[1]: hirte.service: Start request repeated too quickly.
> > Jul 18 13:45:23 control systemd[1]: hirte.service: Failed with result 'core-dump'.
> > Jul 18 13:45:23 control systemd[1]: Failed to start Hirte systemd service controller manager daemon.
> > ```
> > 
> > 
> >     
> >       
> >     
> > 
> >       
> >     
> > 
> >     
> >   
> > Commented the AllowedNodeName in /etc/hirte/hirte.conf and /usr/share/hirte/config/hirte.conf and as you can see there are a segfault right there.
> 
> So that's the problem:
> 
> 1. You can update whatever you want in `/etc/hirte/hirte.conf`, that's a user file, no issues with that
> 2. You should not modify `/usr/share/hirte/config/hirte.conf`, that's hirte default configuration storage and of course you mess up things a lot.
> 
> We haven't yet finished moving default configuration from `/usr/share/hirte/config/hirte.conf` to the to code as described in #301. So you have a crashdump, because when you comment out `AllowedNodeNames` from `/usr/share/hirte/config/hirte.conf` this config option doesn't exist in the configuration object even though this option should always exist (no matter if filled in or not)
> 
> So my suggestion to fix this issue is to finish the work in #301.

If the file is there, users or attackers can change the configuration as demonstrated. Also, curious question, what's the reason to have hirte daemon listening 842 port without the ability to send commands to any agent node? 

Regarding #301, I have a patch almost done with that.
I will workaround this issue with #301 and keep the daemon listening. If the project decide that the daemon should not be loaded with empty AllowedNodeName we can always revive this to avoid cpu cycles in embedded environment which usually seems to have limited hardware.

Fix patch:
diff --git a/config/agent/agent.conf b/config/agent/agent.conf
index cea312c702..ee14741a06 100644
--- a/config/agent/agent.conf
+++ b/config/agent/agent.conf
@@ -8,12 +8,12 @@
 #
 # The unique name of this agent.
 # NodeName defaults the system's hostname.
-NodeName=
+#NodeName=
 
 #
 # The IP address that hirte-agent can use to connect to hirte manager. It must be a valid IPv4 or IPv6 address.
 # One of the ManagerHost or ManagerAddress options must be set for each hirte-agent.
-ManagerHost=
+#ManagerHost=
 
 #
 # The port the manager listens on to establish connections with the hirte agents.
diff --git a/config/hirte/hirte.conf b/config/hirte/hirte.conf
index e21ee0fe02..b269cebd84 100644
--- a/config/hirte/hirte.conf
+++ b/config/hirte/hirte.conf
@@ -9,7 +9,7 @@
 # A comma separated list of unique hirte-agent names. Only nodes with names mentioned in the list can connect to hirte
 # manager. These names are defined in the agent's configuration file under the `NodeName` option.
 # (see `hirte-agent.conf(5)`).
-AllowedNodeNames=
+#AllowedNodeNames=
 
 #
 # The port the manager listens on to establish connections with the hirte agents.
diff --git a/src/agent/agent.c b/src/agent/agent.c
index 525d7cd8e5..da7099f9ae 100644
--- a/src/agent/agent.c
+++ b/src/agent/agent.c
@@ -59,7 +59,6 @@ typedef struct {
         char *method;
 } AgentJobOp;
 
-
 static AgentJobOp *agent_job_op_ref(AgentJobOp *op) {
         op->ref_count++;
         return op;
@@ -372,9 +371,6 @@ Agent *agent_new(void) {
         agent->ref_count = 1;
         agent->event = steal_pointer(&event);
         agent->api_bus_service_name = steal_pointer(&service_name);
-        agent->port = HIRTE_DEFAULT_PORT;
-        agent->host = strdup(HIRTE_DEFAULT_HOST);
-        agent->heartbeat_interval_msec = AGENT_HEARTBEAT_INTERVAL_MSEC;
         LIST_HEAD_INIT(agent->outstanding_requests);
         LIST_HEAD_INIT(agent->tracked_jobs);
         LIST_HEAD_INIT(agent->proxy_services);
@@ -388,7 +384,6 @@ Agent *agent_new(void) {
         agent->connection_state = AGENT_CONNECTION_STATE_DISCONNECTED;
         agent->connection_retry_count = 0;
         agent->wildcard_subscription_active = false;
-        agent->name = get_hostname();
         agent->metrics_enabled = false;
 
         return steal_pointer(&agent);
@@ -535,6 +530,11 @@ bool agent_parse_config(Agent *agent, const char *configfile) {
                 return false;
         }
 
+        result = cfg_agent_def_conf(agent->config);
+        if (result < 0) {
+                fprintf(stderr, "Failed to set default settings for agent: %s", strerror(-result));
+                return false;
+        }
         result = cfg_load_complete_configuration(
                         agent->config,
                         CFG_AGENT_DEFAULT_CONFIG,
@@ -555,14 +555,6 @@ bool agent_parse_config(Agent *agent, const char *configfile) {
                 }
         }
 
-        result = cfg_set_default_section(agent->config, CFG_SECT_AGENT);
-        if (result != 0) {
-                fprintf(stderr,
-                        "Error setting default section for agent '%s', error code '%s'.\n",
-                        CFG_SECT_AGENT,
-                        strerror(-result));
-                return false;
-        }
 
         // set logging configuration
         hirte_log_init(agent->config);
diff --git a/src/libhirte/common/cfg.c b/src/libhirte/common/cfg.c
index 6d3b66270b..7189f6b68f 100644
--- a/src/libhirte/common/cfg.c
+++ b/src/libhirte/common/cfg.c
@@ -9,6 +9,7 @@
 #include <unistd.h>
 
 #include "libhirte/common/list.h"
+#include "libhirte/common/network.h"
 #include "libhirte/hashmap/hashmap.h"
 #include "libhirte/ini/ini.h"
 
@@ -338,3 +339,72 @@ const char *cfg_dump(struct config *config) {
         }
         return cfg_info;
 }
+
+int cfg_agent_def_conf(struct config *config) {
+        int result = 0;
+
+        result = cfg_set_default_section(config, CFG_SECT_AGENT);
+        if (result != 0) {
+                return result;
+        }
+
+        if (cfg_set_value(config, CFG_NODE_NAME, get_hostname()) != 0) {
+                return -1;
+        }
+
+        if (cfg_set_value(config, CFG_MANAGER_HOST, HIRTE_DEFAULT_HOST) != 0) {
+                return -1;
+        }
+
+        if (cfg_set_value(config, CFG_HEARTBEAT_INTERVAL, AGENT_HEARTBEAT_INTERVAL_MSEC) != 0) {
+                return -1;
+        }
+
+        if (cfg_set_value(config, CFG_MANAGER_PORT, HIRTE_DEFAULT_PORT) != 0) {
+                return -1;
+        }
+
+        const char *LOG_LEVEL_INFO = "INFO";
+        if (cfg_set_value(config, CFG_LOG_LEVEL, LOG_LEVEL_INFO) != 0) {
+                return -1;
+        }
+
+        if (cfg_set_value(config, CFG_LOG_TARGET, HIRTE_LOG_TARGET_STDERR) != 0) {
+                return -1;
+        }
+
+        if (cfg_set_value(config, CFG_LOG_IS_QUIET, NULL) != 0) {
+                return -1;
+        }
+        return 0;
+}
+
+int cfg_manager_def_conf(struct config *config) {
+        int result = 0;
+
+        result = cfg_set_default_section(config, CFG_SECT_HIRTE);
+        if (result != 0) {
+                return result;
+        }
+
+        if (cfg_set_value(config, CFG_MANAGER_PORT, HIRTE_DEFAULT_PORT) != 0) {
+                return -1;
+        }
+
+        if (cfg_set_value(config, CFG_ALLOWED_NODE_NAMES, "") != 0) {
+                return -1;
+        }
+
+        if (cfg_set_value(config, CFG_LOG_LEVEL, log_level_to_string(LOG_LEVEL_INFO)) != 0) {
+                return -1;
+        }
+
+        if (cfg_set_value(config, CFG_LOG_TARGET, HIRTE_LOG_TARGET_STDERR) != 0) {
+                return -1;
+        }
+
+        if (cfg_set_value(config, CFG_LOG_IS_QUIET, NULL) != 0) {
+                return -1;
+        }
+        return 0;
+}
diff --git a/src/libhirte/common/cfg.h b/src/libhirte/common/cfg.h
index 57a16f8d2c..7012422892 100644
--- a/src/libhirte/common/cfg.h
+++ b/src/libhirte/common/cfg.h
@@ -182,3 +182,13 @@ bool cfg_s_get_bool_value(struct config *config, const char *section, const char
  * The caller is responsible for freeing the returned string.
  */
 const char *cfg_dump(struct config *config);
+
+/*
+ * Populate the default agent configuration from the source code
+ */
+int cfg_agent_def_conf(struct config *config);
+
+/*
+ * Populate the default manager configuration from the source code
+ */
+int cfg_manager_def_conf(struct config *config);
diff --git a/src/libhirte/common/protocol.h b/src/libhirte/common/protocol.h
index d735bea363..38115698ad 100644
--- a/src/libhirte/common/protocol.h
+++ b/src/libhirte/common/protocol.h
@@ -3,7 +3,7 @@
 
 #include <errno.h>
 
-#define HIRTE_DEFAULT_PORT 842
+#define HIRTE_DEFAULT_PORT "842"
 #define HIRTE_DEFAULT_HOST "127.0.0.1"
 
 #define HIRTE_DBUS_NAME "org.containers.hirte"
@@ -94,7 +94,7 @@ UnitActiveState active_state_from_string(const char *s);
 /* Agent to Hirte heartbeat signals */
 
 // Application-level heartbeat set at 2 seconds.
-#define AGENT_HEARTBEAT_INTERVAL_MSEC (2000)
+#define AGENT_HEARTBEAT_INTERVAL_MSEC "2000"
 #define AGENT_HEARTBEAT_SIGNAL_NAME "Heartbeat"
 
 /* Constants */
diff --git a/src/libhirte/log/log.c b/src/libhirte/log/log.c
index d9e06e9103..fa70903868 100644
--- a/src/libhirte/log/log.c
+++ b/src/libhirte/log/log.c
@@ -141,11 +141,6 @@ void hirte_log_set_quiet(bool is_quiet) {
 }
 
 int hirte_log_init(struct config *config) {
-        // initialize log defaults
-        hirte_log_set_level(LOG_LEVEL_INFO);
-        hirte_log_set_quiet(false);
-        hirte_log_set_log_fn(hirte_log_to_stderr_with_location);
-
         // load log settings from configuration
         const char *target = NULL;
         const char *quiet = NULL;
diff --git a/src/manager/manager.c b/src/manager/manager.c
index 03809743e2..7ec4c9c2b6 100644
--- a/src/manager/manager.c
+++ b/src/manager/manager.c
@@ -38,7 +38,6 @@ Manager *manager_new(void) {
         Manager *manager = malloc0(sizeof(Manager));
         if (manager != NULL) {
                 manager->ref_count = 1;
-                manager->port = HIRTE_DEFAULT_PORT;
                 manager->api_bus_service_name = steal_pointer(&service_name);
                 manager->event = steal_pointer(&event);
                 manager->metrics_enabled = false;
@@ -313,6 +312,12 @@ bool manager_parse_config(Manager *manager, const char *configfile) {
                 return false;
         }
 
+        result = cfg_manager_def_conf(manager->config);
+        if (result != 0) {
+                fprintf(stderr, "Failed to set default settings for manager: %s", strerror(-result));
+                return false;
+        }
+
         result = cfg_load_complete_configuration(
                         manager->config, CFG_HIRTE_DEFAULT_CONFIG, CFG_ETC_HIRTE_CONF, CFG_ETC_HIRTE_CONF_DIR);
         if (result != 0) {
@@ -330,15 +335,6 @@ bool manager_parse_config(Manager *manager, const char *configfile) {
                 }
         }
 
-        result = cfg_set_default_section(manager->config, CFG_SECT_HIRTE);
-        if (result != 0) {
-                fprintf(stderr,
-                        "Error setting default section for hirte '%s', error code '%s'.\n",
-                        CFG_SECT_HIRTE,
-                        strerror(-result));
-                return false;
-        }
-
         // set logging configuration
         hirte_log_init(manager->config);
 


Test patch:
diff --git a/tests/hirte_test/config.py b/tests/hirte_test/config.py
index a518763068..8e9c1422eb 100644
--- a/tests/hirte_test/config.py
+++ b/tests/hirte_test/config.py
@@ -71,7 +71,7 @@ def __init__(
             manager_host: str = "",
             manager_port: str = "8420",
             manager_address: str = "",
-            heartbeat_interval: str = "",
+            heartbeat_interval: str = "2000",
             log_level: str = "DEBUG",
             log_target: str = "journald",
             log_is_quiet: bool = False) -> None: