marineenergy / apps

shiny apps for marineenergy.app
https://marineenergy.github.io/apps/
MIT License
3 stars 1 forks source link

permissions: files not writable #16

Closed bbest closed 2 years ago

bbest commented 3 years ago

From @Neil-Swanson:

Hi Ben,

I’m running into some permissions issues again. I’m trying to run the ‘generate_all_data.R’ script from the Shiny rep to update the three .csv files that are inputs to the Projects page. I’ve updated the Google Sheet on the Google Drive with the new project info from Grace/Sharon, so these files need to be updated. Would you mind running the script to get the new datasets ready?

image

This is a recurring problem despite thinking I fixed it, per mhk-env_server-software: README.md:

echo 'umask 002' >> /etc/profile
bbest commented 3 years ago

Problem

So despite setting the Linux environment properly with group write permissions (with the umask), the R session overrides to being without group write:

Sys.umask()
# "22"
fs::file_touch("data/test_r.txt")

Sys.umask("002")
fs::file_touch("data/test_r2.txt")
Sys.umask()
# "2"
readr::write_csv(data.frame(a = 1:3), file = "data/test2.csv")
cd /share/github/mhk-env_shiny-apps/data
umask
# 0002
touch test.txt
ls -la | grep test
# -rw-r--r--  1 bbest staff        0 Mar  4 16:43 test_r.txt
# -rw-rw-r--  1 bbest staff        0 Mar  4 16:42 test.txt
tail -1 /etc/profile
# umask 002

RStudio Server config? No

Then I thought I found where RStudio Server was overriding this here:

https://docs.rstudio.com/ide/server-pro/1.2.1237-1/access-and-security.html#umask

sudo vi /etc/rstudio/rserver.conf
# server-set-umask=0
docker exec -it rstudio bash

but that didn't work.

Solution: Sys.umask("2") in Rprofile.site

Went ahead with overriding user file mask for all users by editing Rprofile.site Managing R with .Rprofile, .Renviron, Rprofile.site, Renviron.site, rsession.conf, and repos.conf – RStudio Support.

Get directory:

R.home(component = "home")
# "/usr/local/lib/R"

Edit Rprofile.site:

sudo vi /usr/local/lib/R/etc/Rprofile.site

Add this line:

Sys.umask("2") # allow group write vs default 22 group read only

Systematically do this once during installation, now in mhk-env_server-software: README.md:

docker exec rstudio sh -c "echo 'Sys.umask('2')\n' >> /usr/local/lib/R/etc/Rprofile.site"
bbest commented 3 years ago

Hi @Neil-Swanson,

I reran all, and hopefully fixed for future :) Wanted to log these for future reference. Also here's the quick for future in Terminal of rstudio.marineenergy.app:

# change directory, eg
/share/github/mhk-env_shiny-apps/data

# change mode as superuser with group write permissions recursively
sudo chmod -R g+w *
bbest commented 3 years ago

Look at permissions of file

bbest@df3e3af5e27f:/share/github/mhk-env.github.io_dev$ ls -la | grep mgt
-rw-rw-r--  1 bbest    staff  339951 Feb  3 19:49 mgt.html
-rw-r--r--  1 bbest    staff    1171 Feb  3 19:48 mgt.Rmd

So we're missing the group write permission.

Fix permissions

To add the group write permission, please use the command mentioned previously:

# what's the present working directory?
pwd

# superuser do (sudo) change mode (chmod) recursively (-R) group (g) add (+) write (w) permissions on all (*) files within the present working directory
sudo chmod -R g+w *

Check all's well

# list permissions if mgt file
$ ls -la | grep mgt
-rw-rw-r--  1 bbest    staff  339951 Feb  3 19:49 mgt.html
-rw-r--r--  1 bbest    staff    1171 Feb  3 19:48 mgt.Rmd

# get present working directory
$ pwd
/share/github/mhk-env.github.io_dev

# fix permissions
$ sudo chmod -R g+w *

# check that the write flag to the group got added
$ ls -la | grep mgt
-rw-rw-r--  1 bbest    staff  339951 Feb  3 19:49 mgt.html
-rw-rw-r--  1 bbest    staff    1171 Feb  3 19:48 mgt.Rmd

$ groups nswanson
nswanson : staff sudo shiny