Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Speaker Deck
PRO
Sign in
Sign up for free
.ssh/configを管理する .ssh/configで管理する
Ken’ichiro Oyama
November 03, 2016
Technology
15
10k
.ssh/configを管理する .ssh/configで管理する
PHPカンファレンス2016
Ken’ichiro Oyama
November 03, 2016
Tweet
Share
More Decks by Ken’ichiro Oyama
See All by Ken’ichiro Oyama
runn is a package/tool for running operations following a scenario. / golang.tokyo #32
k1low
1
290
GitHub Actions Deep Dive using PHP / PHPerKaigi 2022
k1low
0
900
io/fs.FS for testability. io/fs.FS for abstraction. / Go Conference 2021 Autumn (Online)
k1low
0
300
Continuous Documentation - CI/CDパイプラインを活用した文書化技術 - / Pepabo Tech Conference #16
k1low
1
160
システムの変化に追従可能でかつ理解し易いドキュメントシステムのモデル化 / Web System Architecture #8
k1low
9
3k
目的に沿ったDocumentation as Codeをいかにして実現していくか / PHPerKaigi 2021
k1low
15
4.3k
Documentation as Codeで継続的なドキュメント運用を実現する / July Tech Festa 2021 winter
k1low
6
5k
tblsで実現したいシステムとGoによるその実装 / Fukuoka.go#16
k1low
1
350
データ基盤のメタデータを継続的に管理できる仕組みを作る(ペパボ編) / pepabohatena
k1low
5
1.6k
Other Decks in Technology
See All in Technology
データをモデリングしていたら、組織をモデリングし始めた話 / engineers-in-carta-vol3-data-engineer
pei0804
4
3.2k
スクラムのスケールとチームトポロジー / Scaled Scrum and Team Topologies
daiksy
1
380
miisan's career talk
mii3king
0
210
Custom GitHub Actions by Java
kazamori
0
280
複数のスクラムチームをサポートするエンジニアリングマネジメントの話
okeicalm
0
900
雑な攻撃からELBを守る一工夫 +おまけ / Know-how to protect servers from miscellaneous attacks
hiroga
0
220
JDK Flight Recorder入門
chiroito
1
480
機械学習システムアーキテクチャ入門 #1
asei
3
1.2k
OPENLOGI Company Profile
hr01
0
240
2022年度新卒技術研修「エンジニアマインド」講義
excitejp
PRO
0
330
リファインメントは楽しいかね?
kitamu_mu
1
330
WACATE 2022 夏 ワークショップの目的
imtnd
0
110
Featured
See All Featured
It's Worth the Effort
3n
172
25k
A designer walks into a library…
pauljervisheath
196
16k
Fontdeck: Realign not Redesign
paulrobertlloyd
73
4.1k
Reflections from 52 weeks, 52 projects
jeffersonlam
337
17k
Docker and Python
trallard
27
1.6k
Teambox: Starting and Learning
jrom
123
7.7k
Building a Scalable Design System with Sketch
lauravandoore
447
30k
A Tale of Four Properties
chriscoyier
149
21k
Keith and Marios Guide to Fast Websites
keithpitt
404
21k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
10
3.3k
Why You Should Never Use an ORM
jnunemaker
PRO
47
7k
Writing Fast Ruby
sferik
612
57k
Transcript
.ssh/configを管理する .ssh/configで管理する Kenʼichiro Oyama Fusic Co.,Ltd. 2016.11.3 1 PHPカンファレンス2016
みなさん SSHしてますか? 2 PHPカンファレンス2016
わたしは SSHしてます 3 PHPカンファレンス2016
?> NEXT PHPカンファレンス2016のテーマ 4 PHPカンファレンス2016
SSHとNEXT 5 PHPカンファレンス2016 FTP SSH + パスワード
SSH + 公開鍵認証 「SSHしたら負け」 <- たぶんここがNEXT Docker、EC2 Run Command、etc “NEXT”ではないですが、 今⽇は”SSH + 公開鍵認証”で少しだけ役に⽴ちそ うな話をします
Who 6 PHPカンファレンス2016
k1LoW Kenʼichiro Oyama @k1LoW Fusic Co.,Ltd. エンジニア
基盤ユニット テックリード GitHub organizations fukuokarb / dotcake / emacs-jp / etc. awspecというAWS⽤のテストツールを作って います https://github.com/k1LoW/awspec 7 PHPカンファレンス2016
普段のわたし 複数のプロジェクト 開発中 運⽤中 複数のサーバ
プロジェクト単位 ロール単位(Web、DB、etc) 本番、ステージング、テスト 8 PHPカンファレンス2016
イメージ 複数のプロジェクトの複数のサーバにSSH 9 PHPカンファレンス2016
~/.ssh/config SSH接続の管理をするための設定ファイル ~/.ssh/configはユーザごとの設定ファイル 10 PHPカンファレンス2016 Host github.com
User git Hostname github.com PreferredAuthentications publickey IdentityFile ~/.ssh/github_rsa
/home/k1low/.ssh/config 管理しているサーバへSSH接続するための設定 を記載 秘密鍵も .ssh/ 以下に配置 プロジェクトごと、ロールごと、サーバごとな
どで分けることが多い id_rsaは使わない 秘密鍵だけでなく、その他の接続設定も重要 HostnameやUser ProxyCommandとか 11 PHPカンファレンス2016
.ssh/config どうやって管理していますか? 12 PHPカンファレンス2016
.ssh/configの管理 configのバックアップ/リストア 秘密鍵のバックアップ/リストア サーバ接続情報の追加/削除 チームメンバーへの共有
踏み台サーバなど他サーバへの設置 13 PHPカンファレンス2016
configと秘密鍵に分かれていて ⾯倒 14 PHPカンファレンス2016
configは分割できないので メンバーへの共有も⾯倒 15 PHPカンファレンス2016
今のconfigとバックアップした configのマージも⾯倒 16 PHPカンファレンス2016
sconb 17 PHPカンファレンス2016
sconb “Ssh CONfig Buckup tool” .ssh/config専⽤のバックアップツール https://github.com/k1LoW/sconb
gem install sconb でインストール ※本⽇も⼤変お世話になっているCONBUとは無関係です 18 PHPカンファレンス2016
使い⽅ 19 PHPカンファレンス2016
バックアップ 20 PHPカンファレンス2016 $ sconb dump > ssh_config.json $ cat
ssh_config.json { "github.com": { "Host": "github.com", "User": "git", "Hostname": "github.com", "PreferredAuthentications": "publickey", "IdentityFile": [ "~/.ssh/github_rsa" ] }, ...
絞り込んでバックアップ 21 PHPカンファレンス2016 $ sconb dump example > ssh_config.json $ cat
ssh_config.json { ”example.com": { "Host": ”example.com", "User": ”k1low", "Hostname": ”dev.example.com", "PreferredAuthentications": "publickey", "IdentityFile": [ "~/.ssh/example_rsa" ] } }
リストア 22 PHPカンファレンス2016 $ sconb restore < ssh_config.json Host github.com
User git Hostname github.com PreferredAuthentications publickey IdentityFile ~/.ssh/github_rsa ... $ sconb restore < ssh_config.json > ~/.ssh/cofing
秘密鍵も含めて1ファイル化 23 PHPカンファレンス2016 $ sconb dump --all > ssh_config_with_key.json $
cat ssh_config_with_key.json { "github.com": { "Host": "github.com", "User": "git", "Hostname": "github.com", "PreferredAuthentications": "publickey", "IdentityFile": [ "~/.ssh/github_rsa" ], "IdentityFileContent": [ "-----BEGIN RSA PRIVATE KEY-----\nMIIEpXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX... ] }, ...
秘密鍵のリストア 24 PHPカンファレンス2016 $ sconb keyregen < ssh_config_with_key.json Regenerate ~/.ssh/github_rsa
... ...
つまり ssh_config <-> JSON のコンバータ 25 PHPカンファレンス2016
パイプで各種UNIXコマンドとも 連携できる 26 PHPカンファレンス2016
jqを使ったssh_confg.jsonのマージ jq: JSONをいい感じに操作できるコマンド 27 PHPカンファレンス2016 $ jq -s '.[0]
+ .[1]’ a.json b.json | sconb restore > ~/.ssh/config
.ssh/configを管理する sconbはおいしい 28 PHPカンファレンス2016
別の視点から 29 PHPカンファレンス2016
普段のわたし(再掲) 複数のプロジェクト 開発中 運⽤中 複数のサーバ
プロジェクト単位 ロール単位(Web、DB、etc) 本番、ステージング、テスト 30 PHPカンファレンス2016
イメージ(再掲) 複数のプロジェクトの複数のサーバにSSH 31 PHPカンファレンス2016
突然の◯penSSLの脆弱性発表 32 PHPカンファレンス2016
インベントリ情報 「サーバにイントールされているパッケージの バージョン⼀覧を再度確認して欲しい」 現在稼働しているサーバ数⼗台 まったく別の時期にまったく別のサービスを 構築している
全部SSHでログインして確認。。。??そして その後まとめるの。。。? ツラみがある。。。 33 PHPカンファレンス2016
34 koma PHPカンファレンス2016
koma エージェントレスでリモートホストのインベン トリ情報を収集するツール https://github.com/k1LoW/koma 類似ツール: ohai /
facter gem install koma でインストール `ssh` を `koma ssh` に変えるだけで、リモ ートホストのインベントリ情報をJSONで取得 できる 35 PHPカンファレンス2016
koma ssh 36 PHPカンファレンス2016 $ koma ssh example.com {
"memory": { "swap": { "cached": "652kB", "total": "2097148kB", "free": "2091376kB" }, "total": "1019956kB", "free": "255104kB", "buffers": "310644kB", "cached": "185748kB", ...
koma keys (収集できるインベントリ情報) memory ec2 (disabled) hostname
domain fqdn platform platform_version filesystem cpu virtualization kernel block_device package user group service PHPカンファレンス2016 37
koma run-command 38 PHPカンファレンス2016 $ koma run-command example.com,example.jp uptime {
"example.com": { "uptime": { "exit_signal": null, "exit_status": 0, "stderr": "", "stdout": " 00:18:10 up 337 days, 4:51, 1 user, load average: 0.08, 0.02, 0.01\n" } }, "example.jp": { "uptime": { ...
そう、.ssh/configが設定されて いればね! 39 PHPカンファレンス2016
.ssh/configで管理する 40 PHPカンファレンス2016
ssh_config形式で管理する .ssh/configで管理する 41 PHPカンファレンス2016
koma with ssh_config komaはssh_config形式のフォーマットを STDINから読み込んで実⾏することができる Vagrant上のOSのcpu情報を取得 sconbをでHostをフィルタリング
42 PHPカンファレンス2016 $ vagrant ssh-config | koma ssh --key cpu $ sconb dump dev.* | sconb restore | koma ssh
Vuls 43 PHPカンファレンス2016
Vuls “VULnerability Scanner” バルス Linux/FreeBSD向けの脆弱性スキャンツール Ubuntu、Debian、CentOS、Amazon
Linux、RHELに対応 標準のTUIだけでなくVulsRepoというWebビューワもある NVDやJVNの脆弱性情報などを使⽤してスキャン スキャン対象のサーバーへは “SSH” で接続 TOMLで設定を記述 44 PHPカンファレンス2016
SSH。。。だと。。? 45 PHPカンファレンス2016
ssh_config_to_vuls_config 46 PHPカンファレンス2016
ssh_config_to_vuls_config ssh_config形式をVuls⽤のTOMLファイル形式 に変換 sc2vcコマンド https://github.com/k1LoW/ssh_config_to_vuls_config gem
install ssh_config_to_vuls_config でインストール (当然)sconbでフィルタリングも可能 47 PHPカンファレンス2016 $ cat ~/.ssh/config | sc2vc > vuls_config.toml $ sconb dump dev.* | sconb restore | sc2vc > filtered_config.toml
.ssh/config -> JSON JSON -> .ssh/config JSON -> koma JSON
-> Vuls 48 PHPカンファレンス2016
NEXT 49 PHPカンファレンス2016
ssh_configファイルを集約すれば サーバインベントリ情報も 脆弱性情報も 管理できるのでは? 50 PHPカンファレンス2016
こんなサーバを 51 PHPカンファレンス2016
.ssh/configで管理 52 PHPカンファレンス2016
komad (仮) sconbなJSONをAPI or SCP経由で登録 ssh_config + komaでサーバインベントリ情報
を収集管理 ssh_config + Vulsで脆弱性情報を収集管理 koma run-commandでSSHを通じた外形監視 ちょっと変わったサーバ管理/監視システムが できそう 53 PHPカンファレンス2016
.ssh/configで管理する 54 PHPカンファレンス2016
まとめ 55 PHPカンファレンス2016
まとめ .ssh/configをsconbでJSON形式にすることで 管理容易性、再利⽤性を向上 .ssh/configやssh_config形式のフォーマット を⼊⼒として動くエージェントレスなサーバイ ンベントリ収集ツール koma
Vulsの設定の元として.ssh/configの活⽤ ssh_configを活⽤したサーバ管理/監視システ ムkomad(仮)の可能性 56 PHPカンファレンス2016
さっそく .ssh/configを整理しましょう 古い設定、残っていませんか? 57 PHPカンファレンス2016
Thank you! Fusicはテクノロジーが 好きなエンジニアを募集しています https://fusic.github.io 58
?> 59 PHPカンファレンス2016
NEXT 60 PHPカンファレンス2016
イメージ(再掲) 複数のプロジェクトの複数のサーバにSSH 61 PHPカンファレンス2016
サーバのユーザを管理したい どのサーバにどのユーザがSSHログインできる のか 簡単なものでいい ある程度でいい もしくはSSHログインできる情報をもらえるよ
うにしたい 公開鍵とか秘密鍵とかの管理 62 PHPカンファレンス2016
⼀般的な⽅法 63 PHPカンファレンス2016
PAM Pluggable Authentication Module PAMを使ってユーザ管理サーバ(認証基盤)に 認証の要求をもらう ADとかLDAPが⼀般的らしい
ただ個⼈的にはSTNS推し シンプル 設定がTOML 認証サーバ側をサーバレスにできそう http://qiita.com/shogomuranushi/items/ f09fcdeb146b45452403 新イケメンことP⼭さん(@pyama86)が開発している 64 PHPカンファレンス2016
だかしかし 65 PHPカンファレンス2016
プロジェクトを横断できない 完全弊社都合 66 PHPカンファレンス2016
komad(仮)がssh_configを 払い出したらどうだろう 67 PHPカンファレンス2016
komad(仮)にもらう API経由でssh_config.jsonをもらう 68 PHPカンファレンス2016
どうでしょう。。? イビツなのは承知 komad(仮)サーバの運⽤。。。 無理があるか。。。 69 PHPカンファレンス2016
Thank you! Fusicはテクノロジーが 好きなエンジニアを募集しています https://fusic.github.io 70