feat(gitea): use a dedicated admin token for recruitment
CI / quality (push) Failing after 45s

Recruitment needs `write:admin` and `write:organization`, which the everyday
token must not carry. A second token keeps the repository and issue scopes
least privileged, falls back to `GITEA_TOKEN` so existing installs keep
working, and a 403 now names the missing scope instead of pretending Gitea
did not answer.
This commit is contained in:
BlackAngelTV committed 2026-12-06 18:01:43 +01:00
1 parent 9b45c9bf89
commit adc96e4d75
9 files changed
+141 -34

No files matched your search

+39
View File
@@ -217,6 +217,45 @@ export function registerConfigurationRoutes(router) {
}
}
if (params.service === 'gitea-recruitment') {
const url = String(values.GITEA_URL ?? '').replace(/\/+$/, '');
const token =
String(values.GITEA_RECRUITMENT_TOKEN ?? '').trim() || String(values.GITEA_TOKEN ?? '').trim();
if (!url || !token) return { ok: false, detail: 'URL ou jeton de recrutement manquant.' };
try {
const identity = await fetch(`${url}/api/v1/user`, {
headers: { Authorization: `token ${token}`, Accept: 'application/json' },
signal: AbortSignal.timeout(10_000),
});
if (!identity.ok) {
return { ok: false, detail: `Gitea a répondu ${identity.status} au jeton de recrutement.` };
}
const user = await identity.json();
// `/admin/users` is the route recruitment really calls: it proves both the
// account's admin rights and the token's `write:admin` scope.
const admin = await fetch(`${url}/api/v1/admin/users?limit=1`, {
headers: { Authorization: `token ${token}`, Accept: 'application/json' },
signal: AbortSignal.timeout(10_000),
});
if (!admin.ok) {
return {
ok: false,
detail:
user.is_admin === true
? `« ${user.login} » est administrateur, mais le jeton n’a pas la portée \`write:admin\` (Gitea a répondu ${admin.status}).`
: `« ${user.login} » n’est pas administrateur de l’instance : seuls les admins peuvent créer des comptes Gitea.`,
};
}
return {
ok: true,
detail: `Jeton de recrutement valide : « ${user.login} » peut créer des comptes et gérer les équipes.`,
};
} catch (error) {
return { ok: false, detail: `Gitea injoignable : ${error.message}` };
}
}
throw notFound('Service inconnu.');
},
WIZARD,