Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in repo when using fortios_system_admin to configure ssh_public_key #68497

Closed
yamjoepobuda opened this issue Mar 26, 2020 · 8 comments
Closed
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. collection:frankshen01.testfortios collection Related to Ansible Collections work fortios Fortios community module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md networking Network category support:community This issue/PR relates to code supported by the Ansible community.

Comments

@yamjoepobuda
Copy link

SUMMARY

When attempting to add ssh keys (ssh_public_key1, ssh_public_key2, ssh_public_key3) to adminisistrators using the fortios_system_admin module, the task errors out with a non-descriptive message. Running the same play with "ssh_public_key1" line commented out, the task completes successfully.

I've attempted to define each of the three keys individually, as well as all 3 keys at the same time. I've also reviewed Fortinet's official documentation for this config section (https://kb.fortinet.com/kb/documentLink.do?externalID=FD38771) and the format appears to be what the device is expecting.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

fortios_system_admin

ANSIBLE VERSION
ansible 2.9.6
  config file = /etc/ansible/ansible.cfg
  configured module search path = [u'/home/ansible/.ansible/plugins/modules', u'/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/local/lib/python2.7/dist-packages/ansible
  executable location = /usr/local/bin/ansible
  python version = 2.7.17 (default, Nov  7 2019, 10:07:09) [GCC 7.4.0]
CONFIGURATION
ANSIBLE_NOCOWS(/etc/ansible/ansible.cfg) = True
CACHE_PLUGIN(/etc/ansible/ansible.cfg) = redis
CACHE_PLUGIN_CONNECTION(/etc/ansible/ansible.cfg) = production-a-redis.h6fgmd.0001.usw2.cache.amazonaws.com:6379:0
CACHE_PLUGIN_TIMEOUT(/etc/ansible/ansible.cfg) = 86400
DEFAULT_CALLBACK_WHITELIST(/etc/ansible/ansible.cfg) = [u'datadog_callback']
DEFAULT_FORKS(/etc/ansible/ansible.cfg) = 50
DEFAULT_GATHER_TIMEOUT(/etc/ansible/ansible.cfg) = 20
DEFAULT_HASH_BEHAVIOUR(/etc/ansible/ansible.cfg) = merge
DEFAULT_POLL_INTERVAL(/etc/ansible/ansible.cfg) = 5
DEFAULT_ROLES_PATH(/etc/ansible/ansible.cfg) = [u'/etc/ansible/roles']
DISPLAY_SKIPPED_HOSTS(/etc/ansible/ansible.cfg) = False
HOST_KEY_CHECKING(/etc/ansible/ansible.cfg) = False
PERSISTENT_COMMAND_TIMEOUT(/etc/ansible/ansible.cfg) = 30
PERSISTENT_CONNECT_TIMEOUT(/etc/ansible/ansible.cfg) = 40
RETRY_FILES_ENABLED(/etc/ansible/ansible.cfg) = False
OS / ENVIRONMENT

ubuntu: 18.04
ansible_version: 2.9.6

Fortigate OS: 6.0.9
Fortigate hardware: 60E

Fortigate OS: 6.0.6
Fortigate hardware: 600D, 300D

STEPS TO REPRODUCE

Notable vars:

remote_authorization:
  admins:
    - johndoe

rsa_public_keys:
  johndoe:
    keys:
      - AAAAB3NzaC1yc2EAAAADAQABAAABAQDR3N6ygJB0quJM4586+Txw04ugV3JtUYn4uZJ0PA7ePafJtNvv4DAYPLWuvwOPrk3u5kaRew1eIhLrj7CgsI/nrKB4F7LHUQ8Fd1pJte13i7mTW8BlNbs4ilGSDLdZOpmJU0+Xdfoon/xvoVzK6RCcoaA3+Q/WW2ASlrKmzRhm4Gp/oQrnFE9cUI+s8YfAtR10FAmYEDRezhypy672nccZh4pwHR6s/DgxsqR28JS/X2OvAj5/ErouqIelTNtFmyU/wNhPMYCmKlh5R1wZyPUk98lqA2ReFS8/O+1cN4eQAjHY5956y5zl7yMTCFrMPvscTcP1tl4JLRMg1P/jLmVV

Ansible task:

- name: Configure SSH key 1
  fortios_system_admin:
    host:  "{{ fortios_host }}"
    username: "{{ fortios_username }}"
    password: "{{ fortios_password }}"
    vdom:  "{{ fortios_vdom }}"
    ssl_verify: "False"
    state: "present"
    system_admin:
      name: "{{ item }}"
      ssh_public_key1: "{{ 'ssh-rsa ' + rsa_public_keys[item]['keys'][0]|default(omit) }}"
  loop: "{{ remote_authorization.admins }}"
  when: fos_version is version('6.0.5','>=') and rsa_public_keys[item]['keys'][0] is defined
  register: _ssh_key_1
EXPECTED RESULTS
TASK [fortios-system-admin : Configure SSH key 1] ****************************
changed: [fw-60e.test.internal] => (item=johndoe)
changed: [fw-300d.test.internal] => (item=johndoe)
changed: [fw-600d.test.internal] => (item=johndoe)
ACTUAL RESULTS

Task errors with "Error in repo" on every device, on every run. Unfortunately, every failure I've ever experienced with these modules has had the same error message. I wish this were more descriptive, but I digress.

The command does not get entered into FortiOS. Manually entering the command via cli or FortiManager works fine without issue. Running the same module without ssh_public_key1 defined completes successfully.

Non-verbose output:

TASK [fortios-system-admin : Configure SSH key 1] ******************************
failed: [fw-60e.test.internal] (item=johndoe) => {"ansible_loop_var": "item", "changed": false, "item": "johndoe", "meta": {"build": 335, "error": -5, "http_method": "POST", "http_status": 500, "name": "admin", "path": "system", "revision": "196.0.0.2736635036.1581028194", "serial": "FGTXXXXXXXXXXXXX", "status": "error", "vdom": "root", "version": "v6.0.9"}, "msg": "Error in repo"}
failed: [fw-300d.test.internal] (item=johndoe) => {"ansible_loop_var": "item", "changed": false, "item": "johndoe", "meta": {"build": 272, "error": -5, "http_method": "POST", "http_status": 500, "name": "admin", "path": "system", "revision": "175.0.0.4021061266.1576194083", "revision_changed": false, "serial": "FGTXXXXXXXXXXXXX", "status": "error", "vdom": "root", "version": "v6.0.6"}, "msg": "Error in repo"}
failed: [fw-600d.test.internal] (item=johndoe) => {"ansible_loop_var": "item", "changed": false, "item": "johndoe", "meta": {"build": 272, "error": -5, "http_method": "POST", "http_status": 500, "name": "admin", "path": "system", "revision": "175.0.0.4021061266.1576194083", "serial": "FGTXXXXXXXXXXXXX", "status": "error", "vdom": "root", "version": "v6.0.6"}, "msg": "Error in repo"}

Verbose output (only 1 example shown, since they're all the same):

TASK [fortios-system-admin : Configure SSH key 1] ******************************
task path: /etc/ansible/roles/fortios-system-admin/tasks/main.yml:69
failed: [fw-60e.test.internal] (item=johndoe) => {
    "ansible_loop_var": "item", 
    "changed": false, 
    "invocation": {
        "module_args": {
            "host": "fw-60e.test.internal:8443", 
            "https": true, 
            "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
            "ssl_verify": false, 
            "state": "present", 
            "system_admin": {
                "accprofile": null, 
                "accprofile_override": null, 
                "allow_remove_admin_session": null, 
                "comments": null, 
                "email_to": null, 
                "force_password_change": null, 
                "fortitoken": null, 
                "guest_auth": null, 
                "guest_lang": null, 
                "guest_usergroups": null, 
                "gui_dashboard": null, 
                "gui_global_menu_favorites": null, 
                "gui_vdom_menu_favorites": null, 
                "hidden": null, 
                "history0": null, 
                "history1": null, 
                "ip6_trusthost1": null, 
                "ip6_trusthost10": null, 
                "ip6_trusthost2": null, 
                "ip6_trusthost3": null, 
                "ip6_trusthost4": null, 
                "ip6_trusthost5": null, 
                "ip6_trusthost6": null, 
                "ip6_trusthost7": null, 
                "ip6_trusthost8": null, 
                "ip6_trusthost9": null, 
                "login_time": null, 
                "name": "johndoe", 
                "password": null, 
                "password_expire": null, 
                "peer_auth": null, 
                "peer_group": null, 
                "radius_vdom_override": null, 
                "remote_auth": null, 
                "remote_group": null, 
                "schedule": null, 
                "sms_custom_server": null, 
                "sms_phone": null, 
                "sms_server": null, 
                "ssh_certificate": null, 
                "ssh_public_key1": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDR3N6ygJB0quJM4586+Txw04ugV3JtUYn4uZJ0PA7ePafJtNvv4DAYPLWuvwOPrk3u5kaRew1eIhLrj7CgsI/nrKB4F7LHUQ8Fd1pJte13i7mTW8BlNbs4ilGSDLdZOpmJU0+Xdfoon/xvoVzK6RCcoaA3+Q/WW2ASlrKmzRhm4Gp/oQrnFE9cUI+s8YfAtR10FAmYEDRezhypy672nccZh4pwHR6s/DgxsqR28JS/X2OvAj5/ErouqIelTNtFmyU/wNhPMYCmKlh5R1wZyPUk98lqA2ReFS8/O+1cN4eQAjHY5956y5zl7yMTCFrMPvscTcP1tl4JLRMg1P/jLmVV", 
                "ssh_public_key2": null, 
                "ssh_public_key3": null, 
                "state": null, 
                "trusthost1": null, 
                "trusthost10": null, 
                "trusthost2": null, 
                "trusthost3": null, 
                "trusthost4": null, 
                "trusthost5": null, 
                "trusthost6": null, 
                "trusthost7": null, 
                "trusthost8": null, 
                "trusthost9": null, 
                "two_factor": null, 
                "vdom": null, 
                "wildcard": null
            }, 
            "username": "admin", 
            "vdom": "root"
        }
    }, 
    "item": "johndoe", 
    "meta": {
        "build": 335, 
        "error": -5, 
        "http_method": "POST", 
        "http_status": 500, 
        "name": "admin", 
        "path": "system", 
        "revision": "196.0.0.2736635036.1581028194", 
        "revision_changed": false, 
        "serial": "FGTXXXXXXXXXXXXX", 
        "status": "error", 
        "vdom": "root", 
        "version": "v6.0.9"
    }, 
    "msg": "Error in repo"
}
@ansibot
Copy link
Contributor

ansibot commented Mar 26, 2020

Files identified in the description:

If these files are incorrect, please update the component name section of the description or use the !component bot command.

click here for bot help

@ansibot
Copy link
Contributor

ansibot commented Mar 26, 2020

@yamjoepobuda, just so you are aware we have a dedicated Working Group for network.
You can find other people interested in this in #ansible-network on Freenode IRC
For more information about communities, meetings and agendas see https://github.com/ansible/community

click here for bot help

@ansibot ansibot added affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. fortios Fortios community module This issue/PR relates to a module. needs_triage Needs a first human triage before being processed. networking Network category support:community This issue/PR relates to code supported by the Ansible community. labels Mar 26, 2020
@JonTheNiceGuy
Copy link
Contributor

Hi @yamjoepobuda unfortunately, due to the way the FortiOS handles errors, it doesn't return them through the API. What you're probably better doing, particularly as you've got this in a test environment, is to do this, before you run the above playbook.

  1. SSH to or access the HTTPS terminal on one of the FortiGates in question.
  2. Execute this command diagnose debug enable
  3. Execute this command diagnose debug cli 8 (yes, it's an arbitrary magic number, but bear with me)
  4. Now execute the playbook with just this module that has failed.

You'll see it do something like (sourced from a post I wrote a couple of years ago: https://jon.sprig.gs/blog/post/929)

0: config firewall vip
0: edit "vip8080"
0: unset src-filter
0: unset service
0: set extintf "port1"
0: set portforward enable
0: unset srcintf-filter
0: set mappedip "192.0.2.1-192.0.2.1"
0: unset extport
0: set extport 8080-8081
0: unset mappedport
0: set mappedport 8080
-651: end

If you then try and run that sequence of commands yourself, it'll say why that command wouldn't run.

I went around this quite a bit with the Fortinet TAC team when I was working on this stuff more heavily, before it was mainlined. You might also see some more useful content by trying to execute diagnose debug application httpsd -1 but that puts LOTS AND LOTS of logs out, especially if you're signed into the web console to see this, as each time the web UI asks for a status update, you get a load of junk scrolling up!

@yamjoepobuda
Copy link
Author

Debug output from the firewall:

fw-60e-a #
fw-60e-a #
fw-60e-a # 0: config system admin
0: edit "johndoe"
0: unset ssh-public-key1
-651: set ssh-public-key1 "AAAAB3NzaC1yc2EAAAADAQABAAABAQDR3N6ygJB0quJM4586+Txw04ugV3JtUYn4uZJ0PA7ePafJtNvv4DAYPLWuvwOPrk3u5kaRew1eIhLrj7CgsI/nrKB4F7LHUQ8Fd1pJte13i7mTW8BlNbs4ilGSDLdZOpmJU0+Xdfoon/xvoVzK6RCcoaA3+Q/WW2ASlrKmzRhm4Gp/oQrnFE9cUI+s8YfAtR10FAmYEDRezhypy672nccZh4pwHR6s/DgxsqR28JS/X2OvAj5/ErouqIelTNtFmyU/wNhPMYCmKlh5R1wZyPUk98lqA2ReFS8/O+1cN4eQAjHY5956y5zl7yMTCFrMPvscTcP1tl4JLRMg1P/jLmVV"
(skipped) unset ssh-public-key2

(skipped) unset ssh-public-key3

(skipped) set ssh-public-key3 "__omit_place_holder__718b3b734010dbb252cfdb4c8140695491dc8fa9"

11506 0 cmd =
config system admin
edit johndoe
unset ssh-public-key1
abort

Debug output from the task:

ok: [fw-60e.test.internal] => {
    "_ssh_key_1": {
        "changed": false, 
        "failed": true, 
        "msg": "All items completed", 
        "results": [
            {
                "ansible_loop_var": "item", 
                "changed": false, 
                "failed": true, 
                "invocation": {
                    "module_args": {
                        "host": "fw-60e.test.internal:8443", 
                        "https": true, 
                        "password": "VALUE_SPECIFIED_IN_NO_LOG_PARAMETER", 
                        "ssl_verify": false, 
                        "state": "present", 
                        "system_admin": {
                            "accprofile": null, 
                            "accprofile_override": null, 
                            "allow_remove_admin_session": null, 
                            "comments": null, 
                            "email_to": null, 
                            "force_password_change": null, 
                            "fortitoken": null, 
                            "guest_auth": null, 
                            "guest_lang": null, 
                            "guest_usergroups": null, 
                            "gui_dashboard": null, 
                            "gui_global_menu_favorites": null, 
                            "gui_vdom_menu_favorites": null, 
                            "hidden": null, 
                            "history0": null, 
                            "history1": null, 
                            "ip6_trusthost1": null, 
                            "ip6_trusthost10": null, 
                            "ip6_trusthost2": null, 
                            "ip6_trusthost3": null, 
                            "ip6_trusthost4": null, 
                            "ip6_trusthost5": null, 
                            "ip6_trusthost6": null, 
                            "ip6_trusthost7": null, 
                            "ip6_trusthost8": null, 
                            "ip6_trusthost9": null, 
                            "login_time": null, 
                            "name": "johndoe", 
                            "password": null, 
                            "password_expire": null, 
                            "peer_auth": null, 
                            "peer_group": null, 
                            "radius_vdom_override": null, 
                            "remote_auth": null, 
                            "remote_group": null, 
                            "schedule": null, 
                            "sms_custom_server": null, 
                            "sms_phone": null, 
                            "sms_server": null, 
                            "ssh_certificate": null, 
                            "ssh_public_key1": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDR3N6ygJB0quJM4586+Txw04ugV3JtUYn4uZJ0PA7ePafJtNvv4DAYPLWuvwOPrk3u5kaRew1eIhLrj7CgsI/nrKB4F7LHUQ8Fd1pJte13i7mTW8BlNbs4ilGSDLdZOpmJU0+Xdfoon/xvoVzK6RCcoaA3+Q/WW2ASlrKmzRhm4Gp/oQrnFE9cUI+s8YfAtR10FAmYEDRezhypy672nccZh4pwHR6s/DgxsqR28JS/X2OvAj5/ErouqIelTNtFmyU/wNhPMYCmKlh5R1wZyPUk98lqA2ReFS8/O+1cN4eQAjHY5956y5zl7yMTCFrMPvscTcP1tl4JLRMg1P/jLmVV", 
                            "ssh_public_key2": null, 
                            "ssh_public_key3": null, 
                            "state": null, 
                            "trusthost1": null, 
                            "trusthost10": null, 
                            "trusthost2": null, 
                            "trusthost3": null, 
                            "trusthost4": null, 
                            "trusthost5": null, 
                            "trusthost6": null, 
                            "trusthost7": null, 
                            "trusthost8": null, 
                            "trusthost9": null, 
                            "two_factor": null, 
                            "vdom": null, 
                            "wildcard": null
                        }, 
                        "username": "admin", 
                        "vdom": "root"
                    }
                }, 
                "item": "johndoe", 
                "meta": {
                    "build":335, 
                    "error": -5, 
                    "http_method": "POST", 
                    "http_status": 500, 
                    "name": "admin", 
                    "path": "system", 
                    "revision": "196.0.0.2736635036.1581028194", 
                    "serial": "FGT60EXXXXXXXXXX", 
                    "status": "error", 
                    "vdom": "root", 
                    "version": "v6.0.9"
                }, 
                "msg": "Error in repo"
            }

@JonTheNiceGuy
Copy link
Contributor

JonTheNiceGuy commented Mar 28, 2020 via email

@yamjoepobuda
Copy link
Author

fw-60e-a #
fw-60e-a #
fw-60e-a # config system admin

fw-60e-a (admin) # edit johndoe

fw-60e-a (johndoe) # set ssh-public-key1 "AAAAB3NzaC1yc2EAAAADAQABAAABAQDR3N6ygJB0quJM4586+Txw04ugV3JtUYn4uZJ0PA7ePafJtNvv4DAYPLWuvwOPrk3u5kaRew1eIhLrj7CgsI/nrKB4F7LHUQ8Fd1pJte13i7mTW8BlNbs4ilGSDLdZOpmJU0+Xdfoon/xvoVzK6RCcoaA3+Q/WW2ASlrKmzRhm4Gp/oQrnFE9cUI+s8YfAtR10FAmYEDRezhypy672nccZh4pwHR6s/DgxsqR28JS/X2OvAj5/ErouqIelTNtFmyU/wNhPMYCmKlh5R1wZyPUk98lqA2ReFS8/O+1cN4eQAjHY5956y5zl7yMTCFrMPvscTcP1tl4JLRMg1P/jLmVV"
Invalid public key. The accepted formats are "ssh-rsa AAAAB3NzaC1......" and "ssh-dss AAAAB3NzaC1......"
node_check_object fail! for ssh-public-key1 AAAAB3NzaC1yc2EAAAADAQABAAABAQDR3N6ygJB0quJM4586+Txw04ugV3JtUYn4uZJ0PA7ePafJtNvv4DAYPLWuvwOPrk3u5kaRew1eIhLrj7CgsI/nrKB4F7LHUQ8Fd1pJte13i7mTW8BlNbs4ilGSDLdZOpmJU0+Xdfoon/xvoVzK6RCcoaA3+Q/WW2ASlrKmzRhm4Gp/oQrnFE9cUI+s8YfAtR10FAmYEDRezhypy672nccZh4pwHR6s/DgxsqR28JS/X2OvAj5/ErouqIelTNtFmyU/wNhPMYCmKlh5R1wZyPUk98lqA2ReFS8/O+1cN4eQAjHY5956y5zl7yMTCFrMPvscTcP1tl4JLRMg1P/jLmVV

value parse error before 'AAAAB3NzaC1yc2EAAAADAQABAAABAQDR3N6yg
Command fail. Return code -651

If you look at the debug output above, you'll see that the full string is there... but for some reason it looks like it's truncating the "ssh-rsa"

                            "ssh_certificate": null, 
   =====>                   "ssh_public_key1": "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDR3N6ygJB0quJM4586+Txw04ugV3JtUYn4uZJ0PA7ePafJtNvv4DAYPLWuvwOPrk3u5kaRew1eIhLrj7CgsI/nrKB4F7LHUQ8Fd1pJte13i7mTW8BlNbs4ilGSDLdZOpmJU0+Xdfoon/xvoVzK6RCcoaA3+Q/WW2ASlrKmzRhm4Gp/oQrnFE9cUI+s8YfAtR10FAmYEDRezhypy672nccZh4pwHR6s/DgxsqR28JS/X2OvAj5/ErouqIelTNtFmyU/wNhPMYCmKlh5R1wZyPUk98lqA2ReFS8/O+1cN4eQAjHY5956y5zl7yMTCFrMPvscTcP1tl4JLRMg1P/jLmVV", 
                            "ssh_public_key2": null, 
                            "ssh_public_key3": null,

@yamjoepobuda
Copy link
Author

A suggestion, depending on the outcome of this issue...

Here's the syntax per the FortOS manual:

  config system admin
    edit admin
      set ssh-public-key1 "<key-type> <key-value>"
<key-type> must be ssh-dss for a DSA key or ssh-rsa for an RSA key. 

Might be nice to have something like this as a configuration option, where rsa is default.

ssh_public_key1: "long key string"
  key-type: [rsa, dsa]
ssh_public_key2: "long key string"
  key-type: [rsa, dsa]
ssh_public_key3: "long key string"
  key-type: [rsa. dsa]

Behind the scenes, key-type would translate rsa to ssh-rsa and dsa to ssh-dsa and prepend it to the command being sent. Either way, I believe the README/examples should be updated to match the expected syntax. There's no mention of key-type currently.

https://docs.ansible.com/ansible/latest/modules/fortios_system_admin_module.html

ssh_public_key1 string |   | Public key of an SSH client. The client is authenticated without being asked for credentials. Create the public-private key pair in the SSH client application.

@ansibot ansibot added collection Related to Ansible Collections work collection:fortinet.fortios collection:frankshen01.testfortios needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md labels Apr 24, 2020
@danielmellado danielmellado removed the needs_triage Needs a first human triage before being processed. label May 13, 2020
@danielmellado
Copy link
Contributor

danielmellado commented May 13, 2020

Thank you very much for your interest in Ansible. This plugin is no longer maintained in this repository and has been migrated to https://github.com/fortinet-ansible-dev/ansible-galaxy-fortios-collection
Please re-submit this issue in the above repository.
If you have further questions please stop by IRC or the mailing list:

IRC: #ansible-network on irc.freenode.net
mailing list: https://groups.google.com/forum/#!forum/ansible-project

@ansible ansible locked and limited conversation to collaborators Jun 10, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
affects_2.9 This issue/PR affects Ansible v2.9 bug This issue/PR relates to a bug. collection:frankshen01.testfortios collection Related to Ansible Collections work fortios Fortios community module This issue/PR relates to a module. needs_collection_redirect https://github.com/ansible/ansibullbot/blob/master/docs/collection_migration.md networking Network category support:community This issue/PR relates to code supported by the Ansible community.
Projects
None yet
Development

No branches or pull requests

4 participants