forked from getredash/redash
-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/global redash login logout #75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
29ff9f2
Add GlobalAdminUser model for Redash Global auth
imenattatra 2ecc17d
Add redash_global/cli with two commands
imenattatra ec68cc7
Add session-based login to Redash Global
imenattatra c17266f
Add session-based logout to Redash Global
imenattatra 5961dc0
Build Redash Global admin UI shell with working logout
imenattatra 1082a7b
Suppress Flask-Login's default login prompt message
imenattatra 636f28d
Document Redash Global app setup and CLI usage
imenattatra 2638df0
Throttle Redash Global admin login attempts
imenattatra File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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,36 @@ | ||
| """add GlobalAdminUser | ||
|
|
||
| Revision ID: b8b7fd6b4ffd | ||
| Revises: 66335454929d | ||
| Create Date: 2026-07-08 22:39:39.652218 | ||
|
|
||
| """ | ||
| from alembic import op | ||
| import sqlalchemy as sa | ||
|
|
||
|
|
||
| # revision identifiers, used by Alembic. | ||
| revision = 'b8b7fd6b4ffd' | ||
| down_revision = '66335454929d' | ||
| branch_labels = None | ||
| depends_on = None | ||
|
|
||
|
|
||
| def upgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.create_table('global_admin_users', | ||
| sa.Column('updated_at', sa.DateTime(timezone=True), nullable=False), | ||
| sa.Column('created_at', sa.DateTime(timezone=True), nullable=False), | ||
| sa.Column('id', sa.Integer(), nullable=False), | ||
| sa.Column('username', sa.String(length=255), nullable=False), | ||
| sa.Column('password_hash', sa.String(length=128), nullable=False), | ||
| sa.PrimaryKeyConstraint('id'), | ||
| sa.UniqueConstraint('username') | ||
| ) | ||
| # ### end Alembic commands ### | ||
|
|
||
|
|
||
| def downgrade(): | ||
| # ### commands auto generated by Alembic - please adjust! ### | ||
| op.drop_table('global_admin_users') | ||
| # ### end Alembic commands ### |
This file contains hidden or 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,36 @@ | ||
| # Redash Global | ||
|
|
||
| A small, standalone Flask app for cross-organization ("global") administration, | ||
| running alongside the main Redash app. It shares Redash's PostgreSQL database and | ||
| models but is a **separate application** with its own session cookie, signed by a | ||
| dedicated `GLOBAL_SECRET_KEY`. | ||
|
|
||
| ## Configuration | ||
|
|
||
| `GLOBAL_SECRET_KEY` is **required** — the app refuses to start without it. It must | ||
| differ from the main Redash app's secret. The database connection is inherited | ||
| from Redash's settings (`SQLALCHEMY_DATABASE_URI`), so no separate DB config is needed. | ||
|
|
||
| ## Running CLI commands | ||
|
|
||
| CLI commands (`create_global_admin`, `update_global_admin_password`) are registered | ||
| on the global app, so the `flask` CLI must be told to load it via `FLASK_APP`. | ||
|
|
||
| ### Locally | ||
|
|
||
| ```bash | ||
| env FLASK_APP=redash_global.wsgi_global flask create_global_admin <username> --password <password> | ||
| ``` | ||
|
|
||
| Omit `--password` to be prompted for it interactively. | ||
|
|
||
|
|
||
| ### In staging (Kubernetes) | ||
|
|
||
| `GLOBAL_SECRET_KEY` is already in the pod's environment, so only prepend `FLASK_APP`: | ||
|
|
||
| ```bash | ||
| kube staging exec -it <global-pod> -- \ | ||
| env FLASK_APP=redash_global.wsgi_global \ | ||
| flask create_global_admin <username> --password <password> | ||
| ``` |
This file contains hidden or 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 hidden or 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,50 @@ | ||
| from sys import exit | ||
|
|
||
| from click import argument, command, option, prompt | ||
|
|
||
| from redash.models import db | ||
| from redash_global.models import GlobalAdminUser | ||
|
|
||
|
|
||
| @command(name="create_global_admin") | ||
| @argument("username") | ||
| @option( | ||
| "--password", | ||
| "password", | ||
| default=None, | ||
| help="Password for the admin (leave blank for prompt).", | ||
| ) | ||
| def create_global_admin(username, password=None): | ||
| if GlobalAdminUser.get_by_username(username) is not None: | ||
| print(f"Global admin [{username}] already exists.") | ||
| exit(1) | ||
|
|
||
| if not password: | ||
| password = prompt("Password", hide_input=True, confirmation_prompt=True) | ||
|
|
||
| user = GlobalAdminUser(username=username) | ||
| user.hash_password(password) | ||
|
|
||
| try: | ||
| db.session.add(user) | ||
| db.session.commit() | ||
| except Exception as e: | ||
| print(f"Failed creating global admin: {e}") | ||
| exit(1) | ||
|
|
||
| print(f"Created global admin [{username}].") | ||
|
|
||
|
|
||
| @command(name="update_global_admin_password") | ||
| @argument("username") | ||
| @argument("password") | ||
| def update_global_admin_password(username, password): | ||
| user = GlobalAdminUser.get_by_username(username) | ||
| if user is None: | ||
| print(f"Global admin [{username}] not found.") | ||
| exit(1) | ||
|
|
||
| user.hash_password(password) | ||
| db.session.add(user) | ||
| db.session.commit() | ||
| print(f"Updated password for global admin [{username}].") |
43 changes: 43 additions & 0 deletions
43
redash_global/client/components/GlobalApplicationArea/GlobalDesktopNavbar.jsx
This file contains hidden or 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,43 @@ | ||
| import React from "react"; | ||
| import Menu from "antd/lib/menu"; | ||
|
|
||
| import Link from "@/components/Link"; | ||
| import logoUrl from "@/assets/images/redash_icon_small.png"; | ||
|
|
||
| import LogoutOutlinedIcon from "@ant-design/icons/LogoutOutlined"; | ||
|
|
||
| import "@/components/ApplicationArea/ApplicationLayout/DesktopNavbar.less"; | ||
|
|
||
| function NavbarSection({ children, ...props }) { | ||
| return ( | ||
| <Menu selectable={false} mode="vertical" theme="dark" {...props}> | ||
| {children} | ||
| </Menu> | ||
| ); | ||
| } | ||
|
|
||
| export default function GlobalDesktopNavbar() { | ||
| return ( | ||
| <nav className="desktop-navbar"> | ||
| <NavbarSection className="desktop-navbar-logo"> | ||
| <div role="menuitem"> | ||
| <Link href="./"> | ||
| <img src={logoUrl} alt="Redash" /> | ||
| </Link> | ||
| </div> | ||
| </NavbarSection> | ||
|
|
||
| <NavbarSection className="desktop-navbar-spacer" /> | ||
|
|
||
| <NavbarSection> | ||
| <Menu.Item key="logout"> | ||
| {/* Session logout is handled by the server, so bypass the client-side router. */} | ||
| <a href="/logout" data-skip-router> | ||
| <LogoutOutlinedIcon /> | ||
| <span className="desktop-navbar-label">Log out</span> | ||
| </a> | ||
| </Menu.Item> | ||
| </NavbarSection> | ||
| </nav> | ||
| ); | ||
| } |
57 changes: 55 additions & 2 deletions
57
redash_global/client/components/GlobalApplicationArea/index.jsx
This file contains hidden or 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 |
|---|---|---|
| @@ -1,5 +1,58 @@ | ||
| import React from "react"; | ||
| import React, { useState, useEffect } from "react"; | ||
|
|
||
| import Router from "@/components/ApplicationArea/Router"; | ||
| import ApplicationLayout from "@/components/ApplicationArea/ApplicationLayout"; | ||
| import ErrorMessage from "@/components/ApplicationArea/ErrorMessage"; | ||
| import handleNavigationIntent from "@/components/ApplicationArea/handleNavigationIntent"; | ||
| import { registerComponent } from "@/components/DynamicComponent"; | ||
|
|
||
| import GlobalDesktopNavbar from "./GlobalDesktopNavbar"; | ||
|
|
||
| // Reuse Redash's application chrome, but swap the navbar for one that doesn't | ||
| // depend on an org-scoped currentUser (which doesn't exist in Redash Global). | ||
| registerComponent("ApplicationDesktopNavbar", GlobalDesktopNavbar); | ||
|
|
||
| const routes = [ | ||
| { | ||
| id: "Home", | ||
| path: "/", | ||
| title: "Global Admin", | ||
| render: () => <div>Work in progress</div>, | ||
| }, | ||
| ]; | ||
|
|
||
| export default function GlobalApplicationArea() { | ||
| return <div>Work in progress</div>; | ||
| const [currentRoute, setCurrentRoute] = useState(null); | ||
| const [unhandledError, setUnhandledError] = useState(null); | ||
|
|
||
| useEffect(() => { | ||
| if (currentRoute && currentRoute.title) { | ||
| document.title = currentRoute.title; | ||
| } | ||
| }, [currentRoute]); | ||
|
|
||
| useEffect(() => { | ||
| function globalErrorHandler(event) { | ||
| event.preventDefault(); | ||
| setUnhandledError(event.error); | ||
| } | ||
|
|
||
| document.body.addEventListener("click", handleNavigationIntent, false); | ||
| window.addEventListener("error", globalErrorHandler, false); | ||
|
|
||
| return () => { | ||
| document.body.removeEventListener("click", handleNavigationIntent, false); | ||
| window.removeEventListener("error", globalErrorHandler, false); | ||
| }; | ||
| }, []); | ||
|
|
||
| if (unhandledError) { | ||
| return <ErrorMessage error={unhandledError} />; | ||
| } | ||
|
|
||
| return ( | ||
| <ApplicationLayout> | ||
| <Router routes={routes} onRouteChange={setCurrentRoute} /> | ||
| </ApplicationLayout> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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,28 @@ | ||
| from flask_login import UserMixin | ||
| from passlib.apps import custom_app_context as pwd_context | ||
| from sqlalchemy_utils.models import generic_repr | ||
|
|
||
| from redash.models.base import Column, db, primary_key | ||
| from redash.models.mixins import TimestampMixin | ||
|
|
||
|
|
||
| @generic_repr("id", "username") | ||
| class GlobalAdminUser(UserMixin, TimestampMixin, db.Model): | ||
| __tablename__ = "global_admin_users" | ||
|
|
||
| id = primary_key("GlobalAdminUser") | ||
| username = Column(db.String(255), unique=True, nullable=False) | ||
| password_hash = Column(db.String(128), nullable=False) | ||
|
|
||
| def hash_password(self, password): | ||
| """Hash and store the given password using passlib.""" | ||
| self.password_hash = pwd_context.hash(password) | ||
|
|
||
| def verify_password(self, password): | ||
| """Verify a password against the stored hash.""" | ||
| return self.password_hash and pwd_context.verify(password, self.password_hash) | ||
|
|
||
| @classmethod | ||
| def get_by_username(cls, username): | ||
| """Return the user with the given username, or None.""" | ||
| return cls.query.filter(cls.username == username).first() |
This file contains hidden or 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 |
|---|---|---|
| @@ -1,7 +1,10 @@ | ||
| from flask import Blueprint | ||
|
|
||
| from redash_global.views.auth import login_page, logout_page | ||
| from redash_global.views.index import index_view | ||
|
|
||
| global_blueprint = Blueprint("global", __name__) | ||
|
|
||
| global_blueprint.add_url_rule("/", methods=["GET"], view_func=index_view, endpoint="index") | ||
| global_blueprint.add_url_rule("/login", methods=["GET", "POST"], view_func=login_page, endpoint="login") | ||
| global_blueprint.add_url_rule("/logout", methods=["GET"], view_func=logout_page, endpoint="logout") |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.