Normalize CRLF in AUR SSH keys and document LF base64.
Co-authored-by: Cursor <cursoragent@cursor.com>
@@ -49,40 +49,40 @@ GitLab **masked** variables cannot contain spaces or newlines. An OpenSSH privat
49
49
50
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 + raw key (simplest)
52
### Option B — Variable + base64 (maskable; recommended from Windows)
53
53
54
| Variable | Type | Value |
55
|----------|------|--------|
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 |
58
| `AUR_GIT_AUTHOR_EMAIL` | Variable | Your email |
59
| `AUR_PKGBASE` | Variable (optional) | Defaults to `posprint` |
60
61
Mark `AUR_SSH_PRIVATE_KEY` as **Protected**. File variables cannot be masked; that is normal for SSH keys.
54
GitLab **Masked** variables cannot contain newlines. From Windows, pasting a raw key into a File variable often introduces **CRLF**, which makes Linux OpenSSH report `Load key: invalid format`.
62
55
63
### Option B — Variable + base64 (maskable)
56
Generate **LF-normalized** base64 of the **entire** key file (including BEGIN/END):
64
57
65
On your machine, encode the private key as **one line** (no spaces):
58
```powershell
59
$path = "$env:USERPROFILE\.ssh\id_ed25519_aur_ci"
60
$text = [IO.File]::ReadAllText($path) -replace "`r`n", "`n" -replace "`r", "`n"
61
if (-not $text.EndsWith("`n")) { $text += "`n" }
62
$b64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($text))
63
$b64
64
# Verify (must print BEGIN line):
65
[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($b64)).Substring(0, 35)
66
```
66
67
67
```bash
68
# Linux
69
base64 -w0 ~/.ssh/id_ed25519
68
| Variable | Type | Value |
69
|----------|------|--------|
70
| `AUR_SSH_PRIVATE_KEY_B64` | **Variable** (not File) | The single-line `$b64` string; **Masked** + **Protected** |
70
71
71
# macOS
72
base64 -i ~/.ssh/id_ed25519 | tr -d '\n'
72
Also set `AUR_GIT_AUTHOR_NAME` and `AUR_GIT_AUTHOR_EMAIL`.
73
Remove `AUR_SSH_PRIVATE_KEY` if it is also set (B64 is preferred by the setup script).
73
74
74
# PowerShell (Windows)
75
[Convert]::ToBase64String([IO.File]::ReadAllBytes("$env:USERPROFILE\.ssh\id_ed25519_aur_ci"))
76
```
75
### Option A — File + raw key
77
76
78
77
| Variable | Type | Value |
79
78
|----------|------|--------|
80
| `AUR_SSH_PRIVATE_KEY_B64` | **Variable** (not File) | The single-line base64 string; **Masked** + **Protected** |
81
82
### Common mistake
79
| `AUR_SSH_PRIVATE_KEY` | **File** | Full private key text, including `-----BEGIN OPENSSH PRIVATE KEY-----` / `END` lines |
80
| `AUR_GIT_AUTHOR_NAME` | Variable | Your name |
81
| `AUR_GIT_AUTHOR_EMAIL` | Variable | Your email |
82
| `AUR_PKGBASE` | Variable (optional) | Defaults to `posprint` |
83
83
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.
84
**Mask must be off** for File + raw key (newlines). Protected may stay on.
85
`scripts/aur-ssh-setup.sh` strips CR so Windows CRLF pastes still work (from 0.5.1+).
86
86
87
87
### Public vs private key
88
88
@@ -49,40 +49,40 @@ GitLab **masked** variables cannot contain spaces or newlines. An OpenSSH privat49
49
50
Use **exactly one** of these setups (do not mix File + base64 unless using the auto-detect path below):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 + raw key (simplest)52
### Option B — Variable + base64 (maskable; recommended from Windows)53
53
54
| Variable | Type | Value |54
GitLab **Masked** variables cannot contain newlines. From Windows, pasting a raw key into a File variable often introduces **CRLF**, which makes Linux OpenSSH report `Load key: invalid format`.55
|----------|------|--------|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 |58
| `AUR_GIT_AUTHOR_EMAIL` | Variable | Your email |59
| `AUR_PKGBASE` | Variable (optional) | Defaults to `posprint` |60
61
Mark `AUR_SSH_PRIVATE_KEY` as **Protected**. File variables cannot be masked; that is normal for SSH keys.62
55
63
### Option B — Variable + base64 (maskable)56
Generate **LF-normalized** base64 of the **entire** key file (including BEGIN/END):64
57
65
On your machine, encode the private key as **one line** (no spaces):58
```powershell59
$path = "$env:USERPROFILE\.ssh\id_ed25519_aur_ci"60
$text = [IO.File]::ReadAllText($path) -replace "`r`n", "`n" -replace "`r", "`n"61
if (-not $text.EndsWith("`n")) { $text += "`n" }62
$b64 = [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes($text))63
$b6464
# Verify (must print BEGIN line):65
[Text.Encoding]::UTF8.GetString([Convert]::FromBase64String($b64)).Substring(0, 35)66
```66
67
67
```bash68
| Variable | Type | Value |68
# Linux69
|----------|------|--------|69
base64 -w0 ~/.ssh/id_ed2551970
| `AUR_SSH_PRIVATE_KEY_B64` | **Variable** (not File) | The single-line `$b64` string; **Masked** + **Protected** |70
71
71
# macOS72
Also set `AUR_GIT_AUTHOR_NAME` and `AUR_GIT_AUTHOR_EMAIL`. 72
base64 -i ~/.ssh/id_ed25519 | tr -d '\n'73
Remove `AUR_SSH_PRIVATE_KEY` if it is also set (B64 is preferred by the setup script).73
74
74
# PowerShell (Windows)75
### Option A — File + raw key75
[Convert]::ToBase64String([IO.File]::ReadAllBytes("$env:USERPROFILE\.ssh\id_ed25519_aur_ci"))76
```77
76
78
| Variable | Type | Value |77
| Variable | Type | Value |79
|----------|------|--------|78
|----------|------|--------|80
| `AUR_SSH_PRIVATE_KEY_B64` | **Variable** (not File) | The single-line base64 string; **Masked** + **Protected** |79
| `AUR_SSH_PRIVATE_KEY` | **File** | Full private key text, including `-----BEGIN OPENSSH PRIVATE KEY-----` / `END` lines |81
80
| `AUR_GIT_AUTHOR_NAME` | Variable | Your name |82
### Common mistake81
| `AUR_GIT_AUTHOR_EMAIL` | Variable | Your email |82
| `AUR_PKGBASE` | Variable (optional) | Defaults to `posprint` |83
83
84
**File type + base64 contents** under `AUR_SSH_PRIVATE_KEY` used to fail with `Load key: invalid format`. 84
**Mask must be off** for File + raw key (newlines). Protected may stay on. 85
`scripts/aur-ssh-setup.sh` now auto-detects that and decodes, but prefer Option A or B above.85
`scripts/aur-ssh-setup.sh` strips CR so Windows CRLF pastes still work (from 0.5.1+).86
86
87
### Public vs private key87
### Public vs private key88
88
@@ -6,6 +6,8 @@
6
6
# or File type whose contents are that base64 string
7
7
# AUR_SSH_PRIVATE_KEY — raw OpenSSH private key (File type preferred), or raw key text
8
8
# File contents may also be base64 (auto-detected)
9
#
10
# Always normalizes CRLF → LF (Windows pastes into GitLab often break OpenSSH otherwise).
9
11
set -euo pipefail
10
12
11
13
KEY_PATH="${1:-$HOME/.ssh/id_ed25519}"
@@ -16,6 +18,19 @@ is_raw_ssh_key() {
16
18
grep -qE 'BEGIN (OPENSSH |RSA |EC )?PRIVATE KEY' "$1" 2>/dev/null
17
19
}
18
20
21
normalize_key_file() {
22
# Strip CR; ensure exactly one trailing newline (OpenSSH is picky).
23
local tmp
24
tmp="$(mktemp)"
25
tr -d '\r' < "$KEY_PATH" > "$tmp"
26
# Ensure file ends with a newline
27
if [[ -s "$tmp" ]] && [[ "$(tail -c1 "$tmp" | wc -l)" -eq 0 ]]; then
28
printf '\n' >> "$tmp"
29
fi
30
mv "$tmp" "$KEY_PATH"
31
chmod 600 "$KEY_PATH"
32
}
33
19
34
decode_b64_to_key() {
20
35
local src="$1"
21
36
if [[ -f "$src" ]]; then
@@ -33,7 +48,7 @@ elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" && -f "${AUR_SSH_PRIVATE_KEY}" ]]; then
33
48
if is_raw_ssh_key "$AUR_SSH_PRIVATE_KEY"; then
34
49
cp "$AUR_SSH_PRIVATE_KEY" "$KEY_PATH"
35
50
else
36
# File variable mistakenly filled with base64 instead of raw PEM
51
# File variable filled with base64 instead of raw PEM
37
52
decode_b64_to_key "$AUR_SSH_PRIVATE_KEY"
38
53
fi
39
54
elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" ]]; then
@@ -49,13 +64,20 @@ else
49
64
exit 1
50
65
fi
51
66
52
chmod 600 "$KEY_PATH"
67
normalize_key_file
53
68
54
69
if ! is_raw_ssh_key "$KEY_PATH"; then
55
70
echo "AUR SSH key is not a valid OpenSSH private key after setup." >&2
56
71
echo "Use either:" >&2
57
72
echo " - AUR_SSH_PRIVATE_KEY as File with raw key (BEGIN ... PRIVATE KEY)" >&2
58
73
echo " - AUR_SSH_PRIVATE_KEY_B64 as Variable with one-line base64 of that key" >&2
74
echo "Tip: generate base64 from a LF-normalized key (see docs/AUR.md)." >&2
75
exit 1
76
fi
77
78
# Cheap structural check without printing key material
79
if ! ssh-keygen -y -f "$KEY_PATH" >/dev/null 2>&1; then
80
echo "AUR SSH key failed ssh-keygen validation (often CRLF or truncated paste)." >&2
59
81
exit 1
60
82
fi
61
83
@@ -6,6 +6,8 @@6
# or File type whose contents are that base64 string6
# or File type whose contents are that base64 string7
# AUR_SSH_PRIVATE_KEY — raw OpenSSH private key (File type preferred), or raw key text7
# AUR_SSH_PRIVATE_KEY — raw OpenSSH private key (File type preferred), or raw key text8
# File contents may also be base64 (auto-detected)8
# File contents may also be base64 (auto-detected)9
#10
# Always normalizes CRLF → LF (Windows pastes into GitLab often break OpenSSH otherwise).9
set -euo pipefail11
set -euo pipefail10
12
11
KEY_PATH="${1:-$HOME/.ssh/id_ed25519}"13
KEY_PATH="${1:-$HOME/.ssh/id_ed25519}"@@ -16,6 +18,19 @@ is_raw_ssh_key() {16
grep -qE 'BEGIN (OPENSSH |RSA |EC )?PRIVATE KEY' "$1" 2>/dev/null18
grep -qE 'BEGIN (OPENSSH |RSA |EC )?PRIVATE KEY' "$1" 2>/dev/null17
}19
}18
20
21
normalize_key_file() {22
# Strip CR; ensure exactly one trailing newline (OpenSSH is picky).23
local tmp24
tmp="$(mktemp)"25
tr -d '\r' < "$KEY_PATH" > "$tmp"26
# Ensure file ends with a newline27
if [[ -s "$tmp" ]] && [[ "$(tail -c1 "$tmp" | wc -l)" -eq 0 ]]; then28
printf '\n' >> "$tmp"29
fi30
mv "$tmp" "$KEY_PATH"31
chmod 600 "$KEY_PATH"32
}33
19
decode_b64_to_key() {34
decode_b64_to_key() {20
local src="$1"35
local src="$1"21
if [[ -f "$src" ]]; then36
if [[ -f "$src" ]]; then@@ -33,7 +48,7 @@ elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" && -f "${AUR_SSH_PRIVATE_KEY}" ]]; then33
if is_raw_ssh_key "$AUR_SSH_PRIVATE_KEY"; then48
if is_raw_ssh_key "$AUR_SSH_PRIVATE_KEY"; then34
cp "$AUR_SSH_PRIVATE_KEY" "$KEY_PATH"49
cp "$AUR_SSH_PRIVATE_KEY" "$KEY_PATH"35
else50
else36
# File variable mistakenly filled with base64 instead of raw PEM51
# File variable filled with base64 instead of raw PEM37
decode_b64_to_key "$AUR_SSH_PRIVATE_KEY"52
decode_b64_to_key "$AUR_SSH_PRIVATE_KEY"38
fi53
fi39
elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" ]]; then54
elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" ]]; then@@ -49,13 +64,20 @@ else49
exit 164
exit 150
fi65
fi51
66
52
chmod 600 "$KEY_PATH"67
normalize_key_file53
68
54
if ! is_raw_ssh_key "$KEY_PATH"; then69
if ! is_raw_ssh_key "$KEY_PATH"; then55
echo "AUR SSH key is not a valid OpenSSH private key after setup." >&270
echo "AUR SSH key is not a valid OpenSSH private key after setup." >&256
echo "Use either:" >&271
echo "Use either:" >&257
echo " - AUR_SSH_PRIVATE_KEY as File with raw key (BEGIN ... PRIVATE KEY)" >&272
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" >&273
echo " - AUR_SSH_PRIVATE_KEY_B64 as Variable with one-line base64 of that key" >&274
echo "Tip: generate base64 from a LF-normalized key (see docs/AUR.md)." >&275
exit 176
fi77
78
# Cheap structural check without printing key material79
if ! ssh-keygen -y -f "$KEY_PATH" >/dev/null 2>&1; then80
echo "AUR SSH key failed ssh-keygen validation (often CRLF or truncated paste)." >&259
exit 181
exit 160
fi82
fi61
83