Skip to content

Fix race condition in ProcessesSync causing SSH key mismatch#5012

Draft
philippthun wants to merge 1 commit intocloudfoundry:mainfrom
sap-contributions:fix-ssh-key-mismatch-race-condition
Draft

Fix race condition in ProcessesSync causing SSH key mismatch#5012
philippthun wants to merge 1 commit intocloudfoundry:mainfrom
sap-contributions:fix-ssh-key-mismatch-race-condition

Conversation

@philippthun
Copy link
Copy Markdown
Member

@philippthun philippthun commented Apr 9, 2026

The sync could update an LRP with stale SSH route data from a previous version when the process version changed between the initial scan and the batch execution.

Timeline of the race condition:

  Sync                              User Request
  ----                              ------------
  |                                      |
  | fetch diego LRPs                     |
  | (gets {guid}-{vA} with SSH key A)    |
  |                                      |
  | scan CC processes                    |
  | process has version A, matches       |
  | to_update[id] = diego_lrp_A          |
  |                                      |
  |                                      | update process
  |                                      | version changes to B
  |                                      |
  |                                      | desire_app called
  |                                      | creates {guid}-{vB}
  |                                      | with new SSH key B
  |                                      |
  | re-fetch process by id               |
  | (now has version B)                  |
  |                                      |
  | update_app(process_vB, diego_lrp_A)  |
  | process_guid = {guid}-{vB}           |
  | but uses SSH route from diego_lrp_A! |
  |                                      |
  v                                      v

Result: LRP {guid}-{vB} has SSH key A in routes but SSH key B in run_info (sshd arguments), breaking cf ssh.

Fix: Before executing desire/update, verify the process version still matches what was recorded during the initial scan. Skip if mismatched - the next sync cycle will handle it correctly.

  • I have reviewed the contributing guide

  • I have viewed, signed, and submitted the Contributor License Agreement

  • I have made this pull request to the main branch

  • I have run all the unit tests using bundle exec rake

  • I have run CF Acceptance Tests

@philippthun philippthun force-pushed the fix-ssh-key-mismatch-race-condition branch from 44475cf to 2db1fc1 Compare April 10, 2026 08:43
@philippthun philippthun requested a review from jochenehret April 10, 2026 08:53
The sync could update an LRP with stale SSH route data from a previous
version when the process version changed between the initial scan and
the batch execution.

Timeline of the race condition:

  Sync                              User Request
  ----                              ------------
  |                                      |
  | fetch diego LRPs                     |
  | (gets {guid}-{vA} with SSH key A)    |
  |                                      |
  | scan CC processes                    |
  | process has version A, matches       |
  | to_update[id] = diego_lrp_A          |
  |                                      |
  |                                      | update process
  |                                      | version changes to B
  |                                      |
  |                                      | desire_app called
  |                                      | creates {guid}-{vB}
  |                                      | with new SSH key B
  |                                      |
  | re-fetch process by id               |
  | (now has version B)                  |
  |                                      |
  | update_app(process_vB, diego_lrp_A)  |
  | process_guid = {guid}-{vB}           |
  | but uses SSH route from diego_lrp_A! |
  |                                      |
  v                                      v

Result: LRP {guid}-{vB} has SSH key A in routes but SSH key B in
run_info (sshd arguments), breaking cf ssh.

Fix: Before executing desire/update, verify the process version still
matches what was recorded during the initial scan. Skip if mismatched -
the next sync cycle will handle it correctly.

Co-authored-by: Jochen Ehret <jochen.ehret@sap.com>
@philippthun philippthun force-pushed the fix-ssh-key-mismatch-race-condition branch from 2db1fc1 to 55641e7 Compare April 10, 2026 09:01
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