Skip to content

Conversation

@johnsaigle
Copy link
Contributor

@johnsaigle johnsaigle commented Oct 16, 2019

Brief summary of changes

This PR improves the way UNIX permissions are used in LORIS.

Summary

Old permissions

  • lorisadmin owns all files
  • lorisadmin has sudo
  • www-data/apache2 selectively owns and is the group for web-writable files
    • e.g. drwxrwxrwx 2 www-data www-data 4096 Oct 9 16:30 user_uploads
  • Uses the same permissions as lorisadmin
  • Typical permission codes: 775, for directories, 664 for files
  • Result: On certain files and folders, Apache gets to do everything lorisadmin can do

New permissions

  • lorisadmin owns all files
  • lorisadmin has sudo
  • lorisadmin is the group for all files
    • e.g. drwxrwxrwx 2 lorisadmin lorisadmin 4096 Oct 9 16:30 user_uploads
  • www-data/apache2 is part of the lorisadmin group
  • Typical permission codes: 755 for directories, 644 for files.
  • Result: Certain group permissions on files can be used to limit www-data/apache2 access.

Why?

More details in #5297. In short:

  1. Simplifies install - no need to selectively chgrp to apache2 or www-data user
  2. Prerequisite for creating a Debian package - the lintian tool causes LORIS to fail because of odd permission codes like 775 and 664. See Change to UNIX file permissions on LORIS install #5057
  3. Easier maintenance - everything is now lorisadmin.lorisadmin. Permissions can be tracked using GitHub rather than changed manually.
  4. This is how UNIX permissions are usually used.
  5. Brings us closer to the principle of least-privilege.

Testing instructions

  1. Test the install according to the new instructions. Ensure that LORIS still works.

Links to related tickets (GitHub, Redmine, ...)

@johnsaigle johnsaigle added Category: Cleanup PR or issue introducing/requiring at least one clean-up operation Release: Breaking changes PR that contains changes that might impact the code or accepted practices of active projects Category: Documentation PR or issue that aims to improve the documentation Release: Document at release PR whose changes need to be documented in the wiki (or other documentation) at release Category: Security PR or issue that aims to improve security labels Oct 16, 2019
@johnsaigle
Copy link
Contributor Author

If this is merged, the installation readmes (CentOS, "Install in depth", macOS) should be updated.

Since at this time there are many open PRs dealing with these same files, it will be easier to make these changes once those PRs go through.

maltheism
maltheism previously approved these changes Oct 22, 2019
Copy link
Member

@maltheism maltheism left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome this PR solves a "changing permission error" I face with the current install.sh script.

@maltheism maltheism added the Passed manual tests PR has been successfully tested by at least one peer label Oct 22, 2019
Copy link
Collaborator

@driusan driusan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not actually a change request, just so this doesn't show up in "approved" until the discussion is resolved..

tools/install.sh Outdated
mkdir -p ../modules/document_repository/user_uploads
mkdir -p ../modules/data_release/user_uploads
mkdir -p -m 770 ../modules/document_repository/user_uploads
mkdir -p -m 770 ../modules/data_release/user_uploads
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't seem to do what the PR description says (not this line, the lines below it where things are still being chown'd to apache.apache)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right. I'll remove them

Copy link
Contributor

@PapillonMcGill PapillonMcGill Nov 25, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Even if group would have RWX on the directories, files created by Apache would have ownership of www-data:www-data and Lorisadmin would not be able to modify/erase them and possibly read them.

Ideally, these .../user_uploads directories should be moved outside of /var/www/$projectname.

@gdevenyi
Copy link
Contributor

I strongly suggest symbolic rather than numeric permissions to make things easier to read/interpret at a glance. https://en.wikipedia.org/wiki/Chmod#Symbolic_modes

@driusan
Copy link
Collaborator

driusan commented Oct 25, 2019

I disagree.. when talking about absolute permissions, numeric ones are far more common and, as a result, easier to read

@johnsaigle johnsaigle added the State: Needs work PR awaiting additional work by the author to proceed label Oct 25, 2019
@PapillonMcGill
Copy link
Contributor

  • If linst file uploaded by a user get 644 permission, LORIS will not be able to edit (read only).
    Is this desired?

  • Files (linst or otherwise) created by LORIS (apache) would get www-data:www-data ownership and won't be readable by lorisadmin (without sudo).
    This would be a security improvement but is it desired? (Do lorisadmin user need access to these files?)

@johnsaigle
Copy link
Contributor Author

johnsaigle commented Oct 28, 2019

If linst file uploaded by a user get 644 permission, LORIS will not be able to edit (read only).
Is this desired?

The 6 permission at the beginning means that Apache will be able to read and write the file (since, as you said, the ownership is www-data:www-data). As far as I know the execute permission doesn't need to be set for editing LINST files in the instrument builder. Let me know if I'm wrong or missing something.

Files (linst or otherwise) created by LORIS (apache) would get www-data:www-data ownership and won't be readable by lorisadmin (without sudo).
This would be a security improvement but is it desired? (Do lorisadmin user need access to these files?)

I think it's alright. I can't really see a scenario where you'd need to do this and wouldn't have sudo. Maybe on some production servers? But in this case it makes sense to have an extra measure against deleting user's files.

It's more of an administration question since files uploaded to LORIS shouldn't be under /var/www/loris/ anyway, but rather some other folder like /data/ that is outside the code base. Whoever is administering this on the back-end (dev or sysadmin) should have the powers to delete or read a file if they really need to anyway.

@PapillonMcGill
Copy link
Contributor

@johnsaigle The 6 is for the owner of the files (user=>lorisadmin), not for the group. Apache would have group permission (4) and not be able to modify the file.

As for the 2nd point, entirely approve. and yes, data should not be with the code. I am just asking if the behavior would cause problem to some process (like shell script).

@johnsaigle
Copy link
Contributor Author

I believe www-data will be the owner, as you said here:

Files (linst or otherwise) created by LORIS (apache) would get www-data:www-data ownership and won't be readable by lorisadmin (without sudo).

@johnsaigle johnsaigle removed the State: Needs work PR awaiting additional work by the author to proceed label Oct 28, 2019
@johnsaigle johnsaigle dismissed driusan’s stale review November 5, 2019 16:37

Requested changes were incorporated

@johnsaigle johnsaigle dismissed PapillonMcGill’s stale review November 25, 2019 15:26

requested changes applied

@ridz1208
Copy link
Collaborator

@johnsaigle Before I comment on the code, i have a few questions

  • If we use lorisadmin as a group including the apache user, wouldn't it get confusing (especially internally) for devs ? we already use lorisadmin right now just for the user, shouldn't we use a different name for the group? like webgroup or something that would encompass lorisadmin and apache ? I can just see people altering the permissions anyways thinking that it got misconfigured or wtv...
  • when you say "permissions are going to be tracked on github" aren't they already tracked on github ?
  • shouldn't lorisadmin not have sudo post-installation step ?

@ridz1208
Copy link
Collaborator

@johnsaigle to make this easier
#5815

@johnsaigle johnsaigle added the State: Needs work PR awaiting additional work by the author to proceed label Dec 2, 2019
Copy link
Contributor

@lingma lingma left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This pull request should be rejected. Though some work makes improvement such as "775 to 755" modification, the whole idea is NOT at all acceptable security practice in my eyes. I see really no reason why this modification should go ahead. Moreover, www-data should never be part of lorisadmin, which contains a real user and sudo user, way too dangerous.

@PapillonMcGill
Copy link
Contributor

Moreover, www-data should never be part of lorisadmin, which is already a sudo user, way too dangerous.

@lingma Do not confuse the user lorisadmin with the group lorisadmin.

@johnsaigle
Copy link
Contributor Author

Moreover, www-data should never be part of lorisadmin, which is already a sudo user, way too dangerous.

As @PapillonMcGill mentioned above, the group called lorisadmin will not have the same permissions as the user lorisadmin. www-data will be limited to group permissions of lorisadmin. That's why changing e.g. 755 to 775 make a difference - it restricts the access that the web server has to those files.

@johnsaigle johnsaigle added the State: Needs rebase PR that needs to be rebased to proceed (conflicts, wrong branch...) label Dec 2, 2019
@johnsaigle
Copy link
Contributor Author

Blocked by #5815

@johnsaigle
Copy link
Contributor Author

johnsaigle commented Dec 6, 2019

Well @lingma I think we'll have to agree to disagree here.

I am confident that this change simplifies the development experience and doesn't pose a security issue. I've responded to your security concern to the best of my ability and thinking it through carefully I do not think there is a serious risk here.

I am happy to leave it to another reviewer to weigh in here and hopefully we'll reach a group consensus with some more input.

@lingma
Copy link
Contributor

lingma commented Dec 7, 2019

Loris as a software product has nothing to do with group permission, this is unnecessary and creating possible problems. Just change all read only files to 644, folders to 755. This will not create any problem in development. I think it will be perfect to put all those web server writable folders some where and tell users what to do with them with a guide.

Of course your solution works. I tested without issue, but the idea itself is much out of my taste.

@johnsaigle johnsaigle added State: Needs rebase PR that needs to be rebased to proceed (conflicts, wrong branch...) State: Needs work PR awaiting additional work by the author to proceed State: Needs documentation PR that needs a more exhaustive documentation to proceed and removed State: Blocked PR or issue awaiting an external event such as the merge or another PR to proceed labels Jan 8, 2020
@johnsaigle
Copy link
Contributor Author

Adding Needs Documentation as a note that I should update the CHANGELOG

@driusan
Copy link
Collaborator

driusan commented Jan 8, 2020

wouldn't "Add To Release Notes" be a better reminder?

@johnsaigle johnsaigle added the Release: Add to release notes PR whose changes should be highlighted in the release notes label Jan 8, 2020
@ridz1208
Copy link
Collaborator

ridz1208 commented Jan 8, 2020

I ain't touching this one, i think it's getting enough TLC

@johnsaigle johnsaigle removed State: Needs rebase PR that needs to be rebased to proceed (conflicts, wrong branch...) State: Needs work PR awaiting additional work by the author to proceed State: Needs documentation PR that needs a more exhaustive documentation to proceed labels Jan 29, 2020
Copy link
Contributor

@PapillonMcGill PapillonMcGill left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changes applied earlier have been reverted.

@PapillonMcGill PapillonMcGill added the State: Needs rebase PR that needs to be rebased to proceed (conflicts, wrong branch...) label Feb 10, 2020
@HenriRabalais
Copy link
Collaborator

The amount of labels on this PR is impressive.
labels

@johnsaigle johnsaigle removed the State: Needs rebase PR that needs to be rebased to proceed (conflicts, wrong branch...) label Feb 14, 2020
@johnsaigle johnsaigle removed their assignment Feb 14, 2020
@driusan driusan merged commit fbea18e into aces:master Feb 26, 2020
@ridz1208 ridz1208 added this to the 23.0.0 milestone Feb 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Category: Cleanup PR or issue introducing/requiring at least one clean-up operation Category: Documentation PR or issue that aims to improve the documentation Category: Security PR or issue that aims to improve security Passed manual tests PR has been successfully tested by at least one peer Release: Add to release notes PR whose changes should be highlighted in the release notes Release: Breaking changes PR that contains changes that might impact the code or accepted practices of active projects Release: Document at release PR whose changes need to be documented in the wiki (or other documentation) at release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Change to UNIX file permissions on LORIS install

8 participants