Skip to content

Conversation

@mrshmllow
Copy link
Contributor

@mrshmllow mrshmllow commented Dec 7, 2025

closes #195

This is a very simple wrapper around the Buildbot OAuth2Auth class that you can configure with new options.

Additionally, you can set your own scope and map the claims, if your OIDC provider changes them in some way. It supports syncing groups although you need to include that scope and mapping yourself.

So far I've tested this successfully with PocketID.

As a note: I decided to identify users by the provider's preferred_username because it works well with the admins option

@mrshmllow mrshmllow changed the title add OIDC auth backend add generic OIDC auth backend Dec 7, 2025
@mrshmllow
Copy link
Contributor Author

mrshmllow commented Dec 7, 2025

I wonder if adding new admins alongside the normal admins option with groups would be a good addition here?

@Mic92
Copy link
Member

Mic92 commented Dec 8, 2025

@MagicRB are we able to test this in numtide infra? For my own buildbot the issue might be that I have people that want to login when having access to a nix-community repo.

@mrshmllow
Copy link
Contributor Author

mrshmllow commented Dec 8, 2025

You can test the python-side of this with a mock server as well

$ echo "abc" > /tmp/client_secret && nix run nixpkgs#pipx -- run oidc-provider-mock --user-claims '{"sub": "alice", "email": "alice@example.com", "name": "Alice", "preferred_username": "alice123"}'
tree diff
diff --git a/packages/master.cfg.py b/packages/master.cfg.py
index 8cf3db1..2d91c50 100644
--- a/packages/master.cfg.py
+++ b/packages/master.cfg.py
@@ -3,13 +3,18 @@ from buildbot_nix import (
     NixConfigurator,
     BuildbotNixConfig,
 )
-from buildbot_nix.models import PullBasedConfig, PullBasedRepository
+from buildbot_nix.models import (
+    PullBasedConfig,
+    PullBasedRepository,
+    OIDCConfig,
+    AuthBackendConfig,
+    OIDCMappingConfig,
+)
 import getpass
 import os
 import platform
 import subprocess
 import multiprocessing
-from buildbot.plugins import util
 from buildbot.process.factory import BuildFactory
 from dataclasses import dataclass

@@ -211,6 +216,17 @@ buildbot_nix_config = BuildbotNixConfig(
     url=url,
     gcroots_user=getpass.getuser(),
     admins=["admin"],
+    auth_backend=AuthBackendConfig.oidc,
+    oidc=OIDCConfig(
+        name="Mock",
+        discovery_url="http://localhost:9400/.well-known/openid-configuration",
+        client_id="123",
+        client_secret_file="/tmp/client_secret",
+        scope=["openid", "email", "profile"],
+        mapping=OIDCMappingConfig(
+            email="email", username="preferred_username", full_name="name", groups=None
+        ),
+    ),
 )

 c = BuildmasterConfig = dict(
@@ -221,5 +237,5 @@ c = BuildmasterConfig = dict(
         NixConfigurator(buildbot_nix_config),
     ],
     protocols={"pb": {"port": "tcp:9989:interface=\\:\\:1"}},
-    www=dict(port=PORT, plugins=dict(), auth=util.UserPasswordAuth({"admin": "admin"})),
+    www=dict(port=PORT, plugins=dict()),
 )
image image

I also run this PR on https://buildbot.althaea.zone/ but you wouldn't be able to login

Mic92 and others added 5 commits December 14, 2025 16:10
Aligns OIDCMappingConfig/OIDCConfig with other Pydantic models in the file
that reject unknown fields. This catches typos and accidental
config keys early rather than silently ignoring them.
The "or 'groups'" fallback contradicted the preceding None check.
If self.mapping.groups is not None, use it directly. The dict.get()
default handles missing keys in the user response.
The code directly indexed token["access_token"] which raises KeyError
for malformed responses. Now validates the token first and raises
BuildbotNixError with context if the field is missing.
The OIDC client secret was referenced by full path but not exposed
to systemd via LoadCredential. Now uses a relative credential name
and adds the corresponding LoadCredential entry so the secret is
available in $CREDENTIALS_DIRECTORY at runtime.
@Mic92
Copy link
Member

Mic92 commented Dec 14, 2025

@mrshmllow can you please check? I added documentation and tested the code, you gave me locally.

@Mic92 Mic92 force-pushed the push-zpwpqzvosklt branch from d6fbbb2 to 17a32ab Compare December 14, 2025 17:02
…to separate files

Move detailed GitHub, Gitea, and OIDC authentication documentation
from README.md into dedicated files under docs/. This makes the
README more concise while keeping comprehensive setup instructions
easily accessible.
@Mic92 Mic92 force-pushed the push-zpwpqzvosklt branch from 17a32ab to a186505 Compare December 14, 2025 17:04
@Mic92 Mic92 added this pull request to the merge queue Dec 16, 2025
Merged via the queue into nix-community:main with commit 9f9cbb5 Dec 16, 2025
3 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.

Generic OIDC auth

2 participants