entrypoint: chown www-data: /data and drop privileges if started as root

This commit is contained in:
Alexander A. Klimov 2023-02-15 14:51:26 +01:00
parent 39971df6fa
commit a700df6340

View File

@ -18,6 +18,7 @@ import (
"time"
)
const wwwdataUid = 33
const dataVolume = "/data"
const modsDir = "/usr/share/icingaweb2/modules"
const dirMode = 0750
@ -39,6 +40,24 @@ func entrypoint() error {
return nil
}
if os.Getuid() == 0 {
logf("info", "Giving %s to the www-data user as we're root", dataVolume)
if err := os.Chown(dataVolume, wwwdataUid, wwwdataUid); err != nil {
return err
}
logf("info", "Dropping privileges as we're root")
if err := syscall.Setgid(wwwdataUid); err != nil {
return err
}
if err := syscall.Setuid(wwwdataUid); err != nil {
return err
}
}
if os.Getpid() == 1 {
logf("info", "Initializing %s as we're the init process", dataVolume)