{"record":{"id":"f6a58be62f073226","repo":"testcontainers/testcontainers-java","slug":"kibana-credentials-cannot-have-leading-or-trailing","errorCode":null,"errorMessage":"Kibana credentials cannot have leading or trailing whitespace","messagePattern":"Kibana credentials cannot have leading or trailing whitespace","errorType":"validation","errorClass":"IllegalArgumentException","httpStatus":null,"severity":"error","filePath":"modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/KibanaContainer.java","lineNumber":209,"sourceCode":"     *\n     * @param username the Elasticsearch username (cannot be 'elastic')\n     * @param password the password\n     * @return this container instance\n     * @throws IllegalStateException if a service account token is already configured\n     * @throws IllegalArgumentException if credentials are invalid\n     */\n    public KibanaContainer withKibanaUsernameAndPassword(String username, String password) {\n        if (elasticsearchServiceAccountToken != null) {\n            throw new IllegalStateException(\n                \"Conflicting Elasticsearch credentials: provide either a service account token \" +\n                \"or a username/password pair, not both.\"\n            );\n        }\n        if (StringUtils.isAnyBlank(username, password)) {\n            throw new IllegalArgumentException(\"Kibana credentials cannot be blank\");\n        }\n        if (!username.equals(username.trim()) || !password.equals(password.trim())) {\n            throw new IllegalArgumentException(\"Kibana credentials cannot have leading or trailing whitespace\");\n        }\n        if (\"elastic\".equals(username)) {\n            throw new IllegalArgumentException(\"Username 'elastic' is reserved for internal use by Elasticsearch\");\n        }\n\n        this.elasticsearchUsername = username;\n        this.elasticsearchPassword = password;\n        return this;\n    }\n\n    /**\n     * Configures a service account token for Elasticsearch authentication.\n     *\n     * @param token the service account token\n     * @return this container instance\n     * @throws IllegalStateException if username/password credentials are already configured\n     * @throws IllegalArgumentException if token is blank\n     */","sourceCodeStart":191,"sourceCodeEnd":227,"githubUrl":"https://github.com/testcontainers/testcontainers-java/blob/8e549514e3f01c57d70546fbb8599d138f3903e5/modules/elasticsearch/src/main/java/org/testcontainers/elasticsearch/KibanaContainer.java#L191-L227","documentation":"withKibanaUsernameAndPassword rejects usernames or passwords with leading or trailing whitespace. Environment variables and Kibana config files do not strip surrounding whitespace reliably, so such credentials would silently fail authentication; the library fails fast with IllegalArgumentException instead.","triggerScenarios":"Calling withKibanaUsernameAndPassword where username or password differs from its own trim() — e.g. ' kibana_user' or 'secret\\n'.","commonSituations":"Credentials parsed from files with trailing newline/CRLF; copy-pasted secrets including trailing spaces; YAML/env parsing quirks in CI pipelines.","solutions":["Trim the values before passing them: username.trim(), password.trim().","Sanitize credentials read from files (strip newlines/BOM/quotes).","Check your secrets source for accidental whitespace (trailing newline is the most common)."],"exampleFix":"// before\nkibana.withKibanaUsernameAndPassword(username, password);\n// after\nkibana.withKibanaUsernameAndPassword(username.trim(), password.trim());","handlingStrategy":"validation","validationCode":"if (!username.equals(username.trim()) || !password.equals(password.trim())) throw new IllegalArgumentException(\"Trim credentials before use\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Always .trim() credentials read from files or environment variables.","Normalize secrets at load time in a central utility.","Watch for trailing newlines/CRLF when exporting secrets in CI."],"tags":["kibana","elasticsearch","validation","whitespace"],"backgroundTag":"invalid-argument-format","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"}