Skip to content

Commit c69a592

Browse files
committed
build(container): setup GitHub signing using forwarded SSH key
1 parent a0c2cc9 commit c69a592

File tree

5 files changed

+134
-3
lines changed

5 files changed

+134
-3
lines changed

.devcontainer/README.md

+41-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ The dev container provides a consistent development environment with caching to
1414
2. **Dockerfile**: Specifies the container image and installed tools
1515
3. **project-setup.sh**: Configures the environment after container creation
1616
4. **host-setup.sh**: Sets up the host environment before starting the container
17+
5. **setup-git-signing.sh**: Automatically configures Git to use SSH signing with forwarded SSH keys
1718

1819
## Cache System
1920

@@ -59,11 +60,27 @@ When the container starts, the `project-setup.sh` script will automatically run
5960
- Create package-specific cache directories
6061
- Set up symlinks for package cache directories
6162
- Install project dependencies using yarn
63+
- Configure Git to use SSH signing with your forwarded SSH key
6264
- Source shell customizations if available in PATH (currently depends on base image configuration)
6365

6466
## Environment Variables
6567

66-
Environment variables are defined in the `docker-compose.yml` file, making the configuration self-contained and predictable.
68+
Environment variables are defined in two places:
69+
70+
1. **docker-compose.yml**: Contains most of the environment variables for tools and caching
71+
2. **Environment File**: Personal settings are stored in `/opt/configs/graphprotocol/contracts.env`
72+
73+
### Git Configuration
74+
75+
To enable Git commit signing, add the following settings to your environment file:
76+
77+
```env
78+
# Git settings for commit signing
79+
GIT_USER_NAME=Your Name
80+
81+
```
82+
83+
These environment variables are needed for Git commit signing to work properly. If they are not defined, Git commit signing will not be configured, but the container will still work for other purposes.
6784

6885
## Troubleshooting
6986

@@ -73,4 +90,26 @@ If you encounter permission denied errors when trying to access directories, mak
7390
sudo .devcontainer/host-setup.sh
7491
```
7592

76-
For other issues, check the `project-setup.sh` script for any errors.
93+
### Git SSH Signing Issues
94+
95+
If you encounter issues with Git SSH signing:
96+
97+
1. **SSH Agent Forwarding**: Make sure SSH agent forwarding is properly set up in your VS Code settings
98+
2. **GitHub Configuration**: Ensure your SSH key is added to GitHub as a signing key in your account settings
99+
3. **Manual Setup**: If automatic setup fails, you can manually configure SSH signing:
100+
101+
```bash
102+
# Check available SSH keys
103+
ssh-add -l
104+
105+
# Configure Git to use SSH signing
106+
git config --global gpg.format ssh
107+
git config --global user.signingkey "key::ssh-ed25519 YOUR_KEY_CONTENT"
108+
git config --global gpg.ssh.allowedSignersFile ~/.ssh/allowed_signers
109+
git config --global commit.gpgsign true
110+
111+
# Create allowed signers file
112+
echo "[email protected] ssh-ed25519 YOUR_KEY_CONTENT" > ~/.ssh/allowed_signers
113+
```
114+
115+
For other issues, check the `project-setup.sh` and `setup-git-signing.sh` scripts for any errors.

.devcontainer/docker-compose.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ services:
55
context: .
66
dockerfile: Dockerfile
77
env_file:
8-
- /opt/configs/RembrandtK/rem/rs/graph.env
8+
- /opt/configs/graphprotocol/contracts.env
99
environment:
1010
# Cache directories
1111
- FOUNDRY_CACHE_DIR=/cache/foundry

.devcontainer/project-setup.sh

+8
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,12 @@ else
107107
echo "Shell customizations not found in PATH, skipping..."
108108
fi
109109

110+
# Set up Git SSH signing
111+
echo "Setting up Git SSH signing..."
112+
if [ -f "$SCRIPT_DIR/setup-git-signing.sh" ]; then
113+
"$SCRIPT_DIR/setup-git-signing.sh"
114+
else
115+
echo "WARNING: setup-git-signing.sh not found, skipping Git SSH signing setup"
116+
fi
117+
110118
echo "Project-specific setup completed"

.devcontainer/sample-graph.env

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Sample environment file for Graph Protocol contracts development
2+
# Copy the Git settings below to your actual environment file at:
3+
# /opt/configs/graphprotocol/contracts.env
4+
5+
# Git settings for commit signing
6+
# Add these settings if you want to enable Git commit signing
7+
GIT_USER_NAME=Your Name
8+
GIT_USER_EMAIL=[email protected]

.devcontainer/setup-git-signing.sh

+76
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/bin/bash
2+
# Automatically configure Git to use SSH signing with forwarded SSH keys
3+
set -euo pipefail
4+
5+
echo "Setting up Git SSH signing..."
6+
7+
# Check if SSH agent forwarding is working
8+
if ! ssh-add -l &>/dev/null; then
9+
echo "ERROR: No SSH keys found in agent. SSH agent forwarding is not set up correctly."
10+
echo "SSH signing will not work without SSH agent forwarding."
11+
exit 1
12+
fi
13+
14+
# Get the first SSH key from the agent
15+
SSH_KEY=$(ssh-add -L | head -n 1)
16+
if [ -z "$SSH_KEY" ]; then
17+
echo "ERROR: No SSH keys found in agent. SSH signing will not work."
18+
exit 1
19+
fi
20+
21+
# Extract the key type and key content
22+
KEY_TYPE=$(echo "$SSH_KEY" | awk '{print $1}')
23+
KEY_CONTENT=$(echo "$SSH_KEY" | awk '{print $2}')
24+
25+
# Check if Git user settings are available
26+
if [[ -z "${GIT_USER_NAME:-}" || -z "${GIT_USER_EMAIL:-}" ]]; then
27+
echo "WARNING: Git user settings (GIT_USER_NAME and/or GIT_USER_EMAIL) are not set."
28+
echo "Git commit signing will not be configured."
29+
echo "If you need Git commit signing, add these variables to your environment file."
30+
exit 0
31+
fi
32+
33+
# Set Git user name from environment variable
34+
echo "Setting Git user.name: $GIT_USER_NAME"
35+
git config --global user.name "$GIT_USER_NAME"
36+
37+
# Set Git user email from environment variable
38+
echo "Setting Git user.email: $GIT_USER_EMAIL"
39+
git config --global user.email "$GIT_USER_EMAIL"
40+
41+
# Create the .ssh directory if it doesn't exist
42+
mkdir -p ~/.ssh
43+
chmod 700 ~/.ssh
44+
45+
# Create or update the allowed signers file
46+
echo "Updating allowed signers file..."
47+
ALLOWED_SIGNERS_FILE=~/.ssh/allowed_signers
48+
SIGNER_LINE="$GIT_USER_EMAIL $KEY_TYPE $KEY_CONTENT"
49+
50+
# Create the file if it doesn't exist
51+
if [ ! -f "$ALLOWED_SIGNERS_FILE" ]; then
52+
echo "$SIGNER_LINE" > "$ALLOWED_SIGNERS_FILE"
53+
echo "Created new allowed signers file."
54+
else
55+
# Check if the key is already in the file
56+
if ! grep -q "$KEY_CONTENT" "$ALLOWED_SIGNERS_FILE"; then
57+
# Append the key if it's not already there
58+
echo "$SIGNER_LINE" >> "$ALLOWED_SIGNERS_FILE"
59+
echo "Added new key to allowed signers file."
60+
else
61+
echo "Key already exists in allowed signers file."
62+
fi
63+
fi
64+
65+
chmod 600 "$ALLOWED_SIGNERS_FILE"
66+
67+
# Configure Git to use SSH signing
68+
echo "Configuring Git to use SSH signing..."
69+
git config --global gpg.format ssh
70+
git config --global user.signingkey "key::$KEY_TYPE $KEY_CONTENT"
71+
git config --global gpg.ssh.allowedSignersFile ~/.ssh/allowed_signers
72+
git config --global commit.gpgsign true
73+
74+
echo "Git SSH signing setup complete!"
75+
echo "Your commits will now be automatically signed using your SSH key."
76+
echo "Make sure this key is added to GitHub as a signing key in your account settings."

0 commit comments

Comments
 (0)