You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

75 lines
2.4 KiB

  1. #!/bin/bash
  2. ######################################################
  3. # Name: update-NebulaNodeCert
  4. # Description: Creates a new cert for a node based
  5. # on the node cert provided.
  6. #
  7. # Created By: HMSheets
  8. ######################################################
  9. POSITIONAL=()
  10. while [[ $# -gt 0 ]]
  11. do
  12. key="$1"
  13. case $key in
  14. -n|--nodecertname)
  15. NODECERTNAME="$2"
  16. shift # past argument
  17. shift # past value
  18. ;;
  19. -r|--rootpath) # do not add a trailing '/'
  20. ROOTPATH="$2"
  21. shift # past argument
  22. shift # past value
  23. ;;
  24. -c|--cacertname)
  25. CACERTNAME="$2"
  26. shift # past argument
  27. shift # past value
  28. ;;
  29. -k|--cakeyname)
  30. CAKEYNAME="$2"
  31. shift # past argument
  32. shift # past value
  33. ;;
  34. *) # unknown option
  35. POSITIONAL+=("$1") # save it in an array for later
  36. shift # past argument
  37. ;;
  38. esac
  39. done
  40. set -- "${POSITIONAL[@]}" # restore positional parameters
  41. if [[ -n $1 ]]; then
  42. echo "Invalid Parameter(s) Entered: $1"
  43. exit
  44. fi
  45. DATETIME=$(date '+%Y%m%d-%H%M%S')
  46. NODENAME=$(${ROOTPATH}/nebula-cert print -path ${ROOTPATH}/${NODECERTNAME} -json | jq -s .[].details.name | sed 's/["]//g')
  47. NODEIPS=$(${ROOTPATH}/nebula-cert print -path ${ROOTPATH}/${NODECERTNAME} -json | jq -s --compact-output .[].details.ips | sed 's/[]["]//g')
  48. NODEGROUPS=$(${ROOTPATH}/nebula-cert print -path ${ROOTPATH}/${NODECERTNAME} -json | jq -s --compact-output .[].details.groups | sed 's/[]["]//g') # | sed 's/,/ /g'))
  49. CERTISCASTATUS=$(${ROOTPATH}/nebula-cert print -path ${ROOTPATH}/${NODECERTNAME} -json | jq -s --compact-output .[].details.isCa)
  50. # Create new file name variable
  51. NEWFILENAME="${NODENAME}_${DATETIME}"
  52. if [[ $CERTISCASTATUS == true ]]; then
  53. echo "Certificate is the root CA Certificate. Try again with a node certificate."
  54. exit
  55. fi
  56. if [[ $CERTISCASTATUS == false ]]; then
  57. echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  58. echo "Node Name: ${NODENAME}"
  59. echo "Node IPs: ${NODEIPS}"
  60. echo "Node Groups: ${NODEGROUPS[@]}"
  61. echo "Certificate isCa Status: ${CERTISCASTATUS}"
  62. echo "DateTime: ${DATETIME}"
  63. echo "NEWFILENAME: ${NEWFILENAME}"
  64. echo "~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~"
  65. ${ROOTPATH}/nebula-cert sign -groups ${NODEGROUPS[@]} -ip ${NODEIPS} -name ${NODENAME} -ca-crt ${ROOTPATH}/${CACERTNAME} -ca-key ${ROOTPATH}/${CAKEYNAME} -out-crt ${ROOTPATH}/${NEWFILENAME}.crt -out-key ${ROOTPATH}/${NEWFILENAME}.key
  66. fi