Paranoid Penguin - Samba Security, Part IV
For the past four months in this column, we've been building a secured Samba server for our local LAN, using Swat. To spare those of you who have been following this series a fourth summary of the usage scenario, let's suffice it to say, we're creating a series of file shares with varying user permissions.
This month, I wrap up the series by showing how to create a restricted, “owner-only” share and how to use mount.cifs to make persistent Samba mounts on your client systems.
Last month, we created a public share, SUPPER, and a nonpublic and group-readable share called CHORES. Prior to that, we had set up some global variables that are inherited by all shares. Those global variables were:
workgroup = FED-CENTRAL security = user client schannel = yes server schannel = yes map to guest = Bad User guest account = nobody unix password sync = yes valid users = mick, knute, pepe, skippy, nobody read list = knute, pepe, skippy write list = mick
Attentive readers of Part II of this series [December 2008] may notice that I omitted “admin users” here, even though in Part II, I had set that to mick. This was an embarrassing mistake. On Ubuntu systems at least, this wreaks havoc with how Samba interacts with Linux file permissions.
You'll recall that setting “admin users” causes listed users to be logged on to Samba as root after successfully authenticating as themselves. In other words, if “admin users” is set to mick, any time mick successfully logs on to any share, he'll actually be logged on as root. The expected result is that mick, therefore, will have superuser privileges and won't be restricted from doing anything at all. In practice, the results tend to be much less predictable than that.
For example, on my Ubuntu 8.04 system, suppose I set “admin users” to mick, create a directory on the underlying Linux filesystem that's owned by mick and has permissions of -rwx------ (or 0700), and then I create a Samba share mapped to that directory that has no guest access or read access (that is, a share like the one I'm about to show you how to set up).
If I then try to connect to this share with this command:
bash-$ smbclient //CASA_DE_MICK/BUZZ-OFF -U mick
and enter the correct password when prompted, sure enough, silently and behind the scenes, I'll actually be logged on as root. But the result of this login will be:
Domain=[CASA_DE_MICK] OS=[Unix] Server=[Samba 3.0.28a] tree connect failed: NT_STATUS_ACCESS_DENIED
What? How can this be? Access shouldn't be denied to anything, for root, should it? But denied it will be, if the share in question maps to a directory not owned by root. This may or may not happen on non-Ubuntu systems. My point is that using the “admin users” parameter may result in unpredictable interactions between Samba and Linux filesystems.
As I said last month, letting people use Samba shares with root privileges is dangerous anyhow. Samba client software isn't the correct tool for Samba system administration, Swat is. So now we have two good reasons always to leave “admin users” empty!
Now, let's move on to our share-specific settings. The smb.conf variables that configured SUPPER, as set via the Swat tool, looked like this:
path = /home/mick/supper read only = yes guest ok = yes invalid user = root valid users = read list = write list = mick admin users = hosts allow = 192.168.44 hosts deny = ALL create mask = 0644 browseable = yes available = yes
These variables are set nearly the same for CHORES, except:
path = /home/mick/chores guest ok = no valid users = +users
What do all these variables mean? I explained them in gory detail in the last three issues of LJ, and definitive descriptions can be found for all in the smb.conf(5) man page. Some of these will come into play this month too, as we create that restricted share.
You'll recall that our Samba server has four user accounts: pepe, skippy, knute and mick, which correspond to my three roommates and me. These are UNIX user accounts on my Samba server's underlying OS, with corresponding but separate entries in the Samba server's separate user database. (I explained how to create and synchronize Samba user accounts in Part II of this series, in the December 2008 issue.)
For our restricted share, BUZZ-OFF, only mick should have read access or write access. No other user should have any rights at all on this share. Accordingly, when we create the directory to which this share will point, we'll be sure it's owned by mick and has a permissions mask of 0700 (u+rwx,g-rwx,o-rwx), like this:
drwx------ 2 mick users 4096 2008-11-04 00:00 buzz-off
Figure 1 shows the first round of parameters we'll set upon creating this share in Swat's Basic View.
After setting the path, we set read only to no—I'll be creating new files in this share—and guest ok to no as well, because we don't want to allow any anonymous access. We'll set hosts allow and hosts deny the same as our other shares—to permit access only from the local LAN (your network address is, obviously, probably different).
We'll set browseable to no, so this share won't turn up in people's Network Neighborhood or in smbtree listings. To connect to this share, therefore, we'll need to specify its path when mapping it to a drive or connecting to it with smbclient.
And, we'll leave available set at no until we've clicked the Commit Changes button, clicked the Change View to Advanced button and changed some things in the Advanced View (Figure 2).
As you can see, we're going to blank out the list of valid users except for mick and completely empty the contents of read list. The write list, however, correctly contains the single value of mick.
The only other setting we need to change is create mask, which we'll set to 0600. This is different from the 0700 mask we used when creating the directory itself; the directory's execute bit needs to be set so the directory can be used, but the contents of this directory, which is what the share represents, do not.
Now we can change available to yes and click the Commit Changes button. Our restricted share is ready for use!
To test this, let's first make sure the share doesn't turn up in the local Samba browse list. We can perform this test using smbtree, like so:
bash-$ smbtree -N -b
FED-CENTRAL
\\CASA_DE_MICK iwazaru-ubuntu server (Samba, Ubuntu)
\\CASA_DE_MICK\print$ Printer Drivers
\\CASA_DE_MICK\SUPPER Mick's menus
\\CASA_DE_MICK\CHORES Chore lists
\\CASA_DE_MICK\IPC$ IPC Service (iwazaru-ubuntu server
↪(Samba, Ubuntu))
Sure enough, the new share BUZZ-OFF doesn't appear in the browse list. But, is it nonetheless usable by mick, its owner? Let's find out with smbclient:
bash-$ smbclient //CASA_DE_MICK/BUZZ-OFF -U mick Password: ******** Domain=[CASA_DE_MICK] OS=[Unix] Server=[Samba 3.0.28a] smb: \>
It worked. I've got a Samba prompt! There's no reason not to try a quick directory listing before exiting:
smb: \> dir
. D 0 Tue Nov 4 23:17:34 2008
.. D 0 Tue Nov 4 23:17:34 2008
access-log_10312008.txt 665 Tue Nov 4 23:17:34 2008
52008 blocks of size 262144. 13229 blocks available
smb: \> exit
Everything worked as expected. One last test—just to be sure, I want to try logging in to the share as a guest user. Remember that our Samba server is set up to treat any login involving a nonexistent user name as a guest login:
bash-$ smbclient //CASA_DE_MICK/BUZZ-OFF -U totallyfakeuser Password: ******** Domain=[CASA_DE_MICK] OS=[Unix] Server=[Samba 3.0.28a] tree connect failed: NT_STATUS_ACCESS_DENIED
It failed, in the expected and appropriate way. Our restricted share is accessible, insofar as we want it to be.
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Sponsored by AMD
Built-in forensics, incident response, and security with Red Hat Enterprise Linux 6
Every security policy provides guidance and requirements for ensuring adequate protection of information and data, as well as high-level technical and administrative security requirements for a system in a given environment. Traditionally, providing security for a system focuses on the confidentiality of the information on it. However, protecting the data integrity and system and data availability is just as important. For example, when processing United States intelligence information, there are three attributes that require protection: confidentiality, integrity, and availability.
Learn more about catching the bad guy in this free white paper.
Sponsored by DLT Solutions
| Dynamic DNS—an Object Lesson in Problem Solving | May 21, 2013 |
| Using Salt Stack and Vagrant for Drupal Development | May 20, 2013 |
| Making Linux and Android Get Along (It's Not as Hard as It Sounds) | May 16, 2013 |
| Drupal Is a Framework: Why Everyone Needs to Understand This | May 15, 2013 |
| Home, My Backup Data Center | May 13, 2013 |
| Non-Linux FOSS: Seashore | May 10, 2013 |
- RSS Feeds
- Making Linux and Android Get Along (It's Not as Hard as It Sounds)
- Using Salt Stack and Vagrant for Drupal Development
- Dynamic DNS—an Object Lesson in Problem Solving
- New Products
- Validate an E-Mail Address with PHP, the Right Way
- Drupal Is a Framework: Why Everyone Needs to Understand This
- A Topic for Discussion - Open Source Feature-Richness?
- Download the Free Red Hat White Paper "Using an Open Source Framework to Catch the Bad Guy"
- Tech Tip: Really Simple HTTP Server with Python
- Roll your own dynamic dns
2 hours 7 min ago - Please correct the URL for Salt Stack's web site
5 hours 19 min ago - Android is Linux -- why no better inter-operation
7 hours 34 min ago - Connecting Android device to desktop Linux via USB
8 hours 3 min ago - Find new cell phone and tablet pc
9 hours 1 min ago - Epistle
10 hours 30 min ago - Automatically updating Guest Additions
11 hours 38 min ago - I like your topic on android
12 hours 25 min ago - This is the easiest tutorial
19 hours 44 sec ago - Ahh, the Koolaid.
1 day 39 min ago
Free Webinar: Hadoop
How to Build an Optimal Hadoop Cluster to Store and Maintain Unlimited Amounts of Data Using Microservers
Realizing the promise of Apache® Hadoop® requires the effective deployment of compute, memory, storage and networking to achieve optimal results. With its flexibility and multitude of options, it is easy to over or under provision the server infrastructure, resulting in poor performance and high TCO. Join us for an in depth, technical discussion with industry experts from leading Hadoop and server companies who will provide insights into the key considerations for designing and deploying an optimal Hadoop cluster.
Some of key questions to be discussed are:
- What is the “typical” Hadoop cluster and what should be installed on the different machine types?
- Why should you consider the typical workload patterns when making your hardware decisions?
- Are all microservers created equal for Hadoop deployments?
- How do I plan for expansion if I require more compute, memory, storage or networking?






Comments
Great article
I have looked forward each month to each installment of this series. Great job. Have been using Samba and configuring by manual adjustments within the smb.conf file. This article has helped me now look at my existing configuration (through SWAT) and understand the intent of SWAT.
Years back, the Samba/SWAT documentation was weak and confusing in some areas. I learned to adjust the configuration manually (if you will) and got Samba running to "get by". Now, with the help of these articles, I can greatly improve my security and understanding of Samba configuration settings.
Thanks, Mick for all your work. It paid off with a great article.