Live data from Hacker News

Keeping secrets out of logs (2024)

allan.reyes.sh

21–30 of 56 posts

Re: Keeping secrets out of logs (2024)

#21

One particular thing to be careful of are core dumps. What I did at a previous shop was remove the passwords as part of a smart gdb script that runs when the core is dumped, before it gets written to a readable location. Writing the script also helped to demonstrate how to extract the passwords in the first place.

Stack traces, too. I did some work with a heavy Java shop and pretty much everything sensitive ended up in a stack trace at some point.

Re: Keeping secrets out of logs (2024)

#22
post #20

Earlier quoted context omitted.

Why is logging everything considered lazy?

for one it's extremely costly, in vcpu , storage , transfer rates. and if you're paying a third-party logger , multiply each by 10x

If you're in a testing environment, where your SIT and UAT are looking to break stuff though, don't you usually want to be able to look to a log of everything?

Re: Keeping secrets out of logs (2024)

#23
I think the big problem is when secrets can be anywhere in a string and you don't control the input (e.g, library stacktraces, HTTP responses, JSON that was stringified). You need to pass the secrets to the logger so it can be redacted, it's heavily dependent on the dev and easy to forget during review.

And an exact match is just part of the problem; if a dev redacts the end and another dev redacts the start, you can still reassemble the secret with enough logs.

Re: Keeping secrets out of logs (2024)

#24
post #20

Earlier quoted context omitted.

Why is logging everything considered lazy?

for one it's extremely costly, in vcpu , storage , transfer rates. and if you're paying a third-party logger , multiply each by 10x

That makes it foolish, but I'm not sure if it's lazy.

Re: Keeping secrets out of logs (2024)

#25
post #23

I think the big problem is when secrets can be anywhere in a string and you don't control the input (e.g, library stacktraces, HTTP responses, JSON that was stringified). You need to pass the secrets to the logger so it can be redacted, it's heavily dependent on the dev and easy to forget during review. And an exact match is just part of the problem; if a dev redacts the end and another dev redacts the start, you can…

One direction to venture would be running rsyslog on every node, using regex to match all the known patterns and use various plugins/addons to send all the applications to the local rsyslog instance using a local spooler and then encrypt the rsyslog upstream to centralized logging servers. Rsyslog supports using a spooler so that if the up-stream server is offline for whatever reason the logs are spooled locally and then resume when upstream is online.

Regex matching on logs is slow but if performed on every node the CPU load is distributed vs. doing this upstream. Configuration management can push the regex rules to all the nodes. This won't help with unknown-unknowns but those can be added quickly to all nodes through configuration management after peer review.

Rsyslog also supports encrypting the log stream so that secret leakage is limited to the sending nodes and the central nodes and it checks a few boxes.

Another thing that helps is limiting to warn and above sent upstream and using an agent on the local nodes to monitor for keywords in the range of info to debug to let someone know to go check the node logs. Less junk on the centralized servers that may have SOC1/SOC2/PCI/FEDRAMP log retention requirements. One can not leak what is not sent in the first place.

Re: Keeping secrets out of logs (2024)

#26

I think secrets ending up in the log is an issue but who should have access to view logs of what log should also be an important that is often ignored. This is also scope down the surface area of leakage.

A user's password is something I shouldn't see in a log, even if I'm in control of what gets logged and frequently access them to do my job.

Even if I trust me.

Audits happen. I assume other people will eventually see this bad practice.

Re: Keeping secrets out of logs (2024)

#27
post #20

Earlier quoted context omitted.

for one it's extremely costly, in vcpu , storage , transfer rates. and if you're paying a third-party logger , multiply each by 10x

That makes it foolish, but I'm not sure if it's lazy.

the lazy part comes from the fact that it's easier to be foolish in this case than to be selective about what gets logged. So lazy & foolish.

Re: Keeping secrets out of logs (2024)

#28
post #21

One particular thing to be careful of are core dumps. What I did at a previous shop was remove the passwords as part of a smart gdb script that runs when the core is dumped, before it gets written to a readable location. Writing the script also helped to demonstrate how to extract the passwords in the first place.

Stack traces, too. I did some work with a heavy Java shop and pretty much everything sensitive ended up in a stack trace at some point.

Java is just too verbose in every possible way.

Re: Keeping secrets out of logs (2024)

#29
post #22
post #20

Earlier quoted context omitted.

for one it's extremely costly, in vcpu , storage , transfer rates. and if you're paying a third-party logger , multiply each by 10x

If you're in a testing environment, where your SIT and UAT are looking to break stuff though, don't you usually want to be able to look to a log of everything?

I could see a couple reasons against. For one, it's expensive to seralize/encode your objects into the logger , even if you reduce logging level on prod.

Secondly, you can't represent the heap & stack well as strings. Concurrent threads and object trees are better debugged with a debugger (e.g. gdb).

Re: Keeping secrets out of logs (2024)

#30
This is an excellent write-up of the problem. New hires out of college/bootcamps often have no awareness of the risks here at all. Sometimes even engineers with years of experience but no operational mentorship in their career.

The kitchen sink example in particular is one that trips up people. Without knowing the specifics of how a library may deal with failure edge cases, it can catch you off guard (e.g., axios errors including API key headers).

A lot of these problems come from architectures where secrets go over the wire instead of just using signatures/ids. But in cases where you have to use some third party platform, there's often no choice.

Post reply on HN