BlueGit

timfa posprint

Normalize CRLF in AUR SSH keys and document LF base64.

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

timfa Tim Falken · pushed by timfa

Authored 2026-07-21 · 3 months ago

Hash
2d6bcc6246b38b36b2a45c8571523341ac28ec1d
Parent
b5f13e34
2 files changed +48 −26
docs/AUR.md +24 −24
@@ -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 privat
49
49
50Use **exactly one** of these setups (do not mix File + base64 unless using the auto-detect path below):
50Use **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 |
54GitLab **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
61Mark `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)
56Generate **LF-normalized** base64 of the **entire** key file (including BEGIN/END):
64
57
65On 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"
61if (-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| Variable | Type | Value |
68# Linux
69|----------|------|--------|
69base64 -w0 ~/.ssh/id_ed25519
70| `AUR_SSH_PRIVATE_KEY_B64` | **Variable** (not File) | The single-line `$b64` string; **Masked** + **Protected** |
70
71
71# macOS
72Also set `AUR_GIT_AUTHOR_NAME` and `AUR_GIT_AUTHOR_EMAIL`.
72base64 -i ~/.ssh/id_ed25519 | tr -d '\n'
73Remove `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 key
75[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 mistake
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`.
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 key
87### Public vs private key
88
88
scripts/aur-ssh-setup.sh +24 −2
@@ -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 string
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
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)
8# File contents may also be base64 (auto-detected)
9#
10# Always normalizes CRLF → LF (Windows pastes into GitLab often break OpenSSH otherwise).
9set -euo pipefail
11set -euo pipefail
10
12
11KEY_PATH="${1:-$HOME/.ssh/id_ed25519}"
13KEY_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/null
18 grep -qE 'BEGIN (OPENSSH |RSA |EC )?PRIVATE KEY' "$1" 2>/dev/null
17}
19}
18
20
21normalize_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
19decode_b64_to_key() {
34decode_b64_to_key() {
20 local src="$1"
35 local src="$1"
21 if [[ -f "$src" ]]; then
36 if [[ -f "$src" ]]; then
@@ -33,7 +48,7 @@ elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" && -f "${AUR_SSH_PRIVATE_KEY}" ]]; then
33 if is_raw_ssh_key "$AUR_SSH_PRIVATE_KEY"; then
48 if is_raw_ssh_key "$AUR_SSH_PRIVATE_KEY"; then
34 cp "$AUR_SSH_PRIVATE_KEY" "$KEY_PATH"
49 cp "$AUR_SSH_PRIVATE_KEY" "$KEY_PATH"
35 else
50 else
36 # File variable mistakenly filled with base64 instead of raw PEM
51 # File variable filled with base64 instead of raw PEM
37 decode_b64_to_key "$AUR_SSH_PRIVATE_KEY"
52 decode_b64_to_key "$AUR_SSH_PRIVATE_KEY"
38 fi
53 fi
39elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" ]]; then
54elif [[ -n "${AUR_SSH_PRIVATE_KEY:-}" ]]; then
@@ -49,13 +64,20 @@ else
49 exit 1
64 exit 1
50fi
65fi
51
66
52chmod 600 "$KEY_PATH"
67normalize_key_file
53
68
54if ! is_raw_ssh_key "$KEY_PATH"; then
69if ! is_raw_ssh_key "$KEY_PATH"; then
55 echo "AUR SSH key is not a valid OpenSSH private key after setup." >&2
70 echo "AUR SSH key is not a valid OpenSSH private key after setup." >&2
56 echo "Use either:" >&2
71 echo "Use either:" >&2
57 echo " - AUR_SSH_PRIVATE_KEY as File with raw key (BEGIN ... PRIVATE KEY)" >&2
72 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
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
76fi
77
78# Cheap structural check without printing key material
79if ! 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 exit 1
81 exit 1
60fi
82fi
61
83