啟用SSH存取的多重驗證

為了提高安全性,雲端基礎結構上的Adobe Commerce提供多重要素驗證(MFA)實作,以管理對雲端環境的SSH存取的驗證需求。

在專案上啟用MFA時,所有具有SSH存取權的使用者帳戶都需要雙因素驗證(TFA)代碼或API權杖和SSH憑證才能存取環境。

NOTE
雲端專案預設不會啟用MFA。 雲端基礎結構專案上Adobe Commerce的帳戶擁有者必須提交Adobe Commerce支援票證才能啟用它。 啟用MFA時,所有使用者必須在雲端基礎結構帳戶上的Adobe Commerce上啟用雙因素驗證(TFA),才能以ssh存取專案環境。

SSH存取的憑證

MFA可讓使用者將OAUTH存取權杖與Adobe雲端認證者API產生的短期SSH憑證交換。 如果使用者擁有管理員或貢獻者角色、有效的SSH金鑰和有效的TFA代碼或API權杖,雲端基礎結構上的Adobe Commerce會使用這些憑證來產生暫時SSH憑證。 憑證到期時間設為一小時,但會在目前的工作階段期間自動重新整理。

使用MFA登入專案後,使用者必須使用magento-cloud CLI來產生SSH憑證:

magento-cloud ssh-cert:load

ssh-cert:load命令會產生SSH憑證,並將其安裝在本機使用者的SSH代理程式中。

登入時自動產生憑證

您可以設定本機環境,在您向magento-cloud CLI驗證時自動產生SSH憑證。

若要將SSH憑證自動產生新增到您的magento-cloud CLI設定

  1. 在本機工作站上,在首頁目錄的.magento-cloud資料夾中建立名為config.yaml的檔案(如果不存在)。

    code language-bash
    touch ~/.magento-cloud/config.yaml
    
  2. 將下列設定新增至config.yaml檔案。

    code language-yaml
    api:
       auto_load_ssh_cert: true
    
  3. 使用magento-cloud CLI再次驗證:

    登出:

    code language-bash
    magento-cloud logout
    

    登入:

    code language-bash
    magento-cloud login
    

    請依照回應操作:

    code language-terminal
    Please open the following URL in a browser and log in:
    http://127.0.0.1:5000
    
    Help:
      Leave this command running during login.
      If you need to quit, use Ctrl+C.
    
      To log in using an API token, run: magento-cloud auth:api-token-login
    
    Login information received. Verifying...
    You are logged in.
    
    Generating SSH certificate...
    A new SSH certificate has been generated.
    It will be automatically refreshed when necessary.
    The certificate is included in your SSH configuration: /Users/<user-name>/.ssh/config
    

透過TFA使用SSH連線至環境

在專案上啟用MFA時,您必須先在帳戶上啟用TFA,才能使用SSH連線到遠端環境。 請參閱啟用TFA

recommendation-more-help

必要條件:

對於啟用MFA強制的專案,SSH存取需要下列許可權和帳戶設定:

若要使用SSH與TFA使用者帳戶認證連線

  1. 登入您的帳戶

  2. 在您的本機工作站上,使用magento-cloud CLI來產生SSH憑證。

    code language-bash
    magento-cloud ssh-cert:load
    

    範例回應:

    code language-terminal
    Generating SSH certificate...
      Expires at: 2020-07-13T15:28:13-04:00
      Multi-factor authentication: verified
      Mode: interactive
    The certificate will be automatically refreshed when necessary.
    Checking SSH configuration file: /Users/<user-name>/.ssh/config
    Do you want to update the file automatically? [Y/n] Y
    Configuration file updated successfully: /Users/<user-name>/.ssh/config
    
  3. 使用SSH連線到遠端環境。

    code language-bash
    ssh abcdef7uyxabce-master-7rqtwti--mymagento@ssh.us-5.magento.cloud
    
    code language-terminal
     __  __                   _          ___ _             _
    |  \/  |__ _ __ _ ___ _ _| |_ ___   / __| |___ _  _ __| |
    | |\/| / _` / _` / -_) ' \  _/ _ \ | (__| / _ \ || / _` |
    |_|  |_\__,_\__, \___|_||_\__\___/  \___|_\___/\_,_\__,_|
                |___/
    
     Welcome to Magento Cloud.
    
     This is environment master-7rqtwti
     of project abcdef7uyxabce.
    
    web@mymagento.0:~$
    

透過TFA使用SSH管理原始程式碼

在雲端基礎結構專案上管理Adobe Commerce的原始程式碼時,您會使用SSH來驗證專案的Git存放庫。 如果您的專案已啟用MFA強制執行,您必須先產生SSH憑證,才能使用Git存放庫執行命令列作業。

若要使用SSH與TFA使用者帳戶認證連線

  1. 登入您的帳戶並使用TFA進行驗證。

    note note
    NOTE
    如果您的帳戶未啟用TFA,則必須啟用。 請參閱在雲端帳戶上啟用TFA。
  2. 在您的本機工作站上,使用magento-cloud CLI來產生SSH憑證。

    code language-bash
    magento-cloud ssh-cert:load
    

    範例回應:

    code language-terminal
    Generating SSH certificate...
      Expires at: 2020-07-13T15:28:13-04:00
      Multi-factor authentication: verified
      Mode: interactive
    The certificate will be automatically refreshed when necessary.
    Checking SSH configuration file: /Users/<user-name>/.ssh/config
    Do you want to update the file automatically? [Y/n] Y
    Configuration file updated successfully: /Users/<user-name>/.ssh/config
    
  3. 複製專案環境的Git存放庫:

    code language-bash
    git clone --branch integration abcdef7uyxabce@git.us-3.magento.cloud:abcdef7uyxabce.git myproject
    

    範例回應:

    code language-terminal
    Cloning into 'myproject'...
    Connection to git.us-3.magento.cloud port 22 [tcp/ssh] succeeded!
    remote: counting objects: 22, done.
    Receiving objects: 100% (22/22), 82.42 KiB | 16.48 MiB/s, done.
    

透過API權杖使用SSH連線至環境

在專案上啟用MFA時,需要SSH存取雲端環境的自動化程式需要API權杖。 您可以透過雲端基礎結構帳戶上的Adobe Commerce ,以專案的管理員或貢獻者存取權產生代號。

使用API權杖進行驗證仍需要產生SSH憑證。 自動化程式也必須自動產生SSH憑證。

必要條件:

若要使用SSH與API權杖認證連線

  1. 使用API金鑰驗證登入雲端專案。

    code language-bash
    magento-cloud auth:api-token
    
  2. 在提示下,輸入有效API權杖的值。

    code language-terminal
    Please enter an API token:
    >
    
    The API token is valid.
    You are logged in.
    

範例:自動化SSH指令碼

儲存API權杖有兩個選項。

NOTE
如果儲存API權杖,magento-cloud CLI會自動驗證,而且不需要執行magento-cloud login命令。

選項1:建立環境變數以儲存API權杖

將權杖寫入您的bash_profile

echo "export MAGENTO_CLOUD_CLI_TOKEN=<your api token>" >> ~/.bash_profile

選項2:將權杖新增至config.yaml檔案

  1. 在本機工作站上,在首頁目錄的.magento-cloud資料夾中建立名為config.yaml的檔案(如果不存在)。

    code language-bash
    touch ~/.magento-cloud/config.yaml
    
  2. 將下列設定新增至config.yaml檔案。

    code language-yaml
    api:
       token: <your api token>
    

bash指令碼範例

#!/bin/bash
magento-cloud ssh-cert:load
ssh abcdef7uyxabce-master-7rqtabc--mymagento@ssh.us-3.magento.cloud "tail -n 10 ~/var/log/cloud.log"

疑難排解

使用下列資訊解決SSH連線要求失敗,因為驗證錯誤,例如access requires MFApermission denied

您的要求未提供有效的憑證

如果您的要求未提供有效的憑證,系統會顯示類似下列的訊息:

to Hello user-test (UUID: abaacca12-5cd1-4b123-9096-411add578998), you successfully
authenticated, but could not connect to service abcdef7uyxabce-master-7rqtabc--mymagento@ssh.us-3.magento.cloud:>
(reason: access requires MFA)

請嘗試下列疑難排解程式來解決連線問題:

  • 驗證帳戶TFA設定
  • 再次驗證,然後重新載入憑證

若要驗證TFA組態和驗證

  1. 登入您的帳戶

  2. 在右上角帳戶功能表中,按一下​ My Profile

  3. 在​ 我的設定檔 ​頁面上,按一下「Security」標籤。

    如果TFA已啟用,安全性區段會提供管理TFA設定的選項。

  4. 如果未設定TFA,請按一下​ Set up application ​並依照指示啟用它。 請參閱啟用TFA

  5. 如果設定了TFA,請嘗試再次驗證。

若要驗證及重新載入SSH憑證

  1. 使用magento-cloud CLI再次驗證:

    code language-bash
    magento-cloud logout
    
    code language-bash
    magento-cloud login
    
  2. 重新載入SSH憑證:

    code language-bash
    magento-cloud ssh-cert:load
    

許可權遭拒

如果SSH金鑰遺失或無效,SSH連線要求會傳回Permission denied (publickey)錯誤。

Hello user-test (UUID: abaacca12-5cd1-4b123-9096-411add578998), you successfully authenticated, but could not connect to service oh2wi6klp5ytk-mc-35985-integration-nnulm4a--mymagento (reason: service doesn't exist or you do not have access to it)
oh2wi6klp5ytk-mc-35985-integration-nnulm4a--mymagento@ssh.eu-3.magento.cloud: Permission denied (publickey).

若要修正此問題,請將SSH金鑰新增至您目前的作業階段,或更新SSH設定檔案以自動載入SSH金鑰。 請參閱新增公開SSH金鑰

無法在沒有MFA的情況下存取專案

如果您對已啟用多重驗證(MFA)的專案進行驗證,則在連線至不需要MFA的其他專案時,可能會收到下列錯誤:

ssh abcdef7uyxabce-master-7rqtabc--mymagento@ssh.us-3.magento.cloud

範例回應:

abcdef7uyxabce-master-7rqtabc--mymagento@ssh.us-3.magento.cloud: Permission denied (publickey).

在SSH憑證產生期間,magento-cloud CLI會將額外的SSH金鑰新增至您的本機環境。 如果您的本機SSH設定不包含用於專案存取的SSH金鑰,則預設會使用該金鑰。

若要將您的SSH金鑰新增至本機設定

  1. 建立config檔案(若不存在)。

    code language-bash
    touch ~/.ssh/config
    
  2. 新增IdentityFile設定。

    code language-yaml
    Host *
      IdentityFile ~/.ssh/id_rsa
    
NOTE
您可以新增多個IdentityFile專案至您的設定,以指定多個SSH金鑰。
05f2f56e-ac5d-4931-8cdb-764e60e16f26