rotate_mdradmin.sh 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. #! /usr/local/bin/bash
  2. #
  3. # Requires a new bash than comes with OS X. Install bash from homebrew
  4. # via `brew install bash`
  5. ALL_PROFILES=$( egrep "\[profile" ~/.aws/config | \
  6. awk '{ print $2 }' | \
  7. sed "s/\]//" | \
  8. egrep -v "default|commercial|govcloud" )
  9. read -p "THIS WILL RESET THE MDRADMIN USER PASSWORD IN EVERY PROFILE. Continue [y/N]? " -n 1 -r
  10. if [[ $REPLY =~ ^[Yy]$ ]]; then
  11. echo ""
  12. else
  13. echo Exiting...
  14. exit 10
  15. fi
  16. echo ""
  17. echo "Copy and paste the following into the vault under engineering/cloud/aws/root-credits/MDRAdmin"
  18. echo "If there are errors, try running a second (or third) time"
  19. echo ""
  20. echo \{
  21. for p in $ALL_PROFILES; do
  22. NEWPASS=$( </dev/urandom LC_ALL=C tr -dc 'A-Za-z0-9@#%_+=' | head -c 32 )
  23. # The "@Q" syntax ensures the password is shell escaped
  24. aws --profile $p iam update-login-profile --user-name MDRAdmin --no-password-reset-required --password ${NEWPASS@Q} > /dev/null
  25. echo \ \ \"${p}\": \"${NEWPASS}\",
  26. done
  27. # Trailing comma is a problem, so we'll just add the date
  28. echo \ \ \"LAST_UPDATED\": \"$(date)\"
  29. echo \}