{"record":{"id":"b71b4641c16bcf36","repo":"testcontainers/testcontainers-java","slug":"failed-to-create-kibana-service-account-token-exit-code","errorCode":null,"errorMessage":"Failed to create Kibana service account token. Exit code: {exitCode}, stdout: {stdout}, stderr: {stderr}","messagePattern":"Failed to create Kibana service account token\\. Exit code: (.+?), stdout: (.+?), stderr: (.+?)","errorType":"exception","errorClass":"RuntimeException","httpStatus":null,"severity":"error","filePath":"modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/KibanaContainer.java","lineNumber":573,"sourceCode":"                String curlCommand = String.format(\n                    \"curl -sS%s -u \\\"elastic:$1\\\" -H 'Content-Type: application/json' -X POST '%s'\",\n                    curlTlsArgs,\n                    endpoint\n                );\n\n                Container.ExecResult result = elasticsearch.execInContainer(\n                    \"/bin/sh\",\n                    \"-c\",\n                    curlCommand,\n                    \"sh\",\n                    elasticPassword\n                );\n\n                String stdout = (result.getStdout() == null) ? \"\" : result.getStdout();\n                String stderr = (result.getStderr() == null) ? \"\" : result.getStderr();\n\n                if (result.getExitCode() != 0) {\n                    throw new RuntimeException(\n                        \"Failed to create Kibana service account token. Exit code: \" +\n                        result.getExitCode() +\n                        \", stdout: \" +\n                        stdout +\n                        \", stderr: \" +\n                        stderr\n                    );\n                }\n\n                JsonNode json = OBJECT_MAPPER.readTree(stdout);\n                JsonNode value = json.path(\"token\").path(\"value\");\n                if (value.isTextual() && !value.asText().trim().isEmpty()) {\n                    return value.asText().trim();\n                }\n\n                throw new RuntimeException(\"Service account token response did not contain token.value: \" + stdout);\n            }\n        );","sourceCodeStart":555,"sourceCodeEnd":591,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/KibanaContainer.java#L555-L591","documentation":"The library creates the Kibana service account token by exec'ing the elasticsearch-service-tokens CLI inside the Elasticsearch container. If the command exits non-zero, this RuntimeException is thrown with the exit code plus captured stdout/stderr to make the underlying failure diagnosable.","triggerScenarios":"Any non-zero exit from the token CLI: wrong ES version lacking the tool, corrupted ES installation, ES container filesystem issues, or the CLI failing to write/read the token file (permissions, disk full).","commonSituations":"Elasticsearch image misconfigured via custom DockerImageName or startup scripts; ES container unhealthy at the moment token creation runs; custom images (extensions) that strip the service-tokens binary.","solutions":["Read the stderr/stdout in the message — it contains the CLI's actual failure reason; fix that root cause first.","Verify the Elasticsearch image is an official, unmodified image that includes bin/elasticsearch-service-tokens.","Ensure the ES container is fully healthy (not restarting/crashed) when Kibana starts; check its logs.","Confirm the ES version supports service account tokens (7.10+)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n    String token = kibana.token();\n} catch (RuntimeException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Failed to create Kibana service account token\")) {\n        // message embeds exit code + stdout/stderr; log it and fail fast with context\n        throw new AssertionError(\"Token CLI failed inside ES container: \" + e.getMessage(), e);\n    }\n    throw e;\n}","preventionTips":["Use official, unmodified Elasticsearch images so bin/elasticsearch-service-tokens exists.","Check ES container logs for health issues before Kibana starts.","Use an ES version that supports service account tokens (7.10+)."],"tags":["testcontainers","elasticsearch","kibana","command-failed","service-account"],"backgroundTag":"command-execution-failed","analyzedSha":"8e549514e3f01c57d70546fbb8599d138f3903e5","analyzedAt":"2026-09-12T14:56:41.227Z","contentChangedAt":"2026-09-12T14:56:41.227Z","schemaVersion":2},"datasetVersion":"2026-09-16T04:17:20.429Z"}