Accept File+base64 AUR SSH keys in CI setup.
Co-authored-by: Cursor <cursoragent@cursor.com>
@@ -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 secrets46
## GitLab CI secrets47
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
| 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
61
Mark `AUR_SSH_PRIVATE_KEY` as **Protected**. File variables cannot be masked; that is normal for SSH keys.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
On your machine, encode the private key as **one line** (no spaces):65
On your machine, encode the private key as **one line** (no spaces):66
66
@@ -72,16 +72,17 @@ base64 -w0 ~/.ssh/id_ed2551972
base64 -i ~/.ssh/id_ed25519 | tr -d '\n'72
base64 -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
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 |82
### Common mistake81
|----------|--------|82
| `AUR_SSH_PRIVATE_KEY_B64` | The single-line base64 string; can be **Masked** + **Protected** |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
### Public vs private key87
### Public vs private key87
88
@@ -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 text6
# or File type whose contents are that base64 string7
# AUR_SSH_PRIVATE_KEY — raw OpenSSH private key (File type preferred), or raw key text8
# File contents may also be base64 (auto-detected)7
set -euo pipefail9
set -euo pipefail8
10
9
KEY_PATH="${1:-$HOME/.ssh/id_ed25519}"11
KEY_PATH="${1:-$HOME/.ssh/id_ed25519}"10
12
11
install -d -m 700 "$(dirname "$KEY_PATH")"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/null17
}18
19
decode_b64_to_key() {20
local src="$1"21
if [[ -f "$src" ]]; then22
# GitLab File variable: env value is a path to a temp file23
tr -d '\r\n[:space:]' < "$src" | base64 -d > "$KEY_PATH"24
else25
# Variable type: env value is the base64 string itself26
printf '%s' "$src" | tr -d '\r\n[:space:]' | base64 -d > "$KEY_PATH"27
fi28
}29
13
if [[ -n "${AUR_SSH_PRIVATE_KEY_B64:-}" ]]; then30
if [[ -n "${AUR_SSH_PRIVATE_KEY_B64:-}" ]]; then14
echo "$AUR_SSH_PRIVATE_KEY_B64" | base64 -d > "$KEY_PATH"31
decode_b64_to_key "$AUR_SSH_PRIVATE_KEY_B64"15
elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" && -f "${AUR_SSH_PRIVATE_KEY}" ]]; then32
elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" && -f "${AUR_SSH_PRIVATE_KEY}" ]]; then16
# GitLab CI/CD variable type "File"33
if is_raw_ssh_key "$AUR_SSH_PRIVATE_KEY"; then17
cp "$AUR_SSH_PRIVATE_KEY" "$KEY_PATH"34
cp "$AUR_SSH_PRIVATE_KEY" "$KEY_PATH"35
else36
# File variable mistakenly filled with base64 instead of raw PEM37
decode_b64_to_key "$AUR_SSH_PRIVATE_KEY"38
fi18
elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" ]]; then39
elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" ]]; then19
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'; then41
printf '%s\n' "$AUR_SSH_PRIVATE_KEY" > "$KEY_PATH"42
else43
decode_b64_to_key "$AUR_SSH_PRIVATE_KEY"44
fi20
elif [[ -f "$HOME/.ssh/id_ed25519" ]]; then45
elif [[ -f "$HOME/.ssh/id_ed25519" ]]; then21
cp "$HOME/.ssh/id_ed25519" "$KEY_PATH"46
cp "$HOME/.ssh/id_ed25519" "$KEY_PATH"22
else47
else@@ -25,4 +50,13 @@ else25
fi50
fi26
51
27
chmod 600 "$KEY_PATH"52
chmod 600 "$KEY_PATH"53
54
if ! is_raw_ssh_key "$KEY_PATH"; then55
echo "AUR SSH key is not a valid OpenSSH private key after setup." >&256
echo "Use either:" >&257
echo " - AUR_SSH_PRIVATE_KEY as File with raw key (BEGIN ... PRIVATE KEY)" >&258
echo " - AUR_SSH_PRIVATE_KEY_B64 as Variable with one-line base64 of that key" >&259
exit 160
fi61
28
ssh-keyscan aur.archlinux.org >> "$HOME/.ssh/known_hosts" 2>/dev/null || true62
ssh-keyscan aur.archlinux.org >> "$HOME/.ssh/known_hosts" 2>/dev/null || true