BlueGit

timfa posprint

Accept File+base64 AUR SSH keys in CI setup.

Co-authored-by: Cursor <cursoragent@cursor.com>

timfa Tim Falken · pushed by timfa

Authored 2026-07-21 · 3 months ago

Hash
b5f13e34894477085a67df34c7565bdd9e9ba3d6
Parent
45865615
2 files changed +52 −17
docs/AUR.md +12 −11
@@ -45,22 +45,22 @@ When a Git tag is pushed:
45 45
46 46 ## GitLab CI secrets
47 47
48 GitLab **masked** variables cannot contain spaces or newlines. An OpenSSH private key is multiline, so do **not** paste the raw private key into a masked variable.
48 GitLab **masked** variables cannot contain spaces or newlines. An OpenSSH private key is multiline, so do **not** paste the raw private key into a masked **Variable**.
49 49
50 Use **one** of these:
50 Use **exactly one** of these setups (do not mix File + base64 unless using the auto-detect path below):
51 51
52 ### Option A — File variable (simplest)
52 ### Option A — File + raw key (simplest)
53 53
54 54 | Variable | Type | Value |
55 55 |----------|------|--------|
56 | `AUR_SSH_PRIVATE_KEY` | **File** | Paste the full private key file (including `BEGIN` / `END` lines) |
56 | `AUR_SSH_PRIVATE_KEY` | **File** | Full private key text, including `-----BEGIN OPENSSH PRIVATE KEY-----` / `END` lines |
57 57 | `AUR_GIT_AUTHOR_NAME` | Variable | Your name |
58 58 | `AUR_GIT_AUTHOR_EMAIL` | Variable | Your email |
59 59 | `AUR_PKGBASE` | Variable (optional) | Defaults to `posprint` |
60 60
61 61 Mark `AUR_SSH_PRIVATE_KEY` as **Protected**. File variables cannot be masked; that is normal for SSH keys.
62 62
63 ### Option B — Base64 (maskable)
63 ### Option B — Variable + base64 (maskable)
64 64
65 65 On your machine, encode the private key as **one line** (no spaces):
66 66
@@ -72,16 +72,17 @@ base64 -w0 ~/.ssh/id_ed25519
72 72 base64 -i ~/.ssh/id_ed25519 | tr -d '\n'
73 73
74 74 # PowerShell (Windows)
75 [Convert]::ToBase64String([IO.File]::ReadAllBytes("$env:USERPROFILE\.ssh\id_ed25519"))
75 [Convert]::ToBase64String([IO.File]::ReadAllBytes("$env:USERPROFILE\.ssh\id_ed25519_aur_ci"))
76 76 ```
77 77
78 Store the output in GitLab as:
78 | Variable | Type | Value |
79 |----------|------|--------|
80 | `AUR_SSH_PRIVATE_KEY_B64` | **Variable** (not File) | The single-line base64 string; **Masked** + **Protected** |
79 81
80 | Variable | Notes |
81 |----------|--------|
82 | `AUR_SSH_PRIVATE_KEY_B64` | The single-line base64 string; can be **Masked** + **Protected** |
82 ### Common mistake
83 83
84 CI decodes it via `scripts/aur-ssh-setup.sh`.
84 **File type + base64 contents** under `AUR_SSH_PRIVATE_KEY` used to fail with `Load key: invalid format`.
85 `scripts/aur-ssh-setup.sh` now auto-detects that and decodes, but prefer Option A or B above.
85 86
86 87 ### Public vs private key
87 88
@@ -45,22 +45,22 @@ When a Git tag is pushed:
45
45
46## GitLab CI secrets
46## GitLab CI secrets
47
47
48GitLab **masked** variables cannot contain spaces or newlines. An OpenSSH private key is multiline, so do **not** paste the raw private key into a masked variable.
48GitLab **masked** variables cannot contain spaces or newlines. An OpenSSH private key is multiline, so do **not** paste the raw private key into a masked **Variable**.
49
49
50Use **one** of these:
50Use **exactly one** of these setups (do not mix File + base64 unless using the auto-detect path below):
51
51
52### Option A — File variable (simplest)
52### Option A — File + raw key (simplest)
53
53
54| Variable | Type | Value |
54| Variable | Type | Value |
55|----------|------|--------|
55|----------|------|--------|
56| `AUR_SSH_PRIVATE_KEY` | **File** | Paste the full private key file (including `BEGIN` / `END` lines) |
56| `AUR_SSH_PRIVATE_KEY` | **File** | Full private key text, including `-----BEGIN OPENSSH PRIVATE KEY-----` / `END` lines |
57| `AUR_GIT_AUTHOR_NAME` | Variable | Your name |
57| `AUR_GIT_AUTHOR_NAME` | Variable | Your name |
58| `AUR_GIT_AUTHOR_EMAIL` | Variable | Your email |
58| `AUR_GIT_AUTHOR_EMAIL` | Variable | Your email |
59| `AUR_PKGBASE` | Variable (optional) | Defaults to `posprint` |
59| `AUR_PKGBASE` | Variable (optional) | Defaults to `posprint` |
60
60
61Mark `AUR_SSH_PRIVATE_KEY` as **Protected**. File variables cannot be masked; that is normal for SSH keys.
61Mark `AUR_SSH_PRIVATE_KEY` as **Protected**. File variables cannot be masked; that is normal for SSH keys.
62
62
63### Option B — Base64 (maskable)
63### Option B — Variable + base64 (maskable)
64
64
65On your machine, encode the private key as **one line** (no spaces):
65On your machine, encode the private key as **one line** (no spaces):
66
66
@@ -72,16 +72,17 @@ base64 -w0 ~/.ssh/id_ed25519
72base64 -i ~/.ssh/id_ed25519 | tr -d '\n'
72base64 -i ~/.ssh/id_ed25519 | tr -d '\n'
73
73
74# PowerShell (Windows)
74# PowerShell (Windows)
75[Convert]::ToBase64String([IO.File]::ReadAllBytes("$env:USERPROFILE\.ssh\id_ed25519"))
75[Convert]::ToBase64String([IO.File]::ReadAllBytes("$env:USERPROFILE\.ssh\id_ed25519_aur_ci"))
76```
76```
77
77
78Store the output in GitLab as:
78| Variable | Type | Value |
79|----------|------|--------|
80| `AUR_SSH_PRIVATE_KEY_B64` | **Variable** (not File) | The single-line base64 string; **Masked** + **Protected** |
79
81
80| Variable | Notes |
82### Common mistake
81|----------|--------|
82| `AUR_SSH_PRIVATE_KEY_B64` | The single-line base64 string; can be **Masked** + **Protected** |
83
83
84CI decodes it via `scripts/aur-ssh-setup.sh`.
84**File type + base64 contents** under `AUR_SSH_PRIVATE_KEY` used to fail with `Load key: invalid format`.
85`scripts/aur-ssh-setup.sh` now auto-detects that and decodes, but prefer Option A or B above.
85
86
86### Public vs private key
87### Public vs private key
87
88
scripts/aur-ssh-setup.sh +40 −6
@@ -2,21 +2,46 @@
2 2 # Write ~/.ssh/id_ed25519 for AUR pushes from CI or local scripts.
3 3 #
4 4 # Supported GitLab CI variables (pick one):
5 # AUR_SSH_PRIVATE_KEY_B64 — base64-encoded private key (one line; can be Masked)
6 # AUR_SSH_PRIVATE_KEY — GitLab "File" variable (path to temp file), or raw key text
5 # AUR_SSH_PRIVATE_KEY_B64 — base64 of the private key (Variable type, one line; Masked OK)
6 # or File type whose contents are that base64 string
7 # AUR_SSH_PRIVATE_KEY — raw OpenSSH private key (File type preferred), or raw key text
8 # File contents may also be base64 (auto-detected)
7 9 set -euo pipefail
8 10
9 11 KEY_PATH="${1:-$HOME/.ssh/id_ed25519}"
10 12
11 13 install -d -m 700 "$(dirname "$KEY_PATH")"
12 14
15 is_raw_ssh_key() {
16 grep -qE 'BEGIN (OPENSSH |RSA |EC )?PRIVATE KEY' "$1" 2>/dev/null
17 }
18
19 decode_b64_to_key() {
20 local src="$1"
21 if [[ -f "$src" ]]; then
22 # GitLab File variable: env value is a path to a temp file
23 tr -d '\r\n[:space:]' < "$src" | base64 -d > "$KEY_PATH"
24 else
25 # Variable type: env value is the base64 string itself
26 printf '%s' "$src" | tr -d '\r\n[:space:]' | base64 -d > "$KEY_PATH"
27 fi
28 }
29
13 30 if [[ -n "${AUR_SSH_PRIVATE_KEY_B64:-}" ]]; then
14 echo "$AUR_SSH_PRIVATE_KEY_B64" | base64 -d > "$KEY_PATH"
31 decode_b64_to_key "$AUR_SSH_PRIVATE_KEY_B64"
15 32 elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" && -f "${AUR_SSH_PRIVATE_KEY}" ]]; then
16 # GitLab CI/CD variable type "File"
17 cp "$AUR_SSH_PRIVATE_KEY" "$KEY_PATH"
33 if is_raw_ssh_key "$AUR_SSH_PRIVATE_KEY"; then
34 cp "$AUR_SSH_PRIVATE_KEY" "$KEY_PATH"
35 else
36 # File variable mistakenly filled with base64 instead of raw PEM
37 decode_b64_to_key "$AUR_SSH_PRIVATE_KEY"
38 fi
18 39 elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" ]]; then
19 printf '%s\n' "$AUR_SSH_PRIVATE_KEY" > "$KEY_PATH"
40 if printf '%s' "$AUR_SSH_PRIVATE_KEY" | grep -qE 'BEGIN (OPENSSH |RSA |EC )?PRIVATE KEY'; then
41 printf '%s\n' "$AUR_SSH_PRIVATE_KEY" > "$KEY_PATH"
42 else
43 decode_b64_to_key "$AUR_SSH_PRIVATE_KEY"
44 fi
20 45 elif [[ -f "$HOME/.ssh/id_ed25519" ]]; then
21 46 cp "$HOME/.ssh/id_ed25519" "$KEY_PATH"
22 47 else
@@ -25,4 +50,13 @@ else
25 50 fi
26 51
27 52 chmod 600 "$KEY_PATH"
53
54 if ! is_raw_ssh_key "$KEY_PATH"; then
55 echo "AUR SSH key is not a valid OpenSSH private key after setup." >&2
56 echo "Use either:" >&2
57 echo " - AUR_SSH_PRIVATE_KEY as File with raw key (BEGIN ... PRIVATE KEY)" >&2
58 echo " - AUR_SSH_PRIVATE_KEY_B64 as Variable with one-line base64 of that key" >&2
59 exit 1
60 fi
61
28 62 ssh-keyscan aur.archlinux.org >> "$HOME/.ssh/known_hosts" 2>/dev/null || true
@@ -2,21 +2,46 @@
2# Write ~/.ssh/id_ed25519 for AUR pushes from CI or local scripts.
2# Write ~/.ssh/id_ed25519 for AUR pushes from CI or local scripts.
3#
3#
4# Supported GitLab CI variables (pick one):
4# Supported GitLab CI variables (pick one):
5# AUR_SSH_PRIVATE_KEY_B64 — base64-encoded private key (one line; can be Masked)
5# AUR_SSH_PRIVATE_KEY_B64 — base64 of the private key (Variable type, one line; Masked OK)
6# AUR_SSH_PRIVATE_KEY — GitLab "File" variable (path to temp file), or raw key text
6# or File type whose contents are that base64 string
7# AUR_SSH_PRIVATE_KEY — raw OpenSSH private key (File type preferred), or raw key text
8# File contents may also be base64 (auto-detected)
7set -euo pipefail
9set -euo pipefail
8
10
9KEY_PATH="${1:-$HOME/.ssh/id_ed25519}"
11KEY_PATH="${1:-$HOME/.ssh/id_ed25519}"
10
12
11install -d -m 700 "$(dirname "$KEY_PATH")"
13install -d -m 700 "$(dirname "$KEY_PATH")"
12
14
15is_raw_ssh_key() {
16 grep -qE 'BEGIN (OPENSSH |RSA |EC )?PRIVATE KEY' "$1" 2>/dev/null
17}
18
19decode_b64_to_key() {
20 local src="$1"
21 if [[ -f "$src" ]]; then
22 # GitLab File variable: env value is a path to a temp file
23 tr -d '\r\n[:space:]' < "$src" | base64 -d > "$KEY_PATH"
24 else
25 # Variable type: env value is the base64 string itself
26 printf '%s' "$src" | tr -d '\r\n[:space:]' | base64 -d > "$KEY_PATH"
27 fi
28}
29
13if [[ -n "${AUR_SSH_PRIVATE_KEY_B64:-}" ]]; then
30if [[ -n "${AUR_SSH_PRIVATE_KEY_B64:-}" ]]; then
14 echo "$AUR_SSH_PRIVATE_KEY_B64" | base64 -d > "$KEY_PATH"
31 decode_b64_to_key "$AUR_SSH_PRIVATE_KEY_B64"
15elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" && -f "${AUR_SSH_PRIVATE_KEY}" ]]; then
32elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" && -f "${AUR_SSH_PRIVATE_KEY}" ]]; then
16 # GitLab CI/CD variable type "File"
33 if is_raw_ssh_key "$AUR_SSH_PRIVATE_KEY"; then
17 cp "$AUR_SSH_PRIVATE_KEY" "$KEY_PATH"
34 cp "$AUR_SSH_PRIVATE_KEY" "$KEY_PATH"
35 else
36 # File variable mistakenly filled with base64 instead of raw PEM
37 decode_b64_to_key "$AUR_SSH_PRIVATE_KEY"
38 fi
18elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" ]]; then
39elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" ]]; then
19 printf '%s\n' "$AUR_SSH_PRIVATE_KEY" > "$KEY_PATH"
40 if printf '%s' "$AUR_SSH_PRIVATE_KEY" | grep -qE 'BEGIN (OPENSSH |RSA |EC )?PRIVATE KEY'; then
41 printf '%s\n' "$AUR_SSH_PRIVATE_KEY" > "$KEY_PATH"
42 else
43 decode_b64_to_key "$AUR_SSH_PRIVATE_KEY"
44 fi
20elif [[ -f "$HOME/.ssh/id_ed25519" ]]; then
45elif [[ -f "$HOME/.ssh/id_ed25519" ]]; then
21 cp "$HOME/.ssh/id_ed25519" "$KEY_PATH"
46 cp "$HOME/.ssh/id_ed25519" "$KEY_PATH"
22else
47else
@@ -25,4 +50,13 @@ else
25fi
50fi
26
51
27chmod 600 "$KEY_PATH"
52chmod 600 "$KEY_PATH"
53
54if ! is_raw_ssh_key "$KEY_PATH"; then
55 echo "AUR SSH key is not a valid OpenSSH private key after setup." >&2
56 echo "Use either:" >&2
57 echo " - AUR_SSH_PRIVATE_KEY as File with raw key (BEGIN ... PRIVATE KEY)" >&2
58 echo " - AUR_SSH_PRIVATE_KEY_B64 as Variable with one-line base64 of that key" >&2
59 exit 1
60fi
61
28ssh-keyscan aur.archlinux.org >> "$HOME/.ssh/known_hosts" 2>/dev/null || true
62ssh-keyscan aur.archlinux.org >> "$HOME/.ssh/known_hosts" 2>/dev/null || true