Lost my Cloud Foundry BOSH Director password
I had a colleague who had lost their BOSH Director password. As the password is not stored anywhere, we followed the steps below to set a new one. In order to do this, you will need SSH access to the BOSH virtual machine. In our case, we needed the private key for the AWS instance.
Aside : the password hash is stored in a database, but is not reversible. We could have used a rainbow table to identify another password with the same hash, but it was easier to create a new user and password.
So I connected to my BOSH VM using the private key.
My plan was to get the password from the Director database. First I needed to get the credentials for the database. They are found in the configuration file attached the job that deployed it.
vcap@bm-0a7e7af6-251a-4554-9005-f69b957fe8b2:$cat /var/vcap/jobs/director/config/director.yml
Great. Now I can dump the database (it wasn't very big.)
vcap@bm-0a7e7af6-251a-4554-9005-f69b957fe8b2:$cd /var/vcap/packages/postgres/bin
vcap@bm-0a7e7af6-251a-4554-9005-f69b957fe8b2:/var/vcap/packages/postgres/bin$ ./pg_dump bosh -a -p 5432 -f ~/temp.txt
Then I searched for my user 'bosh_admin' in the dump.
vcap@bm-0a7e7af6-251a-4554-9005-f69b957fe8b2:/var/vcap/packages/postgres/bin$ cat ~/temp.txt |grep bosh_admin
2 bosh_admin $2a$10$y9NPJOBGWChhI7EfWiBMWeKFuUKD/kK*****89jVBFvX47y0ZT2W
I tried that as the password, but it didn't work. Some digging in the source code indicated that it was an unsalted password hash.
Looking at the dump a bit more closely showed me the format for adding a new user.
COPY users (id, username, password) FROM stdin;
1 hm $2a$10$F0/VsvTtMk3cEHdzAFyP8eleOiOCdN59BJLDWG4lJGwVuqIP0VglW
2 bosh_admin $2a$10$y9NPJOBGWChhI7EfWiBMWeKFuUKD/kKWRWAv9GAjVBFvX47y0ZT2W
So I connected to the database.
vcap@bm-0a7e7af6-251a-4554-9005-f69b957fe8b2:/var/vcap/packages/postgres/bin$ ./psql -d bosh -u postgres
Created a bcrypt hash from my password here. And inserted the new user.
bosh=>INSERT INTO users (username, password) VALUES (‘sean’, ‘$2a$04$.asfga0erbevhLAtE8wdfd.ET.UCMMOolOPVkz94dXYgd/n.33gha9hSNa’);
bosh=> select * from users;
----+------------+--------------------------------------------------------------
1 | hm | $2a$10$F0/VsvTtMPPPPPdzAFyP8asdfklajsdg07uiN59BJLDWG4lJGwVuqIP0VglW
2 | bosh_admin | $2a$10$y9PPPPPGWChhI7Ekajsdf9eKFuUKD/kKWRWAv9GAjVBFvX47y0ZT2W
3 | sean | $2a$04$.D9OvbevhLAtE8wABC.ET.UC9dafgaulOPVkz94dXYgd/n.111K0hSNa
And I was then able to login with my new user. I could have deleted the old user, but left it just in case someone else was using it.
The following pages were helpful in arriving at this solution, however some were out of date and others were incomplete.
https://groups.google.com/a/cloudfoundry.org/forum/#!searchin/bosh-users/lost$20password/bosh-users/xwWtwVMNAKw/zaSxIsGWMmwJ
http://www.neilconway.org/docs/sequences/
http://www.ruby-doc.org/gems/docs/b/bcrypt-ruby-maglev--3.0.1/BCrypt/Password.html
http://man.yolinux.com/cgi-bin/man2html?cgi_command=psql
http://man.yolinux.com/cgi-bin/man2html?cgi_command=pg_dump
Also the default user and password for a BOSH instance are 'vcap:c1oudc0w'