ChatGPTでsshd_configを生成してみる

インフラ技術者の雑記
sshd_configの生成を通してインフラで使われる設定ファイルの生成にChatGPTが使えるかどうかを検証します。
また、単純に設定値を生成するだけでなく、設定できる項目や、設定値を複数パターン生成させてみました。
1.sshd_configをChatGPTで生成する手順
1.ChatGPTのアカウントを作る
2.sshd_configを生成するための文章を作成する
3.sshd_configを生成する
検証ではChatGPT plusを用いてGPT4で生成しています。
2.sshd_configを生成した結果
設定値の生成
単純に設定値を生成させることは可能です。
ただし、設定値を生成するだけであれば、インターネット上のドキュメントを参照したほうが信頼性は高く参考になります。
プロンプト:一般的なsshd_configを生成してください。
# This is the sshd server system-wide configuration file. # See sshd_config(5) for more information. # The strategy used for options in the default sshd_config shipped with # OpenSSH is to specify options with their default value where # possible, but leave them commented. # Port 22 # AddressFamily any # ListenAddress 0.0.0.0 # ListenAddress :: # HostKey /etc/ssh/ssh_host_rsa_key # HostKey /etc/ssh/ssh_host_ecdsa_key # HostKey /etc/ssh/ssh_host_ed25519_key # Ciphers and keying # Ciphers aes128-ctr,aes192-ctr,aes256-ctr,aes128-cbc,3des-cbc # MACs hmac-md5,hmac-sha1,umac-64@openssh.com # Logging #SyslogFacility AUTH #LogLevel INFO # Authentication: #LoginGraceTime 2m PermitRootLogin yes #StrictModes yes #MaxAuthTries 6 #MaxSessions 10 RSAAuthentication yes PubkeyAuthentication yes # The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2 # but this is overridden so installations will only check .ssh/authorized_keys AuthorizedKeysFile .ssh/authorized_keys # For this to work you will also need host keys in /etc/ssh/ssh_known_hosts #RhostsRSAAuthentication no # similar for protocol version 2 #HostbasedAuthentication no # Change to yes if you don't trust ~/.ssh/known_hosts for # RhostsRSAAuthentication and HostbasedAuthentication #IgnoreUserKnownHosts no # Don't read the user's ~/.ssh/known_hosts file #IgnoreRhosts yes # Change to no to disable s/key passwords ChallengeResponseAuthentication no PasswordAuthentication yes #PermitEmptyPasswords no # Change to no to disable tunnelled clear text passwords #PasswordAuthentication yes # Kerberos options #KerberosAuthentication no #KerberosOrLocalPasswd yes #KerberosTicketCleanup yes # GSSAPI options #GSSAPIAuthentication no #GSSAPICleanupCredentials yes # Set this to 'yes' to enable PAM authentication, account processing, # and session processing. If this is enabled, PAM authentication will # be allowed through the ChallengeResponseAuthentication and # PasswordAuthentication. Depending on your PAM configuration, # PAM authentication via ChallengeResponseAuthentication may bypass # the setting of "PermitRootLogin without-password". # If you just want the PAM account and session checks to run without # PAM authentication, then enable this but set PasswordAuthentication # and ChallengeResponseAuthentication to 'no'. #UsePAM yes #AllowAgentForwarding yes #AllowTcpForwarding yes #GatewayPorts no #X11Forwarding yes #X11DisplayOffset 10 #X11UseLocalhost yes #PermitTTY yes PrintMotd no #PrintLastLog yes #TCPKeepAlive yes #UseLogin no #UsePrivilegeSeparation sandbox #PermitUserEnvironment no #Compression delayed #ClientAliveInterval 0 #ClientAliveCountMax 3 #ShowPatchLevel no #UseDNS yes #PidFile /var/run/sshd.pid #MaxStartups 10:30:100 #PermitTunnel no #ChrootDirectory none #VersionAddendum none # no default banner path #Banner none # override default of no subsystems Subsystem sftp /usr/lib/openssh/sftp-server # Example of overriding settings on a per-user basis #Match User anoncvs # X11Forwarding no # AllowTcpForwarding no # PermitTTY no # ForceCommand cvs server
設定項目の生成
インフラ関連のソフトウェアを設定する際に困る点は、設定値の重要度が分かりにくいという点です。
数多くあるsshd_configの設定でどれがセキュリティ的に重要なのかは一見しても分からない場合があります。
GPTによる生成では、このような重要度を反映したうえで、設定項目と対応する設定値を生成できます。
信頼できるかどうかは別ですが。
たとえば、セキュリティの観点で低、中、高の3段階で重要度を分類させてみます。
プロンプト SSHD_CONFIGの設定項目を生成してください。 ただし、各項目にセキュリティ的な重要度を示してください。 # 重要度 1. セキュリティとしての重要度は低い 2. セキュリティとしての重要度は中 3. セキュリティとしての重要度は高い # 出力形式 markdownの表形式で出力してください。※ソースコードではなく、表がプレビューされるようにしてください。 | 項目 | 重要度 | 重要度の理由 | | ---- | ---- | ---- | | hoge | hoge | hoge |

設定項目ごとの比較表の生成
各設定項目に対して、セキュリティのレベル別に設定値を出力させることもできます。
たとえば特定の項目を指定したうえで、それぞれの項目についてセキュリティレベルが低、中、高であった場合の設定値を出力させてみます。
プロンプト SSHD_CONFIGを3パターン生成してください。 ただし、以下を条件とします。 # パターン 1. セキュリティ低 2. セキュリティ中 3. セキュリティ高 # 出力形式 | 項目 | パターン1 | パターン2 | パターン3 | | ---- | ---- | ---- | ---- | | hoge | hoge | hoge | hoge | # 項目について 以下の項目を検討してください。 Port Protocol PermitRootLogin PasswordAuthentication PubkeyAuthentication PermitEmptyPasswords AllowUsers ClientAliveInterval LogLevel Ciphers

3.今後の展望
インフラの設定ファイルを作る際は、設定できる項目を列挙して意味を調べ、最適な値を考えます。
GPTのような大規模言語モデルに学習させたうえで、セキュリティなど何らかの観点で重要な項目を列挙してもらうことや、重要度のレベル別に設定値のサンプルを出力してもらうことは、インフラ関連の設定項目を設計する際に役立つと感じます。
最も良い値を考えることよりも、選択肢を3つか4つ作り、その中から今回のシステムにより適している値を考えるほうが楽だからです。
今回はサンプルとしてsshd_configを取り上げましたが、DNS、Webサーバなど他のソフトウェアの設定についても応用できるでしょう。
また逆に、人間が作成した設定ファイルをGPTに通すことで、セキュリティ上の懸念点を指摘させることもできると考えます。
パイプラインのなかにGPTによるレビューを組み込んで、自動的にチェックさせるなどしても面白いかもしれません。