aienos.com
Source of www.aienos.com, served from my own hardware
Brought by drakestapleton
aienos.com / scripts / allen / pusher / omega-projects-pusher-activate
| 1 | #!/bin/bash |
| 2 | # omega-projects-pusher-activate: seal Drake's fine-grained token for the pusher. |
| 3 | # |
| 4 | # Drake first creates, in the GitHub web UI, a fine-grained personal access token with |
| 5 | # resource owner aien-dev, repository access "Only select repositories: omega-projects", |
| 6 | # and repository permissions Contents: Read and write, Issues: Read and write, |
| 7 | # Pull requests: Read and write (Metadata: Read is added automatically). Then: |
| 8 | # |
| 9 | # vault-add-secret OMEGA_PROJECTS_TOKEN # paste it; nothing is echoed |
| 10 | # omega-projects-pusher-activate # seal it for the pusher unit |
| 11 | # |
| 12 | # The value goes from the atlas vault straight into systemd-creds (host+tpm2) at |
| 13 | # /etc/credstore.encrypted/omega-projects-token; it is never printed or written in clear. |
| 14 | # The unit imports it with ImportCredential=; only the service's private credentials |
| 15 | # directory ever holds the decrypted value. |
| 16 | set -euo pipefail |
| 17 | cred=/etc/credstore.encrypted/omega-projects-token |
| 18 | token=$(atlas-vault get OMEGA_PROJECTS_TOKEN) || { echo "OMEGA_PROJECTS_TOKEN is not in the atlas vault" >&2; exit 1; } |
| 19 | if [[ ! $token =~ ^github_pat_[A-Za-z0-9_]{20,250}$ ]]; then |
| 20 | unset token |
| 21 | echo "OMEGA_PROJECTS_TOKEN is not a fine-grained github_pat_ token; refusing it" >&2 |
| 22 | exit 1 |
| 23 | fi |
| 24 | sudo -n install -d -m 0700 -o root -g root /etc/credstore.encrypted |
| 25 | printf '%s' "$token" | sudo -n systemd-creds encrypt --with-key=host+tpm2 \ |
| 26 | --name=omega-projects-token - "$cred.new" |
| 27 | unset token |
| 28 | sudo -n chmod 0600 "$cred.new" |
| 29 | sudo -n mv "$cred.new" "$cred" |
| 30 | echo "sealed $cred; starting omega-projects-pusher.service for any queued items" |
| 31 | sudo -n systemctl start --no-block omega-projects-pusher.service |