@misterhuydo/sentinel 1.2.9 → 1.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@misterhuydo/sentinel",
3
- "version": "1.2.9",
3
+ "version": "1.3.1",
4
4
  "description": "Sentinel — Autonomous DevOps Agent installer and manager",
5
5
  "bin": {
6
6
  "sentinel": "./bin/sentinel.js"
@@ -0,0 +1,94 @@
1
+ #!/bin/bash
2
+ # gen_deploy_keys.sh — Generate one ed25519 deploy key per GitHub repo.
3
+ #
4
+ # Usage:
5
+ # ./gen_deploy_keys.sh org/repo1 org/repo2 ...
6
+ #
7
+ # What it does:
8
+ # 1. Generates ~/.ssh/<repo>.key and ~/.ssh/<repo>.key.pub for each repo
9
+ # 2. Adds a Host block to ~/.ssh/config so git uses the right key per repo
10
+ # 3. Adds github.com to known_hosts (if not already there)
11
+ # 4. Prints each public key for pasting into GitHub → Settings → Deploy keys
12
+ #
13
+ # After running:
14
+ # - Add each printed public key to its repo on GitHub (allow write access)
15
+ # - Use the SSH alias in git URLs: git@github-<repo>:org/repo.git
16
+ # - Test with: ssh -T github-<repo>
17
+
18
+ set -euo pipefail
19
+
20
+ if [[ $# -eq 0 ]]; then
21
+ echo "Usage: $0 org/repo1 org/repo2 ..."
22
+ echo " e.g. $0 Opplysningen1881/sentinel-1881 Opplysningen1881/1881-SSOLoginWebApp"
23
+ exit 1
24
+ fi
25
+
26
+ SSH_DIR="$HOME/.ssh"
27
+ mkdir -p "$SSH_DIR"
28
+ chmod 700 "$SSH_DIR"
29
+
30
+ # Add GitHub host key once
31
+ if ! grep -q "github.com" "$SSH_DIR/known_hosts" 2>/dev/null; then
32
+ echo "Adding GitHub to known_hosts..."
33
+ ssh-keyscan github.com >> "$SSH_DIR/known_hosts" 2>/dev/null
34
+ fi
35
+
36
+ touch "$SSH_DIR/config"
37
+ chmod 600 "$SSH_DIR/config"
38
+
39
+ for repo_path in "$@"; do
40
+ repo="${repo_path##*/}" # strip org/ prefix → just the repo name
41
+ keyfile="$SSH_DIR/${repo}.key"
42
+
43
+ echo ""
44
+ echo "══════════════════════════════════════════════"
45
+ echo " Repo: $repo_path"
46
+ echo " Keyfile: $keyfile"
47
+ echo "══════════════════════════════════════════════"
48
+
49
+ # Generate (skip if key already exists)
50
+ if [[ -f "$keyfile" ]]; then
51
+ echo " Key already exists — skipping generation (delete $keyfile to regenerate)"
52
+ else
53
+ ssh-keygen -t ed25519 -C "sentinel@${repo}" -f "$keyfile" -N "" -q
54
+ echo " Key generated."
55
+ fi
56
+
57
+ # Add SSH config block (skip if Host already configured)
58
+ if ! grep -q "Host github-${repo}" "$SSH_DIR/config" 2>/dev/null; then
59
+ cat >> "$SSH_DIR/config" << EOF
60
+
61
+ Host github-${repo}
62
+ HostName github.com
63
+ User git
64
+ IdentityFile ${keyfile}
65
+ IdentitiesOnly yes
66
+ EOF
67
+ echo " SSH config block added."
68
+ else
69
+ echo " SSH config block already exists — skipping."
70
+ fi
71
+
72
+ echo ""
73
+ echo " ┌─ Add this deploy key to GitHub ─────────────────────────────────────┐"
74
+ echo " │ $repo_path → Settings → Deploy keys → Add deploy key"
75
+ echo " │ Title: sentinel@$(hostname)"
76
+ echo " │ Allow write access: ✓"
77
+ echo " └──────────────────────────────────────────────────────────────────────┘"
78
+ echo ""
79
+ cat "$keyfile.pub"
80
+ done
81
+
82
+ echo ""
83
+ echo "══════════════════════════════════════════════"
84
+ echo "Done. After adding keys on GitHub, test each:"
85
+ for repo_path in "$@"; do
86
+ repo="${repo_path##*/}"
87
+ echo " ssh -T github-${repo}"
88
+ done
89
+ echo ""
90
+ echo "Use SSH aliases in sentinel add:"
91
+ for repo_path in "$@"; do
92
+ repo="${repo_path##*/}"
93
+ echo " sentinel add git@github-${repo}:${repo_path}.git"
94
+ done
@@ -0,0 +1,63 @@
1
+ #!/bin/bash
2
+ # Usage: ./setup_deploy_keys.sh repo1 repo2 ...
3
+ # Generates one deploy key per repo, prints each public key for GitHub.
4
+
5
+ set -e
6
+
7
+ if [[ $# -eq 0 ]]; then
8
+ echo "Usage: $0 repo1 repo2 ..."
9
+ exit 1
10
+ fi
11
+
12
+ SSH_DIR="$HOME/.ssh"
13
+
14
+ # Wipe known state
15
+ echo "Cleaning ~/.ssh ..."
16
+ rm -f "$SSH_DIR"/known_hosts "$SSH_DIR"/known_hosts.old
17
+ for f in "$SSH_DIR"/*.pub "$SSH_DIR"/config; do
18
+ [[ -f "$f" ]] && rm -f "$f" "${f%.pub}"
19
+ done
20
+ rm -f "$SSH_DIR"/config
21
+
22
+ # Re-fetch GitHub host key once
23
+ ssh-keyscan github.com >> "$SSH_DIR/known_hosts" 2>/dev/null
24
+ echo "GitHub host key added."
25
+ echo ""
26
+
27
+ # Fresh SSH config
28
+ CONFIG="$SSH_DIR/config"
29
+
30
+ for repo in "$@"; do
31
+ keyfile="$SSH_DIR/$repo"
32
+
33
+ echo "──────────────────────────────────────────"
34
+ echo "Repo: $repo"
35
+
36
+ # Generate key
37
+ ssh-keygen -t ed25519 -C "sentinel@$repo" -f "$keyfile" -N "" -q
38
+
39
+ # Append SSH config block
40
+ cat >> "$CONFIG" << EOF
41
+
42
+ Host github-$repo
43
+ HostName github.com
44
+ User git
45
+ IdentityFile $keyfile
46
+ IdentitiesOnly yes
47
+ EOF
48
+
49
+ echo ""
50
+ echo "Deploy key for: github.com/Opplysningen1881/$repo"
51
+ echo "→ GitHub: Settings → Deploy keys → Add deploy key (allow write access)"
52
+ echo ""
53
+ cat "$keyfile.pub"
54
+ echo ""
55
+ done
56
+
57
+ chmod 600 "$CONFIG"
58
+
59
+ echo "──────────────────────────────────────────"
60
+ echo "Done. After adding keys on GitHub, test with:"
61
+ for repo in "$@"; do
62
+ echo " ssh -T github-$repo"
63
+ done
@@ -106,6 +106,7 @@ class RepoConfig:
106
106
  cicd_job_url: str = ""
107
107
  health_url: str = "" # optional: HTTP endpoint returning {"Status": "true"}
108
108
  cicd_token: str = ""
109
+ ssh_key_file: str = "" # path to SSH private key; sets GIT_SSH_COMMAND when present
109
110
 
110
111
 
111
112
  # ── Loader ────────────────────────────────────────────────────────────────────
@@ -224,6 +225,7 @@ class ConfigLoader:
224
225
  r.cicd_job_url = d.get("CICD_JOB_URL", "")
225
226
  r.cicd_token = d.get("CICD_TOKEN", "")
226
227
  r.health_url = d.get("HEALTH_URL", "")
228
+ r.ssh_key_file = os.path.expanduser(d.get("SSH_KEY_FILE", ""))
227
229
  self.repos[r.repo_name] = r
228
230
 
229
231
  def _register_sighup(self):
@@ -37,8 +37,10 @@ def _git(args: list[str], cwd: str, env: dict | None = None, timeout: int = GIT_
37
37
 
38
38
 
39
39
  def _git_env(repo: RepoConfig) -> dict:
40
- # GIT_SSH_COMMAND can be set externally for SSH-based repos
41
- return os.environ.copy()
40
+ env = os.environ.copy()
41
+ if repo.ssh_key_file:
42
+ env["GIT_SSH_COMMAND"] = f"ssh -i {repo.ssh_key_file} -o StrictHostKeyChecking=no -o BatchMode=yes"
43
+ return env
42
44
 
43
45
 
44
46
  def _check_protected_paths(patch_path: Path) -> bool: