canonical / jhack

Chock-full of Juju hackery.
Apache License 2.0
49 stars 23 forks source link

"Permission denied" ssh errors on accessing unit-state.db #113

Open sed-i opened 7 months ago

sed-i commented 7 months ago

Issue

show-stored errors out,

$ jhack show-stored cos-proxy/0                       
ERROR:jhack:failed to fetch db; command ['juju', 'scp', 'cos-proxy/0:/var/lib/juju/agents/unit-cos-proxy-0/charm/.unit-state.db', '/home/ubuntu/snap/jhack/235/unit-state-otlo29cu.db'] exited with 1
failed to fetch db; aborting. b'ERROR exit status 1 (scp: /var/lib/juju/agents/unit-cos-proxy-0/charm/.unit-state.db: Permission denied)\n'

because of file permissions:

$ juju ssh cos-proxy/0 ls -la /var/lib/juju/agents/unit-cos-proxy-0/charm/.unit-state.db
-rw------- 1 root root 20480 Dec  6 17:58 /var/lib/juju/agents/unit-cos-proxy-0/charm/.unit-state.db

Solution attempts

ssh-ing with root doesn't work,

$ juju ssh root@cos-proxy/0 hexdump /var/lib/juju/agents/unit-cos-proxy-0/charm/.unit-state.db
root@10.41.168.28: Permission denied (publickey).

but a sudo helps

$ juju ssh cos-proxy/0 sudo hexdump /var/lib/juju/agents/unit-cos-proxy-0/charm/.unit-state.db
0000000 5153 694c 6574 6620 726f 616d 2074 0033
0000010 0010 0101 4000 2020 0000 0900 0000 0500
...
Connection to 10.41.168.28 closed.

Not sure to translate this to a juju scp command, but perhaps could pipe stdout instead?

Environment

sed-i commented 7 months ago

On jhack (edge) 0.3.23 there's a different error:

jhack show-stored cos-proxy/0
Traceback (most recent call last):
  File "/snap/jhack/266/bin/jhack", line 8, in <module>
    sys.exit(main())
  File "/snap/jhack/266/lib/python3.8/site-packages/jhack/main.py", line 58, in main
    from jhack.scenario.snapshot import snapshot
  File "/snap/jhack/266/lib/python3.8/site-packages/jhack/scenario/snapshot.py", line 28, in <module>
    from jhack.scenario.utils import JujuUnitName
  File "/snap/jhack/266/lib/python3.8/site-packages/jhack/scenario/utils.py", line 6, in <module>
    from scenario.scripts.errors import InvalidTargetUnitName
ModuleNotFoundError: No module named 'scenario.scripts'
PietroPasotti commented 5 months ago

I'm working on this, I think the issue has appeared on some recent juju version (did the permissions change on the charm files at some point I recall?)

the importerror has been fixed in the meantime, the ssh issue persists.

Zvirovyi commented 1 month ago

Have the same issue on juju 3.5.0-genericlinux-amd64 (lxd) and jhack 0.4.0.25.4 (rev 337 from latest/stable):

ERROR:jhack:failed to fetch db; command ['juju', 'scp', 'postgresql/0:/var/lib/juju/agents/unit-postgresql-0/charm/.unit-state.db', '/home/zvirovyi/snap/jhack/337/unit-state-gz7m_i0i.db'] exited with 1
failed to fetch db; aborting. b'ERROR exit status 1 (scp: /var/lib/juju/agents/unit-postgresql-0/charm/.unit-state.db: Permission denied)\n'