git: Sign in to Gitea with Pocket ID
Add an `id.nul.ie` OpenID Connect login source to Gitea, kept up to date from `preStart` since Gitea stores login sources in its database. Its client is declared on `middleman` with the secret shared by both. Registration stays disabled, so a Pocket ID sign-in links to an existing account. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit was merged in pull request #13.
This commit is contained in:
1 parent
eeb1f2d15c
commit
712fabcb62
4 files changed
+74
-1
No files matched your search
@@ -20,6 +20,15 @@ The Git forge at `git.nul.ie` (self-registration disabled), configured in
|
|||||||
`gitea`, on [`object`](shill/containers/object.md)) — the secret is spliced into `app.ini` at
|
`gitea`, on [`object`](shill/containers/object.md)) — the secret is spliced into `app.ini` at
|
||||||
startup.
|
startup.
|
||||||
- Mail goes out via `mail.nul.ie`, including the issue-reply incoming-mail poller.
|
- Mail goes out via `mail.nul.ie`, including the issue-reply incoming-mail poller.
|
||||||
|
- **Sign-in with Pocket ID:** `preStart` adds or updates the `id.nul.ie` OpenID Connect login
|
||||||
|
source. The client `gitea` and its secret `gitea/oidc-secret.txt` are declared on
|
||||||
|
[`middleman`](shill/containers/middleman.md#pocket-id).
|
||||||
|
- Registration stays disabled, so a Pocket ID sign-in can't create an account. The first one
|
||||||
|
links to an existing account after signing in with its password.
|
||||||
|
- It runs before the server, which only reads login sources at startup. If it fails, Gitea
|
||||||
|
starts without the source and logs a warning.
|
||||||
|
- The CLI only takes the secret as an argument, so it is briefly visible in the process list
|
||||||
|
while `preStart` runs.
|
||||||
|
|
||||||
### Gitea Actions runner
|
### Gitea Actions runner
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,11 @@
|
|||||||
{ lib, pkgs, config, assignments, allAssignments, ... }:
|
{ lib, pkgs, config, assignments, allAssignments, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) mkMerge;
|
inherit (lib) mkMerge mkAfter getExe;
|
||||||
inherit (lib.my.c) pubDomain;
|
inherit (lib.my.c) pubDomain;
|
||||||
inherit (lib.my.c.colony) prefixes;
|
inherit (lib.my.c.colony) prefixes;
|
||||||
|
|
||||||
|
# Pocket ID login source, client `gitea` (declared on `middleman`)
|
||||||
|
oidcSource = "id.${pubDomain}";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
config = {
|
config = {
|
||||||
@@ -48,6 +51,40 @@ in
|
|||||||
# The default /tmp is on the small tmpfs root, so keep them on the state volume.
|
# The default /tmp is on the small tmpfs root, so keep them on the state volume.
|
||||||
environment.TMPDIR = "${config.services.gitea.stateDir}/tmp";
|
environment.TMPDIR = "${config.services.gitea.stateDir}/tmp";
|
||||||
}
|
}
|
||||||
|
{
|
||||||
|
# Gitea keeps login sources in its database: add the Pocket ID one, or bring it up to
|
||||||
|
# date. The server only reads them at startup, so this runs before it; a failure only
|
||||||
|
# warns, so Gitea still starts. The CLI only takes the secret as an argument.
|
||||||
|
preStart = mkAfter (
|
||||||
|
let
|
||||||
|
gitea = getExe config.services.gitea.package;
|
||||||
|
in
|
||||||
|
''
|
||||||
|
oidc_source_setup() {
|
||||||
|
local oidc_args=(
|
||||||
|
--name '${oidcSource}'
|
||||||
|
--provider openidConnect
|
||||||
|
--key gitea
|
||||||
|
--secret "$(< '${config.age.secrets."gitea/oidc-secret.txt".path}')"
|
||||||
|
--auto-discover-url 'https://${oidcSource}/.well-known/openid-configuration'
|
||||||
|
--scopes openid --scopes email --scopes profile
|
||||||
|
)
|
||||||
|
|
||||||
|
local list oidc_id
|
||||||
|
list="$(${gitea} admin auth list)" || return
|
||||||
|
oidc_id="$(${pkgs.gawk}/bin/awk '$2 == "${oidcSource}" { print $1 }' <<< "$list")" || return
|
||||||
|
if [ -n "$oidc_id" ]; then
|
||||||
|
${gitea} admin auth update-oauth --id "$oidc_id" "''${oidc_args[@]}"
|
||||||
|
else
|
||||||
|
${gitea} admin auth add-oauth "''${oidc_args[@]}"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
if ! oidc_source_setup; then
|
||||||
|
echo "Couldn't set up the ${oidcSource} login source; starting without it" >&2
|
||||||
|
fi
|
||||||
|
'');
|
||||||
|
}
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -139,6 +176,8 @@ in
|
|||||||
"gitea/db.txt" = ownedByGit;
|
"gitea/db.txt" = ownedByGit;
|
||||||
"gitea/mail.txt" = ownedByGit;
|
"gitea/mail.txt" = ownedByGit;
|
||||||
"gitea/minio.txt" = ownedByGit;
|
"gitea/minio.txt" = ownedByGit;
|
||||||
|
# Shared with `middleman`, which registers it with Pocket ID
|
||||||
|
"gitea/oidc-secret.txt" = ownedByGit;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -15,6 +15,8 @@ in
|
|||||||
"middleman/pocket-id-api-key" = { };
|
"middleman/pocket-id-api-key" = { };
|
||||||
# `OAUTH2_PROXY_CLIENT_SECRET` and `OAUTH2_PROXY_COOKIE_SECRET`
|
# `OAUTH2_PROXY_CLIENT_SECRET` and `OAUTH2_PROXY_COOKIE_SECRET`
|
||||||
"middleman/oauth2-proxy.env" = { };
|
"middleman/oauth2-proxy.env" = { };
|
||||||
|
# Client secrets shared with the boxes that run the apps
|
||||||
|
"gitea/oidc-secret.txt" = { };
|
||||||
};
|
};
|
||||||
|
|
||||||
pocket-id = {
|
pocket-id = {
|
||||||
@@ -38,6 +40,14 @@ in
|
|||||||
key = "OAUTH2_PROXY_CLIENT_SECRET";
|
key = "OAUTH2_PROXY_CLIENT_SECRET";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
# Gitea's `id.nul.ie` login source (`git` VM)
|
||||||
|
gitea = {
|
||||||
|
name = "Gitea";
|
||||||
|
callbackURLs = [ "https://git.${pubDomain}/user/oauth2/id.${pubDomain}/callback" ];
|
||||||
|
launchURL = "https://git.${pubDomain}/";
|
||||||
|
secret.file = config.age.secrets."gitea/oidc-secret.txt".path;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
-----BEGIN AGE ENCRYPTED FILE-----
|
||||||
|
YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IHNzaC1lZDI1NTE5IGpJOFJBZyBzU2lH
|
||||||
|
U05YNG5ISEJtTklOZmZRUUI3MWxuU1JRWG0vNEIxekt3NTdWYVdJCldDMENWenl1
|
||||||
|
ZmZCTW1ySFBXZFEvbHZhR0NDOWpLSzhNRTZUcFU1NWZXUWcKLT4gc3NoLWVkMjU1
|
||||||
|
MTkgVkZjdzVnIDdXSXdnK1VvQzJrbWMyRzltL3BZMEZPV2pEV1lSUW5ySXkxaDRC
|
||||||
|
RjRMVDAKRjVRSm9sMGRNUTBWYkdWNlEwKzNTTU8xRXBmV1JDREhtNThabFRIVERU
|
||||||
|
MAotPiBYMjU1MTkgdHFnZ1RKQlRDTmg0TksvaGgrUER6SU5MYWV6WlpEWXA3Qktv
|
||||||
|
MFZJTktTSQpyMHhRb0FNeGFFZkIvUUxjMWlVbkxRY2pKZnhSanlrUWFITWZHUE1i
|
||||||
|
dldvCi0+IFgyNTUxOSBGbkhrVlZYYjZIakZ5MnZ5ZDJXdnoycEVtL08zYjNjNUty
|
||||||
|
OTY2amsrWTJnCk9neE80T25naFBDV3pjZXh0QmFKNW9YZ1VHdXJsREJidHlNRUY5
|
||||||
|
Y0haTDAKLT4gdEkuc210LWdyZWFzZSA0UT5jYyBkICUgIzArNQpCVE5aQnM1blNO
|
||||||
|
L0Nvb1hDMTRSOVNHUmlTM1lmZWcKLS0tIGFBTDN1ZUhSM21LaVFLZDBUQkFJcDJZ
|
||||||
|
OUVSYVp5Q2NIL01IUTNsSmQ3Y2MKAuYjogUq28f/Cdf5jd/RkWaPZEqA+qGAmTnx
|
||||||
|
fXgii0zfKVsAMGtro8wB4RdKYcvyW86k7zYaZobXHzR4ApCF+Zg=
|
||||||
|
-----END AGE ENCRYPTED FILE-----
|
||||||
Reference in new issue
Block a user