Add env var for disabling token auth (#696)

This commit is contained in:
Jonatan Kłosko 2021-11-10 13:54:50 +01:00 committed by GitHub
parent 79049e7f8c
commit 54511d5ffc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 4 deletions

View file

@ -174,6 +174,9 @@ The following environment variables configure Livebook:
long and it can be generated by commands such as: 'openssl rand -base64 48'.
Defaults to a random secret on every boot.
* LIVEBOOK_TOKEN_ENABLED - controls whether token authentication is enabled.
Enabled by default unless `LIVEBOOK_PASSWORD` is set.
<!-- Environment variables -->
If running Livebook as a Docker image or an Elixir release, [the environment

View file

@ -31,10 +31,15 @@ defmodule Livebook do
config :livebook, LivebookWeb.Endpoint, http: [ip: ip]
end
if password = Livebook.Config.password!("LIVEBOOK_PASSWORD") do
config :livebook, authentication_mode: :password, password: password
else
config :livebook, token: Livebook.Utils.random_id()
cond do
password = Livebook.Config.password!("LIVEBOOK_PASSWORD") ->
config :livebook, authentication_mode: :password, password: password
Livebook.Config.token_enabled!("LIVEBOOK_TOKEN_ENABLED") ->
config :livebook, token: Livebook.Utils.random_id()
true ->
config :livebook, authentication_mode: :disabled
end
if runtime = Livebook.Config.default_runtime!("LIVEBOOK_DEFAULT_RUNTIME") do

View file

@ -168,6 +168,13 @@ defmodule Livebook.Config do
end
end
@doc """
Parses token auth setting from env.
"""
def token_enabled!(env) do
System.get_env(env, "1") in ~w(true 1)
end
@doc """
Parses and validates default runtime from env.
"""