Skip to content

Commit

Permalink
Use configured opsman ssh username instead of hardcoded ubuntu (#59)
Browse files Browse the repository at this point in the history
* Use configured opsman ssh username instead of hardcoded ubuntu

* Fix test

* Use ssh user for connecting to director too
  • Loading branch information
zippolyte authored Aug 27, 2020
1 parent ffcb65f commit a100018
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ssh/director_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ func (b DirectorRunner) Run(data environment.Config, dryRun bool, args ...string

`trap 'rm -f ${director_ssh_key_path}; rm -f ${ssh_key_path}' EXIT`,

fmt.Sprintf(`jumpbox_cmd="ubuntu@%s -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -i ${ssh_key_path}"`, data.OpsManager.IP.String()),
fmt.Sprintf(`jumpbox_cmd="%s@%s -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -i ${ssh_key_path}"`, data.OpsManager.SshUser, data.OpsManager.IP.String()),
`ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -J "$jumpbox_cmd" "bbr@${bosh_env}" -i "$director_ssh_key_path"`,
}

Expand Down
3 changes: 2 additions & 1 deletion ssh/director_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var _ = Describe("director ssh runner", func() {
url, _ := url.Parse("https://www.test-url.io")
data = environment.Config{
OpsManager: environment.OpsManager{
SshUser: "ssh_user",
PrivateKey: "private-key-contents",
IP: net.ParseIP("10.0.0.6"),
URL: *url,
Expand Down Expand Up @@ -72,7 +73,7 @@ var _ = Describe("director ssh runner", func() {
`chmod 0600 "${director_ssh_key_path}"`,
`bosh_env="$(OM_CLIENT_ID='client_id' OM_CLIENT_SECRET='client_secret' OM_USERNAME='username' OM_PASSWORD='password' om -t https://www.test-url.io -k curl -s -p /api/v0/deployed/director/credentials/bosh_commandline_credentials | grep -o "BOSH_ENVIRONMENT=\S*" | cut -f2 -d=)"`,
`trap 'rm -f ${director_ssh_key_path}; rm -f ${ssh_key_path}' EXIT`,
`jumpbox_cmd="ubuntu@10.0.0.6 -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -i ${ssh_key_path}"`,
`jumpbox_cmd="ssh_user@10.0.0.6 -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -i ${ssh_key_path}"`,
`ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -J "$jumpbox_cmd" "bbr@${bosh_env}" -i "$director_ssh_key_path"`,
}))
})
Expand Down
2 changes: 1 addition & 1 deletion ssh/opsmanager_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ type OpsManagerRunner struct {
}

func (b OpsManagerRunner) Run(data environment.Config, dryRun bool, args ...string) error {
sshCommand := fmt.Sprintf(`ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -i "${ssh_key_path}" -t ubuntu@"%s"`, data.OpsManager.IP.String())
sshCommand := fmt.Sprintf(`ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -i "${ssh_key_path}" -t %s@"%s"`, data.OpsManager.SshUser, data.OpsManager.IP.String())

sshCommandLines := []string{
`ssh_key_path=$(mktemp)`,
Expand Down
3 changes: 2 additions & 1 deletion ssh/opsmanager_runner_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ var _ = Describe("ops manager ssh runner", func() {
url, _ := url.Parse("https://www.test-url.io")
data = environment.Config{
OpsManager: environment.OpsManager{
SshUser: "ssh_user",
PrivateKey: "private-key-contents",
IP: net.ParseIP("10.0.0.6"),
URL: *url,
Expand Down Expand Up @@ -71,7 +72,7 @@ var _ = Describe("ops manager ssh runner", func() {
`bosh="$(echo "$creds" | jq -r .credential | tr ' ' '\n' | grep '=')"`,
`echo "$bosh"`,
`shell="/usr/bin/env $(echo "$bosh" | tr '\n' ' ') bash -l"`,
`ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -i "${ssh_key_path}" -t ubuntu@"10.0.0.6" "$shell"`,
`ssh -o IdentitiesOnly=yes -o StrictHostKeyChecking=no -i "${ssh_key_path}" -t ssh_user@"10.0.0.6" "$shell"`,
}))
})

Expand Down

0 comments on commit a100018

Please sign in to comment.