Issue with secrets

Hy!

Using the same secret on multiple targets in the container with different filesystem mode results in a weird bahavior:

Image mariadb:10.4.8
On “Red Hat Enterprise Linux Server 7.6 (Maipo)”
docker-ce-cli-18.09.7-3.el7.x86_64
docker-ce-18.09.7-3.el7.x86_64

Stack config snippet:

secrets:
  - test-mysqldb-pw
  - source: test-mysqldb-pw
    target: /run/secrets/db-root-pw
    uid: '0'
    gid: '0'
    mode: 0640
  - source: test-mysqldb-pw
    target: /run/secrets/db-root-pw-othermode-666
    uid: '0'
    gid: '0'
    mode: 0666
  - source: test-mysqldb-pw
    target: /run/secrets/db-root-pw-othermode-777
    uid: '0'
    gid: '0'
    mode: 0777
  - source: test-mysqldb-pw
    target: /run/db-root-pw-othermode-700
    uid: '0'
    gid: '0'
    mode: 700
  - test-mysqldb-pw2
  - source: test-mysqldb-pw2
    target: /run/secrets/db-root-pw2
    uid: '0'
    gid: '0'
    mode: 0600
secrets:
  test-mysqldb-pw:
    external: true
  test-mysqldb-pw2:
   external: true

Results to:

ls -l db*

-rw-rw-rw- 1 root root 4 Oct 17 11:25 db-root-pw-othermode-700

ls -l secrets

total 24
-rw-rw-rw- 1 root root 4 Oct 17 11:25 db-root-pw
-rw-rw-rw- 1 root root 4 Oct 17 11:25 db-root-pw-othermode-666
-rw-rw-rw- 1 root root 4 Oct 17 11:25 db-root-pw-othermode-777
-rw------- 1 root root 5 Oct 17 11:25 db-root-pw2
-rw-rw-rw- 1 root root 4 Oct 17 11:25 test-mysqldb-pw
-rw------- 1 root root 5 Oct 17 11:25 test-mysqldb-pw2

All secrets from the same source are set with the same mode. But i can’t say why.

Is this the expected behavior or bug?

Dont ask why I need this scenario. This was the result of testing secrets.