Share

Tuesday, April 12, 2016

LET-M-READ


An Open Source tool to grant controlled read access to unprivileged users on unix based OS. With LET-M-READ system admins can give read access to unprivileged users without changing the file permissions.
Simply, LET-M-READ makes it possible for an Unprivilaged User to read files (i.e logs) using various system commands like 'more','tail','tail with f','less','cat'.
Features
  • User Authentication
  • Event Log capture
  • Easy UserAddition
  • User Friendly
  • Provides more options to un privilaged user for reading files
Prerequisites
  • LET-M-READ should be started as root user to make it eligible to serve most of the user needs
  • While Making Sudo Entry, If you would like to restrict the user to read only certain directories and its files. Just mention the path as a Startup Parameter (Example Given below)
  • Perl 5.10 or above must be present in the server
  • The commands being used by LET-M-READ less,more,tail,cat must be installled and have proper path precedence and defined in environment variable $PATH. As LET-M-READ will invoke the commands without path (not like /usr/local/bin/more its just 'more')
Supported Opearating System 
Unix based OS with Perl 5.10 and above
For Instance, Let's say I have a user named "testuser" and I want to grant him an access to read files from the directory /opt/securedir using let-m-read. This is how it can be acheived.
How to Use?
  • Download the Zip file & Uncompress it
  • Add the User in LET-M-READ
  • Update the Sudoers file
  • Ask the user to test
Download 
Download the Zip file from https://github.com/AKSarav/LET-M-READ and uncompress it in your desired location
AddUser
LET-M-READ comes with Additional Security. So its required to setup the userid.
Execute the adduser module as follows.
./adduser
Update Sudoers File
As per our requirement, we should grant read access for only /opt/securedir to 'testuser'.
Make sure the user "testuser" is present using 'id' command
 
id testuser
First, you’ll need to use the visudo utility…
sudo visudo
Add the below line ( Please update the correct path of letmread)
testuser ALL=(ALL) NOPASSWD: /path/to/letemreadv1/letmread /opt/securedir
Here:
/path/to/letemreadv1/letmread -> Fully qualified location where you have uncompressed the letmread. 
/opt/securedir -> The Directory, for which you want to grant access to 'testuser'
Now you can communicate to the 'testuser', what is the command he has to execute and what is the let-m-read password he should use.
Invoking LET-M-READ (by testuser)
 sudo /path/to/letemreadv1/letmread /opt/securedir
That's it. Now the user can enjoy reading the file with many commands like more,tail,less etc... and as the Infrastrcuture Owner you no need to worry about changing the file permissions (or) ownership.

The Complete TrailRun
 
mwi@mwi-virtual-machine /opt/sara/perlscripts/letmread/gitrepo $ ./letemread.pl /opt/sara/perlscripts/letmread/gitrepo/

__________________________________________________________________________  

             LET-M-READ V1.0    
__________________________________________________________________________
Enter UserName:sara
Enter Password:
Login Successful
Performing Access Validation on /opt/sara/perlscripts/letmread/gitrepo/

INFO: Let-M-Read have proper permission to read this File (or) Directory 
 
==================================================================================================================================
S.No      LogFileName                                                                                              ModifiedDate 
==================================================================================================================================
1         /opt/sara/perlscripts/letmread/gitrepo/letemread.pl                                                      Apr12 14:45 
2         /opt/sara/perlscripts/letmread/gitrepo/adduser.pl                                                        Apr12 14:45 
3         /opt/sara/perlscripts/letmread/gitrepo/.pwfile                                                           Apr12 15:31 
4         /opt/sara/perlscripts/letmread/gitrepo/letmread.log                                                      Apr12 15:42 
==================================================================================================================================
Enter the S.No of the file you want to read==> 2

You have selected Option:'2'

Performing Access Validation on the File /opt/sara/perlscripts/letmread/gitrepo/adduser.pl 

Performing Access Validation on /opt/sara/perlscripts/letmread/gitrepo/adduser.pl

INFO: Let-M-Read have proper permission to read this File (or) Directory 
 

___________________________________________________________________________________________________________

   How do you want to read the file you have selected [ /opt/sara/perlscripts/letmread/gitrepo/adduser.pl ] ?
   For Instance: If you want to use 'more' to read the file, Type 'm' -or- 'M' 
___________________________________________________________________________________________________________

    [m/M] 'more'        [t/T] 'tail without -f'         [c/C] 'cat' 
    [l/L] 'less'        [tm/TM] 'tail with more'        [tf/TF] 'tail with f'

___________________________________________________________________________________________________________

Enter your option:t


How many lines you want to tail2

 
Opening the file, Please Wait !!


-FILENAME: /opt/sara/perlscripts/letmread/gitrepo/adduser.pl
-COMMAND: tail
-DATE:Tue Apr 12 15:43:20 IST 2016
 

print "\nUserName $uid has been successfully added \n\n";

Event Logging
mwi@mwi-virtual-machine /opt/sara/perlscripts/letmread/gitrepo $ cat letmread.log 
 [Apr 12 15:42:47:47]   'sara' Reading '/opt/sara/perlscripts/letmread/gitrepo/adduser.pl' with command 't'
 [Apr 12 15:43:18:18]   'sara' Reading '/opt/sara/perlscripts/letmread/gitrepo/adduser.pl' with command 't'

Content of ZipFile.

adduser -   this module can be used for adding new username into LET-M-READ
letmread -  this is the core logic module and heart of letmread
license.txt - GPL V3 License Document
more_instructions.txt - A supplementary text file being used by  let-m-read.
README.md - GIT repository Read me file.

Some screenshots:








Hope it helps.

I would be happy to see your feedback through comments. Help LET-M-READ to improve by providing any suggestion/feedback. 

If you find any bug/ want to suggest any moderation please use github (or) comment here.

Cheers,
AK Sarav

sara@mwinventory.in
Join with us at https://www.facebook.com/middlewareinventory

Sunday, April 3, 2016

Google SMTP server as your mail server on Linux Mint / ubuntu

Step 1:  Install mail utilities using get-apt

sudo apt-get install mailutils


Step 2: Update main.cf of "postfix" utility with following configuration elements.

"Postfix is a free and open-source mail transfer agent (MTA) that routes and delivers electronic mail, intended as an alternative to the widely used Sendmail MTA."


relayhost = [smtp.gmail.com]:587
smtp_sasl_auth_enable = yes
smtp_sasl_password_maps = hash:/etc/postfix/sasl_passwd
smtp_sasl_security_options = noanonymous
smtp_tls_CAfile = /etc/postfix/cacert.pem
smtp_use_tls = yes


Step 3: Update your user credentials of  your desired google account in /etc/postfix/sasl_passwd file

[smtp.gmail.com]:01    middlewareinventory@gmail.com:<password>

Step 4: map the password file sasl_passwd to postfix using 'postmap' command

postmap /etc/postfix/sasl_passwd1

Step 5: Reload and Restart postfix MTA.

sudo /etc/init.d/postfix reload
sudo /etc/init.d/postfix stop
sudo /etc/init.d/postfix start

Step 6: Visit http://www.google.com/accounts/DisplayUnlockCaptcha and sign in with your Gmail username and password. If asked, enter the letters in the distorted picture.


Step 7: Allow less secure apps access to your account in google account settings in this link https://www.google.com/settings/security/lesssecureapps



It's time to test

echo "Test mail from Server" | mail -s "TestEmail" sara@mwinventory.in

If everything went well ( If I am not wrong in any previous steps :P)  You should be able to see the message getting delivered to the destination email id. you could also verify it in the system log files like /var/log/mail.log (or) /var/log/syslog

Apr  3 22:54:23 mwi-virtual-machine postfix/pickup[11537]: 0F4A21053D1: uid=1000 from=<mwi@mwi-virtual-machine>
Apr  3 22:54:23 mwi-virtual-machine postfix/cleanup[11646]: 0F4A21053D1: message-id=<20160403172423.0F4A21053D1@mwi-virtual-machine>
Apr  3 22:51:52 mwi-virtual-machine postfix/qmgr[11538]: BE5A71053CD: from=<mwi@mwi-virtual-machine>, size=377, nrcpt=1 (queue active)
Apr  3 22:54:23 mwi-virtual-machine postfix/qmgr[11538]: 0F4A21053D1: from=<mwi@mwi-virtual-machine>, size=377, nrcpt=1 (queue active) 


Additionally, You should also be able to see the "Sent" email in the "Sentitems" of your gmail web login.

Hope it helps.

Thanks,
Sarav
sara@mwinventory.in