goss
概要
- サーバチェックツール
- Serverspec と同類
メリット
- バイナリ置くだけなので導入楽
- 学習コスト低い
- YAML で書けるので可読性ある
- HTTP 通信にてテストを実行できる
command
が使えるので一応なんでもテスト書ける- 実行結果の戻り値の比較
- 標準出力、標準エラー出力の内容の比較もできる
使いづらいと思ったこと
- Serverspec と比べると機能不足感
- description 書けない
- 実行結果からパッと見でなんのテストかわからない
- autoadd で追加したサービスに関しては title, meta つけれるけど、command 等を利用したものにはつけれない
- 同じファイルに同じ内容のテスト項目書くとどっちかは無視される
こうは書かない
file: /etc/ssh/sshd_config: exists: true file: /etc/httpd/conf/httpd.conf: exists: true
こう書く
file: /etc/ssh/sshd_config: exists: true /etc/httpd/conf/httpd.conf: exists: true
それぞれ別ファイルに書いて
render
を実行すると上手くまとめてくれる
内容
インストール
$ curl -fsSL https://goss.rocks/install | sh
自動テスト生成(SSH)
create
$ sudo goss autoadd sshd
execute
$ goss validate
HTTP 通信でのテスト実行
server
$ goss serve --format documentation&
client
$ curl http://localhost:8080/healthz
systemd などを経由して起動したものは
service
その他のプロセス監視はprocess
を使うと良さそうローカルのファイルを利用してリモートサーバのテストを実行する
$ cat /tmp/goss.yaml | ssh -i ~/key -l test xx.xx.xx.xx 'goss --gossfile - validate'
変数の利用
$ goss --vars vars.yaml --gossfile goss.yaml validate
出力フォーマット例
JSON
$ goss --vars vars.yaml --gossfile goss.yaml validate --format json
References
サンプル
SSH の設定で root ログインは禁止になっていることを確認する
file: /etc/ssh/sshd_config: exists: true contains: - "PermitRootLogin no"
3306 ポートが 127.0.0.1 からのみ待ち受けていることを確認する
port: tcp:3306: listening: true ip: - 127.0.0.1
SSH ログイン不可の test ユーザが存在することを確認する
user: test: exists: true shell: /sbin/nologin
テストファイルをまとめたい
gossfile: mysql.yaml: {} web.yaml: {}
80 番ポートが外部に公開されていることを確認する
command: nmap -sS -p 80 xx.xx.xx.xx | grep -i open: exit-status: 0
処理をループで回したい
vars.yaml
target: xx.xx.xx.xx port: - 22 - 80 - 443
test.yaml
command: {{$target := .Vars.target}} {{range .Vars.port}} nmap -sS -p {{.}} {{$target}} | grep -i open: exit-status: 0 {{end}}