Show more prominent warning for app servers (#2962)

This commit is contained in:
Alexandre de Souza 2025-03-17 11:05:11 -03:00 committed by GitHub
parent 64b10e055f
commit ce76af9432
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
8 changed files with 49 additions and 20 deletions

View file

@ -35,7 +35,7 @@ config :livebook,
plugs: [], plugs: [],
rewrite_on: [], rewrite_on: [],
shutdown_callback: nil, shutdown_callback: nil,
teams_auth?: false, teams_auth: nil,
teams_url: "https://teams.livebook.dev", teams_url: "https://teams.livebook.dev",
github_release_info: %{repo: "livebook-dev/livebook", version: Mix.Project.config()[:version]}, github_release_info: %{repo: "livebook-dev/livebook", version: Mix.Project.config()[:version]},
update_instructions_url: nil, update_instructions_url: nil,

View file

@ -293,15 +293,16 @@ defmodule Livebook.Application do
cond do cond do
teams_key && auth -> teams_key && auth ->
Application.put_env(:livebook, :teams_auth?, true)
{hub_id, fun} = {hub_id, fun} =
case String.split(auth, ":") do case String.split(auth, ":") do
["offline", name, public_key] -> ["offline", name, public_key] ->
Application.put_env(:livebook, :teams_auth, :offline)
hub_id = "team-#{name}" hub_id = "team-#{name}"
{hub_id, fn -> create_offline_hub(teams_key, hub_id, name, public_key) end} {hub_id, fn -> create_offline_hub(teams_key, hub_id, name, public_key) end}
["online", name, org_id, org_key_id, agent_key] -> ["online", name, org_id, org_key_id, agent_key] ->
Application.put_env(:livebook, :teams_auth, :online)
hub_id = "team-" <> name hub_id = "team-" <> name
with :error <- Application.fetch_env(:livebook, :identity_provider) do with :error <- Application.fetch_env(:livebook, :identity_provider) do

View file

@ -195,9 +195,9 @@ defmodule Livebook.Config do
Returns if this instance is running with teams auth, Returns if this instance is running with teams auth,
i.e. if there an online or offline hub created on boot. i.e. if there an online or offline hub created on boot.
""" """
@spec teams_auth?() :: boolean() @spec teams_auth() :: :online | :offline | nil
def teams_auth?() do def teams_auth() do
Application.fetch_env!(:livebook, :teams_auth?) Application.fetch_env!(:livebook, :teams_auth)
end end
@doc """ @doc """

View file

@ -308,7 +308,7 @@ defmodule Livebook.Hubs do
@doc """ @doc """
Gets a list of hub app specs. Gets a list of hub app specs.
""" """
@spec get_app_specs() :: list(Livebook.AppSpec.t()) @spec get_app_specs() :: list(Livebook.Apps.AppSpec.t())
def get_app_specs() do def get_app_specs() do
for hub <- get_hubs(), for hub <- get_hubs(),
app_spec <- Provider.get_app_specs(hub), app_spec <- Provider.get_app_specs(hub),

View file

@ -143,18 +143,8 @@ defimpl Livebook.Hubs.Provider, for: Livebook.Hubs.Team do
def disconnect(team), do: TeamClient.stop(team.id) def disconnect(team), do: TeamClient.stop(team.id)
def connection_status(team) do def connection_status(team) do
cond do if reason = TeamClient.get_connection_status(team.id) do
team.offline -> "Cannot connect to Teams: #{reason}.\nWill attempt to reconnect automatically..."
"You are running an offline Workspace for deployment. You cannot modify its settings."
team.user_id == nil ->
"You are running a Livebook app server. This workspace is in read-only mode."
reason = TeamClient.get_connection_status(team.id) ->
"Cannot connect to Teams: #{reason}.\nWill attempt to reconnect automatically..."
true ->
nil
end end
end end

View file

@ -23,6 +23,13 @@ defmodule LivebookWeb.LayoutComponents do
<.sidebar current_page={@current_page} current_user={@current_user} saved_hubs={@saved_hubs} /> <.sidebar current_page={@current_page} current_user={@current_user} saved_hubs={@saved_hubs} />
</div> </div>
<div class="grow overflow-y-auto"> <div class="grow overflow-y-auto">
<.topbar :if={Livebook.Config.teams_auth() == :online} variant="warning">
This Livebook instance has been configured for notebook deployment and is in read-only mode.
</.topbar>
<.topbar :if={Livebook.Config.teams_auth() == :offline} variant="warning">
You are running an offline Workspace for deployment. You cannot modify its settings.
</.topbar>
<div class="md:hidden sticky flex items-center justify-between h-14 px-4 top-0 left-0 z-[500] bg-white border-b border-gray-200"> <div class="md:hidden sticky flex items-center justify-between h-14 px-4 top-0 left-0 z-[500] bg-white border-b border-gray-200">
<div class="pt-1 text-xl text-gray-400 hover:text-gray-600 focus:text-gray-600"> <div class="pt-1 text-xl text-gray-400 hover:text-gray-600 focus:text-gray-600">
<button <button

View file

@ -78,7 +78,7 @@ defmodule LivebookWeb.AuthPlug do
defp redirect_to_authenticate(%{path_info: []} = conn) do defp redirect_to_authenticate(%{path_info: []} = conn) do
path = path =
if Livebook.Apps.list_apps() != [] or Livebook.Config.apps_path() != nil or if Livebook.Apps.list_apps() != [] or Livebook.Config.apps_path() != nil or
Livebook.Config.teams_auth?() do Livebook.Config.teams_auth() != nil do
~p"/apps" ~p"/apps"
else else
~p"/authenticate" ~p"/authenticate"

View file

@ -0,0 +1,31 @@
defmodule LivebookWeb.Integration.AdminLiveTest do
# Not async, because we alter global config (app server instance)
use Livebook.TeamsIntegrationCase, async: false
import Phoenix.LiveViewTest
setup %{teams_auth: teams_auth} do
Application.put_env(:livebook, :teams_auth, teams_auth)
on_exit(fn -> Application.delete_env(:livebook, :teams_auth) end)
:ok
end
for page <- ["/", "/settings", "/learn", "/hub", "/apps-dashboard"] do
@tag page: page, teams_auth: :online
test "GET #{page} shows the app server instance topbar warning", %{conn: conn, page: page} do
{:ok, view, _} = live(conn, page)
assert render(view) =~
"This Livebook instance has been configured for notebook deployment and is in read-only mode."
end
@tag page: page, teams_auth: :offline
test "GET #{page} shows the offline hub topbar warning", %{conn: conn, page: page} do
{:ok, view, _} = live(conn, page)
assert render(view) =~
"You are running an offline Workspace for deployment. You cannot modify its settings."
end
end
end