I simply want to combine the packages plumber and RAppArmor in a way, that users can send code using the plumber-API to a server which is then safely evaluated with the help of profiles in RAppArmor. How can I make the following code work:
#* Evaluate the result
#* @post /eval_res
function(func){
library("RAppArmor")
data <- cbind(rnorm(100),rnorm(100))
eval.secure(nrow(data),profile="r-user")
}
This code chunk is a simplified version of what is happening later. So far, it seems that any object specified in the function, e.g. data, cannot be passed to eval.secure given the user restrictions in r-user (standard profile of RAppArmor). I even tried allowing full access to /** for r-user by editing the profile, without success. Opening plumber on localhost and using curl with curl --data "func=function(x){return(nrow(x))}" "http://localhost:8000/eval_res"
to get the result of eval.secure() results in an empty answer {}
. The same code works without eval.secure() and correctly returns [100]
. Can someone help me so I understand the problem better or even fix the code?
My current workaround is to save everything to a csv before eval.secure() and then read it within the eval.secure granting access to that folder in the r-user profile, but that is definitely not a convincing solution.
For those of you who are confused about the function: In a later step the option func will contain some code which will the be parsed and evaluated, but for this small example I thought it would only add unnecessary complexity.
Thanks in advance!
So
eval.secure
just pass all parameters tounix::eval_safe
. The reason whyeval.secure
does not work is becauseeval_safe
expects to find your variables in itsparent.frame()
, which in the case ofeval.secure
is an empty function body.eval_safe
use of parent.frame()