I recently had (too much) fun trying to import a few existing chef users (opscode’s platform) to another chef server. There is currently no facility to export your existing users (‘clients’ if you are running your own server, ‘users’ on the opscode platform).
What i ended up doing involves a lot of manual typing, but i intend to automate that in the future.
The key is that there is no way you can export you users’ public keys without accessing the underlying CouchDB server, and as i’m pretty sure Opscode uses a multi-tenant CouchDB server, you can’t do that on their platform for obvious security concerns.
So i ended up:
- creating the same users on my new chef server
- use irb on the new chef server to overwrite every new users’ public key using some of chef’s internal methods
Some ranting on Opscode’s platform
knife doesn’t even know about users, as the chef server code on that platform makes the distinction between users (who can upload cookbooks, roles, etc …) and API clients (nodes trying to get their run lists and values stored in data bags). The chef backup script provided by jtimberman only exports roles and nodes, and even after massaging it it to dump clients as well, the public_key field is empty - as if the platform’s server removed it on purpose)
i didn’t find any documentation about the differences in the REST API between the hosted platform and the open source chef server. I suppose that the API is here but not exposed in the gem… i’ll look into that later.
With opscode not allowing to export the public_key of the client, meaning there is no way you can easily script that process, you have to go through the very tedious task of copy and paste every user’s public key and change your new users’ document with their respective public key …
Solution
- quickly hack a chef-client.rb that would allow a client (knife or chef-client to connect using an existing API client that you will not modify during this process - doing so would be a nice way to shoot yourself in the foot :-P
- display the user on opscode’s platform :
https://manage.opscode.com/users/
- copy the public key
- on a console, connected to the chef server (we’re going to use
Chef::ApiClient.cdb_load
andChef::ApiClient.cdb_save
methods, which bypass Chef’s REST API, and need the same access as the chef server …)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
done … now repeat that for the other clients and they should be able to access both servers with the same certificates … this doesn’t scale well, but i’m not going to have to distribute another sets of certificates for this chef development server !