Skip to content

Clean up the Linux config encryption key change - #1352

Merged
LukeButters merged 12 commits into
luke/lev-1171-config-encryption-keyfrom
luke/lev-1171-config-encryption-key-cleanup
Nov 17, 2026
Merged

LukeButters merged 12 commits into
luke/lev-1171-config-encryption-keyfrom
luke/lev-1171-config-encryption-key-cleanup

Conversation

@LukeButters

@LukeButters LukeButters commented Nov 17, 2026 •

Copy link
Copy Markdown
Contributor

Structural cleanup on top of #1348. No intended change to how legacy ciphertext or legacy key files are handled.

Changes (one commit each)

  • Split ConfigurationEncryptionKey out of LinuxGeneratedMachineKey. The legacy source is read-only again; ICryptoKeyNixSource.TryLoad and the NoConfigurationEncryptionKey null object are gone. The new key file now holds only base64(key) (no unused IV).
  • No silent fallback on a broken key. Encrypt uses the legacy scheme only when the key file does not exist; an unreadable or corrupt key throws.
  • Remove duplication. One TryEachLegacyKey helper in LinuxMachineKeyEncryptor; one Decrypt(name, value) helper in FlatDictionaryKeyValueStore instead of the decrypting flag.
  • XmlFileKeyValueStore takes a required IMachineKeyEncryptor instead of optional encryptor + keyFilePath.
  • ITentacleConfigurationUpgrade is two throwing methods (PrepareKey, Run). ServiceCommand and RunAgentCommand do their own catch-and-warn.
  • All Unix P/Invoke lives in UnixFile (now public).
  • AtomicCreateFileWithUserReadWriteAccessOnly is one implementation. On Unix it publishes with link(2) only; the racy File.Move fallback is removed.

New command: replace-certificate

Recovers a Tentacle whose certificate is lost, for example because its configuration encryption key was deleted and there is no backup. It generates a new key and certificate, then updates only the endpoint thumbprint on the existing deployment target or worker in Octopus. Environments, roles, tenants and policy are left alone, unlike register-with --force, which replaces them with whatever is passed. It also re-trusts the server and, for polling Tentacles, keeps the existing subscription ID.

Tentacle replace-certificate --instance <instance> --server https://my-octopus --apiKey API-XXXX --name "<machine name in Octopus>"
  • --id Machines-123 / --id Workers-45 instead of --name. A name is searched in both targets and workers and fails if it matches both.
  • --space for a non-default space.
  • --server-comms-address / --server-comms-port for polling Tentacles (default port 10943).

The missing/corrupt key error message now points at this command.

Tested end to end against a local Octopus Server with a listening Tentacle: deleted the key file, ran the command, and the same machine (same ID, roles, environments) got the new thumbprint and passed a health check.

Behaviour changes to be aware of

  • New key file format is base64(key) rather than base64(key).base64(iv). A key file created by a build of Stop deriving Linux Tentacle's config encryption key from /etc/machine-id #1348 will be reported as corrupt.
  • An unreadable/corrupt key now fails Encrypt instead of quietly writing legacy ciphertext.
  • On Unix, if link fails and the target does not exist (e.g. a file system without hard links), key creation now throws instead of falling back to File.Move.

Not verified

  • replace-certificate was not tested end to end with polling Tentacles, workers, websockets or proxies (unit tests cover a polling worker). It saves the new certificate before updating Octopus, so a failed update leaves them out of sync until it is re-run.

  • Octopus.Manager.Tentacle and the net10.0-windows target were not built; Windows runtime paths (File.Move publish) were not run.

  • Only the Configuration/Commands/FileSystem unit tests (302 passed) and the Linux Docker run of the Configuration tests (159 passed as root and as non-root) were run. Integration tests were built, not run.

  • The catch-and-warn paths in ServiceCommand and RunAgentCommand have no test.

  • UpgradeConfigurationEncryptionCommand still re-checks the upgrade's preconditions; removing that did not come out simpler.

@LukeButters
LukeButters marked this pull request as ready for review November 17, 2026 03:38
@LukeButters
LukeButters requested a review from a team as a code owner November 17, 2026 03:38
@LukeButters
LukeButters merged commit bb13d96 into luke/lev-1171-config-encryption-key Nov 17, 2026
20 of 25 checks passed
@LukeButters
LukeButters deleted the luke/lev-1171-config-encryption-key-cleanup branch November 17, 2026 03:39
LukeButters added a commit that referenced this pull request Nov 23, 2026
* Split the per-instance configuration encryption key from the legacy machine key source

* Do not fall back to legacy encryption when the configuration encryption key is unreadable

* Remove duplicated legacy key and decryption error handling

* Require callers to supply the encryptor when creating an XmlFileKeyValueStore

* Reduce ITentacleConfigurationUpgrade to PrepareKey and Run, both throwing

* Move Unix P/Invoke into UnixFile

* Simplify AtomicCreateFileWithUserReadWriteAccessOnly to one implementation

* Resolve the instance's key path in Tentacle Manager instead of passing null

* Rename WriteUserReadWriteOnly to CreateOwnerOnlyFile

* Read the link error before another call can overwrite it

* Move the upgrade's warn-and-continue handling into TentacleConfigurationUpgrade

* Rename the configuration upgrade's Run to Upgrade
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant