LoginSignup
8
8

More than 5 years have passed since last update.

特定のHostのみからRootLoginを許可する

Posted at

Goal

* chefリポジトリサーバを作成し、knife soloで実行できるようにしたい
* chef soloの実行ユーザは各サーバのrootユーザとしたい
* 各サーバのrootログインをchefリポジトリサーバのみに絞りたい
* 前提として、VPN環境は持っておらず、さくらVPSやAmazon EC2など様々なサービスでサーバを運用していて、さらに様々な場所でwifiを切り替えてそれらサーバを管理している

Plan

chef_execute_constitution.001.jpg

chef_execute_constitution.002.jpg

* chefリポジトリサーバにnomaduserを作成
 (自分自身以外すべてのサーバにrootログインできる権限を持つ最強ユーザ.遊牧民のようにいろんなサーバを渡り歩くことを仕事とするのでnomadと名づけた.)
* nomaduserのpublic keyを全サーバのrootユーザに配り、sshd_config設定でchefリポジトリのIPアドレスのみPermitRootLoginを許可する
* これで、通常ユーザは通常通りssh鍵認証でログイン可能になり、なんらかの理由で何者かがnomaduserのprivate keyを手に入れても、chefリポジトリサーバ上からしかsshすることはできない
* chefリポジトリサーバのnomaduserは厳重管理する必要がある
* この方法でchefリポジトリサーバを踏み台サーバとすることもできるはず

Manual

sshd_config

PermitRootLogin no
PasswordAuthentication no

## ...

# Permit root ssh login for only chef admin servers
Match Address <chefリポジトリサーバIPアドレス(ssh接続元)>
    PermitRootLogin yes
/etc/init.d/sshd restart

※ Matchコマンドで例外をつくることができる項目一覧
http://www.unixuser.org/~euske/doc/openssh/jman/sshd_config.html

すべての設定項目にMatch指令が適用されるわけではありません。使用できる項目は、AcceptEnv ,AllowAgentForwarding ,AllowGroups ,AllowTcpForwarding ,AllowUsers ,AuthenticationMethods ,AuthorizedKeysCommand ,AuthorizedKeysCommandUser ,AuthorizedKeysFile ,AuthorizedPrincipalsFile ,Banner ,ChrootDirectory ,DenyGroups ,DenyUsers ,ForceCommand ,GatewayPorts ,GSSAPIAuthentication ,HostbasedAuthentication ,HostbasedUsesNameFromPacketOnly ,KbdInteractiveAuthentication ,KerberosAuthentication ,MaxAuthTries ,MaxSessions ,PasswordAuthentication ,PermitEmptyPasswords ,PermitOpen ,PermitRootLogin ,PermitTTY ,PermitTunnel ,PubkeyAuthentication ,RekeyLimit ,RhostsRSAAuthentication ,RSAAuthentication ,X11DisplayOffset ,X11ForwardingおよびX11UseLocalHostです。

公開鍵共有

## root user of chef target server

echo "<public key of nomaduser>" >> ~/.ssh/authorized_keys

Alternatives

踏み台サーバを作るならiptables, hosts.allow/hosts.denyなどでACLをかけるのもあり
sshd_configの"PermitRootLogin forced-commands-only"とすると、リモートコマンド実行モードでのみroot ssh可能になるらしいが、これだとknife soloは実行できなかった

8
8
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
8
8