mirror of
https://github.com/gotenberg/gotenberg.git
synced 2026-08-15 20:02:15 +01:00
Merge pull request #206 from tomjvdberg/URL-allow-insecure-connection
Url allow insecure connection
This commit is contained in:
@@ -58,6 +58,12 @@ The hard limit is 100 MB and is defined by Google Chrome itself.
|
|||||||
> The default Google Chrome rpcc buffer size may also be overridden per request thanks to the form field `googleChromeRpccBufferSize`.
|
> The default Google Chrome rpcc buffer size may also be overridden per request thanks to the form field `googleChromeRpccBufferSize`.
|
||||||
> See the [rpcc buffer size section](#html.rpcc_buffer_size).
|
> See the [rpcc buffer size section](#html.rpcc_buffer_size).
|
||||||
|
|
||||||
|
## Google Chrome ignore certificate errors
|
||||||
|
|
||||||
|
When performing a [URL](#url) conversion, Google Chrome will not accept certificate errors .
|
||||||
|
|
||||||
|
You may allow insecure connections by setting `GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS` variable to `"1"`. **You should be careful with this feature and only enable it in your development environment.**
|
||||||
|
|
||||||
## Disable LibreOffice (unoconv)
|
## Disable LibreOffice (unoconv)
|
||||||
|
|
||||||
You may also disable LibreOffice (unoconv) with `DISABLE_UNOCONV`.
|
You may also disable LibreOffice (unoconv) with `DISABLE_UNOCONV`.
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ func main() {
|
|||||||
systemLogger.DebugOpf(op, "configuration: %+v", config)
|
systemLogger.DebugOpf(op, "configuration: %+v", config)
|
||||||
if !config.DisableGoogleChrome() {
|
if !config.DisableGoogleChrome() {
|
||||||
// start Google Chrome headless.
|
// start Google Chrome headless.
|
||||||
if err := chrome.Start(systemLogger); err != nil {
|
if err := chrome.Start(systemLogger, config.GoogleChromeIgnoreCertificateErrors()); err != nil {
|
||||||
systemLogger.FatalOp(op, err)
|
systemLogger.FatalOp(op, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -167,14 +167,14 @@ $ make publish <span class="nv">GOTENBERG_USER_GID</span><span class="o">=</span
|
|||||||
|
|
||||||
<p>You may also add it in your Docker Compose stack:</p>
|
<p>You may also add it in your Docker Compose stack:</p>
|
||||||
|
|
||||||
<pre class="chroma"><span class="k">version</span><span class="p">:</span><span class="w"> </span><span class="s1">'3'</span><span class="w">
|
<pre class="chroma"><span class="nt">version</span><span class="p">:</span><span class="w"> </span><span class="s1">'3'</span><span class="w">
|
||||||
</span><span class="w">
|
</span><span class="w">
|
||||||
</span><span class="w"></span><span class="k">services</span><span class="p">:</span><span class="w">
|
</span><span class="w"></span><span class="nt">services</span><span class="p">:</span><span class="w">
|
||||||
</span><span class="w">
|
</span><span class="w">
|
||||||
</span><span class="w"> </span><span class="c"># your other services</span><span class="w">
|
</span><span class="w"> </span><span class="c"># your other services</span><span class="w">
|
||||||
</span><span class="w">
|
</span><span class="w">
|
||||||
</span><span class="w"> </span><span class="k">gotenberg</span><span class="p">:</span><span class="w">
|
</span><span class="w"> </span><span class="nt">gotenberg</span><span class="p">:</span><span class="w">
|
||||||
</span><span class="w"> </span><span class="k">image</span><span class="p">:</span><span class="w"> </span>thecodingmachine/gotenberg<span class="p">:</span><span class="m">6</span><span class="w">
|
</span><span class="w"> </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l">thecodingmachine/gotenberg:6</span><span class="w">
|
||||||
</span></pre>
|
</span></pre>
|
||||||
|
|
||||||
<blockquote>
|
<blockquote>
|
||||||
@@ -332,6 +332,12 @@ The hard limit is 100 MB and is defined by Google Chrome itself.</p>
|
|||||||
See the <a href="#html.rpcc_buffer_size">rpcc buffer size section</a>.</p>
|
See the <a href="#html.rpcc_buffer_size">rpcc buffer size section</a>.</p>
|
||||||
</blockquote>
|
</blockquote>
|
||||||
|
|
||||||
|
<h2 class="Heading"><a class="Anchor" aria-hidden="true" id="environment_variables.ignore_certificate_errors" href="#environment_variables.ignore_certificate_errors">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>
|
||||||
|
</a>Ignore certificate errors</h2>
|
||||||
|
|
||||||
|
<p>By default the chrome instance will not accept certificate errors when using the URL print method. Setting this environment variable to <code>"1"</code> will allow insecure connections to be used. In dev environment for example. Be careful with this! Do not use in production.</p>
|
||||||
|
|
||||||
<h2 class="Heading"><a class="Anchor" aria-hidden="true" id="environment_variables.disable_libre_office_unoconv" href="#environment_variables.disable_libre_office_unoconv">
|
<h2 class="Heading"><a class="Anchor" aria-hidden="true" id="environment_variables.disable_libre_office_unoconv" href="#environment_variables.disable_libre_office_unoconv">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" width="14" height="14" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-link"><path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"></path><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"></path></svg>
|
||||||
</a>Disable LibreOffice (unoconv)</h2>
|
</a>Disable LibreOffice (unoconv)</h2>
|
||||||
@@ -1700,14 +1706,14 @@ if the API is under heavy load.</p>
|
|||||||
|
|
||||||
<p>For instance, using the following Docker Compose file:</p>
|
<p>For instance, using the following Docker Compose file:</p>
|
||||||
|
|
||||||
<pre class="chroma"><span class="k">version</span><span class="p">:</span><span class="w"> </span><span class="s1">'3'</span><span class="w">
|
<pre class="chroma"><span class="nt">version</span><span class="p">:</span><span class="w"> </span><span class="s1">'3'</span><span class="w">
|
||||||
</span><span class="w">
|
</span><span class="w">
|
||||||
</span><span class="w"></span><span class="k">services</span><span class="p">:</span><span class="w">
|
</span><span class="w"></span><span class="nt">services</span><span class="p">:</span><span class="w">
|
||||||
</span><span class="w">
|
</span><span class="w">
|
||||||
</span><span class="w"> </span><span class="c"># your other services</span><span class="w">
|
</span><span class="w"> </span><span class="c"># your other services</span><span class="w">
|
||||||
</span><span class="w">
|
</span><span class="w">
|
||||||
</span><span class="w"> </span><span class="k">gotenberg</span><span class="p">:</span><span class="w">
|
</span><span class="w"> </span><span class="nt">gotenberg</span><span class="p">:</span><span class="w">
|
||||||
</span><span class="w"> </span><span class="k">image</span><span class="p">:</span><span class="w"> </span>thecodingmachine/gotenberg<span class="p">:</span><span class="m">6</span><span class="w">
|
</span><span class="w"> </span><span class="nt">image</span><span class="p">:</span><span class="w"> </span><span class="l">thecodingmachine/gotenberg:6</span><span class="w">
|
||||||
</span></pre>
|
</span></pre>
|
||||||
|
|
||||||
<p>You may now launch your services using:</p>
|
<p>You may now launch your services using:</p>
|
||||||
|
|||||||
@@ -16,11 +16,11 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
// Start starts Google Chrome headless in background.
|
// Start starts Google Chrome headless in background.
|
||||||
func Start(logger xlog.Logger) error {
|
func Start(logger xlog.Logger, ignoreCertificateErrors bool) error {
|
||||||
const op string = "chrome.Start"
|
const op string = "chrome.Start"
|
||||||
logger.DebugOp(op, "starting new Google Chrome headless process on port 9222...")
|
logger.DebugOp(op, "starting new Google Chrome headless process on port 9222...")
|
||||||
resolver := func() error {
|
resolver := func() error {
|
||||||
cmd, err := cmd(logger)
|
cmd, err := cmd(logger, ignoreCertificateErrors)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -32,7 +32,7 @@ func Start(logger xlog.Logger) error {
|
|||||||
// if the process failed to start correctly,
|
// if the process failed to start correctly,
|
||||||
// we have to restart it.
|
// we have to restart it.
|
||||||
if !isViable(logger) {
|
if !isViable(logger) {
|
||||||
return restart(logger, cmd.Process)
|
return restart(logger, cmd.Process, ignoreCertificateErrors)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -42,7 +42,7 @@ func Start(logger xlog.Logger) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func cmd(logger xlog.Logger) (*exec.Cmd, error) {
|
func cmd(logger xlog.Logger, ignoreCertificateErrors bool) (*exec.Cmd, error) {
|
||||||
const op string = "chrome.cmd"
|
const op string = "chrome.cmd"
|
||||||
binary := "google-chrome-stable"
|
binary := "google-chrome-stable"
|
||||||
args := []string{
|
args := []string{
|
||||||
@@ -66,6 +66,11 @@ func cmd(logger xlog.Logger) (*exec.Cmd, error) {
|
|||||||
"--mute-audio",
|
"--mute-audio",
|
||||||
"--no-first-run",
|
"--no-first-run",
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ignoreCertificateErrors {
|
||||||
|
args = append(args, "--ignore-certificate-errors")
|
||||||
|
}
|
||||||
|
|
||||||
cmd, err := xexec.Command(logger, binary, args...)
|
cmd, err := xexec.Command(logger, binary, args...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, xerror.New(op, err)
|
return nil, xerror.New(op, err)
|
||||||
@@ -93,7 +98,7 @@ func kill(logger xlog.Logger, proc *os.Process) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func restart(logger xlog.Logger, proc *os.Process) error {
|
func restart(logger xlog.Logger, proc *os.Process, ignoreCertificateErrors bool) error {
|
||||||
const op string = "chrome.restart"
|
const op string = "chrome.restart"
|
||||||
logger.DebugOp(op, "restarting Google Chrome headless process using port 9222...")
|
logger.DebugOp(op, "restarting Google Chrome headless process using port 9222...")
|
||||||
resolver := func() error {
|
resolver := func() error {
|
||||||
@@ -101,7 +106,7 @@ func restart(logger xlog.Logger, proc *os.Process) error {
|
|||||||
if err := kill(logger, proc); err != nil {
|
if err := kill(logger, proc); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
cmd, err := cmd(logger)
|
cmd, err := cmd(logger, ignoreCertificateErrors)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -113,7 +118,7 @@ func restart(logger xlog.Logger, proc *os.Process) error {
|
|||||||
// if the process failed to restart correctly,
|
// if the process failed to restart correctly,
|
||||||
// we have to restart it again.
|
// we have to restart it again.
|
||||||
if !isViable(logger) {
|
if !isViable(logger) {
|
||||||
return restart(logger, cmd.Process)
|
return restart(logger, cmd.Process, ignoreCertificateErrors)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,6 +40,9 @@ const (
|
|||||||
// DefaultGoogleChromeRpccBufferSizeEnvVar contains the name
|
// DefaultGoogleChromeRpccBufferSizeEnvVar contains the name
|
||||||
// of the environment variable "DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE".
|
// of the environment variable "DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE".
|
||||||
DefaultGoogleChromeRpccBufferSizeEnvVar string = "DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE"
|
DefaultGoogleChromeRpccBufferSizeEnvVar string = "DEFAULT_GOOGLE_CHROME_RPCC_BUFFER_SIZE"
|
||||||
|
// GoogleChromeIgnoreCertificateErrorsEnvVar contains the name
|
||||||
|
// of the environment variable "GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS".
|
||||||
|
GoogleChromeIgnoreCertificateErrorsEnvVar string = "GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Config contains the application
|
// Config contains the application
|
||||||
@@ -53,6 +56,7 @@ type Config struct {
|
|||||||
defaultListenPort int64
|
defaultListenPort int64
|
||||||
disableGoogleChrome bool
|
disableGoogleChrome bool
|
||||||
disableUnoconv bool
|
disableUnoconv bool
|
||||||
|
googleChromeIgnoreCertificateErrors bool
|
||||||
logLevel xlog.Level
|
logLevel xlog.Level
|
||||||
rootPath string
|
rootPath string
|
||||||
maximumGoogleChromeRpccBufferSize int64
|
maximumGoogleChromeRpccBufferSize int64
|
||||||
@@ -75,6 +79,7 @@ func DefaultConfig() Config {
|
|||||||
rootPath: "/",
|
rootPath: "/",
|
||||||
maximumGoogleChromeRpccBufferSize: 104857600, // ~100 MB
|
maximumGoogleChromeRpccBufferSize: 104857600, // ~100 MB
|
||||||
defaultGoogleChromeRpccBufferSize: 1048576, // 1 MB
|
defaultGoogleChromeRpccBufferSize: 1048576, // 1 MB
|
||||||
|
googleChromeIgnoreCertificateErrors: false,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -188,6 +193,14 @@ func FromEnv() (Config, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
|
googleChromeIgnoreCertificateErrors, err := xassert.BoolFromEnv(
|
||||||
|
GoogleChromeIgnoreCertificateErrorsEnvVar,
|
||||||
|
c.googleChromeIgnoreCertificateErrors,
|
||||||
|
)
|
||||||
|
c.googleChromeIgnoreCertificateErrors = googleChromeIgnoreCertificateErrors
|
||||||
|
if err != nil {
|
||||||
|
return c, err
|
||||||
|
}
|
||||||
return c, nil
|
return c, nil
|
||||||
}
|
}
|
||||||
result, err := resolver()
|
result, err := resolver()
|
||||||
@@ -274,3 +287,7 @@ func (c Config) MaximumGoogleChromeRpccBufferSize() int64 {
|
|||||||
func (c Config) DefaultGoogleChromeRpccBufferSize() int64 {
|
func (c Config) DefaultGoogleChromeRpccBufferSize() int64 {
|
||||||
return c.defaultGoogleChromeRpccBufferSize
|
return c.defaultGoogleChromeRpccBufferSize
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c Config) GoogleChromeIgnoreCertificateErrors() bool {
|
||||||
|
return c.urlIgnoreCertificateErrors
|
||||||
|
}
|
||||||
|
|||||||
@@ -380,6 +380,43 @@ func TestDefaultGoogleChromeRpccBufferSizeFromEnv(t *testing.T) {
|
|||||||
os.Unsetenv(DefaultGoogleChromeRpccBufferSizeEnvVar)
|
os.Unsetenv(DefaultGoogleChromeRpccBufferSizeEnvVar)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGoogleChromeIgnoreCertificateErrorsFromEnv(t *testing.T) {
|
||||||
|
var (
|
||||||
|
expected Config
|
||||||
|
result Config
|
||||||
|
err error
|
||||||
|
)
|
||||||
|
// GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS correctly set to true.
|
||||||
|
os.Setenv(GoogleChromeIgnoreCertificateErrorsEnvVar, "1")
|
||||||
|
expected = DefaultConfig()
|
||||||
|
expected.googleChromeIgnoreCertificateErrors = true
|
||||||
|
result, err = FromEnv()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, expected, result)
|
||||||
|
os.Unsetenv(GoogleChromeIgnoreCertificateErrorsEnvVar)
|
||||||
|
// GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS correctly set to false.
|
||||||
|
os.Setenv(GooleChromeIgnoreCertificateErrorsEnvVar, "0")
|
||||||
|
expected = DefaultConfig()
|
||||||
|
expected.googleChromeIgnoreCertificateErrors = false
|
||||||
|
result, err = FromEnv()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, expected, result)
|
||||||
|
os.Unsetenv(GoogleChromeIgnoreCertificateErrorsEnvVar)
|
||||||
|
// GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS wrongly set.
|
||||||
|
os.Setenv(GoogleChromeIgnoreCertificateErrorsEnvVar, "foo")
|
||||||
|
expected = DefaultConfig()
|
||||||
|
result, err = FromEnv()
|
||||||
|
test.AssertError(t, err)
|
||||||
|
assert.Equal(t, expected, result)
|
||||||
|
os.Unsetenv(GoogleChromeIgnoreCertificateErrorsEnvVar)
|
||||||
|
// GOOGLE_CHROME_IGNORE_CERTIFICATE_ERRORS not set at all.
|
||||||
|
expected = DefaultConfig()
|
||||||
|
expected.googleChromeIgnoreCertificateErrors = false
|
||||||
|
result, err = FromEnv()
|
||||||
|
assert.Nil(t, err)
|
||||||
|
assert.Equal(t, expected, result)
|
||||||
|
}
|
||||||
|
|
||||||
func TestGetters(t *testing.T) {
|
func TestGetters(t *testing.T) {
|
||||||
result := DefaultConfig()
|
result := DefaultConfig()
|
||||||
assert.Equal(t, result.maximumWaitTimeout, result.MaximumWaitTimeout())
|
assert.Equal(t, result.maximumWaitTimeout, result.MaximumWaitTimeout())
|
||||||
@@ -394,4 +431,5 @@ func TestGetters(t *testing.T) {
|
|||||||
assert.Equal(t, result.rootPath, result.RootPath())
|
assert.Equal(t, result.rootPath, result.RootPath())
|
||||||
assert.Equal(t, result.maximumGoogleChromeRpccBufferSize, result.MaximumGoogleChromeRpccBufferSize())
|
assert.Equal(t, result.maximumGoogleChromeRpccBufferSize, result.MaximumGoogleChromeRpccBufferSize())
|
||||||
assert.Equal(t, result.defaultGoogleChromeRpccBufferSize, result.DefaultGoogleChromeRpccBufferSize())
|
assert.Equal(t, result.defaultGoogleChromeRpccBufferSize, result.DefaultGoogleChromeRpccBufferSize())
|
||||||
|
assert.Equal(t, result.googleChromeIgnoreCertificateErrors, result.GoogleChromeIgnoreCertificateErrors())
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ func main() {
|
|||||||
systemLogger.FatalOp(op, err)
|
systemLogger.FatalOp(op, err)
|
||||||
}
|
}
|
||||||
// start Google Chrome headless.
|
// start Google Chrome headless.
|
||||||
if err := chrome.Start(systemLogger); err != nil {
|
if err := chrome.Start(systemLogger, config.GoogleChromeIgnoreCertificateErrors()); err != nil {
|
||||||
systemLogger.FatalOp(op, err)
|
systemLogger.FatalOp(op, err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user