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 -2
View File
@@ -25,8 +25,8 @@ IMGPROXY_KEY=
IMGPROXY_SALT= IMGPROXY_SALT=
# Auth — Authelia Remote-User trust # Auth — Authelia Remote-User trust
# Comma-separated groups allowed to access admin (empty = any authenticated user) # Comma-separated usernames allowed for admin (groups ignored)
ADMIN_GROUPS=lldap_admin,admin,portfolio_admin ADMIN_USERS=jmartin
# When true, require Remote-User header for /api/v1/admin/* (disable only for local dev) # When true, require Remote-User header for /api/v1/admin/* (disable only for local dev)
REQUIRE_REMOTE_USER=true REQUIRE_REMOTE_USER=true
+2 -1
View File
@@ -44,7 +44,8 @@ export const config = {
key: env("IMGPROXY_KEY", ""), key: env("IMGPROXY_KEY", ""),
salt: env("IMGPROXY_SALT", ""), 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(",") .split(",")
.map((s) => s.trim()) .map((s) => s.trim())
.filter(Boolean), .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 { export function isAdminUser(user: AuthUser): boolean {
if (config.adminGroups.length === 0) return true; const name = user.username.trim().toLowerCase();
return user.groups.some((g) => config.adminGroups.includes(g)); return config.adminUsers.some((u) => u.toLowerCase() === name);
} }
/** Dev bypass when REQUIRE_REMOTE_USER=false */ /** Dev bypass when REQUIRE_REMOTE_USER=false */
@@ -41,16 +42,19 @@ export function requireAdmin(req: FastifyRequest, reply: FastifyReply): AuthUser
const user = getRemoteUser(req); const user = getRemoteUser(req);
if (user) { if (user) {
if (!isAdminUser(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 null;
} }
return user; return user;
} }
if (!config.requireRemoteUser) { if (!config.requireRemoteUser) {
return { return {
username: "dev-admin", username: config.adminUsers[0] || "jmartin",
name: "Dev Admin", name: "Dev Admin",
groups: config.adminGroups.length ? [config.adminGroups[0]] : ["admin"], groups: [],
}; };
} }
reply.code(401).send({ reply.code(401).send({