-
Notifications
You must be signed in to change notification settings - Fork 437
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
106 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Authentication with Basic Auth | ||
|
||
Setting up Basic Authentication will protect all routes of your notebook. It is particularly useful for adding authentication to deployed notebooks. Basic Authentication is provided in addition to [Livebook's authentication](../authentication.md) for authoring notebooks. | ||
|
||
## How to | ||
|
||
To integrate Basic Authentication with Livebook, set the `LIVEBOOK_IDENTITY_PROVIDER` environment variable to `basic_auth:<username>:<password>`. | ||
|
||
To do it, run: | ||
|
||
```bash | ||
LIVEBOOK_IDENTITY_PROVIDER=basic_auth:user:pass \ | ||
livebook server | ||
``` | ||
|
||
## Livebook Teams | ||
|
||
[Livebook Teams](https://livebook.dev/teams/) users have access to airgapped notebook deployment via Docker, with pre-configured Zero Trust Authentication, shared team secrets, and file storages. | ||
|
||
Furthermore, if you are deploying multi-session apps via [Livebook Teams](https://livebook.dev/teams/), you can programmatically access data from the authenticated user by calling [`Kino.Hub.app_info/0`](https://hexdocs.pm/kino/Kino.Hub.html#app_info/0). | ||
|
||
To get started, open up Livebook, click "Add Organization" on the sidebar, and visit the "Airgapped Deployment" section of your organization. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
defmodule Livebook.ZTA.BasicAuth do | ||
def child_spec(opts) do | ||
%{id: __MODULE__, start: {__MODULE__, :start_link, [opts]}} | ||
end | ||
|
||
def start_link(options) do | ||
name = Keyword.fetch!(options, :name) | ||
identity_key = Keyword.fetch!(options, :identity_key) | ||
[username, password] = String.split(identity_key, ":", parts: 2) | ||
|
||
Livebook.ZTA.put(name, {username, password}) | ||
:ignore | ||
end | ||
|
||
def authenticate(name, conn, _options) do | ||
{username, password} = Livebook.ZTA.get(name) | ||
conn = Plug.BasicAuth.basic_auth(conn, username: username, password: password) | ||
|
||
if conn.halted do | ||
{conn, nil} | ||
else | ||
{conn, %{payload: %{}}} | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
defmodule Livebook.ZTA.BasicAuthTest do | ||
use ExUnit.Case, async: true | ||
use Plug.Test | ||
|
||
alias Livebook.ZTA.BasicAuth | ||
|
||
import Plug.BasicAuth, only: [encode_basic_auth: 2] | ||
|
||
@name Context.Test.BasicAuth | ||
|
||
setup do | ||
username = "ChonkierCat" | ||
password = Livebook.Utils.random_long_id() | ||
options = [name: @name, identity_key: "#{username}:#{password}"] | ||
|
||
{:ok, username: username, password: password, options: options, conn: conn(:get, "/")} | ||
end | ||
|
||
test "returns the user_identity when credentials are valid", context do | ||
authorization = encode_basic_auth(context.username, context.password) | ||
conn = put_req_header(context.conn, "authorization", authorization) | ||
start_supervised!({BasicAuth, context.options}) | ||
|
||
assert {_conn, %{payload: %{}}} = BasicAuth.authenticate(@name, conn, []) | ||
end | ||
|
||
test "returns nil when the username is invalid", context do | ||
authorization = encode_basic_auth("foo", context.password) | ||
conn = put_req_header(context.conn, "authorization", authorization) | ||
start_supervised!({BasicAuth, context.options}) | ||
|
||
assert {_conn, nil} = BasicAuth.authenticate(@name, conn, []) | ||
end | ||
|
||
test "returns nil when the password is invalid", context do | ||
authorization = encode_basic_auth(context.username, Livebook.Utils.random_long_id()) | ||
conn = put_req_header(context.conn, "authorization", authorization) | ||
start_supervised!({BasicAuth, context.options}) | ||
|
||
assert {_conn, nil} = BasicAuth.authenticate(@name, conn, []) | ||
end | ||
end |