{"record":{"id":"03243da475f68b95","repo":"prestodb/presto","slug":"no-console-from-which-to-read-password","errorCode":null,"errorMessage":"No console from which to read password","messagePattern":"No console from which to read password","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"presto-cli/src/main/java/com/facebook/presto/cli/Console.java","lineNumber":171,"sourceCode":"            return true;\n        }\n        finally {\n            exited.countDown();\n            interruptor.close();\n        }\n    }\n\n    private String getPassword()\n    {\n        checkState(clientOptions.user != null, \"Username must be specified along with password\");\n        String defaultPassword = System.getenv(\"PRESTO_PASSWORD\");\n        if (defaultPassword != null) {\n            return defaultPassword;\n        }\n\n        java.io.Console console = System.console();\n        if (console == null) {\n            throw new RuntimeException(\"No console from which to read password\");\n        }\n        char[] password = console.readPassword(\"Password: \");\n        if (password != null) {\n            return new String(password);\n        }\n        return \"\";\n    }\n\n    private static void runConsole(QueryRunner queryRunner, AtomicBoolean exiting)\n    {\n        try (TableNameCompleter tableNameCompleter = new TableNameCompleter(queryRunner);\n                LineReader reader = new LineReader(getHistory(), commandCompleter(), lowerCaseCommandCompleter(), tableNameCompleter)) {\n            tableNameCompleter.populateCache();\n            StringBuilder buffer = new StringBuilder();\n            while (!exiting.get()) {\n                // read a line of input from user\n                String prompt = PROMPT_NAME;\n                String schema = queryRunner.getSession().getSchema();","sourceCodeStart":153,"sourceCodeEnd":189,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-cli/src/main/java/com/facebook/presto/cli/Console.java#L153-L189","documentation":"When --password is passed without a value (prompting mode) and no default password is configured, the CLI needs an interactive console to read the password securely. System.console() returns null in non-interactive environments (piped stdin, no TTY), so getPassword throws.","triggerScenarios":"Running presto with a password-requiring --user and prompting --password flag while stdin is not a terminal: CI jobs, cron, subprocess with redirected stdin, docker exec without -t.","commonSituations":"Automated pipelines invoking the CLI non-interactively; Docker/supervisor contexts lacking a TTY; scripts piping SQL in via stdin while relying on password prompt.","solutions":["Supply the password non-interactively: use --password <value> or set the password config so the prompt is skipped","Allocate a TTY: run interactively or use docker exec -t / ssh -tt","Use a keystore/token auth alternative that doesn't need a console prompt"],"exampleFix":"// before (CI, no TTY)\npresto --user admin --password --execute \"SELECT 1\"\n// after\npresto --user admin --password \"$PRESTO_PASSWORD\" --execute \"SELECT 1\"","handlingStrategy":"validation","validationCode":"// Only prompt for password when a TTY exists\nif [ ! -t 0 ] && [ -z \"$PRESTO_PASSWORD\" ]; then\n  echo \"No TTY: set PRESTO_PASSWORD or pass --password explicitly\" >&2; exit 1;\nfi","typeGuard":null,"tryCatchPattern":"try { runCli(args); } catch (RuntimeException e) { if (e.getMessage().equals(\"No console from which to read password\")) { /* fall back to env/config-provided credentials */ } else throw e; }","preventionTips":["In CI/cron, always supply credentials via config or flag value, never the prompt","Use docker exec -t or a pseudo-TTY when interactive input is required","Keep secrets out of logs when passing --password with a value"],"tags":["cli","password","non-interactive"],"backgroundTag":"no-tty-for-password-prompt","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}