Skip to content

Support FIREBASE_TENANT_EMULATOR_HOST in TenantManagementService#962

Open
KetanHegde wants to merge 1 commit into
firebase:mainfrom
KetanHegde:feature/tenant-management-emulator
Open

Support FIREBASE_TENANT_EMULATOR_HOST in TenantManagementService#962
KetanHegde wants to merge 1 commit into
firebase:mainfrom
KetanHegde:feature/tenant-management-emulator

Conversation

@KetanHegde

Copy link
Copy Markdown

Summary

This PR adds support for running TenantManagementService against the Firebase Authentication Emulator using a new environment variable, FIREBASE_TENANT_EMULATOR_HOST.

When this environment variable is set, _TenantManagementService uses the emulator endpoint instead of the production Identity Toolkit endpoint and initializes the client with EmulatorAdminCredentials.

Changes

  • Added support for FIREBASE_TENANT_EMULATOR_HOST
  • Added get_tenant_emulator_host() helper
  • Updated _TenantManagementService to use the emulator endpoint when configured
  • Added unit tests covering emulator behavior for tenant management
  • Updated existing tenant management tests to support both production and emulator endpoints

Testing

Executed:

pytest tests/test_tenant_mgt.py

Result:

311 passed

Also verified with:

pylint firebase_admin tests/test_tenant_mgt

The remaining pylint warnings are pre-existing in the test module.

Implements #910

@google-cla

google-cla Bot commented Jul 6, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces support for the Firebase Tenant Emulator by checking the FIREBASE_TENANT_EMULATOR_HOST environment variable and configuring the tenant management service to use the emulator host and credentials when available. The tests have also been updated to run in both emulated and non-emulated modes. Feedback on this PR suggests falling back to the standard FIREBASE_AUTH_EMULATOR_HOST if the tenant-specific emulator host is not set, ensuring a smoother developer experience when running the local Auth emulator.

Comment on lines +82 to +88
def get_tenant_emulator_host():
emulator_host = os.getenv(TENANT_EMULATOR_HOST_ENV_VAR, '')
if emulator_host and '//' in emulator_host:
raise ValueError(
f'Invalid {TENANT_EMULATOR_HOST_ENV_VAR}: "{emulator_host}". '
'It must follow format "host:port".')
return emulator_host

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Currently, if FIREBASE_AUTH_EMULATOR_HOST is set but FIREBASE_TENANT_EMULATOR_HOST is not, _TenantManagementService will still attempt to connect to production. Since tenant management is part of the Firebase Auth service, it is highly recommended to fall back to FIREBASE_AUTH_EMULATOR_HOST when FIREBASE_TENANT_EMULATOR_HOST is not explicitly configured. This ensures a seamless developer experience when running the local Auth emulator without requiring redundant environment variables.

Suggested change
def get_tenant_emulator_host():
emulator_host = os.getenv(TENANT_EMULATOR_HOST_ENV_VAR, '')
if emulator_host and '//' in emulator_host:
raise ValueError(
f'Invalid {TENANT_EMULATOR_HOST_ENV_VAR}: "{emulator_host}". '
'It must follow format "host:port".')
return emulator_host
def get_tenant_emulator_host():
emulator_host = os.getenv(TENANT_EMULATOR_HOST_ENV_VAR, '')
if not emulator_host:
emulator_host = get_emulator_host()
if emulator_host and '//' in emulator_host:
raise ValueError(
f'Invalid {TENANT_EMULATOR_HOST_ENV_VAR}: "{emulator_host}". '
'It must follow format "host:port".')
return emulator_host

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant