CVE-2014-0135 - Kafo does not handle default_values.yaml securely
/tmp/default_values.yaml file has world readable permissions and does not check for existence when it's being created. Therefore it's prone to race-condition attacks. This file contains default values for all parameters (usually autogenerated passwords)Proposed fix steps:
- we'll use mktmpdir which will be passed to kafo_configure puppet module as a parameter
- kafo_configure puppet module will safely create file (check for non-existence, create file with 0600, then dumps data)
- packages (rpm, deb, gem) will remove any existing /tmp/default_values.yaml
#3 Updated by Kurt Seifried over 8 years ago
use Tempfile for files:
use tmpdir for directories (require ‘tmpdir’ and then you can “Dir.mktmpdir”):
I would suggest using Tempfile as well. Belt and suspenders.
#4 Updated by Dominic Cleal over 8 years ago
Using mktmpdir should be sufficient to make this safe, so the child Puppet process is told to only write into that shared temporary space. The bit that concerns me in the check for File.exist? in the Puppet function, which isn't safe against races.
Better is to use an exclusive open on the file which will fail to open the file at the kernel level if it already exists, i.e. http://stackoverflow.com/questions/5226166/how-do-open-a-file-for-writing-only-if-it-doesnt-already-exist-in-ruby
#5 Updated by Marek Hulán over 8 years ago
- File 0001-Fix-4648-store-default-values-securely.patch 0001-Fix-4648-store-default-values-securely.patch added
We could create a tempfile in puppet process but after the process finishes it would be removed. So we could create it rather from kafo but then in puppet process we can't be sure about the origin, therefore I think we should be happy with tmp dir only.
Good catch with File.open Dominic, I'm attaching fixed version for re-review.