LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Security
User Name
Password
Linux - Security This forum is for all security related questions.
Questions, tips, system compromises, firewalls, etc. are all included here.

Notices


Reply
  Search this Thread
Old 07-23-2023, 02:44 PM   #1
Jason.nix
Member
 
Registered: Feb 2023
Posts: 567

Rep: Reputation: 10
Post A question about sudo user


Hello,
I want a user to be in the sudoers file, but not be able to see the contents of a specific file.
What should I do?


Thank you.
 
Old 07-23-2023, 03:21 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,747

Rep: Reputation: 7982Reputation: 7982Reputation: 7982Reputation: 7982Reputation: 7982Reputation: 7982Reputation: 7982Reputation: 7982Reputation: 7982Reputation: 7982Reputation: 7982
Quote:
Originally Posted by Jason.nix View Post
Hello,
I want a user to be in the sudoers file, but not be able to see the contents of a specific file. What should I do?
Since this is in the "Security" forum, I'll suggest you give some thought to this. The main idea is that anyone you give superuser/sudo/elevated rights to on a system is someone you can TRUST. If you can't...you shouldn't be giving them those privileges.

But you CAN do what you're after...maybe. The sudoers file can be edited to allow only SOME commands to be run with elevated privileges, and some not to be run at all. So you could go in and edit sudoers to disallow running vi/emacs as sudo with that file name. For example:
Code:
%sudo !/bin/vi <some file>, !/usr/bin/nano <somefile>
...but that's pointless if you allow them to edit/run visudo, or allow them access to OTHER commands (like cp, mv, etc.), since they can just copy the file elsewhere, rename it, then look at it. There are also things you can do with sudoedit, or using ACL's, but it's a problem that has no real solution. Anyone with elevated rights has an attack vector that makes things easy. If they know what they're doing, you aren't going to keep them out.

This should require a lot of thought before you try to implement anything. Personally, I'd not user sudoers, but just encrypt the file and not give that person the password.
 
1 members found this post helpful.
Old 07-23-2023, 03:29 PM   #3
haertig
Senior Member
 
Registered: Nov 2004
Distribution: Debian, Ubuntu, LinuxMint, Slackware, SysrescueCD, Raspbian, Arch
Posts: 2,331

Rep: Reputation: 357Reputation: 357Reputation: 357Reputation: 357
Assuming you are talking about giving this user root privileges, and want them to be able to view every other file except for the one you are concerned about, that's going to require more than you can do (practically) in the sudoers file alone.

Encrypting the file is one thing. But when the files owner decrypts the file to use it, those decrypted contents will be in system memory which root can read. Yes, that will require a bit of system knowledge to get at, so it depends on how sophisticated this specific sudoer is to determine if this is a security concern worth bothering with.

If you give someone root access, you are giving them the keys to your kingdom. The only way to protect against them abusing their privilege is to move the file you are concerned about to a different kingdom (a different computer).

You can indeed give a sudoer very limited root privileges in the sudoers file. Permission to execute only a few specific commands. But it sounds like you are wanting what I mentioned above, "full root access, except for this one file". That is going to be difficult to implement. Encryption of the file is a good move, especially if your sudoer is not a crackerjack sysadmin that is used to dealing with raw system memory. Moving the file to a different computer takes it away from the sudoers direct grasp, but remember that if you access that remote from from the computer that the sudoer exists on, they still may be able to intercept your communications and see that file.

Last edited by haertig; 07-23-2023 at 03:31 PM.
 
Old 07-24-2023, 09:39 PM   #4
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,683
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
Also consider ACL's: https://www.redhat.com/sysadmin/linu...-control-lists

It may well be that you are looking at an "XY Problem", where you are expressing a problem in terms of what you think will solve it, versus the one that is most appropriate.

This requirement might reasonably be "parsed" thusly; "Why does this user need to be 'in the sudoers file'," yet not be allowed to access 'a particular object?'" It seems quite clear to me that 'the actual issue' has to do with "the security privileges that this user is entitled to have." If the user's capabilities and access are to be limited, then it is fairly axiomatic that he cannot be "rootly."

Last edited by sundialsvcs; 07-24-2023 at 09:52 PM.
 
Old 07-25-2023, 01:41 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,026

Rep: Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343Reputation: 7343
this should go in the other direction, you need to allow only what is really required, nothing more. (for example allow editing a single config file). But if you allowed everything you cannot deny access to only one file, that is impossible. And actually if you could somehow manage it the user will easily find another way to access that file.
 
Old 07-25-2023, 02:26 AM   #6
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,346
Blog Entries: 3

Rep: Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756Reputation: 3756
Quote:
Originally Posted by Jason.nix View Post
I want a user to be in the sudoers file, ...
Why? Which specific activities should that account be able to carry out?
 
Old 07-25-2023, 04:50 AM   #7
yancek
LQ Guru
 
Registered: Apr 2008
Distribution: Slackware, Ubuntu, PCLinux,
Posts: 10,564

Rep: Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498Reputation: 2498
If it is just one file you do not want the person to see, why not encrypt it with gpg, ccrypt or even use 7zip. You need passwords/passphrases when you do this and even root has no access without the passphrase. There are a number of sites explaining these options.

https://devconnected.com/how-to-encrypt-file-on-linux/

https://www.fosslinux.com/27018/best...s-in-linux.htm
 
Old 07-25-2023, 08:15 AM   #8
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,683
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
Technically speaking, the ACL mechanism can be very specific. However, I echo my original "XY Problem" sentiment. If you launch a process successfully using "sudo," then that process runs with "root privileges." Therefore, if you want that process to be limited, especially in such a particular way, then "sudo" is categorically not the proper solution to the problem.
 
Old 08-12-2023, 10:39 AM   #9
sundialsvcs
LQ Guru
 
Registered: Feb 2004
Location: SE Tennessee, USA
Distribution: Gentoo, LFS
Posts: 10,683
Blog Entries: 4

Rep: Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947Reputation: 3947
Also note: while the concept of "ACLs" is different between (network and native) filesystems, both in terms of how they work and what they can and cannot do, they are by-now pretty much supported everywhere. In other words, "you are not limited by the -rwxrwxrwx "Unix® file permissions mask." Your Mileage May Vary™ but this is the proper place to look – probably not "sudo."
 
Old 08-18-2023, 01:24 AM   #10
JJJCR
Senior Member
 
Registered: Apr 2010
Posts: 2,167

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Cool

Quote:
Originally Posted by Jason.nix View Post
Hello,
I want a user to be in the sudoers file, but not be able to see the contents of a specific file.
What should I do?


Thank you.
Quote:
but not be able to see the contents of a specific file
You mean the user is able to open the file, but not able to see specific contents of the file?

File extension? Is it PDF, or what?

Maybe try changing the permissions to 777 for testing only and see how it goes.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: The Differences between Su, Sudo Su, Sudo -s and Sudo -i LXer Syndicated Linux News 0 09-15-2022 07:47 PM
[SOLVED] sudo to user other than root but do not allow sudo to root Westmoreland Linux - Security 4 07-13-2022 01:09 PM
Question about the sudo command, specifically how to have sudo act as if user is root slacker_ Linux - Newbie 17 09-22-2013 03:48 PM
LXer: The Ultimate Sudo FAQ — To Sudo Or Not To Sudo? LXer Syndicated Linux News 13 04-13-2013 01:36 AM
[SOLVED] "sudo: Can't mkdir /var/run/sudo/%user%: File exists" CNBarnes Linux - Server 7 01-10-2011 04:11 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Security

All times are GMT -5. The time now is 01:42 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration