postgres icon indicating copy to clipboard operation
postgres copied to clipboard

alternative to gosu to ensure even naïve vulnerability scanners show no false-positives

Open jesperronn opened this issue 1 year ago • 6 comments

Happy new year 🥂, sorry to rip up in the discussions provided here and in the gosu repository:

https://github.com/docker-library/postgres/issues/1292 https://github.com/docker-library/postgres/issues/1282 https://github.com/docker-library/postgres/issues/1297

While I completely respect and understand the stance of gosu author that vulnerability scanners are naïve and show false positive, I think that much time is wasted by postgres consumers understanding all the details and even move time is spent explaining that the critical issues in postgresql images are false positives.

Therefore this (another thread) on the subject. However the question I would like to ask here is

  • Do you know of a replacement for gosu which can be used and give postresql project the same functionality?

the alternative MUST be actively maintained, in the way that all security issues are actively addressed in a way that even naïve vulnerabiltity scanners understand (at least docker scout and trivy)

Please let's focus this discussion on alternatives to gosu in this image.For comments that mention to fix gosu itself, make those comments in the gosu project.

jesperronn avatar Jan 01 '25 09:01 jesperronn

Same issue with convertigo official image: https://github.com/convertigo/convertigo/issues/876

gosu is used from our first docker version and I don't know what to use instead, without side effects.

nicolas-albert avatar Jan 06 '25 09:01 nicolas-albert

gosu is used from our first docker version and I don't know what to use instead, without side effects.

this is really a fair opinion, and I fully understand your view.

I will recommend reading gosu source code. The two files main.go and setup-user.go contain all relevant code.

As I see it, basically it is a wrapper around shell methods via a standard go library. (disclaimer: first time I look into Go source code).

main.go: https://github.com/tianon/gosu/blob/ccc5c46e5fc49132e0515885cbe8e4ffe79b0fb6/main.go#L72-L77

setup-user.go: https://github.com/tianon/gosu/blob/ccc5c46e5fc49132e0515885cbe8e4ffe79b0fb6/setup-user.go

looking at it it's mostly just setup-user.go that has functionality.

Setup-user contains calls to the two standard go libraries:

"github.com/moby/sys/user"
"golang.org/x/sys/unix"

and the commands that are done in the file could be converted to a basic shell script fairly easily I think.

I will happily assist, but given that gosu is used and has to be replaced, I suggest a thorough testing of the images that are being built right now.

If somebody wants to give a try replacing gosu in a PR, feel free (my skills slightly limited in that area)

jesperronn avatar Jan 08 '25 09:01 jesperronn

I've switched with sudo -n -E -u <user> and no more vulnerabilities in scans. I don't know if their is a side effect but the application starts well.

nicolas-albert avatar Jan 09 '25 08:01 nicolas-albert

@nicolas-albert could you provide a minimal reproducible example based on the code here in this repository?

jesperronn avatar Jan 13 '25 06:01 jesperronn

https://github.com/docker-library/postgres/blob/32b6fcdda7f52830f42dd695e2dc2f739581756b/docker-entrypoint.sh#L313

exec gosu postgres "$BASH_SOURCE" "$@" to exec sudo -n -E -u postgres "$BASH_SOURCE" "$@"

I don't know if you have sudo in your debian or alpine dependencies and you have to remove the gosu setup (that comes with securities alerts).

nicolas-albert avatar Jan 13 '25 06:01 nicolas-albert

You probably want to use setpriv (from util-linux) instead.

See also https://github.com/tianon/gosu/pull/143

tianon avatar Jan 13 '25 19:01 tianon

Cofounder and CEO of VulnFree here. Our images should solve that problem for you for a reasonable cost:

  • https://vulnfree.com/

nathan-git123 avatar Apr 23 '25 16:04 nathan-git123

Alas, setpriv provided by alpine comes from busybox and doesn't appear to support --ruid or --rgid.

jcpunk avatar Jul 23 '25 19:07 jcpunk

apk add --no-cache setpriv gets you the full version from util-linux :eyes:

tianon avatar Jul 23 '25 19:07 tianon