Created
February 4, 2022 13:05
-
-
Save AnatomicJC/60b7be52e89a59e847abddd02d0b1efc to your computer and use it in GitHub Desktop.
passbolt user creation automation example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
set -euo pipefail | |
TMPGNUPGHOME=$(mktemp -d) | |
EMAIL="email@domain.tld" | |
PASSPHRASE="strong-passphrase" | |
FIRSTNAME="John" | |
LASTNAME="Doe" | |
KEYSIZE=2048 | |
PASSBOLT_FQDN="passbolt.domain.tld" | |
# Register a new user and get its uuid + token registration | |
REGISTRATION_URL=$(sudo -H -u www-data bash -c "/usr/share/php/passbolt/bin/cake passbolt register_user -u ${EMAIL} -f ${FIRSTNAME} -l ${LASTNAME} -r user" | grep http) | |
USER_UUID=$(echo "${REGISTRATION_URL}" | cut -d/ -f6) | |
USER_TOKEN=$(echo "${REGISTRATION_URL}" | cut -d/ -f7) | |
# Generate OpenPGP keys | |
gpg --homedir ${TMPGNUPGHOME} --batch --no-tty --gen-key <<EOF | |
Key-Type: default | |
Key-Length: ${KEYSIZE} | |
Subkey-Type: default | |
Subkey-Length: 2048 | |
Name-Real: ${FIRSTNAME} ${LASTNAME} | |
Name-Email: ${EMAIL} | |
Expire-Date: 0 | |
Passphrase: ${PASSPHRASE} | |
%commit | |
EOF | |
gpg --passphrase ${PASSPHRASE} --batch --pinentry-mode=loopback --armor --homedir ${TMPGNUPGHOME} --export-secret-keys ${EMAIL} > secret.asc | |
gpg --homedir ${TMPGNUPGHOME} --armor --export ${EMAIL} > public.asc | |
rm -rf ${TMPGNUPGHOME} | |
# Make an API call to register user | |
curl "https://${PASSBOLT_FQDN}/setup/complete/${USER_UUID}" \ | |
-H "authority: ${PASSBOLT_FQDN}" \ | |
-H "accept: application/json" \ | |
-H "content-type: application/json" \ | |
--data-raw "{\"authenticationtoken\":{\"token\":\"${USER_TOKEN}\"},\"gpgkey\":{\"armored_key\":\"$(sed -z 's/\n/\\n/g' public.asc)\"}}" \ | |
--compressed |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment