์ฒซ ์ฌ์ฉ
์ฒซ ์ฌ์ฉ
์ด ๊ฐ์ด๋๋ ์ค์น๋ถํฐ SSH-Frontiรจre๋ฅผ ํตํ ์ฒซ SSH ๋ช ๋ น๊น์ง ์๋ดํฉ๋๋ค.
1. ์ต์ ๊ตฌ์ฑ ์ค๋น
์ต์ config.toml ํ์ผ์ ๋ง๋ญ๋๋ค:
[global]
log_file = "/var/log/ssh-frontiere/commands.json"
default_timeout = 60
[domains.test]
description = "Domaine de test"
[domains.test.actions.hello]
description = "Commande de test qui affiche un message"
level = "read"
timeout = 10
execute = "/usr/bin/echo hello from ssh-frontiere"
์ด ๊ตฌ์ฑ์ read ์์ค์์ ์ ๊ทผ ๊ฐ๋ฅํ hello ์ก์
์ ๊ฐ์ง ๋จ์ผ ๋๋ฉ์ธ test๋ฅผ ์ ์ํฉ๋๋ค.
2. ์ค์น ๋ฐ ๊ตฌ์ฑ
๋จผ์ ssh-frontiere ๋ฐ์ด๋๋ฆฌ๊ฐ ํ์ํฉ๋๋ค. ์ปดํ์ผ ๊ฐ์ด๋๋ฅผ ์ฐธ์กฐํ๊ฑฐ๋ ๋ฆด๋ฆฌ์ค ํ์ด์ง์์ ์ฌ์ ์ปดํ์ผ๋ ๋ฐ์ด๋๋ฆฌ๋ฅผ ๋ค์ด๋ก๋ํ์ธ์.
# ๋ฐ์ด๋๋ฆฌ ๋ณต์ฌ
sudo cp ssh-frontiere /usr/local/bin/
sudo chmod 755 /usr/local/bin/ssh-frontiere
# ๊ตฌ์ฑ ์ค์น
sudo mkdir -p /etc/ssh-frontiere
sudo cp config.toml /etc/ssh-frontiere/config.toml
sudo chmod 640 /etc/ssh-frontiere/config.toml
# ๋ก๊ทธ ๋๋ ํ ๋ฆฌ ์์ฑ
sudo mkdir -p /var/log/ssh-frontiere
# ์๋น์ค ๊ณ์ ์์ฑ
sudo useradd -m -s /usr/local/bin/ssh-frontiere test-user
# ๊ณ์ ์ ๋ก๊ทธ ์ฐ๊ธฐ ๊ถํ ๋ถ์ฌ
sudo chown test-user:test-user /var/log/ssh-frontiere
3. SSH ํค ๊ตฌ์ฑ
ํด๋ผ์ด์ธํธ ๋จธ์ ์์:
# ํค ์์ฑ
ssh-keygen -t ed25519 -C "test-key" -f ~/.ssh/test-frontiere
์๋ฒ์์, ๊ณต๊ฐ ํค๋ฅผ ~test-user/.ssh/authorized_keys์ ์ถ๊ฐํฉ๋๋ค:
command="/usr/local/bin/ssh-frontiere --level=read",restrict ssh-ed25519 AAAA... test-key
# ๊ถํ ๋ณด์ ์ค์
sudo chmod 700 ~test-user/.ssh
sudo chmod 600 ~test-user/.ssh/authorized_keys
sudo chown -R test-user:test-user ~test-user/.ssh
4. ์ฒซ ํธ์ถ
# ์ฌ์ฉ ๊ฐ๋ฅํ ๋ช
๋ น ํ์
{ echo "help"; echo "."; } | ssh -i ~/.ssh/test-frontiere test-user@serveur
์์ ์๋ต (์๋ฒ๊ฐ ๋จผ์ ๋ฐฐ๋๋ฅผ ๋ณด๋ด๊ณ ์ด์ด์ ์๋ต):
#> ssh-frontiere 0.1.0
+> capabilities session, help, body
#> type "help" for available commands
#> ...
>>> {"command":"help","status_code":0,"status_message":"ok","stdout":null,"stderr":null}
#> ์ค์๋ ์ฌ๋์ด ์ฝ์ ์ ์๋ ๋์๋ง ํ
์คํธ๊ฐ ํฌํจ๋ฉ๋๋ค. help ๋ช
๋ น์ read ์์ค์์ ์ ๊ทผ ๊ฐ๋ฅํ ๋๋ฉ์ธ๊ณผ ์ก์
๋ชฉ๋ก์ ํ์ํฉ๋๋ค.
5. ๋ช ๋ น ์คํ
{ echo "test hello"; echo "."; } | ssh -i ~/.ssh/test-frontiere test-user@serveur
์์ ์๋ต:
>> hello from ssh-frontiere
>>> {"command":"test hello","status_code":0,"status_message":"executed","stdout":null,"stderr":null}
ํ๋ก๊ทธ๋จ ์ถ๋ ฅ(hello from ssh-frontiere)์ >>๋ฅผ ํตํด ์คํธ๋ฆฌ๋ฐ์ผ๋ก ์ ์ก๋๊ณ , ์ด์ด์ >>>๋ฅผ ํตํด ์ต์ข
JSON ์๋ต์ด ์ ์ก๋ฉ๋๋ค. ์ถ๋ ฅ์ด ์คํธ๋ฆฌ๋ฐ์ผ๋ก ์ ์ก๋์๊ธฐ ๋๋ฌธ์ JSON์ stdout๊ณผ stderr ํ๋๋ null์
๋๋ค.
6. ํ๋ฆ ์ดํด
๋ค์๊ณผ ๊ฐ์ ๊ณผ์ ์ด ์์์ต๋๋ค:
- SSH ํด๋ผ์ด์ธํธ๊ฐ
test-frontiereํค๋ก ์ฐ๊ฒฐ sshd๊ฐ ํค๋ฅผ ์ธ์ฆํ๊ณauthorized_keys๋ฅผ ์ฝ์command=์ต์ ์ดssh-frontiere --level=read์คํ์ ๊ฐ์ - SSH-Frontiรจre๊ฐ ๋ฐฐ๋(
#>,+>)๋ฅผ ํ์ํ๊ณ ํค๋๋ฅผ ๋๊ธฐ - ํด๋ผ์ด์ธํธ๊ฐ ๋ช
๋ น
test hello(์ ๋์ฌ ์๋ ์ผ๋ฐ ํ ์คํธ)๋ฅผ ๋ณด๋ด๊ณ.(๋ธ๋ก ๋) - SSH-Frontiรจre๊ฐ ๊ฒ์ฆ: ๋๋ฉ์ธ
test, ์ก์ hello, ์์คread<= ์๊ตฌ๋๋read - SSH-Frontiรจre๊ฐ
/usr/bin/echo hello from ssh-frontiere๋ฅผ ์คํ - ์ถ๋ ฅ์ด ์คํธ๋ฆฌ๋ฐ์ผ๋ก ์ ์ก(
>>)๋ ํ ์ต์ข JSON ์๋ต(>>>)
7. ๊ฑฐ๋ถ ํ ์คํธ
์กด์ฌํ์ง ์๋ ๋ช ๋ น์ ์๋ํฉ๋๋ค:
{ echo "test inexistant"; echo "."; } | ssh -i ~/.ssh/test-frontiere test-user@serveur
์๋ต:
>>> {"command":"test inexistant","status_code":128,"status_message":"rejected: unknown action 'inexistant' in domain 'test'","stdout":null,"stderr":null}
๋ช
๋ น์ด ์คํ๋์ง ์์์ผ๋ฏ๋ก stdout๊ณผ stderr๋ null์
๋๋ค.
๋ค์ ๋จ๊ณ
SSH-Frontiรจre๊ฐ ๋์ํ๊ฒ ๋์์ผ๋, ์์ ๋ง์ ๋๋ฉ์ธ๊ณผ ์ก์ ์ ๊ตฌ์ฑํ ์ ์์ต๋๋ค.