{"record":{"id":"ea773428d774608d","repo":"cube-js/cube","slug":"cubesql-cube-token-is-a-required-env-variable","errorCode":null,"errorMessage":"CUBESQL_CUBE_TOKEN is a required ENV variable","messagePattern":"CUBESQL_CUBE_TOKEN is a required ENV variable","errorType":"panic","errorClass":null,"httpStatus":null,"severity":"critical","filePath":"rust/cubesql/cubesql/src/sql/auth_service.rs","lineNumber":80,"sourceCode":"\n#[derive(Debug)]\npub struct SqlAuthDefaultImpl;\n\ncrate::di_service!(SqlAuthDefaultImpl, [SqlAuthService]);\n\n#[async_trait]\nimpl SqlAuthService for SqlAuthDefaultImpl {\n    async fn authenticate(\n        &self,\n        _request: SqlAuthServiceAuthenticateRequest,\n        _user: Option<String>,\n        password: Option<String>,\n    ) -> Result<AuthenticateResponse, CubeError> {\n        Ok(AuthenticateResponse {\n            context: Arc::new(HttpAuthContext {\n                access_token: env::var(\"CUBESQL_CUBE_TOKEN\")\n                    .ok()\n                    .unwrap_or_else(|| panic!(\"CUBESQL_CUBE_TOKEN is a required ENV variable\")),\n                base_path: env::var(\"CUBESQL_CUBE_URL\")\n                    .ok()\n                    .unwrap_or_else(|| panic!(\"CUBESQL_CUBE_URL is a required ENV variable\")),\n            }),\n            password,\n            skip_password_check: false,\n        })\n    }\n}\n","sourceCodeStart":62,"sourceCodeEnd":90,"githubUrl":"https://github.com/cube-js/cube/blob/7d981676b36392fec34088b9afab6bdcad40207c/rust/cubesql/cubesql/src/sql/auth_service.rs#L62-L90","documentation":"The HTTP-based authentication service builds an HttpAuthContext whose access_token comes from the CUBESQL_CUBE_TOKEN environment variable. If that variable is unset, the code panics because CubeSQL cannot authenticate against the Cube deployment without an API token.","triggerScenarios":"Running the CubeSQL standalone/meta-transport binary with the HTTP auth service without exporting CUBESQL_CUBE_TOKEN before startup.","commonSituations":"Kubernetes/Docker manifests missing the env entry; .env file not loaded; renaming variables during a config refactor; running the binary manually from a shell without the deployment's env.","solutions":["Set CUBESQL_CUBE_TOKEN to the Cube deployment's API token before starting the process","Add the variable to your container spec / .env file and restart","Verify with a shell into the container that `echo $CUBESQL_CUBE_TOKEN` is non-empty"],"exampleFix":"// before\n cargo run -p cubesql\n// after\n CUBESQL_CUBE_TOKEN=<api-token> CUBESQL_CUBE_URL=http://cube:4000 cargo run -p cubesql","handlingStrategy":"validation","validationCode":"// startup preflight before launching cubesql\nfn require_env(key: &str) -> Result<String, String> {\n    match std::env::var(key) {\n        Ok(v) if !v.is_empty() => Ok(v),\n        _ => Err(format!(\"{} is required\", key)),\n    }\n}\nlet _ = require_env(\"CUBESQL_CUBE_TOKEN\")?;","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Add CUBESQL_CUBE_TOKEN to deployment manifests and secret stores together with CUBESQL_CUBE_URL","Run an env preflight check in your entrypoint script","Document required env vars in your deployment README"],"tags":["rust","env-var","auth","panic","startup"],"backgroundTag":"missing-env-var","analyzedSha":"7d981676b36392fec34088b9afab6bdcad40207c","analyzedAt":"2026-09-02T03:45:10.400Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T15:18:49.778Z"}