LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 10-28-2010, 01:18 PM   #1
zaeem
Member
 
Registered: Jan 2010
Posts: 125

Rep: Reputation: 15
Linux user privileges issue


Dear All,

I am facing a strange issue with Linux users (non root). Let me explain this in a bit detail.

I have mysql 5.1.47 running and I need to give read only access so few users who can query mysql database and generate CSV on their home directory, and that user must have read/write access to that directory. For example I created a user 'testing' and directory is created like /home/testing. Now I have to do chmod 777 /home/testing in order to enable mysql to generate CSV in this directory. But issue is that any other user come to this directory (/home/testing) through its FTP login can delete any file. Whereas this directory is home directory of 'testing' user and only he/she must have full access and all other non root users must not able to delete any file in this directory. How to achieve this?

Thanking you in advance
 
Old 10-28-2010, 04:12 PM   #2
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599Reputation: 3599
Quote:
Originally Posted by zaeem View Post
I have to do chmod 777 /home/testing in order to enable mysql to generate CSV
No you don't. And chmodding something 777 is always lets-not-think-about-the-consequences bad advice: you could for instance let the user produces the CSV file to a temporary location ('mktemp'), chown it to a group the FTP user can access, then let the FTP user 'install' it with the required access rights.
 
Old 10-29-2010, 01:47 AM   #3
zaeem
Member
 
Registered: Jan 2010
Posts: 125

Original Poster
Rep: Reputation: 15
Dear unSpawn,

Actually that doesn't fulfill my requirement. Let me try to explain in simple way. I have a production system where MySQL Database is running. I want to give read only access(through mysql read only user) to MySQL where a person can connect to mysql and generate CSVs from MySQL Queries somewhere. So I need to create OS user as well where user can generate CSVs using MySQL Query. Now problem is here, MySQL don't generate CSVs in directory where its not chmod 777 but when I do chmod 777 on user home directory mysql start generating CSVs but all other OS users (non root) also got full access to that directory. I only want to give write access to MySQL and that os User onky.

I hope it will be clear now and you can suggest me its solution as it is driving me crazy.
 
Old 10-29-2010, 04:45 AM   #4
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Gentoo
Posts: 2,125

Rep: Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781
Quote:
MySQL don't generate CSVs in directory where its not chmod 777 but when I do chmod 777 on user home directory mysql start generating CSVs
Do you understand what making the directory permissions 777 does? The permissions are set up according to owner/group/other with 3 bits for read,write, and execute; 777 allows everybody ALL of these abilities which is why everyone can access each others folders! MySQL does not require 777 access, it requires write (and possibly execute on directories) access.

A much safer approach would be to either create a GROUP (the middle permission) that allows MySQL access to that directory and to play both the MySQL system user and the desired user(s) in that group. Similarly, each user has a group associated with them. You could add MySQL to their group, though this is a little less secure.

Unspawn's suggestion is similar, in that it uses group permissions to solve the 777 issue and it addresses the mysql having write access to home folders by creating a common area for the creation of the CSV files where each user can transfer their data from. You could expand upon this to create subdirectories for each user where MySQL and ONLY THAT USER could access. This would achieve all of your stated goals while maximizing the security.
 
Old 10-29-2010, 07:07 AM   #5
Hangdog42
LQ Veteran
 
Registered: Feb 2003
Location: Maryland
Distribution: Slackware
Posts: 7,803
Blog Entries: 1

Rep: Reputation: 422Reputation: 422Reputation: 422Reputation: 422Reputation: 422
Quote:
I have a production system where MySQL Database is running. I want to give read only access(through mysql read only user) to MySQL where a person can connect to mysql and generate CSVs from MySQL Queries somewhere. So I need to create OS user as well where user can generate CSVs using MySQL Query.
How about setting up something like phpMySQL? That would let them create CSV files directly on their own machines with no need for an OS user. You would have to make sure that phpMySQL was locked down tightly, but it might be a more secure approach than having 777 directories.

<edit>

Actually, why don't you open up MySQL for TCP/IP connections and let the people access it that way. The more I think about it the less I think you need to have people logged into the MySQL server to do their work. MySQL was designed to be accessed remotely, so you should think about doing that.
</edit>

Last edited by Hangdog42; 10-29-2010 at 07:10 AM.
 
Old 10-30-2010, 09:03 AM   #6
zaeem
Member
 
Registered: Jan 2010
Posts: 125

Original Poster
Rep: Reputation: 15
Dear Noway2,

I tried the same but no luck. I make a group and added mysql user and other os user to that group. Now I change group of the directory to new one and tried to generate CSV through MySQL but it still gives me Error # 13. I would be very thankful if you can give me commands to implement that.

Thanks you very much for continued support.
 
Old 10-30-2010, 09:06 AM   #7
zaeem
Member
 
Registered: Jan 2010
Posts: 125

Original Poster
Rep: Reputation: 15
Dear Hangdog42,

Thanks for your reply. I can't install PHPMySQL as it is not under my control.

People already accessing MySQL remotely but to generate CSV, MySQL generate it on the same server where it is installed. Thats why I need to create OS user so that MySQL generates CSV in user home directory and user can login through FTP and Picks the files and no other user can have access to that directory.
 
Old 10-30-2010, 10:08 AM   #8
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,279

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
Post output of these commands:
Code:
cat /etc/group
ls -ld /home/testing

Last edited by eSelix; 10-30-2010 at 10:10 AM.
 
Old 11-02-2010, 12:19 AM   #9
zaeem
Member
 
Registered: Jan 2010
Posts: 125

Original Poster
Rep: Reputation: 15
cat /etc/group

root:x:0:root
bin:x:1:root,bin,daemon
daemon:x:2:root,bin,daemon
sys:x:3:root,bin,adm
adm:x:4:root,adm,daemon
tty:x:5:
disk:x:6:root
lp:x:7:daemon,lp
mem:x:8:
kmem:x:9:
wheel:x:10:root
mail:x:12:mail
news:x:13:news
uucp:x:14:uucp
man:x:15:
games:x:20:
gopher:x:30:
dip:x:40:
ftp:x:50:
lock:x:54:
nobody:x:99:
users:x:100:
utmp:x:22:
utempter:x:35:
rpc:x:32:
mailnull:x:47:
smmsp:x:51:
nscd:x:28:
floppy:x:19:
vcsa:x:69:
rpcuser:x:29:
nfsnobody:x:65534:
sshd:x:74:
screen:x:84:
pcap:x:77:
slocate:x:21:
ntp:x:38:
stapdev:x:101:
stapusr:x:102:
dbus:x:81:
haldaemon:x:68:
avahi:x:70:
xfs:x:43:
avahi-autoipd:x:103:
gdm:x:42:
sabayon:x:86:
advcomm:x:500:
mysql:x:104:
zaka:x:501:
zaeem:x:502:
csv:x:504:testing,mysql
testing:x:503:


# ls -ld /home/testing
drwx------ 4 testing csv 4096 Oct 30 10:18 /home/testing
 
Old 11-02-2010, 03:43 AM   #10
eSelix
Senior Member
 
Registered: Oct 2009
Location: Wroclaw, Poland
Distribution: Arch, Kubuntu
Posts: 1,279

Rep: Reputation: 320Reputation: 320Reputation: 320Reputation: 320
Group csv has no access to this directory
Code:
chmod 0770 /home/testing

Last edited by eSelix; 11-02-2010 at 03:49 AM.
 
Old 11-02-2010, 04:16 AM   #11
zaeem
Member
 
Registered: Jan 2010
Posts: 125

Original Poster
Rep: Reputation: 15
Dear eSelix,

Quote:
chmod 0770 /home/testing
After doing chmod 0770 I am still unable to generate CSV file and error is mentioned below.

ERROR 1 (HY000): Can't create/write to file '/home/testing/books.csv' (Errcode: 13)
 
Old 11-02-2010, 04:53 AM   #12
Noway2
Senior Member
 
Registered: Jul 2007
Distribution: Gentoo
Posts: 2,125

Rep: Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781Reputation: 781
I believe that Error 13 is a permissions issue. It looks like the directory permissions should have been taken care of with the last step. Do you perchance have another security application like Apparmor blocking it?
 
Old 11-02-2010, 05:06 AM   #13
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,126
Blog Entries: 2

Rep: Reputation: 124Reputation: 124
Did you restart mysql and your other programs after you added mysql to the the csv group?
 
Old 11-02-2010, 06:26 AM   #14
zaeem
Member
 
Registered: Jan 2010
Posts: 125

Original Poster
Rep: Reputation: 15
Thanks a lot guys. After rebooting MySQL issue is resolved. I really appreciate your help
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
super user privileges check for a normal user in bash script freeindy Programming 2 08-01-2008 06:08 AM
privileges user AIX122 AIX 2 02-28-2008 10:49 PM
User Privileges to network boot a Linux box fmcauley Linux - Newbie 2 01-09-2007 03:59 PM
Linux - How to add a new user with the same root/super-user's privileges? asgarcymed Linux - General 8 12-23-2006 07:45 PM

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

All times are GMT -5. The time now is 12:54 PM.

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