<p>Let's say I have the below yaml:</p>

<pre><code>spec:
  securityContext:
    fsGroup: 5678
  serviceAccountName: some-account
  volumes:
    - name: secrets
      secret:
        secretName: data-secrets
    - name: secrets-sftp-passwd-key
      secret:
        secretName: sftp-passwd-key
  containers:
    - name: sftp
      securityContext:
        runAsUser: 1234
        runAsGroup: 5678
      image: "some/some"
      imagePullPolicy: always
      ports:
        - name: tcp-sftp
          containerPort: 22
      volumeMounts:
      - name: secrets-sftp-passwd-key
        mountPath: /etc/sftp/secret/
      - name: data
        mountPath: "/var/data"
      env:
        - name: "SFTP_USER"
          value: "some_user"
        - name: "SFTP_PASSWD"
          value: "password-1"
</code></pre>

<p>I'm trying to run the container <code>sftp</code> with <code>runAsUser</code> and <code>runAsGroup</code>. The image's entrypoint script is supposed to take the SFTP_USER, SFTP_PASSWD and create certain password and group files using this input. These files are supposed to be created in /var/data folder. After this, a proftpd process is supposed to be started using these password and group files as the 1234 user. The container starts as 1234 user. But the files have a permission of root:5678. And I get the below error:</p>

<pre><code>unable to set UID to 0, current UID: 1234
</code></pre>

<p>The entry point script of the image is as below:</p>

<pre><code>echo "Starting to create password file"
PASSWORD=123456
echo $PASSWORD | /usr/bin/ftpasswd --passwd --file=/var/data/ftpd.passwd --name=virtual --uid=1234 --gid=5678 --home=/var/data/ --shell=/bin/bash --stdin
echo "Password file created"
/usr/bin/ftpasswd --group --name=--group --name=virtual --file=/var/data/ftpd.group --gid=5678 --member=1234
proftpd -n  -4 -c /var/data/proftpd.conf --&gt; This line is throwing the above error. 
</code></pre>

<p>What is going wrong here? Why is it trying to set UID to 0?? I was under the impression that giving <code>runAsUser</code>, <code>runAsGroup</code> and <code>fsGroup</code> will make sure that the /var/data folder has the correct ownership of 1234. </p>

user1452759
<p>The error you're encountered is being being printed by following <a href="https://github.com/proftpd/proftpd/blob/1bbb7b3e667c9f03050c692a9cecbd214bffff85/src/main.c#L2621-L2626" rel="nofollow noreferrer">code</a>: </p>

<pre><code>if (geteuid() != daemon_uid) {
    pr_log_pri(PR_LOG_ERR, "unable to set UID to %s, current UID: %s",
    pr_uid2str(permanent_pool, daemon_uid),
    pr_uid2str(permanent_pool, geteuid()));
    exit(1);
}
</code></pre>

<p>You're seeing this because your container userID is not equal to the <code>daemon_uid</code>. 
If you keep looking for <code>daemon_uid</code> you will find following line: </p>

<pre><code>uid_t *uid = (uid_t *) get_param_ptr(main_server-&gt;conf, "UserID", FALSE);
daemon_uid = (uid != NULL ? *uid : PR_ROOT_UID);
</code></pre>

<p>This means that if the <code>UserID</code> is not provided in config the code assigns<code>PR_ROOT_UID</code> value to the <code>daemon_uid</code> which appears to be 0 (root id). 
This is why the earlier mentioned if statement is generating this error message. </p>

<p>Take a look at the <a href="https://github.com/proftpd/proftpd/blob/1bbb7b3e667c9f03050c692a9cecbd214bffff85/sample-configurations/basic.conf#L28-L30" rel="nofollow noreferrer">example config</a> how to provide userID. </p>
