4 ms·
There's a fairly straight forward pattern for keeping sensitive credentials out of github. It comes straight from http://12factor.net/config http://12factor.net
by olefoo 12y ago
There's a fairly straight forward pattern for keeping sensitive credentials out of github. It comes straight from http://12factor.net/config http://12factor.net/config store configuration data in the environment.
What I do for most projects is keep the tree containing the working directory in a directory that has some other items that don't belong on github (like the project brief, my emacs bookmarks file, random notes related to the project etc. ) and in that directory there is a .credentials file containing a set of export statements somewhat like:
export AWS_ACCESS_KEY=XXXXXXXXXXXXXXXXXXXX
export AWS_SECRET_KEY=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
export AWS_USER_ID=############
If I'm feeling extra paranoid, I'll encrypt that into a blob that I only decrypt when I'm working on said project.
Then at startup the app goes looking for it's config in the environment. This does create issues for some environments ( solving this for docker is trivial ) but you can usually pass environment variables to whatever is executing your code reasonably securely. Now it's not perfect, and environments can sometimes be revealed externally if an attacker is determined and clever and focused on your app for some reason.
But it does give you a hygienic procedure that keeps your credentials that are equivalent to an open draw on your bank account out of public repositories.
- califield 12y agoI use the `dotenv`[1] package with Node.js and it does exactly the same thing: environment variable definitions that you can store elsewhere in a dead-simple format. To be fair, I think they just copied the `foreman` tool from Heroku. However, it works great. Most projects don't need anything more than a flat hierarchy of secret keys and values. Writing your own parser for a `.env` file is a piece of cake, even in shell language. Adding `etcd` is better, but it's too much work for a small project. [1] https://github.com/motdotla/dotenv https://github.com/motdotla/dotenv
- kgilpin 12y ago12 factor and .env make a lot of sense. However they still leave some questions unanswered, such as: How do the secrets get safely distributed to the machines where they are needed? How to revoke/rotate a secret, especially once a compromise is suspected? How to perform all this in DevOps-y, automated systems? This is the problem space I work in.
- olefoo 12y agoIt really depends on the scale you're working at; and whether you can assume that there will be someone available to supply credentials for an instance that had to restart. I've used fabric and ansible to push configs out to small sets of hosts; and yes assumed that the sensitive bits were OK sitting on the filesystem of the production host. Since if an attacker had access to the filesystem there would be more issues and I'd have to invalidate those credentials anyhow. At a larger scale you'll want something like etcd or consul or even just a centralized key server that new instances call and ask for their configuration. The thing is that anything predicated on HMAC secrets is vulnerable to those secrets being exposed. The secret has to be in the clear at some point to perform authentication or signing and a sufficiently determined attacker will be able to get that string. A system is only as secure as the humans running it can confirm it to be secure. This is why it's best to reduce your attack surface and ensure that you can log access and do process inventory and egress filtering and the whole checklist of prevention, detection and remediation. There is no magic pixie dust that will make your system fully secure; you will always be making tradeoffs and managing risk rather than eliminating it.
- greenleafjacob 12y agoIf you're feeling fancy, you can use my library to asymmetrically encrypt credentials using RSA keys [1]. [1]: https://github.com/jacobgreenleaf/greybox https://github.com/jacobgreenleaf/greybox
- stouset 12y agoThe fact that this uses RSA directly seriously worries me. Is the RSA library using OAEP? Does it properly blind it's inputs before signing? What's the modulus? Does key generation avoid using weak keys? Maybe the answer to these questions and others is satisfactory, but getting RSA catastrophically wrong is easy enough that I'm extremely skeptical that a library will get it right. Honestly, I'd be infinitely more likely to use your library if it just used GPG under the hood. That's one less piece of crypto I feel compelled to audit.
- verroq 12y agoIf you read the code it's obvious that it uses a Python named 'rsa' which implements PKCS#1
- stouset 12y agoYou have completely missed the point. I did read the code, and I saw it used the `rsa` library. I read the code for that library, and also saw it claims to use PKCS#1 padding. None of these obviates my point. There are dozens of other ways to fuck up an RSA implementation. Some obvious, many not. I am not an expert in Python, nor am I an expert in auditing secure RSA implementations. Neither are most of this project's intended audience, I would warrant. Using RSA like this directly, in my opinion, dramatically increases the likelihood of a significant implementation oversight when compared to something as widely-used, audited, and established as GPG. And it should cause security-conscious users to be much more distrustful of it. As a security professional, adding to the list of libraries and crypto implementations for me to audit does not reduce my workload: it massively increases it. If it were a conceptually simple wrapper around GPG, I would consider deploying it without a second thought. GPG, while crusty and imperfect, is at least more difficult to misuse. As it stands, I would need to spend significant time relearning RSA implementation best practices and ensuring it adheres to them. The fact that others aren't likely to do (or be capable of doing) this legwork only makes the problem worse; bad crypto is often little better than no crypto. And until proven otherwise, the default assumption should be that something uses bad crypto.
- makmanalp 12y agoThose who use ansible can use ansible-vault to encrypt credentials (http://docs.ansible.com/playbooks_vault.html http://docs.ansible.com/playbooks_vault.html) and chef has encrypted data bags (https://docs.chef.io/chef/essentials_data_bags.html https://docs.chef.io/chef/essentials_data_bags.html). Really, any raw config shouldn't ever make it in the repo anyway, other than sample.conf.