Ansible:FortiGate のシステム管理者を設定する

ネットワーク

ここでは Ansible を使用した FortiGate の設定について記載しています。通常の方法で FortiGate のシステム管理者を設定する方法については次の記事を参照してください。
FortiGate で管理者アカウントを作成する手順

作業環境

■ Ansible 側

  • CentOS 8.0
  • Python 3.7.7
  • Ansible 2.9.6

■ FortiGate 側

  • 型番:FortiGate 60E
  • バージョン:v6.0.6 build0272 (GA)

fortios_system_admin モジュール

fortios_system_admin モジュールを使用することで FortiGate のコンフィグにおける config system admin の各項目を設定することができます。

  • 管理者アカウントの新規作成/削除
  • 管理者アカウントの設定変更

などに利用できます。

主なパラメータ

パラメータ必須選択肢/デフォルト説明
host対象機器のIPアドレス
usernameSSH用のユーザ
password・”” ←SSH用のパスワード
vdom・root ←対象機器のバーチャルドメイン
https・no
・yes ←
HTTPSを使用するかどうか
ssl_verify・no
・yes ←
対象機器の証明書を検証するかどうか
state・present
・absent
present ⇒ アカウント作成
absent ⇒ アカウント削除
※Ansible 2.9 から使用可能
system_adminconfig system admin の設定項目を
子要素として指定する
 – accprofile適用する管理者プロファイル
 – name対象の管理者アカウント名
 – passwordアカウントのパスワード
 – state・present
・absent
present ⇒ アカウント作成
absent ⇒ アカウント削除
※Ansible 2.8 ではこのレベルで指定
 – trusthost1「信頼されるホスト」設定に該当
trusthost1~trusthost10まで設定可能

備考

  • Ansible 2.8 から追加されたモジュール
  • Legacy モードでの実行のためには fortiosapi が必要
  • httpapi での実行が可能
  • state パラメータについて公式ドキュメントでは必須表記が無かったが、動作確認した結果から、実際には必須と思われる

使用例

httpapi を使用してモジュールを実行する例です。

■ インベントリ:hosts

[forti]
10.1.10.100

[forti:vars]
ansible_user=admin
ansible_password=password
ansible_network_os=fortios
ansible_connection=httpapi
ansible_httpapi_use_ssl=yes
ansible_httpapi_validate_certs=no

10.1.10.100 は操作対象の FortiGate のIPアドレスです。
httpapi で使用する変数をグループ変数として定義しています。

管理者アカウントの新規作成

以下の要件で管理者アカウントを新規作成します。

  • アカウント名:admin2
  • パスワード:password
  • 管理者プロファイル:prof_admin

■ Playbook:systemAdminAdd.yml

- hosts: all
  gather_facts: no
  tasks:
    - name: fortios_system_admin test
      fortios_system_admin:
        state: "present"
        system_admin:
          name: "admin2"
          password: "password"
          accprofile: "prof_admin"

アカウントを作成する場合は system_admin の要素として以下2項目の指定が必須となります。

  • name
  • accprofile

逆に言うと上の2項目だけ指定すればアカウントを作成できます。

■ Playbook 実行

# ansible-playbook -i hosts systemAdminAdd.yml

PLAY [all] **********************************************************************************************************

TASK [fortios_system_admin test] ************************************************************************************
changed: [10.1.10.100]

PLAY RECAP **********************************************************************************************************
10.1.10.100                : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

■ 実行前の FortiGate のコンフィグ

FGT # show system admin
config system admin
    edit "admin"
        #(略)
    next
end

■ 実行後の FortiGate のコンフィグ

FGT # show system admin
config system admin
    edit "admin"
        #(略)
    next
    edit "admin2"
        set accprofile "prof_admin"
        set vdom "root"
        set password ENC #(略)
    next
end

admin2 が作成されました。また Playbook で指定していない項目はデフォルト値となっています。

管理者アカウントの設定変更

上で追加した admin2 アカウントに対して以下設定を追加します。

  • 信頼されるホスト:10.1.10.20/32

■ Playbook:systemAdminEdit.yml

- hosts: all
  gather_facts: no
  tasks:
    - name: fortios_system_admin test
      fortios_system_admin:
        state: "present"
        system_admin:
          name: "admin2"
          trusthost1: "10.1.10.20 255.255.255.255"

■ Playbook 実行

# ansible-playbook -i hosts systemAdminEdit.yml

PLAY [all] **********************************************************************************************************

TASK [fortios_system_admin test] ************************************************************************************
changed: [10.1.10.100]

PLAY RECAP **********************************************************************************************************
10.1.10.100                : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

■ 実行後の FortiGate のコンフィグ

FGT # show system admin
config system admin
    edit "admin"
        #(略)
    next
    edit "admin2"
        set trusthost1 10.1.10.20 255.255.255.255
        set accprofile "prof_admin"
        set vdom "root"
        set password ENC #(略)
    next
end

信頼されるホスト(trusthost1)の設定が追加されました。

管理者アカウントの削除

上で追加/編集した admin2 アカウントを削除します。

■ Playbook:systemAdminDel.yml

- hosts: all
  gather_facts: no
  tasks:
    - name: fortios_system_admin test
      fortios_system_admin:
        state: "absent"
        system_admin:
          name: "admin2"

■ Playbook 実行

# ansible-playbook -i hosts systemAdminDel.yml

PLAY [all] **********************************************************************************************************

TASK [fortios_system_admin test] ************************************************************************************
changed: [10.1.10.100]

PLAY RECAP **********************************************************************************************************
10.1.10.100                : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

■ 実行後の FortiGate のコンフィグ

FGT # show system admin
config system admin
    edit "admin"
        #(略)
    next
end

admin2 アカウントが削除されました。

未解決問題

既存アカウントのパスワード変更がエラーとなりました。

■ Playbook:systemAdminPass.yml

- hosts: all
  gather_facts: no
  tasks:
    - name: fortios_system_admin test
      fortios_system_admin:
        state: "present"
        system_admin:
          name: "admin2"
          password: "password"

■ Playbook 実行

# ansible-playbook -i hosts systemAdminPass.yml

PLAY [all] **********************************************************************************************************

TASK [fortios_system_admin test] ************************************************************************************
fatal: [10.1.10.100]: FAILED! => {"ansible_facts": {"discovered_interpreter_python": "/usr/libexec/platform-python"}, "changed": false, "meta": {"build": 272, "http_method": "PUT", "http_status": 403, "mkey": "admin2", "name": "admin", "path": "system", "revision": "199.0.0.4024576521.1589599412", "serial": "FGT*************", "status": "error", "vdom": "root", "version": "v6.0.6"}, "msg": "Error in repo"}

PLAY RECAP **********************************************************************************************************
10.1.10.100                : ok=0    changed=0    unreachable=0    failed=1    skipped=0    rescued=0    ignored=0

http_status が 403 なので権限関係の問題だと思いますが未解決です。

fortios_system_accprofile モジュール

fortios_system_accprofile モジュールを使用することで FortiGate のコンフィグにおける config system accprofile の各項目を設定することができます。

  • 管理者プロファイルの新規作成/削除
  • 管理者プロファイルの設定変更

などに利用できます。

主なパラメータ

パラメータ必須選択肢/
デフォルト
説明
host対象機器のIPアドレス
usernameSSH用のユーザ
password・”” ←SSH用のパスワード
vdom・root ←対象機器のバーチャルドメイン
https・no
・yes ←
HTTPSを使用するかどうか
ssl_verify・no
・yes ←
対象機器の証明書を検証するかどうか
state・present
・absent
present ⇒ アカウント作成
absent ⇒ アカウント削除
※Ansible 2.9 から使用可能
system_accprofileconfig system accprofile の設定項目を
子要素として指定する
 – admintimeout0 – 480アイドルタイムアウト時間(分)
 – admintimeout_override・enable
・disable
アイドルタイムアウトのオーバーライド
 – commentsプロファイルのコメント
 – name対象の管理者プロファイル名
 – state・present
・absent
present ⇒ アカウント作成
absent ⇒ アカウント削除
※Ansible 2.8 ではこのレベルで指定
 – authgrp
 – ftviewgrp
 – secfabgrp
 – vpngrp
 – wifi
・none
・read
・read-write
順に以下のアクセス権限
・ユーザ & デバイス
・FortiView
・セキュリティファブリック
・VPN
・WiFi & スイッチ
 – fwgrp
 – loggrp
 – netgrp
 – sysgrp
 – utmgrp
・none
・read
・read-write
・custom
順に以下のアクセス権限
・ファイアウォール
・ログ & レポート
・ネットワーク
・システム
・セキュリティプロファイル
 – ○○_permission権限のカスタム設定
例:fwgrp_permission
詳細は公式ドキュメント参照

■ 参考:管理者プロファイル設定画面

備考

  • Ansible 2.8 から追加されたモジュール
  • Legacy モードでの実行のためには fortiosapi が必要
  • httpapi での実行が可能
  • state パラメータについて公式ドキュメントでは必須表記が無かったが、動作確認した結果から、実際には必須と思われる

使用例

httpapi を使用してモジュールを実行する例です。

■ インベントリ:hosts

[forti]
10.1.10.100

[forti:vars]
ansible_user=admin
ansible_password=password
ansible_network_os=fortios
ansible_connection=httpapi
ansible_httpapi_use_ssl=yes
ansible_httpapi_validate_certs=no

10.1.10.100 は操作対象の FortiGate のIPアドレスです。
httpapi で使用する変数をグループ変数として定義しています。

管理者プロファイルの新規作成

全項目について読み書き権限を付与したプロファイルを作成します。

■ Playbook:systemAccprofileAdd.yml

- hosts: all
  gather_facts: no
  tasks:
    - name: fortios_system_accprofile test
      fortios_system_accprofile:
        state: "present"
        system_accprofile:
          name: "test_profile"
          authgrp: "read-write"
          ftviewgrp: "read-write"
          secfabgrp: "read-write"
          vpngrp: "read-write"
          wifi: "read-write"
          fwgrp: "read-write"
          loggrp: "read-write"
          netgrp: "read-write"
          sysgrp: "read-write"
          utmgrp: "read-write"

■ Playbook 実行

# ansible-playbook -i hosts systemAccprofileAdd.yml

PLAY [all] **********************************************************************************************************

TASK [fortios_system_accprofile test] *******************************************************************************
changed: [10.1.10.100]

PLAY RECAP **********************************************************************************************************
10.1.10.100                : ok=1    changed=1    unreachable=0    failed=0    skipped=0    rescued=0    ignored=0

■ 実行前の FortiGate のコンフィグ

FGT# show full-configuration system accprofile
config system accprofile
    edit "prof_admin"
        #(略)
    next
end

■ 実行後の FortiGate のコンフィグ

FGT# show full-configuration system accprofile
config system accprofile
    edit "prof_admin"
        #(略)
    next
    edit "test_profile"
        set comments ''
        set secfabgrp read-write
        set ftviewgrp read-write
        set authgrp read-write
        set sysgrp read-write
        set netgrp read-write
        set loggrp read-write
        set fwgrp read-write
        set vpngrp read-write
        set utmgrp read-write
        set wifi read-write
        set admintimeout-override disable
    next
end

test_profile が追加されました。

ちなみに、以下のように管理者プロファイル新規作成時に権限を指定しなかった項目については権限無しの状態になります。

■ Playbook

- hosts: all
  gather_facts: no
  tasks:
    - name: fortios_system_accprofile test
      fortios_system_accprofile:
        state: "present"
        system_accprofile:
          name: "test_profile"

■ 実行後の FortiGate のコンフィグ

FGT# show full-configuration system accprofile
config system accprofile
    edit "prof_admin"
        #(略)
    next
    edit "test_profile"
        set comments ''
        set secfabgrp none
        set ftviewgrp none
        set authgrp none
        set sysgrp none
        set netgrp none
        set loggrp none
        set fwgrp none
        set vpngrp none
        set utmgrp none
        set wifi none
        set admintimeout-override disable
    next
end

―――――――――――――

タイトルとURLをコピーしました