Enabling auth orphans pre-existing agents, collections and skills (root user bucket)
维护者通常 1 天内回复
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 45/100
- Issue 类型
- 功能
- 描述清晰度
- 基本清楚
- 活跃度
- 活跃
- 技术栈
- go
调研方向
Start with core/services/agentpool/user_storage.go, where the empty user ID resolves to the base directory, then getUserID in core/http/endpoints/localai/agents.go. Step 1 is the narrowest first change: at startup, when auth is enabled and the root bucket holds agents, collections or skills, log a warning with the counts and a docs pointer. Steps 2 and 3 (admin listing, the LOCALAI_AUTH_LEGACY_OWNER migration) touch agent_pool.go and the collections and skills services, so they need maintainer direction first. Done means the warning appears in the logs in that state and not otherwise.
由索引模型根据 Issue 内容生成。
描述
Is your feature request related to a problem? Please describe.
When an existing instance turns on LOCALAI_AUTH, everything that was created while auth was off stays in the
root bucket (userID == "") and becomes unreachable over the API — for every user, including admins.
What happens, per resource:
- Agents.
UserScopedStorage.resolve("")maps the empty user to the base directory
(core/services/agentpool/user_storage.go), and with auth on every request carries a real user ID
(getUserIDincore/http/endpoints/localai/agents.go).GET /api/agentstherefore never lists the legacy agents,
and?all_users=truedoes not include them either. The agents are still started bypool.StartAll(), but their
LLM calls fail with 401 when theirapi_keyis empty andLOCALAI_AGENT_POOL_API_KEYis unset. They keep running
(includingperiodic_runs) without anyone being able to see, edit, pause or delete them. - Collections, skills / git repos, tasks / jobs, outputs. Same pattern:
CollectionsBackendForUser,
SkillsServiceForUserand the job service fall back to the root instance only foruserID == "", so after the switch
users get a fresh, emptyusers/<uid>/…area. - Agent state (character, scheduler state, long-term memory) has no API at all, so it cannot be exported before
the switch either.
There is no startup message about it, and nothing in the docs says what happens to existing data. On our instance
(8 agents, about 100 collections, a few hundred thousand chunks) this would have looked like "all data gone" right
after enabling auth.
Reproduction (no models needed):
- Start LocalAI without auth, create an agent and a collection (
POST /api/agents,POST /api/agents/collections). - Restart with
LOCALAI_AUTH=trueandLOCALAI_ADMIN_EMAIL=<you>, register as that admin. GET /api/agentsandGET /api/agents?all_users=truewith the admin key: the agent is missing.
GET /api/agents/collections: the collection is missing. The agent still shows up in the logs as running.
Related: re-creating the agents by hand under the admin works (POST /api/agents with the old config), but every
create or update without api_key auto-generates a new agent:<name> key that inherits the owner's role
(CreateAgentForUser / UpdateAgentForUser / ImportAgentForUser in core/services/agentpool/agent_pool.go). For a
migration done by an admin, that gives every migrated agent an admin-level key, and repeated updates pile up keys.
Passing an explicit api_key avoids both, but that is not obvious.
Describe the solution you'd like
Three steps, each useful on its own:
- Startup warning. When auth is enabled and the root bucket is not empty, log a warning with the number of root
agents / collections / skills and a pointer to the docs. Cheap, and it turns a silent loss into a visible decision. - Admin visibility of the root bucket. Show it to admins as an "unowned" group:
?all_users=trueincludes root
agents and collections under a reserved owner (e.g."" → "unowned"), the admin UI lists them, and admins can
export (GET …/config, the existing agent export) and delete them. Read/export/delete only; no running as another
user. - Opt-in migration:
LOCALAI_AUTH_LEGACY_OWNER=<email or user id>. On startup with auth on, move the root bucket
once to that user's area (agents, collections, skills, tasks, outputs, agent state), write a marker so it never runs
twice, and log what was moved. If the user does not exist yet, skip and warn. Agents moved this way keep an
explicitly configuredapi_key; for empty ones the migration does not auto-generate an owner key but leaves
them onLOCALAI_AGENT_POOL_API_KEYand warns, so a migration by an admin never mints admin-level agent keys.
Docs: a short section in the auth docs ("Enabling auth on an existing instance") covering the root bucket, the
bootstrap rule (the first registered user becomes admin, also in invite mode, unless LOCALAI_ADMIN_EMAIL is set),
the recommended order, and the api_key behaviour of agent create/update.
Describe alternatives you've considered
- Re-create everything by hand under the admin via the API. That works for agent configs and lets us re-ingest
collections, but agent state and long-term memory are lost, and it needs care withapi_key(see above). - Keep auth off and put a reverse proxy with SSO in front. That's what we do today, but it gives no per-user
separation inside LocalAI, which is the reason to useLOCALAI_AUTHin the first place. - Moving files on disk from the base directory to
users/<uid>/by hand. Possible, but it depends on internal layout
details, so it is not something users should have to do.
Additional context
Found while testing a switch from an external UI to LocalAI's built-in auth on a copy of a production instance
(agent pool in LocalAGI mode). Happy to send a PR for step 1 (and the
docs) first, then 2 and 3 if the direction is fine with you.
AI-assisted draft (Claude Code), reviewed and submitted by the reporter.
- 主要语言
- Go
- 星标
- 50k
- 派生
- 4.6k
- 平均合并
- 19 小时 21 分钟
- 30 天内合并 PR
- 325
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 提供 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
mudler/LocalAI 的其他 Issue
-
[Bug] Qwen3.8-27b Uncensored Fails to Download due to 404可能重新可做 关联的 PR 已关闭且未合并。 未关闭bug unconfirmed
难度 1/5 1 小时以内 新手友好度 70/100
维护者通常 1 天内回复
-
Realtime: ASR EOU language tags leak into the LLM conversation (unintended reply-language switching)可能已有人在做 @nexxtmobile 于 16 天前认领。 未关闭area/api bug unconfirmed
难度 2/5 1-3 小时 新手友好度 70/100
维护者通常 1 天内回复
-
Open Responses API doesn't accept "output_text" as an input Item可能重新可做 关联的 PR 已关闭且未合并。 未关闭bug unconfirmed
难度 2/5 1-3 小时 新手友好度 78/100
mudler/LocalAI#12337 · 1 条评论 ·
维护者通常 1 天内回复
-
Gallery model audio-cpp-sortformer-diarization fails to install: SHA mismatch, reproducible across retries可能重新可做 关联的 PR 已关闭且未合并。 未关闭
难度 2/5 1-3 小时 新手友好度 76/100
mudler/LocalAI#11995 · 1 条评论 ·
维护者通常 1 天内回复
-
Agent pool Postgres DSN is logged in cleartext, including the password, while the auth DSN is redacted可能已有人在做 @localai-org-maint-bot 于 51 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 75/100
mudler/LocalAI#11991 · 1 条评论 ·
维护者通常 1 天内回复
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 72/100
limitlessprojects/Go-Hybrid#3342 ·
维护者通常 1 天内回复
-
status/ready type/bug
难度 2/5 1-3 小时 新手友好度 65/100
buildpacks/pack#2733 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
-
kind/bug needs-priority needs-triage
难度 2/5 1-3 小时 新手友好度 72/100
konveyor/tackle2-hub#1166 · 1 条评论 ·
维护者通常 4 天内回复
-
难度 2/5 1-3 小时 新手友好度 62/100
router-for-me/CLIProxyAPI#7209 ·
维护者通常 1 天内回复