Skip to content

Updating authenticators from latest in Tiled - #81

Merged
dmgav merged 30 commits into
bluesky:mainfrom
davidpcls:auth_updates_from_tiled
Aug 3, 2026
Merged

Updating authenticators from latest in Tiled#81
dmgav merged 30 commits into
bluesky:mainfrom
davidpcls:auth_updates_from_tiled

Conversation

@davidpcls

@davidpcls davidpcls commented Jan 29, 2026

Copy link
Copy Markdown
Contributor

Description

These changes bring in the authenticators from Tiled 0.2.12 into bluesky-httpserver along with the required changes to the app and supporting files to support them. This allows us to use the same authentication setup as from Tiled deployments (at least at the current moment). The main other change is to remove the "mode" flag and instead use the class type to determine if it is an internal or external authenticator.

Part of this work is also the updating of the bluesky-queueserver-api, for which I have created a PR. Both are required in order for the OIDC workflows to work.

Like Tiled, the authentication flow forces a login prompt on each attempt to login. I have tried to minimize any differences between similar functions/files in Tiled and bluesky-httpserver.

Motivation and Context

This solves the problem of having different authentication schemes to maintain between Tiled and HTTP server, which came from the same code around 3 years ago. Tiled has been updated but HTTP server was not. This addresses that.

Summary of Changes for Release Notes

Updated authenticators based off Tiled v0.2.12.
Made minimal changes to app.py and authentication.py to support the changes. Some new endpoints needed to be created to do this, but fairly minimal. The majority of the work was getting the unit test runners stable.
Added local parallel unit test runners to aid development.
Updated the github runners to be more stable and reliable by making the port used dynamic.

Fixed

Added

  • Authenticators.py from Tiled v0.2.12
  • protocols.py from Tiled v0.2.12
  • new endpoints for authorization workflows in app.py
  • Pending sessions in the database
  • Documentation and examples on using OIDC based off Tiled

Changed

  • Unit tests to support above changes
  • Unit test structure to be a little more stable
  • The LDAP container as the previous one was no longer supported

Removed

How Has This Been Tested?

Testing was done against MS Entra. I tested that these workflows work for both internal (localhost) and external servers. Using this the login workflow changes to just simply being:

from bluesky_queueserver_api.http import REManagerAPI
from bluesky_queueserver_api import BPlan
RM = REManagerAPI(http_server_uri="http://localhost:60610", http_auth_provider="entra/authorize")
RM.login()

While this was tested with MS Entra, the design is based on Tiled's OIDC and testing used the OIDC flow with MS Entra, so it should theoretically work with all other authenticators using OIDC.

TODO:

  • Migrate in changes from tiled 0.2.10 to 0.2.12
  • Update unit tests
  • Update documentation for authenticators

@danielballan
danielballan requested a review from dmgav February 3, 2026 15:34
@danielballan

Copy link
Copy Markdown
Member

Wow, thanks @davidpcls!

@danielballan
danielballan requested a review from sligara7 February 3, 2026 15:35
@dmgav

dmgav commented Feb 3, 2026

Copy link
Copy Markdown
Contributor

Thank you. I am going to try to fix the unit tests first, I may push a few commits.

@prjemian

prjemian commented Feb 3, 2026

Copy link
Copy Markdown

If either of you intend to commit more work to this PR, put it in Draft mode. Change the mode back when you are ready for final review.

@davidpcls
davidpcls marked this pull request as draft February 3, 2026 17:41
@davidpcls

Copy link
Copy Markdown
Contributor Author

@prjemian , thanks I've converted it.

@dmgav sure that sounds good.

@dmgav
dmgav force-pushed the auth_updates_from_tiled branch from 579d82a to f54ef36 Compare February 5, 2026 16:21
@dmgav

dmgav commented Feb 5, 2026

Copy link
Copy Markdown
Contributor

I fixed the unit tests. I also rebased the branch to main, so I had to force push the changes.

@davidpcls

Copy link
Copy Markdown
Contributor Author

Thanks for working on that @dmgav! I just got things setup so I can test with this against MS Entra, so I'll go about verifying there are no other changes required for this to work properly. Took a little longer than expected to get the Entra stuff worked out.

This is working okay, although it doens't really work smoothly for the
API based login and the http command based login isn't great, as it
requires the user to copy and past token around. Compared to ldap
which just logs the user in.

So still some work to do here to smooth out the user experience.
This solves the problem that what was implemented was actually
authenticating the application and not the user like expected. It worked
but it required that the user input a code. This solves that problem so
that when you click the login link, if you are already logged in with
you SSO provider you'll just automatically log in to the HTTP Server.
Likewise if you use the bluesky queueserver api, when you call RM.Login
you'll automatically be logged in, no user interaction required.
These should correct some of the problems in the last CI workflow.

I moved the LDAP and docker image into the continuous_integration folder
so it matches tiled.
This addresses documentation problems, the levels were incorrect as I
did not understand what the next level should have been in the docs.

I've also updated the usage documentation a little to be more useful.
These allow for running the unit tests in a containerized system just
like how they are done in the ci pipeline, but locally and in a way that
can maximize processor usage and minimize runtime.
@davidpcls

Copy link
Copy Markdown
Contributor Author

I've added in these changes, I'm going to work on cleaning up failing unit tests now and then I will update the pull request description to match your style and provide information on testing. After that I will remove the WIP status.

@davidpcls

Copy link
Copy Markdown
Contributor Author

Please also see the related PR for the API: bluesky/bluesky-queueserver-api#62

This is a set of test changes intended to improve the reliability of unit testing, as the current unit tests are randomly failing due to test design. Primarily this appears to be centered around LDAP. So this work was to:

* Fix for ldap errors
* Hardening unit tests so they fail less frequency
* Try to handle console output more reliably
@davidpcls
davidpcls marked this pull request as ready for review March 20, 2026 19:54
@davidpcls davidpcls changed the title WIP - Updating authenticators from latest in Tiled Updating authenticators from latest in Tiled Mar 20, 2026
@davidpcls
davidpcls marked this pull request as draft March 20, 2026 19:58
@davidpcls

Copy link
Copy Markdown
Contributor Author

Sorry, got excited about the unit tests passing. I need to do one last integration test first, which is why I converted it back into a WIP

@davidpcls davidpcls left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Comments to assist others reviewing the code

Comment thread bluesky_httpserver/database/core.py
Comment thread bluesky_httpserver/database/core.py
Comment thread bluesky_httpserver/database/core.py
Comment thread bluesky_httpserver/protocols.py
Comment thread scripts/docker/run_shard_in_container.sh
Comment thread scripts/run_ci_docker_parallel.sh
@davidpcls

Copy link
Copy Markdown
Contributor Author

After these changes, still seems to be working for me. Neato.

@davidpcls
davidpcls marked this pull request as ready for review July 22, 2026 15:47
@davidpcls
davidpcls requested a review from dmgav July 22, 2026 15:48
@dmgav

dmgav commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

While testing the changes I noticed that the function app_factory() is called twice during the server startup using uvicorn. As a result, the authenticators are instantiated twice. For some authenticators (ProxiedOIDCAuthenticator and EntraAuthenticator) this results in duplicated requests to the authentication server (https://github.com/davidpcls/bluesky-httpserver/blob/90e047992fe44dfb6d8a94bf58f8aef5b3c813c0/bluesky_httpserver/authenticators.py#L289). The following change to the __getattr__() function in server.py seems to fix the issue:

def __getattr__(name):
    """
    This supports tiled.server.app.app by creating app on demand.
    """
    if name == "app":
        try:
            _app = app_factory()
            globals()["app"] = _app   # cache in module dict — prevents second call
            return _app
        except Exception as err:
            raise Exception("Failed to create app.") from err
    raise AttributeError(name)

@davidpcls

davidpcls commented Jul 28, 2026

Copy link
Copy Markdown
Contributor Author

@dmgav , interesting that it's doing that. Tiled is using the exact same code for getattr. I'm curious why it doesn't have this same problem, or if it does. Just looking into that now.

@davidpcls

Copy link
Copy Markdown
Contributor Author

It looks like tiled starts the apps differently.

Do we even need getattr ? We can start it just fine with:

app = app_factory()

Rather than having getattr.

I think getattr just solves us importing server.start_server

@dmgav

dmgav commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

I don't remember why we implemented server:start_server. It is an easier way to start it in demo mode, and it allows to pass extra parameters to build_app function, but it can not be used in production with gunicorn. I don't know if anyone is using this function. We can probably temporarily fix the __getattr__ function for now, and then change the startup code so that it matches Tiled later.

Comment thread docs/source/configuration.rst Outdated
@davidpcls

Copy link
Copy Markdown
Contributor Author

I don't remember why we implemented server:start_server. It is an easier way to start it in demo mode, and it allows to pass extra parameters to build_app function, but it can not be used in production with gunicorn. I don't know if anyone is using this function. We can probably temporarily fix the __getattr__ function for now, and then change the startup code so that it matches Tiled later.

Sounds good, I've committed the changes just now

@dmgav

dmgav commented Jul 31, 2026

Copy link
Copy Markdown
Contributor

@davidpcls Do you mind if I push some minor changes to this branch?

Comment thread docs/source/configuration.rst
danielballan
danielballan previously approved these changes Jul 31, 2026
@dmgav
dmgav merged commit d53d171 into bluesky:main Aug 3, 2026
9 checks passed
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.

4 participants