はじめての使い方
はじめての使い方
このガイドでは、インストールから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ドメインを1つ定義しています。
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が動作するようになりました。次は独自のドメインとアクションを設定しましょう。