Slide 1

Slide 1 text

Ruby DSL × SSH con g = Nymphia !! @mozamimy

Slide 2

Slide 2 text

Con gure everyday vimrc bashrc hako_apps Apache rewrite rules Fluend Sendmail etc... 2

Slide 3

Slide 3 text

SSH con g 3

Slide 4

Slide 4 text

Why so dif cult? 気を抜くと SSH con g が破滅してる 構造的に書けるようになっていない ご家庭や仕事のインフラが混じると最悪 基本フラットに 1 ファイルとして書く 他人のファイル読むの難しい とにかく冗長 4

Slide 5

Slide 5 text

What is Nymphia? identity_file :private, '~/.ssh/id_rsa.1' my_server_port = 4321 host 'alice', 'my server on VPS' do hostname 'alice.example.com' user 'alice' port my_server_port use_identify_file :private end Host alice Hostname alice.example.com User alice Port 4321 IdentityFile ~/.ssh/id_rsa.1 5

Slide 6

Slide 6 text

Motivation Ruby の DSL を作ってみたかった SSH con g に秩序をもたらしたい 構造化して DRY にしたい ファイルを分けて管理したい Ruby を使った構成管理ツー ルに組み込みやすそう 6

Slide 7

Slide 7 text

簡単なつかいかた ( 雰囲気) 7

Slide 8

Slide 8 text

Install $ gem install nymphia CLI $ nymphia --help nymphia -f, --file=FILE Your DSL code file -o, --output=FILE Output file (default: stdout) 8

Slide 9

Slide 9 text

Basis source identity_file :private, '~/.ssh/id_rsa.1' my_server_port = 4321 host 'alice', 'my server on VPS' do hostname 'alice.example.com' user 'alice' port my_server_port use_identify_file :private end 9

Slide 10

Slide 10 text

Basis compiled # # This config is generated by Nymphia 0.1.1 # # my server on VPS Host alice Hostname alice.example.com User alice Port 4321 IdentityFile ~/.ssh/id_rsa.1 10

Slide 11

Slide 11 text

Splitting les identity_file :private, '~/.ssh/id_rsa.1' host 'alice', 'my server on VPS' do hostname 'alice.example.com' user 'alice' port 4321 use_identify_file :private end load 'other_nymphia_file.nym.rb' load で別ファイルを読み込める 単一の con g として出力される 11

Slide 12

Slide 12 text

Proxy and Gateway ナマの SSH con g は全てが Host proxy や gateway として使うホストをコー ドレ ベルでわかるようにしたい 12

Slide 13

Slide 13 text

Proxy identity_file :company_proxy, '~/.ssh/id_rsa.company.gw' proxy 'awsproxy.company.apne1' do hostname 'gw.apne1.example.com' user 'alice' port 19822 use_identify_file :company_proxy # SOCKS proxy dynamic_forward 23921 # ssh tunnels local_forward 'mysql-server', { 'localhost' => 13306, 'mysql.apne.aws.example.com' => 3306, } end 13

Slide 14

Slide 14 text

Proxy host と基本は同じ ブロック内は host と同様に書ける proxy 内では local_foward というメソッドが使える LocalForward をハッシュできれいに書ける 14

Slide 15

Slide 15 text

Proxy compiled # # This config is generated by Nymphia 0.1.1 # Host awsproxy.company.apne1 Hostname gw.apne1.example.com User alice Port 19822 IdentityFile ~/.ssh/id_rsa.company.gw DynamicForward 23921 LocalForward localhost:13306 mysql.apne.aws.example.com:3306 15

Slide 16

Slide 16 text

Gateway de ne a gateway identity_file :company, '~/.ssh/id_rsa.company' identity_file :company_gateway, '~/.ssh/id_rsa.company.gw' gateway 'company.gateway' do hostname 'gw.example.com' user 'alice' port 19822 end host の代わりに gateway でゲー トウェイを定義 ブロック内は普通の host とおなじ 16

Slide 17

Slide 17 text

group 'company.ap-northeast-1' do use_gateway 'company.gateway' default_params do check_host_ip 'no' strict_host_key_checking 'no' user 'alice' port 9822 use_identify_file :company, :company_gateway end host '*.apne.aws.example.com' host 'alice.apne.aws.example.com' do hostname '10.16.16.16' user 'white_rabbit' port 7777 end end 17

Slide 18

Slide 18 text

Gateway use_gateway で先に定義した gateway をグルー プに 適用できる default_params でグルー プ内のホストにデフォルト で適用するパラメー タをまとめて書いておける default_params は上書き可能 18

Slide 19

Slide 19 text

Gateway # # This config is generated by Nymphia 0.1.1 # Host company.gateway Hostname gw.example.com User alice Port 19822 Host *.apne.aws.example.com CheckHostIp no StrictHostKeyChecking no User alice Port 9822 IdentityFile ~/.ssh/id_rsa.company IdentityFile ~/.ssh/id_rsa.company.gw ProxyCommand ssh company.gateway -q -W %h:%p 19

Slide 20

Slide 20 text

Gateway Host alice.apne.aws.example.com CheckHostIp no StrictHostKeyChecking no IdentityFile ~/.ssh/id_rsa.company IdentityFile ~/.ssh/id_rsa.company.gw ProxyCommand ssh company.gateway -q -W %h:%p Hostname 10.16.16.16 User white_rabbit Port 7777 20

Slide 21

Slide 21 text

Future issues 構文解析して SSH con g → Ruby に変換 ほんとはここまでやりたかった.. Treetop ? Racc ? Racc のほうがよさげ OpenSSH の比較的新しい機能に追従する ProxyJump とか Include とか.. コンパイルなしに SSH できる $ nymphia ssh みたい なサブコマンドを作る 簡易プロビジョニング ホー ムディレクトリ以下に .bashrc 置くとか 21