Live data from Hacker News

Environment Variables Considered Harmful for Your Secrets

movingfast.io

111–120 of 120 posts

Re: Environment Variables Considered Harmful for Your Secrets

#111
post #22

My company has an internal bit of infrastructure that I think is a somewhat novel approach that allows us to never have any secrets stored unencrypted on disk. There's a server (a set of servers, actually, for redundancy) called the secret server, and its only job is to run a daemon that owns all the secrets. When an app on another server is started up, it must be done from a shell (we use cap) which has an SSH agent…

If anyone's interested in a somewhat out-of-the-box version of what's described above, using a Consul server/cluster to hold this information should give you basically everything ntucker listed. It's pretty trivial to setup and configuring it to store its data on an encrypted partition is also pretty simple. It's got ACLs and can support TLS connections as well. It's also got a bunch of features that the above system doesn't have, like being distributed (redundancy isn't the same thing as consensus) and datacenter-aware (I'd prefer to have different secrets per-datacenter, when possible).

We've been using it to store our application secrets for some time and had no complaints.

Re: Environment Variables Considered Harmful for Your Secrets

#112
post #25

Fundamentally, any secrets you store will have some mode of access - there's a downside to each and every way of distributing them. If you're shelling out to commands you think might snarf credentials, the environment is easy for them to pick it out of, but if they're running as the same user then they could probably read the secrets from the config file. If they aren't running as the same user, you need a way of pas…

You could use a kernel service that checksums the calling DLL or even all code loaded in the calling process and compares that against a list of trusted callers before doling out the secret. Disadvantage, of course, is that you will have to update the list of trusted callers whenever they change. Mac OS X automates that by automatically trusting binaries signed with the same key (trades some security for convenience)…

Wow, this is the only thing I've seen in this thread which doesn't just add another layer of turtles to the problem. With your suggestion, even if an attacker could gain access to the box, they wouldn't be able to get at the secrets. Is there any prior art/blog posts/software for this approach you could point me at?

Re: Environment Variables Considered Harmful for Your Secrets

#113
ENV propagation to unwanted targets is a legit point.

Our most common crash report scenario is the airbrake gem sending crash reports from our rails app to errbit. I can confirm airbrake gem does not post any sensible env data.

Of course, this is only a good news for that specific case, others apps may transfer environment, and we can't just wonder for each app installed "what will it ever send ?".

Re: Environment Variables Considered Harmful for Your Secrets

#114
post #25

Earlier quoted context omitted.

You could use a kernel service that checksums the calling DLL or even all code loaded in the calling process and compares that against a list of trusted callers before doling out the secret. Disadvantage, of course, is that you will have to update the list of trusted callers whenever they change. Mac OS X automates that by automatically trusting binaries signed with the same key (trades some security for convenience)…

Wow, this is the only thing I've seen in this thread which doesn't just add another layer of turtles to the problem. With your suggestion, even if an attacker could gain access to the box, they wouldn't be able to get at the secrets. Is there any prior art/blog posts/software for this approach you could point me at?

For the Mac OS X technology, https://developer.apple.com/library/mac/documentation/Securi... is a good starting point.

I don't know of full open source equivalents. Parts of Apple's code are open source, though, for example http://opensource.apple.com/source/security_systemkeychain/s... (may not even compile; not all Apple's open source releases do)

Re: Environment Variables Considered Harmful for Your Secrets

#115

This article is misguided. Environment variables can be more secure than files. Furthermore, in the presented case there's no improvement in security by switching to a file. To address my second claim first: file permissions work at the user or group level. ACLs / MAC likewise. SELinux can be configured to assist in this case but it's not as trivial as it appears at first glance, it would be easier to use environment…

You are programming. You can do anything. But a guiding principle should be not to surprise other people. Environment contain information about the environment, search paths and the like. They don't contain secrets. That would surprise people.

Sure you can sanitize the environment, and make sure to wipe out sensitive data after reading it, but if that step fails for some reason, the only way you will notice is when you have a data leak. That's not a way to fail safe. You may the one to never make mistakes, but your coworkers aren't that perfect. That can only lead to security problems in the end.

When given the choice to store your secrets in regular config files or make up something with environment variables, choose the former. Doing it the expected way will buy you lots of goodness later on: You can use ACLs or policies to restrict access, you can allow just a limited number of reads, or pretty much anything else the VFS allows you to.

When you are not alone in your programming, do not inflict onto others what you wouldn't want inflicted on yourself. Avoid surprises.

Re: Environment Variables Considered Harmful for Your Secrets

#116
post #108
post #31

Earlier quoted context omitted.

There are lots of problems with this, not the least of which being: • Configuration files can be trivially forged (rsa without signing) • Many configuration files can be trivially decrypted without the key (rsa use on potentially big files) • Keys can be trivially recovered in multiple ways (global variable, ptrace) Users might be tricked into using your library despite the fact it offers them no real security except…

Your criticisms don't seem to make much sense... * Preventing forgery/tampering is an orthogonal issue and can be done by intrusion-detection software. * "trivially decrypted without the key" -- How? The size of the file is not going to make any difference here. * Of course, the key can be recovered if you have the ability to ptrace. What's your point? That's going to be true of any solution out there. Why don't you…

Writing software that may run in a potentially hostile environment should be done with great care, and a thorough analysis of what you are actually protecting against.

This is a job for people who take programming seriously, not amateurs who can't be bothered to read the documentation of the modules they are using, e.g.

http://stuvel.eu/files/python-rsa-doc/usage.html

Note especially the bits about signing RSA, and how to use it to encrypt files. Doing raw RSA on strings longer than 245 bytes is unwise, and inventing new protocols for RSA is unwise. That the author does these things is strong evidence that the author is not demonstrating "great care".

If the author believes forgery/tampering is orthogonal and/or protection from in-process attacks, then the author should state that. That's part of the analysis step.

> Of course, the key can be recovered if you have the ability to ptrace. What's your point? That's going to be true of any solution out there.

Nonsense. If you delete the key from memory, it is obvious that someone cannot use ptrace to recover it afterwards. Detailing what is at risk, and what is not at risk is part of the analysis step.

Re: Environment Variables Considered Harmful for Your Secrets

#117
post #104

Earlier quoted context omitted.

Using a setuid helper (even if it's called sudo) is still starting a program as root.

Not necessarily; sudo on Fedora has CAP_SETUID instead of the setuid bit, so it doesn't actually run as root. http://fedoraproject.org/wiki/Features/RemoveSETUID

But CAP_SETUID, unless I'm confusing it with something else, can be used to set the UID to 0 and thereby gain all the same privileges as if the program had been started as root, can't it? Presumably it has some advantage that I'm not getting – does it have to be combined with e.g. SELinux to be useful?

Re: Environment Variables Considered Harmful for Your Secrets

#118
post #116
post #108

Earlier quoted context omitted.

Your criticisms don't seem to make much sense... * Preventing forgery/tampering is an orthogonal issue and can be done by intrusion-detection software. * "trivially decrypted without the key" -- How? The size of the file is not going to make any difference here. * Of course, the key can be recovered if you have the ability to ptrace. What's your point? That's going to be true of any solution out there. Why don't you…

Writing software that may run in a potentially hostile environment should be done with great care, and a thorough analysis of what you are actually protecting against. This is a job for people who take programming seriously, not amateurs who can't be bothered to read the documentation of the modules they are using, e.g. http://stuvel.eu/files/python-rsa-doc/usage.html Note especially the bits about signing RSA, and h…

> Writing software that may run in a potentially hostile environment should be done with great care, and a thorough analysis of what you are actually protecting against.

The first section of his documentation states what the purpose of the module is and what's it is trying to protect against. The use of RSA there is pretty reasonable, so I don't know why you're being so hard on him. It also talks about how this project is a variation on another project, so it's not like he is going off half-cocked and implementing something crazy.

> This is a job for people who take programming seriously, not amateurs

Everyone starts out as an amateur. You can either be an internet know-it-all that wants to show off how little you know or you can provide constructive feedback.

> who can't be bothered to read the documentation of the modules they are using, e.g. http://stuvel.eu/files/python-rsa-doc/usage.html > Note especially the bits about signing RSA, and how to use it to encrypt files. Doing raw RSA on strings longer than 245 bytes is unwise, and inventing new protocols for RSA is unwise. That the author does these things is strong evidence that the author is not demonstrating "great care".

Did you bother to read the documentation yourself? It directly talks about encrypting large files. Yes, it's true that trying to encrypt more data than is supported for a key size will leak information, which is why implementations throw an error if you try to do that. The usage documentation you pointed to discusses that and provides options to cope with it. But, in this case, he is not even encrypting the whole file, just the values of certain properties, which are probably going to be small enough to not require any extra measures.

And, again, what does signing have to do with how RSA is being used in greybox?

> If the author believes forgery/tampering is orthogonal and/or protection from in-process attacks, then the author should state that. That's part of the analysis step.

They did state the scope of the project and there is really no need for them to go into deep detail about deployment. Are you going to criticize him for not pointing out that the whole system needs to be secured from tampering? Of course not, so stop acting like a douchebag.

>> Of course, the key can be recovered if you have the ability to ptrace. What's your point? That's going to be true of any solution out there. > Nonsense. If you delete the key from memory, it is obvious that someone cannot use ptrace to recover it afterwards. Detailing what is at risk, and what is not at risk is part of the analysis step.

You have to ask, where did the key come from in the first place? The private key file has to exist somewhere that is accessible on the box so that the process can read it in the first place. If someone has ptrace, they can probably read a file as well.

Ultimately, it's about the level of risk people are willing to live with. For what greybox seems targeted at, it's encrypting properties in files that are committed to a repo and then using a private key that is only available on certain machines to read that property. For some use cases, that is probably a perfectly fine level of security and better than what is being done in some cases anyways.

Re: Environment Variables Considered Harmful for Your Secrets

#119
post #118
post #116

Earlier quoted context omitted.

Writing software that may run in a potentially hostile environment should be done with great care, and a thorough analysis of what you are actually protecting against. This is a job for people who take programming seriously, not amateurs who can't be bothered to read the documentation of the modules they are using, e.g. http://stuvel.eu/files/python-rsa-doc/usage.html Note especially the bits about signing RSA, and h…

> Writing software that may run in a potentially hostile environment should be done with great care, and a thorough analysis of what you are actually protecting against. The first section of his documentation states what the purpose of the module is and what's it is trying to protect against. The use of RSA there is pretty reasonable, so I don't know why you're being so hard on him. It also talks about how this proje…

> You have to ask, where did the key come from in the first place?

It is sensible to type it in while the system is still in single-user mode.

If you left the private key in a file that is right next to your encrypted configuration file, then it remains as I stated previously: No security except false security.

> Everyone starts out as an amateur.

This is not the forum for an education on programming. A library that states it was written as a learning exercise with a request for criticism will be treated that way. A library proposed to solve problems recognised in the linked article will not.

> Ultimately, it's about the level of risk people are willing to live with.

People are notoriously bad at recognising and evaluating risk.

Re: Environment Variables Considered Harmful for Your Secrets

#120
post #119
post #118

Earlier quoted context omitted.

> Writing software that may run in a potentially hostile environment should be done with great care, and a thorough analysis of what you are actually protecting against. The first section of his documentation states what the purpose of the module is and what's it is trying to protect against. The use of RSA there is pretty reasonable, so I don't know why you're being so hard on him. It also talks about how this proje…

> You have to ask, where did the key come from in the first place? It is sensible to type it in while the system is still in single-user mode. If you left the private key in a file that is right next to your encrypted configuration file, then it remains as I stated previously: No security except false security. > Everyone starts out as an amateur. This is not the forum for an education on programming. A library that…

> If you left the private key in a file that is right next to your encrypted configuration file, then it remains as I stated previously: No security except false security.

Shut up and read the goal of the project already. It is trying to protect secrets that are stored in a repo and it achieves that goal.

Secrets on a deployed host will always be in the clear on that host, it's just a fact of life. Many barriers can be put in place, but at the end of the day, a program will always need access to the plaintext version of the secret at some point.

> It is sensible to type it in while the system is still in single-user mode.

No it isn't. Services have to restart all the time, saying that a human has to be ready to type in a password at any moment is not practical.

> This is not the forum for an education on programming.

But it is a forum for you to post invalid criticisms of a project and act like a dick? That's bullshit. This is "hacker news", it's a perfectly fine place for a technical discussion. If you thought there were problems with the project and this wasn't the right place to discuss it, then file issues on the github project.

> A library that states it was written as a learning exercise with a request for criticism will be treated that way. A library proposed to solve problems recognised in the linked article will not.

There is no difference, you're just trying to justify your bad behavior.

Post reply on HN