OpenTofu 1.13.11: Set bastion_host_key After Updating
OpenTofu 1.13.11 checks the bastion with bastion_host_key. With only host_key set, that check is silently off. Set the key for each server.
After an upgrade to OpenTofu 1.13.11 or 1.12.13, a bastion configuration that sets only host_key still connects without an error, but the bastion's host key is not checked. The fixed versions check the bastion with bastion_host_key instead of host_key, and skip the check if that value is empty. In every connection block that has bastion_host, set the key for each of the two servers.
The 1.13.11 changelog lists this change under SECURITY ADVISORIES and says it can also be a breaking change. It tells anyone who used host_key with a bastion to set bastion_host_key to the same value. That advice is right only if the value really is the bastion's key, or the key of the CA that signed the bastion's certificate.
What changed
For the bastion connection, the fixed code [passes BastionHostKey](https://github.com/opentofu/opentofu/blob/v1.13.11/internal/communicator/ssh/provisioner.go#L296-L304). Version 1.13.10, the release just before the fix, [passed connInfo.HostKey](https://github.com/opentofu/opentofu/blob/v1.13.10/internal/communicator/ssh/provisioner.go#L296-L304) in the same place. If the value is empty, the code [keeps ssh.InsecureIgnoreHostKey()](https://github.com/opentofu/opentofu/blob/v1.13.11/internal/communicator/ssh/provisioner.go#L330-L333). The bastion and the final server use the same function, so an empty host_key also skips the check for the final server. The official documentation also says that SSH host key validation is disabled by default.
| Values set | Bastion check before the fix | Bastion check in 1.13.11 |
|---|---|---|
host_key only | Checked with host_key | Not checked |
bastion_host_key only | Not checked (the value was not used) | Checked with bastion_host_key. The final server is not checked |
| Both | Checked with host_key | Checked with bastion_host_key |
| Neither | Not checked | Not checked |
The behavior before the fix comes from the changelog and the 1.13.10 source, and was not run. On 1.13.11, the case with only host_key and the case with both values were tested. The other two rows come from the source.
Before the fix, host_key alone was used to check both servers. If a bastion connection with host_key set succeeded, that value matched both servers. Either both servers used the same host key, or the same CA signed both servers' host certificates. If you have since replaced a server or rotated a key, verify the value again instead of copying it. bastion_host_key was not used before, so if yours holds a wrong value, the connection is refused only after the update.
[1] Check the version and upgrade to a fixed release in a supported series.
$ tofu versionOpenTofu v1.13.11on linux_amd64| Series | Fix | Support ends (checked December 2, 2026, KST) |
|---|---|---|
| 1.13 | 1.13.11 | 2027-08-01 |
| 1.12 | 1.12.13 | 2027-02-01 |
| 1.11 | Not found in the changelog | 2026-08-01 (passed) |
1.11.14, the last planned release in the 1.11 series, recommends moving to a newer series. On December 2, 2026 (KST), this issue was not among the 10 public security advisories in the OpenTofu repository. The changelogs and the text of PR #4885 give no CVE or GHSA number either. Check the version on each CI runner and each team member's computer too.
[2] In the directory that holds your configuration, find the affected connection blocks. This is the result for a sample directory.
$ grep -rnE --include='*.tf' --include='*.tofu' --include='*.json' '\b(bastion_host|bastion_host_key|host_key)\b' . | sort./.terraform/modules/vm/main.tf:3: host_key = var.host_key./.terraform/modules/vm/main.tf:4: bastion_host = "bastion.example.com"./db.tofu:2: bastion_host = "bastion.example.com"./db.tofu:3: bastion_host_key = var.bastion_host_key./json/extra.tf.json:1:{"connection": {"bastion_host": "bastion.example.com"}}./main.tf:3: host_key = var.host_key./main.tf:4: bastion_host = "bastion.example.com"Check that every block with bastion_host has both keys. In this sample, main.tf, the vm module and extra.tf.json lack bastion_host_key, while db.tofu and extra.tf.json lack host_key. Do not edit downloaded modules in .terraform/modules. Change the module's source instead. This command misses modules that have not been downloaded, and it cannot tell whether a variable is set to an empty value.
[3] Get both servers' public host keys through a channel you trust. Check each server on its console, or get the keys from the server administrator or your configuration management. This example reads an ECDSA key. If HostKey in the sshd configuration points elsewhere, use that file.
$ ssh-keygen -lf /etc/ssh/ssh_host_ecdsa_key.pub$ cat /etc/ssh/ssh_host_ecdsa_key.pubCopy only the public key, the file that ends in .pub. ssh-keyscan shows the key of whichever server answers on the network. It does not prove that the server is genuine. If you use it, compare its fingerprint with the one you read on the console.
If a server has several host keys, the key type must match too. When the test bastion had both ECDSA and ED25519 keys, 1.13.11 connected with the ECDSA key but **refused the same bastion's ED25519 key with key mismatch**. With a bastion that had only its ED25519 key, the same ED25519 value worked. If this happens, do not turn the check off. Use a public key of another type that you have verified on the console. Servers with RSA keys were not tested.
If you use a CA, set the public key of the CA that signed that server's host certificate. OpenTofu writes the value as an [@cert-authority line](https://github.com/opentofu/opentofu/blob/v1.13.11/internal/communicator/ssh/provisioner.go#L345-L348). If the server does not present a certificate, the same value is compared as a plain host key. In the test, the bastion used a host certificate issued for the name bastion.example.com. The CA's public key worked, and an unrelated key was refused.
[4] Set each value separately. This is a complete main.tf that only checks the connection, for a disposable environment. Replace host, bastion_host, user and private_key with that environment's values. In your production configuration, add only the two keys to connection, and use the variable definitions below that reject empty values.
variable "host_key" { type = string default = ""} variable "bastion_host_key" { type = string default = ""} resource "terraform_data" "ssh_check" { connection { type = "ssh" user = "deploy" private_key = file("/lab/client") host = "app.example.com" host_key = var.host_key bastion_host = "bastion.example.com" bastion_host_key = var.bastion_host_key timeout = "10s" } provisioner "remote-exec" { inline = ["echo ssh-check-ok"] }}The empty defaults here are only for the empty-value comparison in [5]. Keep the private key out of your repository.
In production, make plan stop when a value is empty. Remove the defaults, then add nullable = false and a validation rule.
variable "host_key" { type = string nullable = false validation { condition = trimspace(var.host_key) != "" error_message = "host_key must not be empty." }} variable "bastion_host_key" { type = string nullable = false validation { condition = trimspace(var.bastion_host_key) != "" error_message = "bastion_host_key must not be empty." }}This was checked on 1.13.11 with tofu plan -input=false only, without connecting to any server. When bastion_host_key was empty, only spaces, not set or null, the plan stopped with exit code 1. With both values set, it exited 0. A configuration with empty defaults and no validation exited 0 even when bastion_host_key was not set. This rule checks only whether a value is empty. Use [3] and [5] to check that it is the right key, and separately check values written directly in connection and variables in other modules.
[5] Check the connection in a disposable environment, not on production resources. Provisioners run commands on real servers, so do not run apply on a production configuration for this test. Put only the main.tf above in an empty directory. Set the environment variables TF_VAR_host_key and TF_VAR_bastion_host_key to the public keys you verified in [3], then run:
$ tofu init -no-color$ tofu apply -auto-approve -no-colorThis is the bastion part of the output when both values are correct.
terraform_data.ssh_check (remote-exec): Using configured bastion host...terraform_data.ssh_check (remote-exec): Host: bastion.example.com…terraform_data.ssh_check (remote-exec): Checking Host Key: trueterraform_data.ssh_check (remote-exec): Connected!terraform_data.ssh_check (remote-exec): ssh-check-okFor each connection attempt, Checking Host Key appears twice, once for the final server and once for the bastion, and the lines repeat on every retry. Check that both say true. The line only shows whether a value is set (source), so it says true even if the value is wrong. Check for Connected! as well. With host_key set and bastion_host_key empty, the final server still showed true, but the bastion showed the following and the run succeeded.
terraform_data.ssh_check (remote-exec): Checking Host Key: falseterraform_data.ssh_check (remote-exec): Connected!terraform_data.ssh_check (remote-exec): ssh-check-okA successful run does not prove that verification is on. These are the test results. The final server and the bastion use different keys, and each has both an ECDSA and an ED25519 key.
host_key | bastion_host_key | Result |
|---|---|---|
| Final server's ECDSA key | Bastion's ECDSA key | Success |
| Final server's ECDSA key | Final server's ECDSA key (same value copied) | Refused at the bastion |
| Bastion's ECDSA key | Bastion's ECDSA key | Refused at the final server |
| Final server's ECDSA key | Empty | Success, but the bastion is not checked |
This is the error from the second case, where the same value was copied.
timeout - last error: Error connecting to bastion: ssh: handshake failed:knownhosts: key mismatchThe third case fails at the final server.
timeout - last error: SSH authentication failed (deploy@app.example.com:22):ssh: handshake failed: knownhosts: key mismatchThe error starts with timeout, but the cause is the key mismatch that follows. Even when a key does not match, OpenTofu keeps retrying until timeout, which was 10 seconds in this test. For Error connecting to bastion, verify the bastion's key again as in [3]. For SSH authentication failed (…@final server), verify the final server's key. If you did not expect the key to change, find out why the server changed before you set a new value. For the same check in OpenSSH, see REMOTE HOST IDENTIFICATION HAS CHANGED.
Clearing or removing host_key or bastion_host_key can make the error go away, but it turns verification off. It is not a fix.
Analyze your auth.log (SSH) log in the browser ↗ — nothing is uploaded.
Check it with the ssh_config generator tool ↗ — calculated in your browser.