Shell script to monitor file ownership change and change it back

I need a shell script to monitor some file ownership changes and change them back. I think it should be based on inotify or fswatch (based on what I read here Is there a command like "watch" or "inotifywait" on the Mac?) but I haven’t figure out how to do that exactly.

My use case is this, my web-app runs inside docker and when Devops guys log inside docker to check the system, they always forgot they log inside docker using root (normally they just run docker exec container_id /bin/bash), so when they make a change to a file, the file ownership will be changed from www-data to root. They always forgot to change it back, then that causes all kinds of problem.

So I am thinking about writing a script to monitor some specific files, whenever their ownerships changed the script will change it back.

Source: StackOverflow