20.6. IdM クライアントでサービスアカウントとしてコマンドを実行する IdM WebUI での sudo ルールの作成

IdM では、RunAs エイリアス を使用して、sudo ルールを設定し、別のユーザーまたはグループとして sudo コマンドを実行できます。たとえば、データベースアプリケーションをホストする IdM クライアントが存在し、そのアプリケーションに対応するローカルサービスアカウントとしてコマンドを実行する必要があるとします。

この例を使用して、run_third-party-app_report という IdM WebUI に sudo ルールを作成し、idm_user アカウントが idmclient ホストで thirdpartyapp サービスアカウントとして /opt/third-party-app/bin/report コマンドを実行できるようにします。

前提条件

  • IdM 管理者としてログインしている。
  • IdM で idm_user のユーザーアカウントを作成し、ユーザーのパスワードを作成してそのアカウントのロックを解除している。CLI を使用して新しい IdM ユーザーを追加する方法の詳細は、コマンドラインを使用したユーザーの追加 を参照してください。
  • idmclient ホストにローカル idm_user アカウントが存在しない。idm_user ユーザーは、ローカルの /etc/passwd ファイルには表示されません。
  • idmclient ホストに、third-party-app という名前のカスタムアプリケーションがインストールされている。
  • third-party-app アプリケーションの report コマンドが、/opt/third-party-app/bin/report ディレクトリーにインストールされている。
  • third-party-app アプリケーションにコマンドを実行するために、thirdpartyapp という名前のローカルサービスアカウントを作成している。

手順

  1. /opt/third-party-app/bin/report コマンドを、sudo コマンドの IdM データベースに追加します。

    1. PolicySudoSudo Commands の順に移動します。
    2. 右上にある Add をクリックして、Add sudo command ダイアログボックスを開きます。
    3. コマンド /opt/third-party-app/bin/report を入力します。

      ラベルが sudo コマンドの追加のポップアップウィンドウのスクリーンショット。 "/opt/third-party-app/bin/report" の内容で、"Sudo command" というラベルが付いた必須フィールドがあります。Description フィールドは空白です。ウィンドウの右下のボタンには "Add" - "Add and Add Another" - "Add and Edit" - "Cancel" の 4 つのボタンがあります。
    4. Add をクリックします。
  2. 新しい sudo コマンドエントリーを使用して、新しい sudo ルールを作成します。

    1. PolicySudoSudo ルールに移動します。
    2. 右上にある Add をクリックして、Add sudo rule ダイアログボックスを開きます。
    3. sudo ルールの名前 run_third-party-app_report を入力します。

      "Add sudo rule" というラベルが付いたポップアップウィンドウのスクリーンショット。 "run_third-party-app_report" という内容の "Rule name" のラベルが付いた必須フィールドがあります。ウィンドウの右下のボタンには "Add" - "Add and Add Another" - "Add and Edit" - "Cancel" の 4 つのボタンがあります。
    4. Add and Edit をクリックします。
    5. ユーザーを指定します。

      1. Who セクションで、Specified Users and Groups のラジオボタンを選択します。
      2. User category the rule applies to のサブセクションで Add をクリックして、Add users into sudo rule "run_third-party-app_report" ダイアログボックスを開きます。
      3. Available 列の Add users into sudo rule "run_third-party-app_report" ダイアログボックスで、idm_user チェックボックスをオンにして、これを Prospective 列に移動します。

        "Add users into sudo rule" というラベルが付いたポップアップウィンドウのスクリーンショット。 左側の Available リストからユーザーを選択し、これらを右側の Prospective 列に移動できます。ウィンドウの右下には、"Add" - "Cancel" の 2 つのボタンがあります。
      4. Add をクリックします。
    6. ホストを指定します。

      1. Access this host セクションで、Specified Hosts and Groups ラジオボタンを確認します。
      2. Host category this rule applies to サブセクションで Add をクリックして、 Add hosts into sudo rule "run_third-party-app_report" ダイアログボックスを開きます。
      3. Available 列の Add hosts into sudo rule "run_third-party-app_report" ダイアログボックスで、idmclient.idm.example.com チェックボックスをオンにして、これを Prospective 列に移動します。

        "Add hosts into sudo rule" というラベルが付いたポップアップウィンドウのスクリーンショット。 左側の Available リストからホストを選択し、これらを右側の Prospective 列に移動できます。ウィンドウの右下には、"Add" - "Cancel" の 2 つのボタンがあります。
      4. Add をクリックします。
    7. コマンドを指定します。

      1. Run Commands セクションの Command category the rule applies to サブセクションで、Specified Commands and Groups ラジオボタンにチェックを入れます。
      2. Sudo Allow Commands サブセクションで Add をクリックして、Add allow sudo commands into sudo rule "run_third-party-app_report" ダイアログボックスを開きます。
      3. Available 列の Add allow sudo commands into sudo rule "run_third-party-app_report" ダイアログボックスで、/opt/third-party-app/bin/report チェックボックスをオンにして、これを Prospective 列に移動します。

        "Add allow sudo commands into sudo rule" というラベルが付いたポップアップウィンドウのスクリーンショット。 左側の Available リストから sudo コマンドを選択し、これらを右側の Prospective 列に移動できます。ウィンドウの右下には、"Add" - "Cancel" の 2 つのボタンがあります。
      4. Add をクリックして、run_third-party-app_report のページに戻ります。
    8. RunAs ユーザーを指定します。

      1. As Whom で、指定したユーザーとグループ のラジオボタンを確認します。
      2. RunAs ユーザー サブセクションで Add をクリックして、Add RunAs users into sudo rule "run_third-party-app_report" ダイアログボックスを開きます。
      3. Add RunAs users into sudo rule "run_third-party-app_report" ダイアログボックスで、External ボックスに thirdpartyapp サービスアカウントを入力し、これを Prospective 列に移動します。

        外部ユーザーとして "thirdpartyapp" サービスアカウントを指定できるダイアログボックスのスクリーンショット。
      4. Add をクリックして、run_third-party-app_report のページに戻ります。
    9. 左上隅にある Save をクリックします。

新しいルールはデフォルトで有効になります。

図20.3 sudo ルールの詳細

追加した sudo ルールの概要のスクリーンショット。"Who" セクションには、"idm_user" のエントリーがあります。 "Access this host" セクションには "idmclient.idm.example.com" があります。 "Run Commands" セクションには、"/opt/third-party-app/bin/report" コマンドがあります。"As Whom" セクションには、"thirdpartyapp" アカウントがリスト表示されます。
注記

サーバーからクライアントへの変更の伝播には数分かかる場合があります。

検証手順

  1. idmclient ホストに idm_user アカウントとしてログインします。
  2. 新しい sudo ルールをテストします。

    1. idm_user アカウントが実行可能な sudo ルールを表示します。

      [idm_user@idmclient ~]$ sudo -l
      Matching Defaults entries for idm_user@idm.example.com on idmclient:
          !visiblepw, always_set_home, match_group_by_gid, always_query_group_plugin,
          env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE KDEDIR LS_COLORS",
          env_keep+="MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE",
          env_keep+="LC_COLLATE LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES",
          env_keep+="LC_MONETARY LC_NAME LC_NUMERIC LC_PAPER LC_TELEPHONE",
          env_keep+="LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET XAUTHORITY KRB5CCNAME",
          secure_path=/sbin\:/bin\:/usr/sbin\:/usr/bin
      
      User idm_user@idm.example.com may run the following commands on idmclient:
          (thirdpartyapp) /opt/third-party-app/bin/report
    2. report コマンドを thirdpartyapp サービスアカウントとして実行します。

      [idm_user@idmclient ~]$ sudo -u thirdpartyapp /opt/third-party-app/bin/report
      [sudo] password for idm_user@idm.example.com:
      Executing report...
      Report successful.