Skip to content

Instantly share code, notes, and snippets.

@havenwood
Last active December 12, 2015 02:38
Show Gist options
  • Save havenwood/4699887 to your computer and use it in GitHub Desktop.
Save havenwood/4699887 to your computer and use it in GitHub Desktop.
If `credentials` file still has 0644 legacy permissions, update to 0600

Existing code from lib/rubygems/config_file.rb:

def credentials_path
  File.join Gem.user_home, '.gem', 'credentials'
end

permissions = 0600 & (~File.umask)
File.open(credentials_path, 'w', permissions) do |f|
  f.write config.to_yaml
end

The above doesn't deal with existing credentials files with 0644 permissions. Would something along these lines be able to go somewhere reasonable to update existing credentials to 0600?:

if File.exist? credentials_path
  unless File.stat(credentials_path).mode.to_s(8).end_with? '0600'
    File.chmod 0600, credentials_path
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment