fix(hermes): scope existing Git identity to raw repository host via CI
Repair Canina Hermes Git route / routing (push) Successful in 3s
Repair Canina Hermes Git route / routing (push) Successful in 3s
This commit is contained in:
1 parent
dc34c57a0c
commit
209339dc57
2 files changed
+78
No files matched your search
@@ -0,0 +1,24 @@
|
||||
name: Repair Canina Hermes Git route
|
||||
on:
|
||||
push:
|
||||
branches:
|
||||
- ops/hermes-git-routing-20261106
|
||||
jobs:
|
||||
routing:
|
||||
runs-on: canina
|
||||
steps:
|
||||
- name: Apply scoped runtime routing without restart
|
||||
env:
|
||||
REPAIR_SHA: ${{ github.sha }}
|
||||
REPAIR_REF: ${{ github.ref }}
|
||||
run: |
|
||||
set -eu
|
||||
[ "$REPAIR_REF" = refs/heads/ops/hermes-git-routing-20261106 ]
|
||||
case "$REPAIR_SHA" in *[!0-9a-f]*|'') exit 2 ;; esac
|
||||
[ "${#REPAIR_SHA}" -eq 40 ]
|
||||
export http_proxy= https_proxy= HTTP_PROXY= HTTPS_PROXY=
|
||||
wget --no-proxy -qO repair.py "https://git.parsaaghayi.ir/parsa/canina/raw/commit/${REPAIR_SHA}/infra/hermes-git-routing/repair.py"
|
||||
python3 repair.py
|
||||
docker exec -i -u 10000 -e HOME=/opt/data -e HERMES_HOME=/opt/data canina-hermes python3 - --apply < repair.py
|
||||
docker exec -u 10000 -e HOME=/opt/data -e HERMES_HOME=/opt/data canina-hermes git ls-remote ssh://git@git.parsaaghayi.ir:222/parsa/canina.git refs/heads/develop
|
||||
docker exec -u 10000 -e HOME=/opt/data -e HERMES_HOME=/opt/data canina-hermes git ls-remote canina-gitea:parsa/canina.git refs/heads/develop
|
||||
@@ -0,0 +1,54 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Narrow Canina gateway Git routing repair; run as UID10000 only."""
|
||||
import hashlib,json,os,pathlib,subprocess,sys,tempfile
|
||||
HOME=pathlib.Path('/opt/data')
|
||||
BLOCK='''\n# Managed Canina repository SSH route (no credential provisioning).
|
||||
Match originalhost git.parsaaghayi.ir user git
|
||||
Port 222
|
||||
IdentityFile /opt/data/.ssh/canina_gitea
|
||||
IdentitiesOnly yes
|
||||
StrictHostKeyChecking yes
|
||||
UserKnownHostsFile /opt/data/.ssh/gitea_known_hosts
|
||||
ConnectTimeout 10
|
||||
'''
|
||||
GUIDANCE='''# Canina execution preflight
|
||||
|
||||
This gateway runs as UID10000 with HOME=HERMES_HOME=/opt/data; Docker root is not the worker identity.
|
||||
Before reporting Git credentials missing, run read-only `git ls-remote canina-gitea:parsa/canina.git refs/heads/develop` from the actual worker. The dedicated existing key is /opt/data/.ssh/canina_gitea; pinned trust is /opt/data/.ssh/gitea_known_hosts. Never print/copy private keys, disable host verification, request a new key/token without testing the existing route, or embed HTTPS tokens in URLs. Browser vault login tools are for website forms, not SSH key provisioning.
|
||||
Raw repository URL: ssh://git@git.parsaaghayi.ir:222/parsa/canina.git. Diagnose URL/SSH host matching independently from repository permissions. A successful read does not establish push permission or CI publication.
|
||||
Use isolated worktrees and exact tool exit/results. Delegation dispatched is not completed; wait for delivered results, and distinguish failed access, implementation, tests, CI and live acceptance. Do not report feature completion from plans, tool presence or another agent's unsupported claim. Do not replay unrelated feature requests while repairing Hermes.
|
||||
Preserve owner approval gates, existing sessions and all unrelated profiles. All code/config repair changes must be tracked in Git and released through CI/CD; never restart gateways or deploy site features merely to test access.
|
||||
'''
|
||||
def config_probe(path,host,user='git'):
|
||||
r=subprocess.run(['ssh','-F',str(path),'-G','-l',user,host],capture_output=True,text=True,timeout=10,check=True)
|
||||
return dict(line.split(' ',1) for line in r.stdout.splitlines() if ' ' in line and line.split(' ',1)[0] in {'port','identitiesonly','stricthostkeychecking','identityfile','userknownhostsfile','hostname'})
|
||||
def test():
|
||||
with tempfile.TemporaryDirectory() as t:
|
||||
p=pathlib.Path(t)/'config'; p.write_text('Host canina-gitea\n HostName git.parsaaghayi.ir\n User git\n Port 222\n IdentityFile /opt/data/.ssh/canina_gitea\n IdentitiesOnly yes\n StrictHostKeyChecking yes\n UserKnownHostsFile /opt/data/.ssh/gitea_known_hosts\n'+BLOCK)
|
||||
d=config_probe(p,'git.parsaaghayi.ir'); assert d['port']=='222' and d['identitiesonly']=='yes' and d['stricthostkeychecking']=='true' and d['identityfile']=='/opt/data/.ssh/canina_gitea',d
|
||||
assert config_probe(p,'unrelated.example')['port']=='22'
|
||||
assert config_probe(p,'git.parsaaghayi.ir','other')['port']=='22'
|
||||
assert config_probe(p,'canina-gitea')['port']=='222'
|
||||
print('PASS: raw git route, alias route, unrelated host and unrelated user isolation')
|
||||
def apply():
|
||||
assert os.getuid()==10000 and os.getenv('HERMES_HOME')=='/opt/data'
|
||||
cfg=HOME/'.ssh/config'; before=cfg.read_text(); guide=HOME/'.hermes.md'
|
||||
assert 'Host canina-gitea\n' in before
|
||||
assert not guide.exists() or guide.read_text()==GUIDANCE,'unmanaged guidance exists'
|
||||
assert 'Match originalhost git.parsaaghayi.ir' not in before or BLOCK in before,'unmanaged raw host route'
|
||||
if BLOCK not in before:
|
||||
assert 'Host git.parsaaghayi.ir' not in before
|
||||
backup=HOME/'.ssh/config.before-canina-routing-20261106'
|
||||
if backup.exists(): assert backup.read_text()==before,'backup conflict'
|
||||
else:
|
||||
fd=os.open(backup,os.O_WRONLY|os.O_CREAT|os.O_EXCL,0o600)
|
||||
with os.fdopen(fd,'w') as f: f.write(before)
|
||||
tmp=cfg.with_suffix('.repair-new'); tmp.write_text(before+BLOCK); tmp.chmod(cfg.stat().st_mode & 0o777); os.replace(tmp,cfg)
|
||||
if not guide.exists():
|
||||
fd=os.open(guide,os.O_WRONLY|os.O_CREAT|os.O_EXCL,0o600)
|
||||
with os.fdopen(fd,'w') as f:f.write(GUIDANCE)
|
||||
d=config_probe(cfg,'git.parsaaghayi.ir'); assert d['port']=='222' and d['identityfile']=='/opt/data/.ssh/canina_gitea',d
|
||||
print(json.dumps({'status':'applied','uid':os.getuid(),'config_sha256':hashlib.sha256(cfg.read_bytes()).hexdigest(),'guidance_sha256':hashlib.sha256(guide.read_bytes()).hexdigest(),'restart':False}))
|
||||
if __name__=='__main__':
|
||||
test()
|
||||
if '--apply' in sys.argv: apply()
|
||||
Reference in new issue
Block a user