Skip to content

Commit 337b54c

Browse files
committed
Complete SSH key integration across all build systems
- Updated Makefile to generate SSH keys with correct naming (cpu_rsa/cpu_rsa.pub) - SSH keys are now generated and embedded in initramfs at /etc/cpu_rsa.pub - Updated build info to include SSH key information and security warnings - Enhanced GitHub Actions workflows to include SSH keys in release assets - Updated documentation with SSH key usage examples - Fixed workflow paths and dependencies for proper SSH key integration
1 parent 0932bdf commit 337b54c

File tree

4 files changed

+114
-49
lines changed

4 files changed

+114
-49
lines changed

.github/workflows/build.yml

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,16 @@ jobs:
6767
go build -o ../../u-root-bin ./
6868
cd ../cpu
6969
70+
- name: Generate SSH keys
71+
run: |
72+
mkdir -p build/binaries
73+
echo "Generating default SSH keys for CPU..."
74+
ssh-keygen -t rsa -b 4096 -f build/binaries/cpu_rsa -N "" -C "cpu-default-key"
75+
echo "SSH keys generated:"
76+
echo " Private key: build/binaries/cpu_rsa"
77+
echo " Public key: build/binaries/cpu_rsa.pub"
78+
ls -la build/binaries/cpu_rsa*
79+
7080
- name: Build cpu binary for aarch64
7181
run: |
7282
cd build/repos/cpu
@@ -90,9 +100,10 @@ jobs:
90100
echo "Creating u-root initramfs with cpud as init..."
91101
mkdir -p ../../initramfs
92102
93-
# Build the initramfs with cpud bundled in as init
103+
# Build the initramfs with cpud bundled in as init and include SSH public key
94104
echo "Building initramfs with u-root..."
95105
GOOS=linux GOARCH=arm64 ../../u-root-bin -format=cpio -o ../../initramfs/cpud-initramfs.cpio \
106+
-files "../../binaries/cpu_rsa.pub:etc/cpu_rsa.pub" \
96107
-initcmd="cpud" \
97108
./cmds/cpud \
98109
../u-root/cmds/core/ls \
@@ -136,15 +147,24 @@ jobs:
136147
echo "Files in this archive:" >> BUILD_INFO.txt
137148
echo "- cpu: CPU client binary" >> BUILD_INFO.txt
138149
echo "- cpud: CPU daemon binary" >> BUILD_INFO.txt
150+
echo "- cpu_rsa: Default SSH private key" >> BUILD_INFO.txt
151+
echo "- cpu_rsa.pub: Default SSH public key" >> BUILD_INFO.txt
139152
echo "- cpud-initramfs.cpio.gz: U-root initramfs with cpud as init" >> BUILD_INFO.txt
140153
echo "" >> BUILD_INFO.txt
141154
echo "Usage:" >> BUILD_INFO.txt
142155
echo " ./cpu -h # Show CPU client help" >> BUILD_INFO.txt
143156
echo " ./cpud -h # Show CPU daemon help" >> BUILD_INFO.txt
144157
echo "" >> BUILD_INFO.txt
158+
echo "SSH Keys:" >> BUILD_INFO.txt
159+
echo " Default SSH keys are provided for convenience" >> BUILD_INFO.txt
160+
echo " Private key: cpu_rsa" >> BUILD_INFO.txt
161+
echo " Public key: cpu_rsa.pub (also embedded in initramfs)" >> BUILD_INFO.txt
162+
echo " WARNING: These are default keys - generate your own for production!" >> BUILD_INFO.txt
163+
echo "" >> BUILD_INFO.txt
145164
echo "Initramfs usage:" >> BUILD_INFO.txt
146165
echo " Use cpud-initramfs.cpio.gz as initrd with Linux kernel" >> BUILD_INFO.txt
147166
echo " Boot parameters: init=/init" >> BUILD_INFO.txt
167+
echo " SSH public key is embedded at /etc/cpu_rsa.pub" >> BUILD_INFO.txt
148168
cat BUILD_INFO.txt
149169
150170
- name: Create checksums
@@ -153,6 +173,8 @@ jobs:
153173
echo "Creating checksums..."
154174
sha256sum cpu > cpu.sha256
155175
sha256sum cpud > cpud.sha256
176+
sha256sum cpu_rsa > cpu_rsa.sha256
177+
sha256sum cpu_rsa.pub > cpu_rsa.pub.sha256
156178
sha256sum BUILD_INFO.txt > BUILD_INFO.txt.sha256
157179
cd ../initramfs
158180
sha256sum cpud-initramfs.cpio.gz > cpud-initramfs.cpio.gz.sha256
@@ -221,9 +243,13 @@ jobs:
221243
files: |
222244
build/binaries/cpu
223245
build/binaries/cpud
246+
build/binaries/cpu_rsa
247+
build/binaries/cpu_rsa.pub
224248
build/binaries/BUILD_INFO.txt
225249
build/binaries/cpu.sha256
226250
build/binaries/cpud.sha256
251+
build/binaries/cpu_rsa.sha256
252+
build/binaries/cpu_rsa.pub.sha256
227253
build/binaries/BUILD_INFO.txt.sha256
228254
build/binaries/cpud-initramfs.cpio.gz
229255
build/binaries/cpud-initramfs.cpio.gz.sha256
@@ -242,10 +268,20 @@ jobs:
242268
- `BUILD_INFO.txt` - Build information and usage notes
243269
- `*.sha256` - SHA256 checksums for verification
244270
271+
### SSH Keys
272+
- `cpu_rsa` - Default SSH private key
273+
- `cpu_rsa.pub` - Default SSH public key (also embedded in initramfs)
274+
- `cpu_rsa.sha256` - Private key checksum
275+
- `cpu_rsa.pub.sha256` - Public key checksum
276+
277+
**⚠️ WARNING**: These are default keys for convenience. Generate your own keys for production use!
278+
245279
### Initramfs
246280
- `cpud-initramfs.cpio.gz` - U-root initramfs with cpud as init
247281
- `cpud-initramfs.cpio.gz.sha256` - Initramfs checksum
248282
283+
The initramfs includes the SSH public key at `/etc/cpu_rsa.pub` for automatic authentication.
284+
249285
### Archive
250286
- `cpu-binaries-aarch64-${{ env.CPU_VERSION }}.tar.gz` - Complete archive with all binaries
251287
- `cpu-binaries-aarch64-${{ env.CPU_VERSION }}.tar.gz.sha256` - Archive checksum
@@ -254,18 +290,26 @@ jobs:
254290
255291
### Download individual binaries:
256292
```bash
257-
# Download binaries
293+
# Download binaries and keys
258294
wget https://github.com/${{ github.repository }}/releases/download/${{ github.event.inputs.release_tag || github.ref_name }}/cpu
259295
wget https://github.com/${{ github.repository }}/releases/download/${{ github.event.inputs.release_tag || github.ref_name }}/cpud
296+
wget https://github.com/${{ github.repository }}/releases/download/${{ github.event.inputs.release_tag || github.ref_name }}/cpu_rsa
297+
wget https://github.com/${{ github.repository }}/releases/download/${{ github.event.inputs.release_tag || github.ref_name }}/cpu_rsa.pub
260298
261299
# Make executable
262300
chmod +x cpu cpud
301+
chmod 600 cpu_rsa
302+
chmod 644 cpu_rsa.pub
263303
264304
# Verify (optional)
265305
wget https://github.com/${{ github.repository }}/releases/download/${{ github.event.inputs.release_tag || github.ref_name }}/cpu.sha256
266306
wget https://github.com/${{ github.repository }}/releases/download/${{ github.event.inputs.release_tag || github.ref_name }}/cpud.sha256
307+
wget https://github.com/${{ github.repository }}/releases/download/${{ github.event.inputs.release_tag || github.ref_name }}/cpu_rsa.sha256
308+
wget https://github.com/${{ github.repository }}/releases/download/${{ github.event.inputs.release_tag || github.ref_name }}/cpu_rsa.pub.sha256
267309
sha256sum -c cpu.sha256
268310
sha256sum -c cpud.sha256
311+
sha256sum -c cpu_rsa.sha256
312+
sha256sum -c cpu_rsa.pub.sha256
269313
```
270314
271315
### Download complete archive:

.github/workflows/package.yml

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,13 @@ jobs:
5555
git clone https://github.com/u-root/cpu.git
5656
cd cpu
5757
echo "CPU_VERSION=$(git describe --tags --always)" >> $GITHUB_ENV
58+
59+
- name: Generate SSH keys
60+
run: |
61+
echo "Generating default SSH keys for CPU..."
62+
ssh-keygen -t rsa -b 4096 -f binaries/cpu_rsa -N "" -C "cpu-default-key"
63+
echo "SSH keys generated:"
64+
ls -la binaries/cpu_rsa*
5865
5966
- name: Build binaries
6067
run: |
@@ -70,9 +77,11 @@ jobs:
7077
FROM scratch
7178
COPY binaries/cpu /usr/local/bin/cpu
7279
COPY binaries/cpud /usr/local/bin/cpud
80+
COPY binaries/cpu_rsa /etc/cpu_rsa
81+
COPY binaries/cpu_rsa.pub /etc/cpu_rsa.pub
7382
COPY BUILD_INFO.txt /BUILD_INFO.txt
7483
LABEL org.opencontainers.image.title="CPU Binaries"
75-
LABEL org.opencontainers.image.description="Prebuilt CPU binaries for aarch64"
84+
LABEL org.opencontainers.image.description="Prebuilt CPU binaries for aarch64 with SSH keys"
7685
LABEL org.opencontainers.image.source="https://github.com/${{ github.repository }}"
7786
LABEL org.opencontainers.image.version="${{ env.CPU_VERSION }}"
7887
LABEL org.opencontainers.image.licenses="BSD-3-Clause"
@@ -91,10 +100,18 @@ jobs:
91100
Files in this package:
92101
- /usr/local/bin/cpu: CPU client binary
93102
- /usr/local/bin/cpud: CPU daemon binary
103+
- /etc/cpu_rsa: Default SSH private key
104+
- /etc/cpu_rsa.pub: Default SSH public key
105+
106+
WARNING: These are default keys for convenience - generate your own for production!
94107
95108
Usage:
96109
docker run --rm ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest /usr/local/bin/cpu -h
97110
docker run --rm ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest /usr/local/bin/cpud -h
111+
112+
Extract SSH keys from container:
113+
docker run --rm ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest cat /etc/cpu_rsa > cpu_rsa
114+
docker run --rm ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest cat /etc/cpu_rsa.pub > cpu_rsa.pub
98115
EOF
99116
100117
- name: Build and push Docker image

Makefile

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ CPU_BINARY := $(BINARIES_DIR)/cpu
2626
CPUD_BINARY := $(BINARIES_DIR)/cpud
2727
INITRAMFS_FILE := $(INITRAMFS_DIR)/cpud-initramfs.cpio.gz
2828
BUILD_INFO := $(BINARIES_DIR)/BUILD_INFO.txt
29+
SSH_PRIVATE_KEY := $(BINARIES_DIR)/cpu_rsa
30+
SSH_PUBLIC_KEY := $(BINARIES_DIR)/cpu_rsa.pub
2931

3032
# Version detection
3133
CPU_VERSION := $(shell cd $(CPU_REPO) 2>/dev/null && git describe --tags --always 2>/dev/null || echo "unknown")
@@ -66,6 +68,18 @@ $(GO_WORK): $(CPU_REPO) $(UROOT_REPO)
6668
@echo "use ./repos/cpu" >> $(GO_WORK)
6769
@echo "use ./repos/u-root" >> $(GO_WORK)
6870

71+
$(SSH_PRIVATE_KEY): | $(BUILD_DIR)
72+
@echo "Generating default SSH keys for CPU..."
73+
@mkdir -p $(BINARIES_DIR)
74+
@if [ ! -f "$(SSH_PRIVATE_KEY)" ]; then \
75+
ssh-keygen -t rsa -b 4096 -f $(SSH_PRIVATE_KEY) -N "" -C "cpu-default-key"; \
76+
echo "SSH keys generated:"; \
77+
echo " Private key: $(SSH_PRIVATE_KEY)"; \
78+
echo " Public key: $(SSH_PUBLIC_KEY)"; \
79+
else \
80+
echo "SSH keys already exist, skipping generation"; \
81+
fi
82+
6983
# Repository management
7084
repos: $(CPU_REPO) $(UROOT_REPO) ## Clone all repositories
7185

@@ -89,7 +103,7 @@ $(CPUD_BINARY): $(GO_WORK) $(UROOT_BIN)
89103
@echo "Building cpud binary for aarch64..."
90104
@cd $(CPU_REPO) && GOOS=$(GOOS) GOARCH=$(GOARCH) CGO_ENABLED=$(CGO_ENABLED) go build -o ../../binaries/cpud ./cmds/cpud
91105

92-
$(BUILD_INFO): $(CPU_BINARY) $(CPUD_BINARY)
106+
$(BUILD_INFO): $(CPU_BINARY) $(CPUD_BINARY) $(SSH_PRIVATE_KEY)
93107
@echo "Creating build info..."
94108
@cd $(CPU_REPO) && CPU_VERSION=$$(git describe --tags --always) && \
95109
echo "U-Root CPU Binaries for aarch64 (Local Build)" > ../../binaries/BUILD_INFO.txt && \
@@ -101,19 +115,28 @@ $(BUILD_INFO): $(CPU_BINARY) $(CPUD_BINARY)
101115
echo "Files in this archive:" >> ../../binaries/BUILD_INFO.txt && \
102116
echo "- cpu: CPU client binary" >> ../../binaries/BUILD_INFO.txt && \
103117
echo "- cpud: CPU daemon binary" >> ../../binaries/BUILD_INFO.txt && \
118+
echo "- cpu_rsa: Default SSH private key" >> ../../binaries/BUILD_INFO.txt && \
119+
echo "- cpu_rsa.pub: Default SSH public key" >> ../../binaries/BUILD_INFO.txt && \
104120
echo "- cpud-initramfs.cpio.gz: U-root initramfs with cpud as init" >> ../../binaries/BUILD_INFO.txt && \
105121
echo "" >> ../../binaries/BUILD_INFO.txt && \
106122
echo "Usage:" >> ../../binaries/BUILD_INFO.txt && \
107123
echo " ./cpu -h # Show CPU client help" >> ../../binaries/BUILD_INFO.txt && \
108124
echo " ./cpud -h # Show CPU daemon help" >> ../../binaries/BUILD_INFO.txt && \
109125
echo "" >> ../../binaries/BUILD_INFO.txt && \
126+
echo "SSH Keys:" >> ../../binaries/BUILD_INFO.txt && \
127+
echo " Default SSH keys are provided for convenience" >> ../../binaries/BUILD_INFO.txt && \
128+
echo " Private key: cpu_rsa" >> ../../binaries/BUILD_INFO.txt && \
129+
echo " Public key: cpu_rsa.pub (also embedded in initramfs)" >> ../../binaries/BUILD_INFO.txt && \
130+
echo " WARNING: These are default keys - generate your own for production!" >> ../../binaries/BUILD_INFO.txt && \
131+
echo "" >> ../../binaries/BUILD_INFO.txt && \
110132
echo "Initramfs usage:" >> ../../binaries/BUILD_INFO.txt && \
111133
echo " Use cpud-initramfs.cpio.gz as initrd with Linux kernel" >> ../../binaries/BUILD_INFO.txt && \
112134
echo " Boot parameters: init=/init" >> ../../binaries/BUILD_INFO.txt && \
135+
echo " SSH public key is embedded at /etc/cpu_rsa.pub" >> ../../binaries/BUILD_INFO.txt && \
113136
echo "" >> ../../binaries/BUILD_INFO.txt && \
114137
echo "Build system: Makefile" >> ../../binaries/BUILD_INFO.txt
115138

116-
binaries: check-go $(CPU_BINARY) $(CPUD_BINARY) $(BUILD_INFO) ## Build cpu and cpud binaries
139+
binaries: check-go $(CPU_BINARY) $(CPUD_BINARY) $(BUILD_INFO) $(SSH_PRIVATE_KEY) ## Build cpu and cpud binaries
117140
@echo "Verifying built binaries..."
118141
@ls -la $(BINARIES_DIR)/
119142
@echo ""
@@ -122,14 +145,19 @@ binaries: check-go $(CPU_BINARY) $(CPUD_BINARY) $(BUILD_INFO) ## Build cpu and c
122145
@echo "CPUD binary info:"
123146
@file $(CPUD_BINARY)
124147
@echo ""
148+
@echo "SSH key info:"
149+
@echo "Private key: $(SSH_PRIVATE_KEY)"
150+
@echo "Public key: $(SSH_PUBLIC_KEY)"
151+
@echo ""
125152
@echo "Binary sizes:"
126153
@du -h $(BINARIES_DIR)/*
127154

128-
$(INITRAMFS_FILE): $(CPUD_BINARY) $(UROOT_BIN)
155+
$(INITRAMFS_FILE): $(CPUD_BINARY) $(UROOT_BIN) $(SSH_PUBLIC_KEY)
129156
@echo "Creating u-root initramfs with cpud as init..."
130157
@rm -f $(INITRAMFS_DIR)/*
131158
@echo "Building initramfs with u-root..."
132159
@cd $(CPU_REPO) && GOOS=$(GOOS) GOARCH=$(GOARCH) ../../u-root-bin -format=cpio -o ../../initramfs/cpud-initramfs.cpio \
160+
-files "../../binaries/cpu_rsa.pub:etc/cpu_rsa.pub" \
133161
-initcmd="cpud" \
134162
./cmds/cpud \
135163
../u-root/cmds/core/ls \

docs/INITRAMFS.md

Lines changed: 19 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -7,61 +7,37 @@ This guide explains how to use the CPU initramfs that boots directly into the cp
77
The CPU initramfs is a u-root-based initial RAM filesystem that:
88
- Boots directly into the cpud daemon
99
- Provides a minimal Linux environment
10-
- Automatically mounts essential filesystems (`/proc`, `/sys`### Troubleshooting
11-
12-
### Common Issues
10+
- Automatically mounts essential filesystems (`/proc`, `/sys`, `/dev`)
11+
- Includes a default SSH public key for authentication (`/etc/cpu_rsa.pub`)
12+
- Starts cpud as the init process
1313

14-
1. **Boot Hangs**: Check console output, ensure correct kernel
15-
2. **Network Issues**: Verify network configuration and drivers
16-
3. **Permission Issues**: Ensure proper filesystem permissions
17-
4. **Pi won't boot**: Check config.txt and cmdline.txt syntax
14+
## SSH Key Authentication
1815

19-
### Raspberry Pi Specific Issues
16+
The initramfs includes a default SSH public key at `/etc/cpu_rsa.pub` for convenient authentication. The corresponding private key is available in the release binaries.
2017

21-
#### **Pi doesn't boot with initramfs**
22-
```bash
23-
# Check config.txt syntax
24-
sudo nano /boot/firmware/config.txt
18+
**⚠️ WARNING**: These are default keys for convenience. Generate your own keys for production use!
2519

26-
# Ensure correct path and format
27-
initramfs cpud-initramfs.cpio.gz followkernel
20+
### Using the Default Keys
2821

29-
# Verify file exists and permissions
30-
ls -la /boot/firmware/cpud-initramfs.cpio.gz
31-
```
32-
33-
#### **No network on Pi**
3422
```bash
35-
# Check if interface is up
36-
ip link show
37-
38-
# Bring up ethernet
39-
ip link set eth0 up
40-
dhclient eth0
23+
# Download the private key from the release
24+
wget https://github.com/ericvh/cpu-prebuilt/releases/latest/download/cpu_rsa
25+
chmod 600 cpu_rsa
4126

42-
# Check cable connection
43-
ethtool eth0
27+
# Use with CPU client
28+
./cpu -key cpu_rsa user@target-system
4429
```
4530

46-
#### **No console output**
47-
```bash
48-
# In cmdline.txt, ensure console is set
49-
console=serial0,115200 console=tty1
31+
### Generating Your Own Keys
5032

51-
# Enable UART in config.txt
52-
enable_uart=1
53-
```
54-
55-
#### **Pi 4/5 specific issues**
5633
```bash
57-
# Ensure 64-bit mode is enabled
58-
arm_64bit=1
34+
# Generate your own key pair
35+
ssh-keygen -t rsa -b 4096 -f my_cpu_key -N ""
5936

60-
# Check if using correct boot partition
61-
ls -la /boot/firmware/ # Pi 4/5
62-
ls -la /boot/ # Pi 3 and earlier
63-
````)
64-
- Starts cpud as the init process
37+
# Replace the public key in the initramfs (requires rebuilding)
38+
# Or use cpu with your custom key
39+
./cpu -key my_cpu_key user@target-system
40+
```
6541

6642
## Use Cases
6743

0 commit comments

Comments
 (0)