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

DTT1 - Iteration 3 - Provision module - Module documentation #4851

Closed
2 tasks done
Tracked by #4852
fcaffieri opened this issue Jan 16, 2024 · 6 comments · Fixed by #4962
Closed
2 tasks done
Tracked by #4852

DTT1 - Iteration 3 - Provision module - Module documentation #4851

fcaffieri opened this issue Jan 16, 2024 · 6 comments · Fixed by #4962
Assignees

Comments

@fcaffieri
Copy link
Member

fcaffieri commented Jan 16, 2024

Epic: #4852


Description

The objective of this issue is to generate the documentation of the Provision module.

Tasks

  • Generate documentation on the use of the module for end users.
  • Generate technical documentation about the module graph and flow.
@pro-akim
Copy link
Member

pro-akim commented Feb 12, 2024

Update

SAMPLE

Provision module

User documentation

The Provision module installs libraries, dependencies and applications on the allocated infrastructure (From Allocation module)

This module can be executed as follows:
A. Installing and using Workflow engine
B. Direct execution

A. Installing and using Workflow engine

The execution of the workflow is done through the installation of its library.

Initially, Python libraries must be installed. we recommended the use of virtual environments. Follow the technical documentation at https://docs.python.org/3/library/venv.html.

  1. Create the python environment:

    python3 -m venv {environment_name}
  2. Activate the environment:

     source {venv directory}/bin/activate
  3. Clone the wazuh-qa repository:

    Navigate to the project directory and switch to the project branch:

    https://github.com/wazuh/wazuh-qa.git
    cd wazuh-qa
    git checkout {project-branch}
  4. Install requirements:

    pip3 install -r deployability/deps/requirements.txt
  5. Install the Workflow engine library and its launcher:

    While in wazuh-qa:

    cd modules
    pip3 uninstall -y workflow_engine && pip3 install .

Run the module by doing the following steps:

  1. Test fixture to execute:

    It is required to create a fixture (YAML file) where the infrastructure, provisioning, and tests to be executed is declared.

    Note: You can find some fixture examples in 'deployability/modules/workflow_engine/examples/'

    Example:

    version: 0.1
    description: This workflow is used to provision agents hosts por DDT1 PoC
    variables:
      agents-os:
        - linux-ubuntu-22.04-amd64
      infra-provider: vagrant
      working-dir: /tmp/dtt1-poc
    
    tasks:
      - task: "allocate-{agent}"
        description: "Allocate resources for the {agent} agent."
        do:
          this: process
          with:
            path: python3
            args:
              - modules/allocation/main.py
              - action: create
              - provider: "{infra-provider}"
              - size: small
              - composite-name: "{agent}"
              - inventory-output: "{working-dir}/agent-{agent}/inventory.yaml"
              - track-output: "{working-dir}/agent-{agent}/track.yaml"
        cleanup:
          this: process
          with:
            path: python3
            args:
              - modules/allocation/main.py
              - action: delete
              - track-output: "{working-dir}/agent-{agent}/track.yaml"
        foreach:
          - variable: agents-os
            as: agent
    
      - task: "provision-install-{agent}"
        description: "Provision resources for the {agent} agent."
        do:
          this: process
          with:
            path: python3
            args:
              - modules/provision/main.py
              - inventory: "{working-dir}/agent-{agent}/inventory.yaml"
              - dependencies:
                - agent: "{working-dir}/agent-{agent}/inventory.yaml"
              - install:
                - component: curl
                - component: python
                  type: source
                  version: "{python-version}"
                - component: virtualenv
                  type: pip
                - component: deps/requirements.txt
                  type: pip
                - component: pyyaml
                  type: pip
                  version: 6.0.1
        depends-on:
          - "allocate-{agent}"
        foreach:
          - variable: agents-os
            as: agent

    Following the schema of the example:

    Configure the following parameters depending on your allocation:

    variables/agent-os
    variables/manager-os
    infra-provider
    working-dir
    tasks

    Pay attention to the tasks:

    args
    depends-on

    Note: In args, configure the launcher's path correctly (main.py files in each module), and to fill depends-on, consider the steps of your provision (allocation and provision)

  2. Command execution (local):

    Execute the command by referencing the parameters required by the library (launcher).

    python3 -m workflow_engine {.yaml fixture path}

    Example

    python3 -m workflow_engine modules/workflow_engine/examples/dtt1-agents-poc.yaml

B. Direct execution

To execute the Allocation module without installing the Workflow engine, you can use the launcher ('module/provision/main.py'):

  1. Execution

While in wazuh-qa/deployability

python3 module/provision/main.py --inventory-manager { inventory .yaml} --install "{'component': '{component}', 'type': '{type}', 'version': '{version}'}" 

Example:

python3 module/provision/main.py --inventory-manager /tmp/dtt1-poc/manager-linux-ubuntu-22.04-amd64/inventory.yaml --install "{'component': 'pyyaml', 'type': 'pip', 'version' : '6.0.1'}" 

Technical documentation

The provision module allows for the installation and uninstallation of libraries, dependencies, and applications in the infrastructure.

It can receive instructions either through the command line or be mediated through the Workflow Engine.

In both cases, the following information is required:

  - task: "provision-install-{agent}"
    description: "Provision resources for the {agent} agent."
    do:
      this: process
      with:
        path: python3
        args:
          - modules/provision/main.py
          - inventory: "{working-dir}/agent-{agent}/inventory.yaml"
          - dependencies:
            - agent: "{working-dir}/agent-{agent}/inventory.yaml"
          - install:
            - component: curl
            - component: python
              type: source
              version: "{python-version}"
            - component: virtualenv
              type: pip
            - component: deps/requirements.txt
              type: pip
            - component: pyyaml
              type: pip
              version: 6.0.1
    depends-on:
      - "allocate-{agent}"
    foreach:
      - variable: agents-os
        as: agent

The snippet obtained from a Workflow fixture highlights the parameters necessary for its operation. These include the inventory path, the dependency/library to install, and the installation type.

It requires an infrastructure on which to perform its actions.

The module is composed of:

image

Provision.drawio.zip

License

WAZUH Copyright (C) 2015 Wazuh Inc. (License GPLv2)

@wazuhci wazuhci moved this from In progress to Pending review in Release 4.9.0 Feb 12, 2024
@wazuhci wazuhci moved this from Pending review to In review in Release 4.9.0 Feb 14, 2024
@damarisg
Copy link
Member

Being general is ok.

However, I will mark some details:

  1. You should add the branch that contains the development to the step and clarify that it is temporary.

  2. Is it available to Linux and Windows? If it only works on Linux, you must identify the OSs.

  3. the fixture examples have {agent} variable. To be clear, you must add a full example because the agent could be the OS, the agent hostname, the agent ID, etc.

@wazuhci wazuhci moved this from In review to On hold in Release 4.9.0 Feb 14, 2024
@pro-akim
Copy link
Member

pro-akim commented Feb 15, 2024

Update

Considering the Review Notes:

  1. Note adding the temporary dev branch added
  2. and 3. Fixture now has different Os agents.

PR added.

@wazuhci wazuhci moved this from On hold to In progress in Release 4.9.0 Feb 15, 2024
@pro-akim pro-akim linked a pull request Feb 15, 2024 that will close this issue
@wazuhci wazuhci moved this from In progress to Pending review in Release 4.9.0 Feb 15, 2024
@wazuhci wazuhci moved this from Pending review to In review in Release 4.9.0 Feb 15, 2024
pro-akim added a commit that referenced this issue Feb 15, 2024
@wazuhci wazuhci moved this from In review to Pending review in Release 4.9.0 Feb 15, 2024
@wazuhci wazuhci moved this from Pending review to In progress in Release 4.9.0 Feb 19, 2024
pro-akim added a commit that referenced this issue Feb 19, 2024
@wazuhci wazuhci moved this from In progress to Pending review in Release 4.9.0 Feb 19, 2024
@fcaffieri fcaffieri added level/task Task issue and removed level/subtask Subtask issue labels Mar 18, 2024
@wazuhci wazuhci moved this from Pending review to In review in Release 4.9.0 Mar 21, 2024
@wazuhci wazuhci moved this from In review to On hold in Release 4.9.0 Mar 21, 2024
@fcaffieri
Copy link
Member Author

We need to adapt the documentation with this recommendations:

  • We could have a short introduction about allocation in the User documentation section. In the tech documentation section under it, we can see a short intro about the allocation module but nothing similar for the user doc above.
  • Styles using passive voice are vague. We could change to active voice instead. For example, "You must install Python libraries. We recommend using virtual environments" rather than "... must be installed..." and "... is recommended to use...".
  • Maybe creating some subsections with subtitles to separate topics like one for setting up the repository and environment, another one for using the workflow library, another for manually running it, and so on.
  • Paths could use links to easily check files content in Github. For example: Module functions /wazuh-qa/deployability/modules/allocation/allocation.py: Module-specific functions responsible for triggering the allocation.
  • If required, we could review phrasing as well as expanding some topics.

@wazuhci wazuhci moved this from On hold to In progress in Release 4.9.0 Apr 1, 2024
pro-akim added a commit that referenced this issue Apr 1, 2024
@pro-akim
Copy link
Member

pro-akim commented Apr 1, 2024

Update

Sample of #4851 (comment) was changed following #4851 (comment) criteria

@wazuhci wazuhci moved this from In progress to Pending review in Release 4.9.0 Apr 1, 2024
@wazuhci wazuhci moved this from Pending review to In review in Release 4.9.0 Apr 1, 2024
@rauldpm
Copy link
Member

rauldpm commented Apr 1, 2024

LGTM

@rauldpm rauldpm closed this as completed Apr 1, 2024
@wazuhci wazuhci moved this from In review to Done in Release 4.9.0 Apr 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Status: Done
Development

Successfully merging a pull request may close this issue.

4 participants