The Inner Guts of Bitbucket [video]
blog.bitbucket.org
blog.bitbucket.org
Also, would be super curious to see and hear more about their patch to SSHD to allow it to read from a database instead of disk. This would be super useful for us as well (https://commando.io).
Lastly, it was really interesting that switching to bcrypt took their servers down, and they were forced to write a custom sha1 to bcrypt cache. One solution would be to not hash (bcrypt) API tokens, but instead just encrypt them and store in PostgreSQL. The side benefit of this, is users could view their API tokens again if needed.
Obviously it is less secure, but Stripe for example allows you to view your API tokens, and thus they are not hashing them.
It's based on this patch: https://github.com/wuputahllc/openssh-for-git
Either way, if you want to tinker with opensshd I can recommend it as a starting point. It's very small, readable and easily tweaked.
From the sshd_config man page: "Specifies a program to be used for lookup of the user's public keys. The program will be invoked with its first argument the name of the user being authorized, and should produce on standard output AuthorizedKeys lines"