LinuxQuestions.org
Visit Jeremy's Blog.
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 02-11-2009, 09:17 PM   #1
issinho
Member
 
Registered: Jun 2005
Location: Bosie, ID
Distribution: Fedora Core 4, Kurumin,BackTrack, Slackware 10.2, IPCop
Posts: 105

Rep: Reputation: 15
How can I make a folder unmovable?


Okay, I've been browsing various man pages and websites and cannot find an answer to this question (well, at least not one that is satisfactory for my needs).

Here's my situation:

I have a folder that files move in and out of on a regular basis via automation. The other day, someone was able to move some of these folders into another location, which, pretty much, broke my automated processes.

I want to stop that from ever happening again. I looked into the immutable attribute, but soon discovered that this option renders the folder nonoperational for my needs (I still need to be able to write to and remove files from the directory).

The sticky bit, also doesn't appear to be a viable option as who moved the folder was logged in as the folder's owner.

So there's the question: how do you make a folder un-deletable and immovable while still allowing read/write access to the files within the directory?

I turn it over to the community to see how this can be done. Thank you for any and all pointers.
 
Old 02-11-2009, 10:01 PM   #2
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
Deny write access to the parent directory of that directory. Deleting a file performs a write operation on the directory containing the file. In this case, the file entry is a directory. Either deny write access to the parent directory or set the stick bit.

If might be better if the directory wasn't in a publicly accessible directory. For example, if it is reachable from a share, perhaps it should be shared on its own.
 
Old 02-11-2009, 10:08 PM   #3
slimm609
Member
 
Registered: May 2007
Location: Chas, SC
Distribution: slackware, gentoo, fedora, LFS, sidewinder G2, solaris, FreeBSD, RHEL, SUSE, Backtrack
Posts: 430

Rep: Reputation: 67
you can add an immutable flag to the directory

chattr +i <dir>

someone as root would have to do a chattr -i <dir> to be able to move it.

and ls -l** does not show the immutable flag

you could view the flags with lsattr

if you really wanted rename chattr to something weird that only you would know and then do a <whatever you named it> +i <dir>

tho i would recommend leaving it as chattr because alot of people have no clue what it is or does and they would have to be root or whoever owns the file to remove the flag so it can be moved or deleted


NOTE: setting the flag on a file will deny any write ability to that file

Last edited by slimm609; 02-11-2009 at 10:09 PM.
 
Old 02-11-2009, 10:49 PM   #4
issinho
Member
 
Registered: Jun 2005
Location: Bosie, ID
Distribution: Fedora Core 4, Kurumin,BackTrack, Slackware 10.2, IPCop
Posts: 105

Original Poster
Rep: Reputation: 15
Problems with both solutions

See, here's where we reach a problem:

The automated process moves files in and out of these directories and staff goes through the directories periodically to remove files that didn't get moved.

the chattr doesn't work because files cannot be created/deleted as needed.

another issue is that, the issue that caused to me to look into this a little, the user who had moved the directory was logged in as that directory's owner, so the sticky bit wouldn't help (as best I know, anyway).

anything else?
 
Old 02-11-2009, 10:58 PM   #5
anomie
Senior Member
 
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Blog Entries: 5

Rep: Reputation: Disabled
I think jschiwal's answer solves your problem.

Code:
[fugu ~]$ mkdir foo
[fugu ~]$ mkdir foo/bar
[fugu ~]$ ls -ld foo
drwxrwxr-x  3 me me 4096 Feb 11 22:54 foo
[fugu ~]$ chmod a-w foo
[fugu ~]$ ls -ld foo
dr-xr-xr-x  3 me me 4096 Feb 11 22:54 foo
[fugu ~]$ mv foo/bar /tmp/
mv: cannot remove `foo/bar': Permission denied
In this example, "bar" represents your users' work directory. It would help if "bar"'s owner was not also an owner of "foo" (so that he couldn't add write permissions back).

If this will not work, please clearly explain why not.
 
Old 02-12-2009, 12:10 AM   #6
issinho
Member
 
Registered: Jun 2005
Location: Bosie, ID
Distribution: Fedora Core 4, Kurumin,BackTrack, Slackware 10.2, IPCop
Posts: 105

Original Poster
Rep: Reputation: 15
Perhaps I should clarify a little further

Okay, this server sits between two different systems in different locations (kind of a DMZ on a private network, if you will). Let's call this server B. So, box C sends files to server B who turns around and passes it onto server A. This is a gross over simplification, but is about as detailed as I can get right now.

Now, the directories in question are the drop points for this process. They get dumped into these directories and are taken from these directories with a few moments of them actually being on server B.

The other day, someone removed a couple of these critical directories to another place on the box, causing automation to not be able to drop the files in the correct location (as they weren't there to dump into).

So, the issue is that I need to make it so that nobody can move or delete these directories, but not have that effect on the files under them.

Here's an example from me removing the write permissions on the test folder:

Code:
[~]$ ls -l |grep foo
dr-xr-xr-x 3 root    root    4096 2009-02-11 22:58 foo
[~]$ touch ./foo/file1
touch: cannot touch `./foo/file1': Permission denied
[~]$ touch ./foo/bar/file1
touch: cannot touch `./foo/bar/file1': Permission denied
As you can see, this example doesn't permit writing to the directory, which is a must in this case. The chattr command is similar, and the problem with the sticky bit is that the user who moved the directory was the owner, so that isn't enough.

Hope this sheds enough light on this. Let me know, please.
 
Old 02-12-2009, 12:39 AM   #7
jschiwal
LQ Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682Reputation: 682
My first recommendation is if you have foo/bar/files, that foo not be writable. You can still save files in /foo/bar/. If you don't want /bar to be deletable with the sticky bit set, make the owner root so a regular user can't delete it. Look at the /tmp/ directory as a model. / is only root writable. /tmp has full write permissions, but no regular user can delete the /tmp directory because the parent directory isn't writable by normal users. The sticky bit on /tmp protects the contents from deletion from other users.

It would be better to have a bar/ share so that users don't access foo at all. If you have /foo/bar and /foo/bar2, you can have a bar/ and a bar2 share.
 
Old 02-15-2009, 01:01 PM   #8
moljac024
Member
 
Registered: May 2007
Location: Serbia, Europe
Distribution: Arch Linux
Posts: 54

Rep: Reputation: 15
It might be smart to have some checks in your scripts to see if the directories exists, just in case. You can have it re-create them if they're not there. Keep It Simple Stupid
 
  


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
how to make available folder in Apache? mac1234mac Linux - Software 1 05-27-2006 12:01 PM
Hi, I need to know how to make a new folder using the terminal? grupoapunte Linux - Newbie 1 05-19-2005 06:23 PM
How to make a folder FireInTheDark Linux - Newbie 2 11-28-2004 04:55 AM
How to make folder index? alexaltair Linux - General 7 11-25-2003 03:54 AM
How do I make a shared folder under RH? Da_Quest Linux - Networking 18 08-20-2003 08:25 PM

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

All times are GMT -5. The time now is 02:52 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