{"record":{"id":"ffb7fc06bf246872","repo":"apache/hadoop","slug":"no-console-available-for-prompting-user","errorCode":null,"errorMessage":"No console available for prompting user.","messagePattern":"No console available for prompting user\\.","errorType":"exception","errorClass":"IOException","httpStatus":null,"severity":"warning","filePath":"hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/alias/CredentialShell.java","lineNumber":476,"sourceCode":"            e.getMessage());\n        throw e;\n      } catch (IOException e) {\n        getOut().println(\"Credential \" + alias + \" has NOT been created. \" +\n            e.getMessage());\n        throw e;\n      }\n    }\n\n    @Override\n    public String getUsage() {\n      return USAGE + \":\\n\\n\" + DESC;\n    }\n  }\n\n  protected char[] promptForCredential() throws IOException {\n    PasswordReader c = getPasswordReader();\n    if (c == null) {\n      throw new IOException(\"No console available for prompting user.\");\n    }\n\n    char[] cred = null;\n\n    boolean noMatch;\n    do {\n      char[] newPassword1 = c.readPassword(\"Enter alias password: \");\n      char[] newPassword2 = c.readPassword(\"Enter alias password again: \");\n      noMatch = !Arrays.equals(newPassword1, newPassword2);\n      if (noMatch) {\n        if (newPassword1 != null) {\n          Arrays.fill(newPassword1, ' ');\n        }\n        c.format(\"Passwords don't match. Try again.%n\");\n      } else {\n        cred = newPassword1;\n      }\n      if (newPassword2 != null) {","sourceCodeStart":458,"sourceCodeEnd":494,"githubUrl":"https://github.com/apache/hadoop/blob/2add9630210752f88ceb1bb74eb65e37bf41da8e/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/security/alias/CredentialShell.java#L458-L494","documentation":"'hadoop credential create <alias>' prompts twice for the new secret via promptForCredential(); the prompt needs a System.console(). When stdin/stdout are not a console (script, cron, CI, piped input), getPasswordReader() returns null and create aborts with this IOException before writing anything.","triggerScenarios":"Running 'hadoop credential create <alias> -provider ...' non-interactively: cron jobs, CI pipelines, docker exec without -t, input redirected from /dev/null, orchestration tools (Ansible/Puppet) shelling out.","commonSituations":"Automated cluster provisioning that bootstraps credential stores; container images running hadoop credential; documentation tested interactively then wired into scripts.","solutions":["Pass the secret explicitly: hadoop credential create <alias> -value <secret> -provider <path> (value flag bypasses prompting)","Or run the command with a TTY allocated (ssh -t, docker exec -it, expect)","For full control in automation, use the Java API: provider.createCredentialEntry(alias, value.toCharArray()) + provider.flush()"],"exampleFix":"# before (no console -> fails)\nhadoop credential create fs.s3a.secret.key -provider jceks://file/creds.jceks < /dev/null\n\n# after (non-interactive)\nhadoop credential create fs.s3a.secret.key -value 's3cret' -provider jceks://file/creds.jceks","handlingStrategy":"validation","validationCode":"// Fail fast before launching the shell from a non-interactive context\nif (System.console() == null) {\n  cmd.add(\"-value\"); cmd.add(secret);   // non-interactive path for 'credential create'\n} else {\n  // interactive double-prompt is fine\n}","typeGuard":null,"tryCatchPattern":"try {\n  runShell(\"credential\", \"create\", alias, \"-provider\", providerUri);\n} catch (IOException ex) {\n  if (ex.getMessage().contains(\"No console available\")) {\n    // rerun with -value <secret>, or use the API: createCredentialEntry + flush\n  } else { throw ex; }\n}","preventionTips":["Automated provisioning should use -value or the Java API, never interactive prompts","For docker/ssh contexts allocate a TTY (-it / ssh -t) when prompts are required","Note -value appears in shell history - clear it or prefer password files/API in production"],"tags":["hadoop","credential-shell","console","no-tty","interactive"],"backgroundTag":"console-not-available","analyzedSha":"2add9630210752f88ceb1bb74eb65e37bf41da8e","analyzedAt":"2026-08-22T19:55:07.957Z","schemaVersion":2},"datasetVersion":"2026-08-22T20:17:22.307Z"}