FortiGate의 API를 이용하는 방법으로 일반적인 로그인 계정을 사용할 수 있다.

하지만, FortiGate에서 지원하는 REST API 계정을 이용하면 조금 더 쉽게 이용할 수 있다.

아래 환경은 REST API 계정을 생성하여 진행하였습니다.


1. REST API Admin 계정 생성


위의 계정 생성 시 아래와 같은 API Key가 발급됩니다.(해당 Key는 분실 시 찾을 수 없으며, 최초 1회에만 확인 가능)


2. Postman을 이용한 API Key를 이용한 작업 수행 (GET)


위에서 생성한 Key를 아래 access_token의 vlaue에 기입

https://<resouce 위치>&access_token=<API Key>


(예시)

https://192.168.111.99/api/v2/cmdb/firewall/address?vdom=root&access_token=4s7g1Nn6j0xdmbn9ghrrQmzQcqfs7q

GET 함수를 이용해 address 객체를 호출한 화면



3. Postman을 이용한 API Key를 이용한 작업 수행 (POST)


https://<resouce 위치>&access_token=<API Key> 이후 json 형식의 body 추가


(예시)

POST 함수를 이용해testaddr1e3이라는address 객체를 생성하는 화면




4. Postman을 이용한 API Key를 이용한 작업 수행 (PUT)


https://<resouce 위치>&access_token=<API Key> 이후 json 형식의 body 추가


(예시)

PUT 함수를 이용해 정책 ID1 번의 name을 100으로 Action을 deny로 변경하는 화면


5. Postman을 이용한 API Key를 이용한 작업 수행 (DELETE)

https://<resouce 위치>&access_token=<API Key>


(예시)

DELETE 함수를 이용해 정책 ID1번을 삭제하는 화면


6. API 오류시 debug 방법

#diagnose debg enable

#diagnose debug application httpsd -1

(Rest API 호출 시 HTTP가 이용됨에 따라 httpd 디버그 명령어로 메시지를 확인할 수 있습니다. )

(단, 관리자 WEB 접근 또한 디버그가 발생함으로 디버그 시 관리자 WEB 종료 후 CLI로 확인필요)


APIkey가 맞지 않을 경우 

[httpsd 2513- 1576139166info]ap_invoke_handler[593]-- newrequest(handler='api_cmdb_v2-handler', uri='/api/v2/cmdb/firewall/address?vdom=root&access_token=******************************',method='GET') [httpsd 2513- 1576139166info]ap_invoke_handler[597]-- User-Agent:curl/7.67.0 [httpsd 2513- 1576139166info]ap_invoke_handler[600]-- Source:192.168.10.1:59480Destination:192.168.10.62:443 [httpsd 2513- 1576139166info]api_cmdb_v2_handler[2055]-- receivedapi_cmdb_v2_requestfrom'192.168.10.1' [httpsd 2513- 1576139166info]api_access_check_for_api_key[914]-- Noapi-userfound. [httpsd 2513- 1576139166warning]_lock_out_check_and_lock_out[538]-- Failedapi-keyloginattemptfrom192.168.10.1.(1/3attemptswithin60s). [httpsd 2513- 1576139166info]ap_invoke_handler[616]-- requestcompleted(handler='api_cmdb_v2-handler'result==0)

 TrustedHost가 맞지 않을 경우

(0.0.0.0/0일 경우에도 아래와 같음) [httpsd 2391- 1576138147info]ap_invoke_handler[593]-- newrequest(handler='api_cmdb_v2-handler', uri='/api/v2/cmdb/firewall/address?vdom=root&access_token=******************************',method='GET') [httpsd 2391- 1576138147info]ap_invoke_handler[597]-- User-Agent:curl/7.67.0 [httpsd 2391- 1576138147info]ap_invoke_handler[600]-- Source:192.168.10.1:58350Destination:192.168.10.62:443 [httpsd 2391- 1576138147info]api_cmdb_v2_handler[2055]-- receivedapi_cmdb_v2_requestfrom'192.168.10.1' [httpsd 2391- 1576138147info]api_access_check_for_api_key[924]-- Peernottrusted:192.168.10.1. [httpsd 2391- 1576138147warning]_lock_out_check_and_lock_out[538]-- Failedapi-keyloginattemptfrom192.168.10.1.(1/3attemptswithin480s). [httpsd 2391- 1576138147info]ap_invoke_handler[616]-- requestcompleted(handler='api_cmdb_v2-handler'result==0) 

여러 번 틀려서 lockout된 경우

[httpsd 181- 1576137987info]ap_invoke_handler[593]-- newrequest(handler='api_cmdb_v2-handler', uri='/api/v2/cmdb/firewall/address?vdom=root&access_token=******************************',method='GET') [httpsd 181- 1576137987info]ap_invoke_handler[597]-- User-Agent:curl/7.67.0 [httpsd 181- 1576137987info]ap_invoke_handler[600]-- Source:192.168.10.1:58179Destination:192.168.10.62:443 [httpsd 181- 1576137987info]api_cmdb_v2_handler[2055]-- receivedapi_cmdb_v2_requestfrom'192.168.10.1' [httpsd 181- 1576137987warning]_api_key_lock_out[620]-- Requestfrom192.168.10.1willbeignored.Lockedoutfor154moreseconds. [httpsd 181- 1576137987info]ap_invoke_handler[616]-- requestcompleted(handler='api_cmdb_v2-handler'result==0)