mirror of
https://github.com/livebook-dev/livebook.git
synced 2025-10-06 11:35:54 +08:00
Add env var for disabling token auth (#696)
This commit is contained in:
parent
79049e7f8c
commit
54511d5ffc
3 changed files with 19 additions and 4 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.
|
||||
"""
|
||||
|
|
Loading…
Add table
Reference in a new issue