Skip to content

Commit

Permalink
Allow running libinteractive problems without sandboxing (#115)
Browse files Browse the repository at this point in the history
Libinteractive problems required bind-mounting, but that's not enabled
without a sandbox.

This change falls back to symlinking when the sandboxing is disabled.
  • Loading branch information
lhchavez authored Jan 24, 2023
1 parent 32f89b0 commit ba9209d
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ RUN mkdir /tmp/karel && \
# Install a newer version of the omegajail binary.
RUN rm -rf /var/lib/omegajail && \
curl -sSL https://github.com/omegaup/omegajail/releases/download/v3.10.2/omegajail-focal-distrib-x86_64.tar.xz | tar xJ -C / && \
curl -sL https://github.com/omegaup/libinteractive/releases/download/v2.0.29/libinteractive.jar \
curl -sL https://github.com/omegaup/libinteractive/releases/download/v2.0.30/libinteractive.jar \
-o /usr/share/java/libinteractive.jar

FROM base
Expand Down
55 changes: 50 additions & 5 deletions runner/sandbox.go
Original file line number Diff line number Diff line change
Expand Up @@ -332,11 +332,52 @@ func (o *OmegajailSandbox) Run(
"--run", lang,
"--run-target", target,
}
for path, mountTarget := range extraMountPoints {
params = append(
params,
"--bind", fmt.Sprintf("%s:%s", path, mountTarget),
)
for mountSource, mountTarget := range extraMountPoints {
if o.DisableSandboxing {
// When we have sandboxing disabled, we can't bind-mount, so we symlink
// the targets instead.
relTarget, err := filepath.Rel("/home", mountTarget)
if err != nil {
err = errors.Wrapf(
err,
"filepath.Rel(%q, %q)", "/home", mountTarget,
)
return &RunMetadata{
Verdict: "JE",
ExitStatus: -1,
}, err
}
symlinkTarget := path.Join(chdir, relTarget)
if st, err := os.Stat(symlinkTarget); err == nil && st.Mode().IsDir() {
err = os.Remove(symlinkTarget)
if err != nil {
err = errors.Wrapf(
err,
"remove(%q)", symlinkTarget,
)
return &RunMetadata{
Verdict: "JE",
ExitStatus: -1,
}, err
}
}
err = os.Symlink(mountSource, symlinkTarget)
if err != nil {
err = errors.Wrapf(
err,
"symlink(%q, %q)", mountSource, symlinkTarget,
)
return &RunMetadata{
Verdict: "JE",
ExitStatus: -1,
}, err
}
} else {
params = append(
params,
"--bind", fmt.Sprintf("%s:%s", mountSource, mountTarget),
)
}
}
if len(extraParams) > 0 {
params = append(params, "--")
Expand Down Expand Up @@ -385,6 +426,10 @@ func (o *OmegajailSandbox) invokeOmegajail(ctx *common.Context, omegajailParams
},
)
cmd := exec.Command(omegajailFullParams[0], omegajailFullParams[1:]...)
cmd.Env = []string{
"RUST_BACKTRACE=1",
"RUST_LOG=debug",
}
omegajailErrorFile := errorFile + ".omegajail"
omegajailErrorFd, err := os.Create(omegajailErrorFile)
if err != nil {
Expand Down

0 comments on commit ba9209d

Please sign in to comment.