Skip to content

Fetch Azure bastion SSH key from Pulumi state#172

Open
Lytol wants to merge 1 commit intomainfrom
bs-azure-bastion-keys
Open

Fetch Azure bastion SSH key from Pulumi state#172
Lytol wants to merge 1 commit intomainfrom
bs-azure-bastion-keys

Conversation

@Lytol
Copy link
Contributor

@Lytol Lytol commented Mar 10, 2026

Description

The Azure bastion SSH key was previously written to ~/.ssh/ during pulumi up via a local.run_output command. This only worked for the engineer who ran the initial deployment — other engineers couldn't connect because the key wasn't on their machine.

This PR exports the SSH key as a Pulumi stack output and fetches it on demand when starting a proxy session.

Code Flow

  1. Python: The bastion SSH private key is exported as a secret stack output (bastion_ssh_private_key) from the persistent stack via azure_workload_persistent.py.
  2. Go (target.go): BastionName() and JumpBoxId() are consolidated into a single BastionInfo() method that fetches all bastion connection details (name, jumpbox ID, SSH key) from the persistent stack in one lookup.
  3. Go (proxy.go): When starting a proxy session, the SSH key is written to a temp file via os.CreateTemp, used for the SSH SOCKS connection, and cleaned up in Stop().
  4. Go (workon.go): PTD_ROOT is now exported to the workon shell environment so that pulumi commands work correctly within the shell.

Rollout

The bastion_ssh_private_key output must be registered via pulumi up on the persistent stack for each Azure workload before deploying the new binary. I will run ensure on all Azure workloads so the new stack output is in place for everyone before merging.

Category of change

  • New feature (non-breaking change which adds functionality)
  • Refactor: a code change that neither fixes a bug nor adds a feature

…stem

Previously, the bastion SSH key was written to ~/.ssh/ during `pulumi up`
via a local command, which only worked for the engineer who ran the initial
deployment. Other engineers would fail to connect because the key wasn't
on their machine.

Now the SSH key is exported as a Pulumi stack output and fetched on demand
when starting a proxy session. The key is written to a temp file and
cleaned up when the proxy stops.

Additional changes:
- Consolidate BastionName/JumpBoxId into single BastionInfo lookup
- Export PTD_ROOT in workon shell for manual pulumi commands
- Remove local.run_output that wrote SSH key to ~/.ssh/
@Lytol Lytol requested a review from a team as a code owner March 10, 2026 21:44
"app_gateway_subnet_id": self.app_gateway_subnet.id,
"bastion_name": self.bastion.bastion_host.name,
"bastion_jumpbox_id": self.bastion.jumpbox_host.id,
"bastion_ssh_private_key": self.bastion.jumpbox_ssh_key.private_key_openssh,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs to be explicitly marked as a secret if we're going to put it in the output?

This probably makes more sense to fetch from azure secret vault, right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The resource output is marked as secret, so our own output inherits that (meaning, it's a secret already):
image

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I used pulumi state as an intermediary since we don't have a comprehensive Azure Secrets solution yet. But honestly, I'm not sure what advantage we even gain from using Azure Secrets here. What I care about most: 1) least surprise: no one should run into an error or have to debug (like we have been if you hadn't run persistent on your local machine for a particular workload) and 2) secrets need to be stored securely (which they are here). 🤷 I could be convinced otherwise, but this honestly feels like a reasonable long-term solution, too.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no you're spot on as long as we're encrypting it.

Copy link
Collaborator

@stevenolen stevenolen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm!

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.

2 participants