CloudNative Days Spring 2021 ONLINE キーノートでの発表資料です。
https://event.cloudnativedays.jp/cndo2021/talks/1071
本セッションでは、DockerとKubernetesのもつ基本的な機能の概要を、コンテナの仕組みをふまえつつイラストを用いて紹介していきます。一般にあまり焦点をあてて取り上げられることは多くありませんが、コンテナの作成や管理を担う低レベルなソフトウェア「コンテナランタイム」も本セッションの中心的なトピックのひとつです。
本セッションは、拙著「イラストで分かるDockerとKubernetes」(技術評論社)の内容を参考にしています。
https://www.amazon.co.jp/dp/4297118378
CloudNative Days Spring 2021 ONLINE キーノートでの発表資料です。
https://event.cloudnativedays.jp/cndo2021/talks/1071
本セッションでは、DockerとKubernetesのもつ基本的な機能の概要を、コンテナの仕組みをふまえつつイラストを用いて紹介していきます。一般にあまり焦点をあてて取り上げられることは多くありませんが、コンテナの作成や管理を担う低レベルなソフトウェア「コンテナランタイム」も本セッションの中心的なトピックのひとつです。
本セッションは、拙著「イラストで分かるDockerとKubernetes」(技術評論社)の内容を参考にしています。
https://www.amazon.co.jp/dp/4297118378
6. OSPN
root権限の取り扱い
A. rootで直接ログイン
– sshdの設定で制御可能
– 公開鍵認証でrootとしてログインさせる
• パスワード認証は無効化
B. 一般ユーザーでログインさせる
a. suコマンドを実行してrootに変更
• 設定作業が多いインストール直後には向いている
• rootとして実行したコマンドは記録されない
b. sudoコマンドを実行してroot権限でコマンド実行
• コマンド実行履歴が/var/log/secureに記録される
7. OSPN
su コマンド実行の制限
• PAMを設定してsuコマンドの実行を制御
– trust:suコマンド実行時にrootパスワードを要求しない
– require:suコマンドを実行するにはwheelグループに所
属している必要がある
• /etc/pam.d/suを編集
– 設定のコメントアウトを外して保存すると即時有効
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth sufficientpam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
#auth required pam_wheel.so use_uid
9. OSPN
/etc/sudoersの設定例
## Allow root to run any commands anywhere
root ALL=(ALL) ALL ←rootは何でもOK
(略)
## Allows people in group wheel to run all commands
%wheel ALL=(ALL) ALL
↑wheelグループ所属は何でもOKだがパスワードが必要
## Same thing without a password
# %wheel ALL=(ALL) NOPASSWD: ALL ALL
↑wheelグループ所属は何でもOKでパスワードが不要
## Allows members of the users group to mount and unmount the
## cdrom as root
# %users ALL=/sbin/mount /mnt/cdrom, /sbin/umount /mnt/cdrom
↑usersグループで実行できるコマンドを指定した形式
## Allows members of the users group to shutdown this system
# %users localhost=/sbin/shutdown -h now
↑usersグループでこのホストだけで実行できるコマンドを指定した形式
9
このいずれかを有効に
することが多い
13. OSPN
公開鍵・秘密鍵の作成
% ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/tmiyahar/.ssh/id_rsa):(エンターキー)
Enter passphrase (empty for no passphrase):(パスフレーズは非表示)
Enter same passphrase again:(パスフレーズは非表示)
Your identification has been saved in /Users/tmiyahar/.ssh/id_rsa
Your public key has been saved in /Users/tmiyahar/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:E59fCUG1YBC8frrfcDCtyvTi9vNUQHcLuo7Zik/hSnE tmiyahar@Toru-MBP-16
↑フィンガープリントは公開鍵のハッシュ値
$ ls -l .ssh
合計 8
-rw------- 1 tmiyahar staff 2655 10 22 12:37 id_rsa ←秘密鍵
-rw-r--r-- 1 tmiyahar staff 574 10 22 12:37 id_rsa.pub ←公開鍵
13
17. OSPN
公開鍵のサーバへの転送
A) ターミナルに対してコピー&ペースト
– 公開鍵は単なるテキストなので
– 安全な接続を経由して行うこと
B) scpコマンドやsftpコマンドで転送
– SELinuxが有効な場合、/tmpなどに転送した
ファイルをコピーして使わないこと
– 必ずcatコマンドでauthorized_keysに追記
C) ssh-copy-idコマンドを実行
– 転送からauthorized_keys配置まで自動実行
17
18. OSPN
sshコマンドで接続
% ssh sshuser@192.168.156.101
The authenticity of host '192.168.156.101 (192.168.156.101)' can't be established.
ED25519 key fingerprint is SHA256:nKWsgCAF9YdR02YZKp0QqIk0/TDy/PzUJHCQnNCtxjM.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.156.101' (ED25519) to the list of known hosts.
Enter passphrase for key /Users/xxx/.ssh/id_rsa ': (パスフレーズを入力。非表示)
[sshuser@server ~]$
• 初めて接続するサーバーはホスト証明書が送られ
てくる
• yesと入力することで~/.ssh/known_hostsに
記録される
• 次回以降はホスト証明書を照合して異なっている
場合には警告を表示して接続させない(サーバー
のすり替えなどの防止)
18
20. OSPN
最近のSSHサーバーの設定
• /etc/ssh/sshd_configの設定
– PermitRootLogin prohibit-password
– rootでのパスワード認証は許可されていない
• これとは別に/etc/ssh/sshd_config.d/01-
permitrootlogin.confが作成されている
– インストール時に「パスワードによるroot SSHログ
インを許可」をチェックしている場合
– sshd_configを修正するだけでなく01-
permitrootlogin.confも削除する必要がある
20
# This file has been generated by the Anaconda Installer.
# Allow root to log in using ssh. Remove this file to opt-out.
PermitRootLogin yes