{"record":{"id":"c177e088ea939e07","repo":"theonedev/onedev","slug":"unauthorized-c177e0","errorCode":null,"errorMessage":"Unauthorized","messagePattern":"Unauthorized","errorType":"http","errorClass":"UnauthorizedException","httpStatus":401,"severity":"error","filePath":"server-core/src/main/java/io/onedev/server/web/resource/AgentResource.java","lineNumber":40,"sourceCode":"import io.onedev.commons.utils.FileUtils;\nimport io.onedev.commons.utils.StringUtils;\nimport io.onedev.commons.utils.TarUtils;\nimport io.onedev.commons.utils.ZipUtils;\nimport io.onedev.server.OneDev;\nimport io.onedev.server.service.AgentService;\nimport io.onedev.server.service.AgentTokenService;\nimport io.onedev.server.service.SettingService;\nimport io.onedev.server.model.AgentToken;\nimport io.onedev.server.security.SecurityUtils;\n\npublic class AgentResource extends AbstractResource {\n\n\tprivate static final long serialVersionUID = 1L;\n\n\t@Override\n\tprotected ResourceResponse newResourceResponse(Attributes attributes) {\n\t\tif (!SecurityUtils.isAdministrator()) \n\t\t\tthrow new UnauthorizedException();\n\t\t\n\t\tif (!new File(Bootstrap.installDir, \"agent\").exists())\n\t\t\tthrow new ExplicitException(\"No agent package to download\");\n\n\t\tResourceResponse response = new ResourceResponse();\n\t\tresponse.setContentType(MimeTypes.OCTET_STREAM);\n\t\tresponse.disableCaching();\n\t\t\n\t\tString fileName = StringUtils.substringAfterLast(\n\t\t\t\tattributes.getRequest().getUrl().getPath(), \"/\");\n\t\tresponse.setFileName(fileName);\n\t\t\n\t\tresponse.setWriteCallback(new WriteCallback() {\n\n\t\t\t@Override\n\t\t\tpublic void writeData(Attributes attributes) throws IOException {\n\t\t\t\tFile tempDir = FileUtils.createTempDir(\"agent\");\n\t\t\t\ttry {","sourceCodeStart":22,"sourceCodeEnd":58,"githubUrl":"https://github.com/theonedev/onedev/blob/d44925c47c37992c828ea673a5f9620539bc3ff2/server-core/src/main/java/io/onedev/server/web/resource/AgentResource.java#L22-L58","documentation":"AgentResource serves the OneDev agent installation package, restricted to administrators. After the administrator check passes, it verifies that the packaged agent directory exists under Bootstrap.installDir; if it does not, it throws this ExplicitException because the server installation has no agent package to distribute.","triggerScenarios":"Administrator requests the agent package download while the '<installDir>/agent' directory is missing on the server host.","commonSituations":"Partial or custom server installation that omitted the bundled agent files; installDir misconfigured (wrong path or relative path in a container); upgrade/cleanup script deleted the agent directory; running the server from a stripped-down distribution.","solutions":["Restore the agent package directory under the OneDev install dir (reinstall/repair OneDev or copy the bundled 'agent' folder from a complete distribution).","Verify Bootstrap.installDir points to the real installation root (fix launch script/env if wrong).","Upgrade OneDev to a distribution that bundles the agent package.","If in a container, use the official image/complete archive rather than a trimmed build."],"exampleFix":"// before: site dir missing package\nls /opt/onedev  # no 'agent' dir\n\n// after: restore from distribution\ncp -r onedev-complete/agent /opt/onedev/agent","handlingStrategy":"validation","validationCode":"// Check the package exists on the server before requesting download\nFile agentDir = new File(Bootstrap.installDir, \"agent\");\nif (!agentDir.exists())\n    throw new IllegalStateException(\"Agent package missing; reinstall OneDev distribution\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Install OneDev from the complete distribution/archive that bundles the agent folder.","Exclude the install dir from aggressive cleanup scripts.","Verify installDir configuration after moving or copying the installation."],"tags":["agent","missing-file","installation"],"backgroundTag":"file-not-found","analyzedSha":"d44925c47c37992c828ea673a5f9620539bc3ff2","analyzedAt":"2026-09-06T07:18:27.995Z","contentChangedAt":"2026-09-06T07:18:27.995Z","schemaVersion":2},"datasetVersion":"2026-09-14T00:17:10.932Z"}