Giter Club home page Giter Club logo

fotoobo's Introduction

fotoobo | Fortinet Toolbox

make IT easy

GitHub release (latest by date) GitHub License PyPi Python versions
GitHub Workflow Status GitHub open issues GitHub closed issues
GitHub Repo stars GitHub watchers GitHub forks GitHub contributors

This is fotoobo, the mighty Fortinet toolbox for managing your Fortinet environment. It is meant to be extendable to your needs.

For detailed documentation see fotoobo.readthedocs.io

Contribution

To contribute to this project please start by reading and accepting our Collective Code Construction Contract.

License

fotoobo is licensed under the LGPL v3.

Since it is a python application which does not compile to a binary before distribution, we want to clarify the following:

fotoobo may be used as an imported module under the same terms that the LGPL states for dynamically linked (binary) libraries. So you may use fotoobo (unmodified) with code under another license (free or commercial).

All changes to the fotoobo code itself are subject to the LGPL v3.

fotoobo's People

Contributors

dependabot[bot] avatar lucmurer avatar patrikspiess avatar skftnt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

fotoobo's Issues

extend fotoobo command autocompletion

Automatic completion should be more relevant:

  • if you type fotoobo fgt get version it should present you with a list of the hosts from the inventory

Same applies for all other commands

introduce fgt config info

Add a new command fotoobo fgt config info

The subcommand info should display the FortiGate information from the parsed configuration file.

traceback when syslog server in fotoobo.yaml is not resolvable

If you set a syslog server in fotoobo.yaml for logging which is not resolvable by dns (name not known or timeout) it gives a treaceback:

socket.gaierror: [Errno -2] Name or service not known

or

socket.gaierror: [Errno -3] Temporary failure in name resolution

Instead fotoob should give a propper error message (and maybe continue anyway?)

SysLogHandler: Exception ignored in atexit callback

When the syslog server is not resolvable (see #72) there is an exception originated in the python standard-Library:

Exception ignored in atexit callback: <function shutdown at 0x7f39db663eb0>
Traceback (most recent call last):
  File "/usr/lib64/python3.10/logging/__init__.py", line 2183, in shutdown
    h.close()
  File "/usr/lib64/python3.10/logging/handlers.py", line 945, in close
    self.socket.close()
AttributeError: 'SysLogHandler' object has no attribute 'socket'

How to reproduce:

  • Configure a SysLog server that has a non-resolvable hostname/fqdn
  • Run some fotoobo command (for example fotoobo fgt get version)

This seems to be an upstream issue:

Probably the latter will solve the imminent effect, but not the base problem. Perhaps we need to fix this upstream.

Refactor tests

At the moment we use @patch from unittest.mock for monkeypatching in tests.
We should switch to monkeypatch from pytest to be consistent in all tests.

Refactor files/functions structure in utils

In the utils the functions are named the same as the files. For very function there is an own file. This give naming clashes.
We strip one level and put the functions in a file one level higher
So there is no more file with the same name as the function within => Naming clash resolved

parallel processing

Candidates for paralle processing are:

  • fotoobo fgt backup
  • fotoobo fgt get version
  • fotoobo fgt monitor hamaster

How should we do parallel processing at all?

install error with poetry 1.4.1

on macos, poetry 1.4.1 was release a few days ago.

Problem
i was not able to install fotoobo with 'poetry install'

• Installing black (22.10.0): Failed

  _WheelFileValidationError

  ["In /Users/MYUSERNAME/Library/Caches/pypoetry/artifacts/9a/87/53/8a817f0bf6562226d9de0d3ad0eb2eb28c8191e978d21740991796e053/black-22.10.0-1fixedarch-cp311-cp311-macosx_11_0_x86_64.whl, hash / size of black-22.10.0.dist-info/WHEEL didn't match RECORD"]

  at /usr/local/Cellar/poetry/1.4.1/libexec/lib/python3.11/site-packages/installer/sources.py:289 in validate_record
      285│                         f"In {self._zipfile.filename}, hash / size of {item.filename} didn't match RECORD"
      286│                     )
      287│ 
      288│         if issues:
    → 289│             raise _WheelFileValidationError(issues)
      290│ 
      291│     def get_contents(self) -> Iterator[WheelContentElement]:
      292│         """Sequential access to all contents of the wheel (including dist-info files).
      293│ 

Solution
downgrad poetry locall to the previous version:

poetry self update 1.4.0

and all seems to work fine ...

Backup transfer should support SFTP

Due to security reasons a backup transferred to an FTP server should support SFTP (encrypted)

Example: https://sftptogo.com/blog/python-sftp/

ToDo:

  • Make SFTP the default, but allow to use FTP in the inventory
  • Log a warning if FTP is used, because config (and especially the hashed passwords) are transferred unencrypted to the backup server

Tests in tests/helpers/test_log.py fail after switching to daylight saving time on March 26th

>       assert syslog_formatter.format(log_record) == expected_string
E       AssertionError: assert '<10>1 1970-0... test_message' == '<10>1 1970-0... test_message'
E         Skipping 55 identical trailing characters in diff, use -v to show
E         - <10>1 1970-01-01T01:00:00+02:00 dummy
E         ?                            ^
E         + <10>1 1970-01-01T01:00:00+01:00 dummy
E         ?                            ^

Wouldn't it be better to check the time format with a regex instead of a fully qualified string?

Introduce fgt config get

Add a utility to get the parsed configuration
By adding a path it should be possible to get just parts of the configuration
(pretty)print or save it in json format

Review cli command structure

Command structure seems more accidental than intentional at the moment: Sometimes the command structure is very specific (fotoobo fgt check hamaster), sometimes there seems to lack a subcommand (fotoobo convert checkpoint).

I think there should be a general structure like:

  • fotoobo <asset-type> <do-word> <object> (e.g. fotoobo fgt check hamaster)
  • or fotoobo <do-word> <asset-type> <object> (e.g. fotoobo convert checkpoint assets)

Improve output when there is an error

When there is an error fotoobo will just print a line and exit. We should use the facility of rich here, and print a panel with the error message.

Tests fail when no dns resolution is possible for syslog logging

It seems the tests use the fotoobo.log if one is found. And if there is a syslog server configured but name resolution fails some tets fail because it tries to resolve the hostname given in the fotoobo logging configuration:

___ test_cli_convert_no_args ___

    def test_cli_convert_no_args() -> None:
        """Test convert cli without issuing any arguments"""
        result = runner.invoke(app, ["convert"])
>       assert result.exit_code == 2
E       AssertionError: assert 1 == 2
E        +  where 1 = <Result gaierror(-3, 'Temporary failure in name resolution')>.exit_code

tests/cli/test_cli_convert.py:19: AssertionError

or

___ test_cli_convert_no_args ___

    def test_cli_convert_no_args() -> None:
        """Test convert cli without issuing any arguments"""
        result = runner.invoke(app, ["convert"])
>       assert result.exit_code == 2
E       AssertionError: assert 1 == 2
E        +  where 1 = <Result gaierror(-2, 'Name or service not known')>.exit_code

tests/cli/test_cli_convert.py:19: AssertionError

Command `fmg post` has wrong options order

The Command fmg post has wrong options order. FortiManger should be optional (default: fmg) and at the end of the options list. As with other fmg commands.
This is a breaking change!

Same output/error handling for all functions

There are differences in the output/error handling for different commands:

  • fotoobo fgt get version presents the data in a nice table, even in the case of failure
  • fotoobo fmg get version will just print the error (in case of error), even no "Error"-panel

save_with_template() is not able to use absolute path for template file

If an absolute path is given to the ems monitor utilities they all fail as using a relative path is hardcoded in save_with_template()

template_env = jinja2.Environment(loader=jinja2.FileSystemLoader("./"), trim_blocks=True)

Change the logic to be able to use relative AND absulte paths

Document templating possibility for `monitor` commands

During the review of the CLI structure & help texts we saw, that the whole template mechanism used by the monitoring command is basically undocumented. Especially document the following:

  • How to create templates
  • What variables exist during template execution (for which command & generally)

Syslog messages should follow rfc5424 standard

The syslog message format is defined in rfc5424 section 6

https://www.rfc-editor.org/rfc/rfc5424#section-6

  • change the syslog message format to comply with rfc5424
  • document it

From rfc5424 I understood the following syntax:
VERSION TIMESTAMP HOSTNAME APP-NAME PROCID MSGID STRUCTURED-DATA MSG

PRIVAL = Facility * 8 + Severity
VERSION = 1
APP-NAME = fotoobo
PROCID = os.getpid()
MSGID = "AUDIT" for audit messages
STRUCTURED-DATA = "-" (we leave it empty)

At the moment an autit message looks like this:
AUDIT:fotoobo:username=vader:hostname=deathstar:command="/home/vader/.local/bin/fotoobo greet"
But it should be this way:
<110>1 TIMESTAMP deathstar fotoobo 666 AUDIT - username=vader hostname=deathstar command="/home/vader/.local/bin/fotoobo greet"

Add options to add a custom CA for secure connections

It is not always the case that internal devices have certificates signed by a global CA accepted by the host operating system that runs fotoobo.

So we should add options to the configuration / inventory to add custom CA certificates / known good certificate information:

  • Add a custom CA to the inventory (or globally to fotoobo.yaml?)
  • Perhaps give the possibility to provide the known good hash of the respective certificate per device in the inventory. -> Need to check, whether Python SSL/TLS support supports this...

Review cli help texts

The help texts should be reviewed (for example fotoobo fgt backup -h):

  • Better describe what happens if an optional argument is omitted (backup all FortiGates in inventory)
  • Better describe the meaning of the arguments: What is the intention of the argument (e.g. source/target to read/write to)?
  • Probably also other improvements

Add https_port option for Fortinet devices in inventory

The connection port for Fortinet devices is appended to the hostname option. e.g.: fortgate.local:10443
In case the hostname is used for anything else than https connections it's not optimal if the port number is appended to the hostname directly.
Add an option https_port to the Fortinet devices and specify 443 as default.

Improve configuration handling

Load the fotoobo configuration in the following order:

  • Command line options
  • fotoobo.yaml in local folder
  • fotoobo.yaml in user config folder (~/.config/fotoobo.yaml)

If none of the above is presend use good defaults
Make the config search method extendable to add more directories in the future

optimize test for exception

in /home/pspiess/projects/mnet/fotoobo/tests/cli/fmg/test_cli_fmg_get.py we do not test for exception with with pytest.rises(...).
Should test for exceptions like in other tests

Remove backup_dir from fotoobo.yaml

Backup_dir is only used for fgt backup and schould be removed from global setting in fotoobo.yaml
Instead add backup_dir as argument for the CLI command

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.