短命の証明書
Cloudflare Accessは、ユーザーのAccessログインによって生成されたトークンに基づいて発行された短命の証明書で、従来のSSHキーのモデルを置き換えることができます。従来のモデルでは、ユーザーはキーペアを生成し、その公開鍵をSalt ↗のようなインフラ管理ツールにコミットするか、管理者にアップロードします。これらの鍵は数ヶ月または数年の間変更されないことがあります。
Cloudflare Accessは、エンドユーザーが鍵を生成する負担を取り除き、短命の証明書を使用してインフラへのアクセスのセキュリティを向上させます。
Cloudflare Accessの短命の証明書は、Accessの背後にあるかどうかに関わらず、任意の最新のSSHサーバーで機能します。ただし、追加のセキュリティや監査機能、ブラウザベースのターミナルなどの機能を考慮して、サーバーをAccessの背後に置くことをお勧めします。
Cloudflare Accessの背後にサーバーを保護するには:
- サーバーをパブリックホスト名ルートに接続します。
- サーバー用のセルフホスト型Accessアプリケーションを作成します。
Cloudflare Accessは、トークンからアイデンティティを取得し、短命の証明書を使用してターゲットインフラでユーザーを認証します。
The simplest setup is one where a user’s Unix username matches their email address prefix. Issued short-lived certificates will be valid for the user’s email address prefix. For example, if a user in your Okta or GSuite organization is registered as jdoe@example.com, they would log in to the SSH server as jdoe.
For testing purposes, you can run the following command to generate a Unix user on the machine:
sudo adduser jdoeAdvanced setup: Differing usernames
SSH certificates include one or more principals in their signature which indicate the Unix usernames the certificate is allowed to log in as. Cloudflare Access will always set the principal to the user’s email address prefix. For example, when jdoe@example.com tries to connect, Access issues a short-lived certificate authorized for the principal jdoe.
By default, SSH servers authenticate the Unix username against the principals listed in the user’s certificate. You can configure your SSH server to accept principals that do not match the Unix username.
Username matches a different email
To allow jdoe@example.com to log in as the user johndoe, add the following to the server’s /etc/ssh/sshd_config:
Match user johndoe AuthorizedPrincipalsCommand /bin/echo 'jdoe' AuthorizedPrincipalsCommandUser nobodyThis tells the SSH server that, when someone tries to authenticate as the user johndoe, check their certificate for the principal jdoe. This would allow the user jdoe@example.com to sign into the server with a command such as:
ssh johndoe@serverUsername matches multiple emails
To allow multiple email addresses to log in as vmuser, add the following to the server’s /etc/ssh/sshd_config:
Match user vmuser AuthorizedPrincipalsFile /etc/ssh/vmusers-list.txtThis tells the SSH server to load a list of principles from a file. Then, in /etc/ssh/vmusers-list.txt, list the email prefixes that can log in as vmuser, one per line:
jdoebwaynerobinUsername matches all users
To allow any Access user to log in as vmuser, add the following command to the server’s /etc/ssh/sshd_config:
Match user vmuser AuthorizedPrincipalsCommand /bin/bash -c "echo '%t %k' | ssh-keygen -L -f - | grep -A1 Principals" AuthorizedPrincipalsCommandUser nobodyThis command takes the certificate presented by the user and authorizes whatever principal is listed on it.
Allow all users
To allow any Access user to log in with any username, add the following to the server’s /etc/ssh/sshd_config:
AuthorizedPrincipalsCommand /bin/bash -c "echo '%t %k' | ssh-keygen -L -f - | grep -A1 Principals"AuthorizedPrincipalsCommandUser nobodySince this will put the security of your server entirely dependent on your Access configuration, make sure your Access policies are correctly configured.
-
Zero Trustで、Access > Service Auth > SSHに移動します。
-
Applicationドロップダウンで、SSHサーバーを表すAccessアプリケーションを選択します。
-
Generate certificateを選択します。アプリケーションにスコープされた公開鍵を含む行が表示されます。
-
鍵を保存するか、サーバーの設定に便利な場所に保管します。 サービス認証ダッシュボードでこの公開鍵をコピーするために戻ることができます。
- ステップ3でダッシュボードから生成された公開鍵をコピーします。
-
Use the following command to change directories to the SSH configuration directory on the remote target machine:
Terminal window cd /etc/ssh -
Once there, you can use the following command to both generate the file and open a text editor to input/paste the public key.
Terminal window vim ca.pub -
In the
ca.pubfile, paste the public key without any modifications.The
ca.pubfile can hold multiple keys, listed one per line. Empty lines and comments starting with#are also allowed. -
Save the
ca.pubfile. In some systems, you may need to use the following command to force the file to save depending on your permissions:Terminal window :w !sudo tee %:q!
The following procedure makes two changes to the sshd_config file on the remote target machine. The first change requires that you uncomment a field already set in most default configurations; the second change adds a new field.
-
While staying within the
/etc/sshdirectory on the remote machine, open thesshd_configfile.Terminal window vim /etc/ssh/sshd_config -
Go to the row named
PubkeyAuthentication. In most default configurations, the row will appear commented out as follows:# PubkeyAuthentication yes -
Remove the
#symbol to uncomment the line; keep the settingyesenabled. -
Next, add a new line below
PubkeyAuthenticationas follows:TrustedUserCAKeys /etc/ssh/ca.pubSave the file and quit the editor. You might need to use the following command again to save and exit.
:w !sudo tee %:q!
Once you have modified your SSHD configuration, restart the SSH service on the remote machine.
For older Debian/Ubuntu versions:
sudo service ssh restartFor newer Debian/Ubuntu versions:
sudo systemctl restart sshFor CentOS/RHEL 6 and older:
sudo service sshd restartFor CentOS/RHEL 7 and newer:
sudo systemctl restart sshdクライアント側では、デバイスを構成してCloudflare Accessを使用して保護されたマシンにアクセスします。短命の証明書を使用するには、SSH設定ファイル(~/.ssh/config)に以下の設定を含める必要があります。
時間を節約するために、以下のcloudflaredコマンドを使用して必要な設定コマンドを印刷できます:
cloudflared access ssh-config --hostname vm.example.com --short-lived-cert手動で設定することを好む場合、生成されたSSH設定の例は次のとおりです:
Match host vm.example.com exec "/usr/local/bin/cloudflared access ssh-gen --hostname %h" HostName vm.example.com ProxyCommand /usr/local/bin/cloudflared access ssh --hostname %h IdentityFile ~/.cloudflared/vm.example.com-cf_key CertificateFile ~/.cloudflared/vm.example.com-cf_key-cert.pubエンドユーザーは、Cloudflareのブラウザベースのターミナルを使用して、設定なしでSSHセッションに接続できます。ユーザーはアプリケーションのURLにアクセスし、Cloudflareのターミナルが短命の証明書のフローを処理します。これを有効にするには、ブラウザレンダリングを有効にするを参照してください。
あなたのSSHサーバーは現在Cloudflare Accessの背後で保護されています — ユーザーは接続する前にアイデンティティプロバイダーで認証を求められます。また、Gateway Audit SSHポリシーを設定することで、SSHコマンドのログ記録を有効にすることもできます。