์ฒซ ์‚ฌ์šฉ

์ฒซ ์‚ฌ์šฉ

์ด ๊ฐ€์ด๋“œ๋Š” ์„ค์น˜๋ถ€ํ„ฐ 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. ํ๋ฆ„ ์ดํ•ด

๋‹ค์Œ๊ณผ ๊ฐ™์€ ๊ณผ์ •์ด ์žˆ์—ˆ์Šต๋‹ˆ๋‹ค:

  1. SSH ํด๋ผ์ด์–ธํŠธ๊ฐ€ test-frontiere ํ‚ค๋กœ ์—ฐ๊ฒฐ
  2. sshd๊ฐ€ ํ‚ค๋ฅผ ์ธ์ฆํ•˜๊ณ  authorized_keys๋ฅผ ์ฝ์Œ
  3. command= ์˜ต์…˜์ด ssh-frontiere --level=read ์‹คํ–‰์„ ๊ฐ•์ œ
  4. SSH-Frontiรจre๊ฐ€ ๋ฐฐ๋„ˆ(#>, +>)๋ฅผ ํ‘œ์‹œํ•˜๊ณ  ํ—ค๋”๋ฅผ ๋Œ€๊ธฐ
  5. ํด๋ผ์ด์–ธํŠธ๊ฐ€ ๋ช…๋ น test hello (์ ‘๋‘์‚ฌ ์—†๋Š” ์ผ๋ฐ˜ ํ…์ŠคํŠธ)๋ฅผ ๋ณด๋‚ด๊ณ  . (๋ธ”๋ก ๋)
  6. SSH-Frontiรจre๊ฐ€ ๊ฒ€์ฆ: ๋„๋ฉ”์ธ test, ์•ก์…˜ hello, ์ˆ˜์ค€ read <= ์š”๊ตฌ๋˜๋Š” read
  7. SSH-Frontiรจre๊ฐ€ /usr/bin/echo hello from ssh-frontiere๋ฅผ ์‹คํ–‰
  8. ์ถœ๋ ฅ์ด ์ŠคํŠธ๋ฆฌ๋ฐ์œผ๋กœ ์ „์†ก(>>)๋œ ํ›„ ์ตœ์ข… 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๊ฐ€ ๋™์ž‘ํ•˜๊ฒŒ ๋˜์—ˆ์œผ๋‹ˆ, ์ž์‹ ๋งŒ์˜ ๋„๋ฉ”์ธ๊ณผ ์•ก์…˜์„ ๊ตฌ์„ฑํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.