Creating an Admin User
Relevant source files
The following files were used as context for generating this wiki page:
The process of creating an admin user in the superset-ext utility allows administrators to establish initial access credentials for the Apache Superset instance. This functionality is essential for managing the Superset application after its database and permissions have been initialized.
The extension wraps the underlying Superset CLI (specifically the Flask AppBuilder/FAB component) to provide a seamless interface through Meltano. Users can provide admin details either through interactive terminal prompts or by passing explicit command-line flags.
Sources: README.md:46-51, superset_ext/extension.py:101-125
Architectural Overview
The admin user creation process involves three layers: the Meltano CLI entry point, the Python extension logic, and the underlying superset binary. The superset-ext utility acts as an orchestrator, ensuring that the correct environment variables are set before invoking the Superset CLI's fab create-admin command.
The diagram shows the flow from the initial user command through the extension layers to the final execution of the Superset FAB command.
Sources: superset_ext/main.py:46-77, superset_ext/extension.py:101-118, pyproject.toml:53
Command Implementation
The admin creation functionality is exposed via the create-admin command. This command is defined using the typer library, which handles argument parsing and terminal prompting.
Execution Flow
- Input Collection: The CLI collects the username, first name, last name, email, and password. If these are not provided as flags,
typerprompts the user interactively. - Extension Call: The
Supersetextension class receives these parameters via thecreate_adminmethod. - Process Invocation: The extension uses a
superset_invoker(an instance ofmeltano.edk.process.Invoker) to run thesuperset fab create-admincommand with the formatted arguments.
Sources: superset_ext/main.py:46-77, superset_ext/extension.py:27-33, superset_ext/extension.py:101-125
User Interaction Sequence
This sequence illustrates how user input is captured and passed down through the system to the external Superset process.
Sources: superset_ext/main.py:46-77, superset_ext/extension.py:113-125
Configuration and Parameters
The create-admin command supports several options. In the code, these are implemented as typer.Option objects with default values and prompting enabled.
| Parameter | Type | Default | Description |
|---|---|---|---|
username | String | admin | The login identifier for the admin user. |
firstname | String | admin | The first name of the user. |
lastname | String | user | The last name of the user. |
email | String | admin@superset | The contact email for the user. |
password | String | N/A | The secret password (prompts with hidden input). |
Sources: superset_ext/main.py:48-68, superset_ext/extension.py:101-111
Prerequisites and Environment
Before creating an admin, the extension must be initialized. The initialize method in the extension ensures that the database directory exists and runs superset db upgrade, superset init, and superset fab create-permissions.
Sources: superset_ext/extension.py:49-100
Environment variables play a critical role in locating the database where the user will be created. The prepared_env utility sets up the following keys:
SUPERSET_HOME: Defaults to$MELTANO_PROJECT_ROOT/.meltano/utilities/superset.SQLALCHEMY_DATABASE_URI: Defaults to a SQLite database within theSUPERSET_HOMEdirectory.SUPERSET_CONFIG_PATH: Path to the generated Python configuration file.
Sources: superset_ext/utils.py:61-100
Error Handling
The extension provides robust error handling during user creation:
- Subprocess Errors: If the underlying
supersetcommand fails (e.g., database not reachable), asubprocess.CalledProcessErroris caught, and the error is logged usinglog_subprocess_error. The application then exits with the return code of the failed process. - Uncaught Exceptions: The CLI layer wraps the extension call in a general try-except block to catch and log unexpected errors before exiting with status code 1.
Sources: superset_ext/extension.py:126-130, superset_ext/main.py:73-77
Summary
Creating an admin user is a vital post-initialization step for superset-ext. By wrapping the fab create-admin command, the extension ensures that administrators can easily set up their environment with proper credentials while maintaining the configuration isolation provided by the Meltano environment.
Sources: README.md:46-51, superset_ext/extension.py:99