Code Monkey home page Code Monkey logo

Comments (3)

jmfernandez avatar jmfernandez commented on August 21, 2024

In order to double check I have been having a look at the different points where directories are created, and as I was remembering no one of the os.makedirs calls explicitly set the directory permissions. So, the permissions used before applying the umask for the directory creation are the default ones, described at https://docs.python.org/3/library/os.html#os.makedirs

So, my guess is that the initial umask inherited by the process calling WfExS is what it can be troublesome in the first call.

from wfexs-backend.

dcl10 avatar dcl10 commented on August 21, 2024

@jmfernandez, I've done some reading and a little playing around. I think the best thing to do is: in the places where you are calling os.makedirs, you should explicitly set the mode parameter using an octal number. e.g. 0o777 for all permissions for everyone, or 0o755 for everything for you and r+x for everyone else. Or more conservatively 0o644 for r+w for you and r only for everyone else. The choice depends on what the directories are used for.

from wfexs-backend.

jmfernandez avatar jmfernandez commented on August 21, 2024

Hi @dcl10 , the real point there is that umask is a property from any process, inheriting its initial value from the parent process which forked the program. You can see the effect of the different umask values using the very same mode of 0o777:

jmfernandez@pavonis[1]:/tmp> mkdir playground
jmfernandez@pavonis[2]:/tmp> cd playground
jmfernandez@pavonis[3]:/tmp/playground> umask
0022
jmfernandez@pavonis[4]:/tmp/playground> python -c 'import os; os.makedirs("default_mask", mode=0o777)'
jmfernandez@pavonis[5]:/tmp/playground> ls -ld
drwxr-xr-x 1 jmfernandez users 24 ago 25 19:08 .
jmfernandez@pavonis[6]:/tmp/playground> ls -ld *
drwxr-xr-x 1 jmfernandez users 0 ago 25 19:08 default_mask
jmfernandez@pavonis[7]:/tmp/playground> umask 0222
jmfernandez@pavonis[8]:/tmp/playground> umask
0222
jmfernandez@pavonis[9]:/tmp/playground> python -c 'import os; os.makedirs("ro_mask", mode=0o777)'
jmfernandez@pavonis[10]:/tmp/playground> ls -ld *
drwxr-xr-x 1 jmfernandez users 0 ago 25 19:08 default_mask
dr-xr-xr-x 1 jmfernandez users 0 ago 25 19:08 ro_mask
jmfernandez@pavonis[11]:/tmp/playground> umask 0077
jmfernandez@pavonis[12]:/tmp/playground> python -c 'import os; os.makedirs("useronly_mask", mode=0o777)'
jmfernandez@pavonis[13]:/tmp/playground> ls -ld *
drwxr-xr-x 1 jmfernandez users 0 ago 25 19:08 default_mask
dr-xr-xr-x 1 jmfernandez users 0 ago 25 19:08 ro_mask
drwx------ 1 jmfernandez users 0 ago 25 19:09 useronly_mask
jmfernandez@pavonis[14]:/tmp/playground> umask 0777
jmfernandez@pavonis[15]:/tmp/playground> python -c 'import os; os.makedirs("noone_mask", mode=0o777)'
jmfernandez@pavonis[16]:/tmp/playground> ls -ld *
drwxr-xr-x 1 jmfernandez users 0 ago 25 19:08 default_mask
d--------- 1 jmfernandez users 0 ago 25 19:10 noone_mask
dr-xr-xr-x 1 jmfernandez users 0 ago 25 19:08 ro_mask
drwx------ 1 jmfernandez users 0 ago 25 19:09 useronly_mask

The mask from the umask property is applied by the operating system when a file or directory creation operation is requested from the process. It is done so in order to give control to the user over the default permissions without having to change every program.

Of course, a process is allowed to change its own umask property value, as you can see:

jmfernandez@pavonis[1]:/tmp> mkdir playground2
jmfernandez@pavonis[2]:/tmp> cd playground2
jmfernandez@pavonis[3]:/tmp/playground2> umask
0022
jmfernandez@pavonis[4]:/tmp/playground2> umask 0777
jmfernandez@pavonis[5]:/tmp/playground2> python -c 'import os; os.makedirs("noone_mask", mode=0o777)'
jmfernandez@pavonis[6]:/tmp/playground2> python -c 'import os; os.umask(0o000); os.makedirs("everyone_mask", mode=0o777)'
jmfernandez@pavonis[7]:/tmp/playground2> ls -ld *
drwxrwxrwx 1 jmfernandez users 0 ago 25 19:23 everyone_mask
d--------- 1 jmfernandez users 0 ago 25 19:23 noone_mask

Typical programs changing its umask are shells (like bash), daemons and services. Outside these scenarios, it is considered an antipattern that a program changes its own umask, as then the user cannot tweak the permissions through the initially inherited umask.

So, my recommendation is that the umask should be adjusted just before WfExS-backend is run. For instance to something like umask 0077 or umask 0027, depending on whether you trust the default group of the user.

from wfexs-backend.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.