use stdlib SecureRandom to generate a password

Replaces the now-yanked passgen gem with something available in the Ruby
standard library. Why `.alphanumeric(72)`? This method will reliably
crank out 72-character strings that meet the upper, lower, and numeric
requirement of Azure.

From the docs on the Azure terraform provider:

> NOTE: admin_password must be between 6-72 characters long and must
> satisfy at least 3 of password complexity requirements from the
> following:
> 1. Contains an uppercase character
> 2. Contains a lowercase character
> 3. Contains a numeric digit
> 4. Contains a special character

So, this should suffice.

Signed-off-by: Robb Kidd <robb@thekidds.org>
This commit is contained in:
Robb Kidd 2019-07-01 13:30:53 -04:00
parent 8bcbaf6967
commit 30a4f8ea58
2 changed files with 2 additions and 3 deletions

View file

@ -28,7 +28,6 @@ group :test do
gem "mocha", "~> 1.1" gem "mocha", "~> 1.1"
gem "ruby-progressbar", "~> 1.8" gem "ruby-progressbar", "~> 1.8"
gem "webmock", "~> 3.0" gem "webmock", "~> 3.0"
gem "passgen"
gem "m" gem "m"
gem "pry", "~> 0.10" gem "pry", "~> 0.10"
gem "pry-byebug" gem "pry-byebug"

View file

@ -3,7 +3,6 @@
require "bundler" require "bundler"
require "bundler/gem_helper" require "bundler/gem_helper"
require "rake/testtask" require "rake/testtask"
require "passgen"
require "train" require "train"
require_relative "tasks/maintainers" require_relative "tasks/maintainers"
require_relative "tasks/spdx" require_relative "tasks/spdx"
@ -252,8 +251,9 @@ namespace :test do
creds = connection.options creds = connection.options
# Determine the storage account name and the admin password # Determine the storage account name and the admin password
require "securerandom"
sa_name = (0...15).map { (65 + rand(26)).chr }.join.downcase sa_name = (0...15).map { (65 + rand(26)).chr }.join.downcase
admin_password = Passgen.generate(length: 12, uppercase: true, lowercase: true, symbols: true, digits: true) admin_password = SecureRandom.alphanumeric(72)
# Use the first 4 characters of the storage account to create a suffix # Use the first 4 characters of the storage account to create a suffix
suffix = sa_name[0..3] suffix = sa_name[0..3]