I have a file with a secret and a generator application that reads it and generates something similar to a license.
There are users on that Linux machine who are allow to use that application.
Because that app read that secret file, these users must have read permission to that file.
Is there a way to remove the read permission from these users - just let the app read that file through that app only, when these users run it?
I want to give only ones who run that app the ability to read that file, and through that file only. Not just cat
it and watch its content.
- I saw a way solving it using
chmod 400 secret_file
chmod 110 generator
chmod u+s generator
This way users in the same group as generator
can execute generator
and can't read secret_file
.
But because generator
is with setuid
then generator
can read secret_file
.
This is a nice solution, but I wanted to have the user's name in generator
, and using that solution I always get the owner's name.
This is how I get the user's name from c/cpp application:
#include <pwd.h>
uid_t uid = geteuid();
struct passwd *pw = getpwuid(uid);
std::string user_name = pw->pw_name;
Is there another way to solve this issue?
Can somehow apparmor
help? (I couldn't understand)
A follow up question - is there way to make file executable only through a specific script?
What I mean is that I don't want generator
to be executed from a shell. I want it to be executed only from another script generator.sh
which calls generator
, because I do more stuff in generator.sh
. I want user who runs bluntly generator
to fail, and user who runs generator.sh
to succeed.
sudo
– Chris Davies Dec 30 '20 at 22:22uid_t uid = getuid();
and that's it, + using thechmod 110 generator, chmod u+s generator
, right? wow, that's nice. Regarding the script, is that related to the follow up question? I want to have "normal" users who run the appgenerator
, but just through a script. – hudac Dec 30 '20 at 22:33generator
to be executed from a shell. I want it to be executed only from another scriptgenerator.sh
which callsgenerator
, because I do more stuff ingenerator.sh
. I want user who runs bluntlygenerator
to fail, and user who runsgenerator.sh
to succeed. – hudac Dec 30 '20 at 22:36