interplane.Get Omega
Read in your language

aienos.com

Source of www.aienos.com, served from my own hardware

Brought by drakestapleton

branch main Branches Tags History

aienos.com / scripts / allen / pusher / omega-projects-pusher-activate

31 lines · 1667 bytes Raw Blame History
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.
16set -euo pipefail
17cred=/etc/credstore.encrypted/omega-projects-token
18token=$(atlas-vault get OMEGA_PROJECTS_TOKEN) || { echo "OMEGA_PROJECTS_TOKEN is not in the atlas vault" >&2; exit 1; }
19if [[ ! $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
23fi
24sudo -n install -d -m 0700 -o root -g root /etc/credstore.encrypted
25printf '%s' "$token" | sudo -n systemd-creds encrypt --with-key=host+tpm2 \
26 --name=omega-projects-token - "$cred.new"
27unset token
28sudo -n chmod 0600 "$cred.new"
29sudo -n mv "$cred.new" "$cred"
30echo "sealed $cred; starting omega-projects-pusher.service for any queued items"
31sudo -n systemctl start --no-block omega-projects-pusher.service