Skip to content
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

Remove DEV_MODE and USE_FAKE_FXA_AUTH, replace with PROD_MODE and FXA_CONFIG #23049

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

KevinMind
Copy link
Contributor

@KevinMind KevinMind commented Feb 3, 2025

Fixes: mozilla/addons#15331

Description

This commit introduces several changes to simplify and improve the authentication and environment configuration:

  • Replaced DEV_MODE with PROD_MODE derived from version JSON instead of environment variable
  • Removed USE_FAKE_FXA_AUTH setting replaced with FXA_CONFIG to control fake authentication
  • Simplified conditional logic around development and production environments to rely on stable build time variables

Context

This patch simplifies the configuration of "prod" versus "dev" mode by relying on build time parameters that reliably inform what kind of server to run. Environment variables can be overwritten and have no direct connection to the build, but get_version_json can tell you exactly waht kind of image you are running.

Additionally, sometimes you want to run in prod mode, but don't want to setup a real authentication server. Now you can do that because we use a more granular check for fake FXA based on the presence of valid fxa credentials at runtime.

Testing

Dev mode

Run in dev mode

make up DOCKER_TARGET=development

App should run in dev mode with debug toolbar and non compiled assets

Prod mode

Run in prod mode

make up DOCKER_TARGET=production

Expect compiled assets, no debug toolbar (unless DEBUG=True is explicitly set)
and finally, fake fxa should still be used by default.

Real auth

To run with real auth you must set the environment variables

FXA_CLIENT_ID=id
FXA_CLIENT_SECRET=secret

and run in either dev or prod mode. Try both.

Checklist

  • Add #ISSUENUM at the top of your PR to an existing open issue in the mozilla/addons repository.
  • Successfully verified the change locally.
  • The change is covered by automated tests, or otherwise indicated why doing so is unnecessary/impossible.
  • Add before and after screenshots (Only for changes that impact the UI).
  • Add or update relevant docs reflecting the changes made.

@KevinMind KevinMind requested review from a team and diox and removed request for a team February 3, 2025 16:40
@KevinMind KevinMind force-pushed the fake-fxa-auth branch 4 times, most recently from 0928b7f to 2731dee Compare February 3, 2025 21:03
…_CONFIG

This commit introduces several changes to simplify and improve the authentication and environment configuration:

- Replaced `DEV_MODE` with `PROD_MODE` derived from version JSON instead of environment variable
- Removed `USE_FAKE_FXA_AUTH` setting replaced with `FXA_CONFIG` to control fake authentication
- Simplified conditional logic around development and production environments to rely on stable build time variables
"""Return whether or not to use a fake FxA server for authentication.
Should always return False in production"""
return settings.DEV_MODE and settings.USE_FAKE_FXA_AUTH
return config.get('client_id') == '.'
Copy link
Member

Choose a reason for hiding this comment

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

The main benefit of the explicit settings checks was to avoid accidentally having fake FxA enabled on dev/stage/prod if an environnement variable wasn't set properly (something we can't easily see/test/control ourselves until after deployment).

We should at least keep something like USE_FAKE_FXA_AUTH, change it ALLOW_FAKE_FXA_AUTH and use it here on top of the check on client_id being . to keep the same guarantee.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was thinking about a Django system check that raises if those values are not set in production. Wdyt?

Copy link
Member

Choose a reason for hiding this comment

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

But how would that check pass on local envs then ? You'd end up needing a similar mechanism to special case local envs ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was actually thinking we could have a django check that ensures those values are not '.' in production. Would that also solve the issue? Production pods would just fail if they start without proper auth configured.

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.

[Task]: Enable fake FXA in local production images
2 participants