Skip to content

Commit

Permalink
fix: Use no sandbox mode for chromium
Browse files Browse the repository at this point in the history
* Running Grafana under unprivileged user have issues running with sandbox mode

* Ref: chrome-php/chrome#106

Signed-off-by: Mahendra Paipuri <mahendra.paipuri@gmail.com>
  • Loading branch information
mahendrapaipuri committed Mar 13, 2024
1 parent cefebd5 commit 47a6e2e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
9 changes: 5 additions & 4 deletions .config/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ ARG grafana_image=grafana-enterprise

FROM grafana/${grafana_image}:${grafana_version}

# Install chromium
RUN apk add chromium

# Make it as simple as possible to access the grafana instance for development purposes
# Do NOT enable these settings in a public facing / production grafana instance
ENV GF_AUTH_ANONYMOUS_ORG_ROLE "Admin"
Expand All @@ -11,9 +14,7 @@ ENV GF_AUTH_BASIC_ENABLED "false"
# Set development mode so plugins can be loaded without the need to sign
ENV GF_DEFAULT_APP_MODE "development"

# Inject livereload script into grafana index.html
USER root
RUN sed -i 's/<\/body><\/html>/<script src=\"http:\/\/localhost:35729\/livereload.js\"><\/script><\/body><\/html>/g' /usr/share/grafana/public/views/index.html

# Install chromium
RUN apk add chromium
# Inject livereload script into grafana index.html
RUN sed -i 's/<\/body><\/html>/<script src=\"http:\/\/localhost:35729\/livereload.js\"><\/script><\/body><\/html>/g' /usr/share/grafana/public/views/index.html
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ ARG grafana_image=grafana-enterprise

FROM grafana/${grafana_image}:${grafana_version}

RUN apk add -U texlive
RUN apk add -U chromium

# Make it as simple as possible to access the grafana instance for development purposes
# Do NOT enable these settings in a public facing / production grafana instance
Expand Down
9 changes: 8 additions & 1 deletion pkg/plugin/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,15 @@ func (r *report) renderPDF() ([]byte, error) {
return nil, err
}

// Chrome executor options
opts := append(chromedp.DefaultExecAllocatorOptions[:],
chromedp.NoSandbox,
)

// create context
ctx, cancel := chromedp.NewContext(context.Background())
allocCtx, allocCtxCancel := chromedp.NewExecAllocator(context.Background(), opts...)
defer allocCtxCancel()
ctx, cancel := chromedp.NewContext(allocCtx)
defer cancel()

// capture pdf
Expand Down

0 comments on commit 47a6e2e

Please sign in to comment.