Skip to content
This repository has been archived by the owner on Apr 27, 2022. It is now read-only.

permission issues when writing to logs #163

Open
naved001 opened this issue Mar 28, 2018 · 5 comments
Open

permission issues when writing to logs #163

naved001 opened this issue Mar 28, 2018 · 5 comments

Comments

@naved001
Copy link
Contributor

We open the permissions of /var/log/bmi/ims.log so non-root users can also run bmi commands. But quite often, the permissions change and people are unable to run bmi commands.
@VijayalakshmiVJ

@naved001
Copy link
Contributor Author

Hi @VijayalakshmiVJ any updates on this?

@VijayalakshmiVJ
Copy link

VijayalakshmiVJ commented Apr 13, 2018 via email

@mihirborkar
Copy link

mihirborkar commented May 10, 2018

I debugged the issue of file rollover as mentioned,
and found out that with in logging.handlers we were using RotatingFileHandler which by default produces a new file with default permissions 644 by using _open, thus I made changes in /usr/lib64/python2.7/logging/handlers.py to create files with open permissions :

def doRollover(self):
    """
    Do a rollover, as described in __init__().
    """

    if self.stream:
        self.stream.close()
        self.stream = None
    if self.backupCount > 0:
        for i in range(self.backupCount - 1, 0, -1):
            sfn = "%s.%d" % (self.baseFilename, i)
            dfn = "%s.%d" % (self.baseFilename, i + 1)
            if os.path.exists(sfn):
                #print "%s -> %s" % (sfn, dfn)
                if os.path.exists(dfn):
                    os.remove(dfn)
                os.rename(sfn, dfn)
        dfn = self.baseFilename + ".1"
        if os.path.exists(dfn):
            os.remove(dfn)
        os.rename(self.baseFilename, dfn)
        #print "%s -> %s" % (self.baseFilename, dfn)
    self.stream = self._open1()
**def _open1(self):
     prevumask=os.umask(0o000)
     #os.fdopen(os.open('/path/to/file', os.O_WRONLY, 0600))
     retcall=logging.handlers.RotatingFileHandler._open(self)
     os.system("chmod 777 /var/log/bmi/ims.log")
     os.umask(prevumask)
     return retcall**

I know its not the best way to go about it but it does the work.
Kindly let me know your thoughts on this.

Regards,
Mihir

@naved001
Copy link
Contributor Author

I think the best solution is to actually separate the client and the server, and then the bmi user which runs the server will have appropriate permissions.

@apoorvemohan
Copy link
Collaborator

As bmi server runs as root for now, as a quick fix we can force it to set permissions to the log files upon create/rollover.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants