Could someone adapt the code below to be used on a remote server? I couldn't find any simple example on the package pages or on the internet that addressed this issue. Here's the code:
global.r
# Init DB using credentials data
credentials <- data.frame(
user = c("shiny", "shinymanager"),
password = c("azerty", "12345"),
# password will automatically be hashed
admin = c(FALSE, TRUE),
stringsAsFactors = FALSE
)
# you can use keyring package to set database key
library(keyring)
key_set("R-shinymanager-key", "obiwankenobi")
# Init the database
create_db(
credentials_data = credentials,
sqlite_path = "www/database.sqlite", # will be created
passphrase = key_get("R-shinymanager-key", "obiwankenobi")
)
ui.r
library(shiny)
library(shinymanager)
ui <- fluidPage(
tags$h2("My secure application"),
verbatimTextOutput("auth_output")
)
ui <- secure_app(ui, enable_admin = TRUE)
server.r
server <- function(input, output, session) {
# check_credentials directly on sqlite db
res_auth <- secure_server(
check_credentials = check_credentials(
"www/database.sqlite",
passphrase = key_get("R-shinymanager-key", "obiwankenobi")
# passphrase = "passphrase_wihtout_keyring"
)
)
output$auth_output <- renderPrint({
reactiveValuesToList(res_auth)
})
# your classic server logic
}
The file .log
in /var/log/shiny-server/testeshimanager is:
su: ignore --preserve-environment, it's mutually exclusive to --login.
Error in b_file_set(self, private, service, username, keyring, prompt) :
Aborted setting keyring key
Calls: runApp ... ..stacktraceon.. -> key_set -> <Anonymous> -> b_file_set
Execution halted
I didn't find anything doable to unravel such error. Just for information, the shiny server is running perfectly. Another example, very simple, works. Therefore, all folders and files have maximum execution permission, that is, chmod -R 777
. The difficulty lies precisely in using the shinymanager
package on the remote server.
After a lot of research and study, I managed to make
shinymanager
work on the server. However, after adding two command lines and the app working, the exhausting process began. I will summarize in steps according to the experience I had. I don't know if it's the best, because I'm not a database connoisseur, much less information security.global.R
file.global.R
database.sqlite
was created! If not, then check with the shiny user if the key was created, delete them and start over from step two In theterminal
,and then in
R
,database.sqlite
file was created, you can comment out the lineskeyring_create("system", password="secret")
andkeyring_unlock(keyring = "system", password = "secret")
in theglobal.R
file. Once that was done, I changed the permissions of thedatabase.sqlite
file withchmod 777 database.sqlite
.Finally the login screen appeared. Hope it helps someone.