<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
<channel>
<title>Coder Legion - Recent posts tagged prevent</title>
<link>https://coderlegion.com/tag/prevent</link>
<description>Powered by Question2Answer</description>
<item>
<title>Understanding Systemd.exec—Part 3: Disabling the COPY TO PROGRAM feature in Postgres.</title>
<link>https://coderlegion.com/16112/understanding-systemd-exec-part-3-disabling-the-copy-to-program-feature-in-postgres</link>
<description>
&lt;p&gt;Hello, I'm Ganesh. I'm building &lt;em&gt;git-lrc&lt;/em&gt;, an AI code reviewer that runs on every commit. It is free, unlimited, and source-available on Github. &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;Star Us&lt;/a&gt; to help devs discover the project. Do give it a try and share your feedback for improving the product.&lt;/p&gt;

&lt;p&gt;In previous article we discussed how this feature may be attacker entry point to server.&lt;/p&gt;

&lt;p&gt;So, now let's implment custom systemd configuration to disable this feature.&lt;/p&gt;

&lt;h2&gt;
  
  
  Securing Postgres with systemd.exec options
&lt;/h2&gt;

&lt;p&gt;I found only way for now to disable this feature is to create custom systemd configuration.&lt;/p&gt;

&lt;p&gt;Let's identify the postgres version.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;gk@jarvis:~&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;psql &lt;span class=&quot;nt&quot;&gt;--version&lt;/span&gt;
psql &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;PostgreSQL&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; 16.13 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;Ubuntu 16.13-0ubuntu0.24.04.1&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
gk@jarvis:~&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Based on postgress version we can use different postgresctl command.&lt;/p&gt;

&lt;p&gt;We can add custom systemd configuration for each postgres version.&lt;/p&gt;

&lt;p&gt;So, How attacker mostly use copy function to get inside the server?&lt;/p&gt;

&lt;p&gt;Here, how simple funtion can be used to get inside the server.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;using shell&lt;/li&gt;
&lt;li&gt;using curl&lt;/li&gt;
&lt;li&gt;using wget&lt;/li&gt;
&lt;li&gt;using bash&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Still goes on Many ways you can use copy function to get inside the server.&lt;/p&gt;

&lt;p&gt;Based on my analysis and continuous retry on disable feature on by one.&lt;br&gt;
I got working configureation  which will disconnect from postgres access.&lt;/p&gt;
&lt;h2&gt;
  
  
  Available options In systemd.exec For postgres
&lt;/h2&gt;

&lt;p&gt;Let's analyze these options and try to disable them using systemd.exec options.&lt;/p&gt;

&lt;p&gt;we can use&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;TemporaryFileSystem&lt;br&gt;
This will create read only filesystem for specific directory.&lt;br&gt;
We can make sure they don't have direct access to system utilities.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;BindReadOnlyPaths&lt;br&gt;
Re-expose only what's needed by postgres. Example postgres binaries, libraries etc.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ProtectSystem&lt;br&gt;
Block /usr, /boot, /etc from write access&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ProtectHome&lt;br&gt;
This will block access to /home directory.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PrivateTmp&lt;br&gt;
This will create temporary /tmp and /var/tmp directories for the service.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ReadWritePaths&lt;br&gt;
This is main thing as we disabled all the feature postgress data should be writable to some directory. Which can be:&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;/var/lib/postgresql&lt;/li&gt;
&lt;li&gt;/var/run/postgresql&lt;/li&gt;
&lt;li&gt;/var/log/postgresql&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Just have a look based on your version.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;NoNewPrivileges&lt;br&gt;
If a service process tries to gain more privileges, the kernel will deny it.&lt;br&gt;
This can prevent attackers from escalating privileges even if they compromise the service.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;RestrictNamespaces&lt;br&gt;
This option can be used to restrict the namespaces that a service can access.&lt;br&gt;
This is mainly for if they try to break out from the container/VM. &lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;RestrictAddressFamilies&lt;br&gt;
This option can be used to restrict the address families that a service can access.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ProtectKernelTunables&lt;br&gt;
This option can be used to prevent a service from modifying kernel tunables.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ProtectKernelModules&lt;br&gt;
This option can be used to prevent a service from loading kernel modules.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ProtectControlGroups&lt;br&gt;
This will prevent the service from accessing the cgroups of other processes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ProtectProc&lt;br&gt;
This will prevent the service from accessing the process information of other processes.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;UMask&lt;br&gt;
This will set the umask of the service.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;CapabilityBoundingSet&lt;br&gt;
This will set the capability bounding set of the service.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;AmbientCapabilities&lt;br&gt;
This will set the ambient capabilities of the service.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SystemCallFilter&lt;br&gt;
This will set the system call filter of the service.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SystemCallErrorNumber&lt;br&gt;
This will set the system call error number of the service.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;MemoryDenyWriteExecute&lt;br&gt;
This will set the memory deny write execute of the service.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;LockPersonality&lt;br&gt;
This will lock the personality of the service.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;RestrictSUIDSGID&lt;br&gt;
This will prevent the service from using SUID and SGID bits.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;
&lt;h2&gt;
  
  
  Configuring Systemd for postgres
&lt;/h2&gt;

&lt;p&gt;So, Now let's create custom configuration for postgres.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;mkdir&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; /etc/systemd/system/postgresql@16-main.service.d
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;vim /etc/systemd/system/postgresql@16-main.service.d/override.conf
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now add these options to the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;Service]
&lt;span class=&quot;c&quot;&gt;# &amp;#9472;&amp;#9472; BYPASS pg_ctlcluster (it's a perl script &amp;mdash; breaks TemporaryFileSystem) &amp;#9472;&amp;#9472;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;ExecStart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;ExecStart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/usr/lib/postgresql/16/bin/postgres &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;-D&lt;/span&gt; /var/lib/postgresql/16/main &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;config_file&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/etc/postgresql/16/main/postgresql.conf &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;hba_file&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/etc/postgresql/16/main/pg_hba.conf &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;ident_file&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/etc/postgresql/16/main/pg_ident.conf &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
  &lt;span class=&quot;nt&quot;&gt;-c&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;external_pid_file&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/run/postgresql/16-main.pid
&lt;span class=&quot;nv&quot;&gt;ExecStop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;ExecStop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/usr/lib/postgresql/16/bin/pg_ctl stop &lt;span class=&quot;nt&quot;&gt;-D&lt;/span&gt; /var/lib/postgresql/16/main &lt;span class=&quot;nt&quot;&gt;-m&lt;/span&gt; fast
&lt;span class=&quot;nv&quot;&gt;ExecReload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;ExecReload&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/usr/lib/postgresql/16/bin/pg_ctl reload &lt;span class=&quot;nt&quot;&gt;-D&lt;/span&gt; /var/lib/postgresql/16/main

&lt;span class=&quot;nv&quot;&gt;User&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;postgres
&lt;span class=&quot;nv&quot;&gt;Group&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;postgres

&lt;span class=&quot;c&quot;&gt;# &amp;#9472;&amp;#9472; BLANK ALL EXECUTABLE DIRS &amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;TemporaryFileSystem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/usr/bin:ro
&lt;span class=&quot;nv&quot;&gt;TemporaryFileSystem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/bin:ro
&lt;span class=&quot;nv&quot;&gt;TemporaryFileSystem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/usr/sbin:ro
&lt;span class=&quot;nv&quot;&gt;TemporaryFileSystem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/sbin:ro
&lt;span class=&quot;nv&quot;&gt;TemporaryFileSystem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/usr/local/bin:ro
&lt;span class=&quot;nv&quot;&gt;TemporaryFileSystem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/usr/local/sbin:ro
&lt;span class=&quot;nv&quot;&gt;TemporaryFileSystem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/snap:ro
&lt;span class=&quot;nv&quot;&gt;TemporaryFileSystem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/opt:ro

&lt;span class=&quot;c&quot;&gt;# &amp;#9472;&amp;#9472; RE-EXPOSE ONLY WHAT'S NEEDED &amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;BindReadOnlyPaths&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/usr/lib/postgresql/16/bin/postgres:/usr/lib/postgresql/16/bin/postgres
&lt;span class=&quot;nv&quot;&gt;BindReadOnlyPaths&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/usr/lib/postgresql/16/bin/pg_ctl:/usr/lib/postgresql/16/bin/pg_ctl
&lt;span class=&quot;nv&quot;&gt;BindReadOnlyPaths&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/usr/lib/postgresql/16/lib:/usr/lib/postgresql/16/lib
&lt;span class=&quot;nv&quot;&gt;BindReadOnlyPaths&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/lib/x86_64-linux-gnu:/lib/x86_64-linux-gnu
&lt;span class=&quot;nv&quot;&gt;BindReadOnlyPaths&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/usr/lib/x86_64-linux-gnu:/usr/lib/x86_64-linux-gnu

&lt;span class=&quot;c&quot;&gt;# &amp;#9472;&amp;#9472; FILESYSTEM &amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;ProtectSystem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;strict
&lt;span class=&quot;nv&quot;&gt;ProtectHome&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes
&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;PrivateTmp&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes
&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;ReadWritePaths&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;/var/lib/postgresql /var/run/postgresql /var/log/postgresql

&lt;span class=&quot;c&quot;&gt;# &amp;#9472;&amp;#9472; BEHAVIORAL &amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;NoNewPrivileges&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes
&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;RestrictNamespaces&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes
&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;RestrictAddressFamilies&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;AF_UNIX AF_INET AF_INET6
&lt;span class=&quot;nv&quot;&gt;ProtectKernelTunables&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes
&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;ProtectKernelModules&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes
&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;ProtectControlGroups&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes
&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;ProtectProc&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;invisible
&lt;span class=&quot;nv&quot;&gt;UMask&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;0027
&lt;span class=&quot;nv&quot;&gt;CapabilityBoundingSet&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;AmbientCapabilities&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;

&lt;span class=&quot;c&quot;&gt;# &amp;#9472;&amp;#9472; SYSCALL FILTER &amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&amp;#9472;&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;SystemCallFilter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;@system-service @file-system @network-io
&lt;span class=&quot;nv&quot;&gt;SystemCallErrorNumber&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;EPERM
&lt;span class=&quot;nv&quot;&gt;MemoryDenyWriteExecute&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes
&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;LockPersonality&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes
&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;RestrictSUIDSGID&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;yes&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Note: There may many issues setting up this configuration. So, make sure this only done on Staging env and test it thoroughly.&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;systemctl daemon-reload
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;systemctl restart postgresql@16-main.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So, If you check status&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;systemctl status postgresql@16-main.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will see all the options are enabled.&lt;/p&gt;

&lt;p&gt;If there any issues just check logs&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;journalctl &lt;span class=&quot;nt&quot;&gt;-u&lt;/span&gt; postgresql@16-main.service &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-n&lt;/span&gt; 50
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Reverting Configuration
&lt;/h2&gt;

&lt;p&gt;Finaly to remove this configuration just run&lt;/p&gt;

&lt;p&gt;First we have remove the conf file.&lt;/p&gt;

&lt;p&gt;And restart daemon and restart service.&lt;br&gt;
&lt;/p&gt;

&lt;div class=&quot;highlight js-code-highlight&quot;&gt;
&lt;pre class=&quot;highlight shell&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;sudo rm&lt;/span&gt; /etc/systemd/system/postgresql@16-main.service.d/override.conf
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;systemctl daemon-reload
&lt;span class=&quot;nb&quot;&gt;sudo &lt;/span&gt;systemctl restart postgresql@16-main.service
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;This is the only way I found to disable copy function in postgres. This may be experimental but still worth for adding this config if you want disable postgress copy to program function.&lt;/p&gt;

&lt;p&gt;Reference Man Page Systemd : &lt;a href=&quot;https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://www.freedesktop.org/software/systemd/man/latest/systemd.exec.html&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Discussion in HN: &lt;a href=&quot;https://news.ycombinator.com/item?id=37164115&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://news.ycombinator.com/item?id=37164115&lt;/a&gt;&lt;br&gt;
PostgreSQL Discussion : &lt;a href=&quot;https://www.postgresql.org/message-id/CAKFQuwZZ0zAMpp2KjBr5bUS7RvBqouD2Kqne6YtbgZn%3DnzL1xA%40mail.gmail.com&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://www.postgresql.org/message-id/CAKFQuwZZ0zAMpp2KjBr5bUS7RvBqouD2Kqne6YtbgZn%3DnzL1xA%40mail.gmail.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;&lt;img src=&quot;https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fabn6nl3iehrohehnxgje.png&quot; alt=&quot;git-lrc&quot; width=&quot;800&quot; height=&quot;373&quot;&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Any feedback or contributors are welcome! It&amp;rsquo;s online, source-available, and ready for anyone to use. &lt;br&gt;
&amp;#11088; Star it on GitHub: &lt;a href=&quot;https://github.com/HexmosTech/git-lrc&quot; rel=&quot;noopener noreferrer nofollow&quot;&gt;https://github.com/HexmosTech/git-lrc&lt;/a&gt;&lt;/p&gt;


</description>
<category>Other</category>
<guid isPermaLink="true">https://coderlegion.com/16112/understanding-systemd-exec-part-3-disabling-the-copy-to-program-feature-in-postgres</guid>
<pubDate>Sat, 02 May 2026 23:50:26 +0000</pubDate>
</item>
</channel>
</rss>