Skip to content

Commit

Permalink
crocochrome: start chromium as a different user
Browse files Browse the repository at this point in the history
  • Loading branch information
nadiamoe committed May 29, 2024
1 parent c6942b9 commit 867cd83
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion crocochrome.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package crocochrome

import (
"bytes"
"context"
"crypto/rand"
"encoding/hex"
Expand All @@ -10,6 +11,7 @@ import (
"net"
"os/exec"
"sync"
"syscall"
"time"

"github.com/grafana/crocochrome/chromium"
Expand Down Expand Up @@ -95,19 +97,37 @@ func (s *Supervisor) Session() (SessionInfo, error) {

go func() {
logger.Debug("starting session")
stdout := &bytes.Buffer{}
stderr := &bytes.Buffer{}

cmd := exec.CommandContext(ctx,
s.opts.ChromiumPath,
"--headless",
"--remote-debugging-address=0.0.0.0",
"--remote-debugging-port="+s.opts.ChromiumPort,
"--no-sandbox", // TODO: Sandbox.
"--no-sandbox",
)
cmd.Env = []string{}
cmd.SysProcAttr = &syscall.SysProcAttr{
Credential: &syscall.Credential{
// nobody:nobody on alpine.
Uid: 65534,
Gid: 65534,
},
}
cmd.Stdout = stdout
cmd.Stderr = stderr

err := cmd.Run()
if err != nil && !errors.Is(ctx.Err(), context.Canceled) {
logger.Error("running chromium", "err", err)
logger.Error("chromium output", "stdout", stdout.String())
logger.Error("chromium output", "stderr", stderr.String())
return
}

logger.Debug("chromium output", "stdout", stdout.String())
logger.Debug("chromium output", "stderr", stderr.String())
}()

version, err := chromium.Version(net.JoinHostPort("localhost", s.opts.ChromiumPort), 2*time.Second)
Expand Down

0 comments on commit 867cd83

Please sign in to comment.