Mount a configmap and change file permission and owner

Asking for help? Comment out what you need so we can get more information to help you!

Cluster information:

Kubernetes version:
Client Version: version.Info{Major:“1”, Minor:“22”, GitVersion:“v1.22.1”, GitCommit:“632ed300f2c34f6d6d15ca4cef3d3c7073412212”, GitTreeState:“clean”, BuildDate:“2021-08-19T15:45:37Z”, GoVersion:“go1.16.7”, Compiler:“gc”, Platform:“linux/amd64”}
Server Version: version.Info{Major:“1”, Minor:“29”, GitVersion:“v1.29.0+rke2r1”, GitCommit:“3f7a50f38688eb332e2a1b013678c6435d539ae6”, GitTreeState:“clean”, BuildDate:“2023-12-13T22:06:58Z”, GoVersion:“go1.21.5 X:boringcrypto”, Compiler:“gc”, Platform:“linux/amd64”}
WARNING: version difference between client (1.22) and server (1.29) exceeds the supported minor version skew of +/-1
Cloud being used: bare-metal
Installation method: rancher
Host OS: opensuse
CNI and version:
CRI and version:

You can format your yaml by highlighting it and pressing Ctrl-Shift-C, it will make your output easier to read.

Hi, I have a configmap with a configuration file I need to mount into my application container. I also need to set the owner from 0 to 1000 and file permissions of this file to 0600 instead of default 0644.

I tried using a combination of volume.configMap.defaultMode = 0600 and securityContext.fsGropu = 1000 but this won’t work because the defaultMode is not taking place. I also tried using an initContainer with a command to make the desired changes but I get an error saying I can’t change a read only filesystem.

How can I mount a configmap and set the user owner and the filepermissions in k8s?

thank you