Authorize admin by username jmartin only

Drop group membership checks; trust Authelia Remote-User when it
equals the configured ADMIN_USERS list (default: jmartin).
This commit is contained in:
2026-07-24 09:38:23 -04:00
parent 6340dc5df9
commit f03d448303
3 changed files with 13 additions and 8 deletions
+2 -1
View File
@@ -44,7 +44,8 @@ export const config = {
key: env("IMGPROXY_KEY", ""),
salt: env("IMGPROXY_SALT", ""),
},
adminGroups: env("ADMIN_GROUPS", "lldap_admin,admin,portfolio_admin")
/** Comma-separated usernames allowed for admin (groups ignored). */
adminUsers: env("ADMIN_USERS", "jmartin")
.split(",")
.map((s) => s.trim())
.filter(Boolean),
+9 -5
View File
@@ -31,9 +31,10 @@ export function getRemoteUser(req: FastifyRequest): AuthUser | null {
};
}
/** Allow only configured usernames (default: jmartin). Groups are ignored. */
export function isAdminUser(user: AuthUser): boolean {
if (config.adminGroups.length === 0) return true;
return user.groups.some((g) => config.adminGroups.includes(g));
const name = user.username.trim().toLowerCase();
return config.adminUsers.some((u) => u.toLowerCase() === name);
}
/** Dev bypass when REQUIRE_REMOTE_USER=false */
@@ -41,16 +42,19 @@ export function requireAdmin(req: FastifyRequest, reply: FastifyReply): AuthUser
const user = getRemoteUser(req);
if (user) {
if (!isAdminUser(user)) {
reply.code(403).send({ error: "Forbidden", message: "Insufficient group membership" });
reply.code(403).send({
error: "Forbidden",
message: `User “${user.username}” is not authorized for admin.`,
});
return null;
}
return user;
}
if (!config.requireRemoteUser) {
return {
username: "dev-admin",
username: config.adminUsers[0] || "jmartin",
name: "Dev Admin",
groups: config.adminGroups.length ? [config.adminGroups[0]] : ["admin"],
groups: [],
};
}
reply.code(401).send({