[refactor] moving cubes into own package"
Publish snapshot / snapshot (push) Successful in 1m2s

[fix] default parameter run records parameters in session for replay[fix] remove default parameters for several cubes
This commit is contained in:
Benjamin Diedrichsen
2026-07-28 12:18:10 +02:00
parent ac050c4459
commit 6ecb2c366f
130 changed files with 3386 additions and 520 deletions
@@ -0,0 +1,110 @@
# ssh-keyman
**Deploy existing SSH keys to host**
## Purpose
This cube deploys pre-existing SSH key pairs from your local machine to a remote server, configuring them for automatic use with specified hosts (like GitHub, GitLab, etc.).
## What This Cube Does
1. **Copies SSH keys to the server**
- Transfers both private and public keys from local directory to remote `.ssh` folder
- Sets correct file permissions (600 for private, 644 for public)
2. **Configures SSH client**
- Creates/updates `.ssh/config` to use the deployed key for specified hosts
- Disables strict host key checking for easier automation
- Maps each host to use the correct identity file
3. **Ensures security**
- Sets proper directory permissions (700 for `.ssh`)
- Ensures keys are owned by the specified user
## Configuration
### Parameters
- **KEY_NAME** (string, default: `'id_ed25519'`)
- Name of the SSH key file (without extension)
- Must exist in the KEY_DIR directory locally
- **USER** (string, default: `'vagrant'`)
- Username for which to deploy the SSH key
- Inherited from `user-add` dependency
- **HOSTS** (string, default: `'github.com'`)
- Space-separated list of hosts to add to known_hosts
- Example: `'github.com gitlab.com bitbucket.org'`
## Dependencies
- **user-add** - Creates the user account first
## Use Cases
Deploy GitHub SSH key:
```javascript
exec('ssh-keyman', {
KEY_NAME: 'id_github',
HOSTS: 'github.com'
})
```
Deploy key for multiple Git services:
```javascript
exec('ssh-keyman', {
KEY_NAME: 'id_git',
HOSTS: 'github.com gitlab.com bitbucket.org'
})
```
## What Gets Configured
After deployment, the `.ssh/config` file will contain entries like:
```
Host github.com
IdentityFile /home/{USER}/.ssh/id_github
StrictHostKeyChecking no
```
This means when you run `git clone git@github.com:user/repo.git`, it will automatically use the deployed key.
## Key File Requirements
The local KEY_DIR must contain:
- `{KEY_NAME}` - Private key file
- `{KEY_NAME}.pub` - Public key file
For example, if `KEY_NAME=id_github`, you need:
- `./vault/tmp/id_github`
- `./vault/tmp/id_github.pub`
## Security Considerations
- **Private keys are sensitive**: Ensure your local KEY_DIR is secure
- **StrictHostKeyChecking disabled**: Convenient but less secure
- Consider enabling it for production: Edit `/home/{USER}/.ssh/config`
- **Backup your keys**: Keep secure copies of private keys
- **Use different keys**: Consider separate keys for different services
## Post-Installation
Test SSH connection:
```bash
ssh -T git@github.com
# Should show: "Hi username! You've successfully authenticated..."
```
Clone a repository:
```bash
git clone git@github.com:user/repo.git
# Should work without prompting for credentials
```
@@ -0,0 +1,96 @@
from pyinfra.operations import server, files, apt, systemd
from pyinfra import host
import subprocess
import json
def get_keyman_config():
"""Get keyman configuration by calling keyman --print-config"""
try:
result = subprocess.run(
['keyman', '--print-config'],
capture_output=True,
text=True,
check=True
)
return json.loads(result.stdout)
except (subprocess.CalledProcessError, json.JSONDecodeError, FileNotFoundError):
return None
# Load keyman config for defaults
keyman_config = get_keyman_config()
USER = host.data.USER
KEY = host.data.KEY_NAME
# Use KEY_DIR from host data, or fall back to keyman config tmpDir
DIR = host.data.get('KEY_DIR')
if not DIR and keyman_config:
DIR = keyman_config.get('tmpDir')
if not DIR:
DIR = '../../vault/tmp' # Final fallback
# Support multiple hosts separated by space
HOSTS = map(str.lstrip, str(host.data.HOSTS).split(' '))
# 🔹 Define remote paths
SSH_DIR = f"/home/{USER}/.ssh" if USER != "root" else "/root/.ssh"
PRIVATE_KEY_PATH = f"{SSH_DIR}/{KEY}"
PUBLIC_KEY_PATH = f"{SSH_DIR}/{KEY}.pub"
# Ensure the .ssh directory exists
files.directory(
name="Ensure .ssh directory exists",
path=SSH_DIR,
present=True,
mode=700,
user=USER,
group=USER,
_sudo=True
)
# Copy private key to the remote server
files.put(
name="Copy private key",
src=f"{DIR}/{KEY}",
dest=PRIVATE_KEY_PATH,
mode="600",
user=USER,
group=USER,
_sudo=True,
)
# Copy public key to the remote server
files.put(
name="Copy public key",
src=f"{DIR}/{KEY}.pub",
dest=PUBLIC_KEY_PATH,
mode="644",
user=USER,
group=USER,
_sudo=True,
)
# Ensure correct permissions for the private key
server.shell(
name="Set correct permissions for private key",
commands=[f"chmod 600 {PRIVATE_KEY_PATH}"],
_sudo=True,
)
files.file(
name="Ensure .ssh/config directory exists",
path=f"/home/{USER}/.ssh/config",
present=True,
user=USER,
group=USER,
_sudo=True
)
for host in HOSTS:
files.line(
name=f"Configure SSH key for {host}",
path=f"{SSH_DIR}/config",
line=f"Host {host}\n IdentityFile {SSH_DIR}/{KEY}\n StrictHostKeyChecking no",
_sudo=True
)
@@ -0,0 +1,19 @@
import { Manifest } from '@bitsquare/nopy-cube';
import { z } from 'zod';
export default Manifest({
id: 'ssh:keyman',
name: 'Deploy an ssh key managed by keyman',
dependencies: () => [],
schema: z.object({
KEY_NAME: z
.string()
.describe('Name of the SSH key file (without extension)')
.default('id_ed25519'),
USER: z.string().describe('Username for which to deploy the SSH key').default('vagrant'),
HOSTS: z
.string()
.describe('Space-separated list of hosts to add to known_hosts')
.default('github.com'),
}),
});