Skip to content

Latest commit

 

History

History

scap

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 

Creating a GitLab CI/CD pipeline that runs an OpenSCAP (Open Security Content Automation Protocol) scan against a Windows target and publishes the results using GitLab Pages involves several steps. Below is a basic example of how this can be set up. This example assumes you have a basic understanding of GitLab CI/CD, GitLab Pages, and OpenSCAP. It also assumes you have the necessary permissions to execute commands on the Windows target.

Step 1: Preparing Your Environment

  1. OpenSCAP for Windows: Ensure that OpenSCAP is installed and properly configured on your Windows target. Currently, OpenSCAP's primary support is for Linux-based systems, but you can use the WSL (Windows Subsystem for Linux) or a similar solution to run OpenSCAP on Windows.

  2. GitLab Runner Configuration: Ensure you have a GitLab Runner configured to run jobs in your pipeline. This runner can be set up on a Linux machine that has network access to your Windows target. If you're using WSL on the Windows target, you might be able to set up the runner directly on it.

  3. SSH Access: Ensure you have SSH access set up from your GitLab Runner host to your Windows target for executing commands remotely.

Step 2: Writing the .gitlab-ci.yml File

Create or edit the .gitlab-ci.yml file in your GitLab repository to define the pipeline. The following is a simplified example of what the .gitlab-ci.yml file might look like:

stages:
  - scan
  - publish

scan_windows:
  stage: scan
  script:
    - ssh user@windows-target "wsl oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_standard --report /var/www/html/report.html /usr/share/xml/scap/ssg/content/ssg-windows-ds.xml"
  artifacts:
    paths:
      - report.html
    expire_in: 1 week
  only:
    - main

publish:
  stage: publish
  dependencies:
    - scan_windows
  script:
    - mkdir public
    - mv report.html public/
  artifacts:
    paths:
      - public
    expire_in: 1 week
  only:
    - main
  pages:
    stage: publish
    script:
      - mv report.html public/
    artifacts:
      paths:
        - public

Explanation:

  • Stages: Defined two stages, scan for running the OpenSCAP scan and publish for publishing the results.
  • scan_windows Job: This job connects to the Windows target via SSH and runs the OpenSCAP scan using WSL. Replace user@windows-target with your actual SSH connection details and adjust the OpenSCAP command as needed. The output report is saved as an artifact.
  • publish Job: This job takes the report generated by the scan_windows job, moves it into the public/ directory (required by GitLab Pages), and publishes it to GitLab Pages.

Step 3: Configuring GitLab Pages

Ensure your GitLab project is configured to use GitLab Pages. The publish job in the .gitlab-ci.yml file automatically makes the public/ directory available as a static website.

Final Notes:

  • This example uses SSH to execute a command remotely on a Windows target. Make sure the user you're using for SSH has the necessary permissions to run OpenSCAP scans.
  • The OpenSCAP command provided is just an example. You'll need to adjust it based on the specific scan you want to perform and the profiles you're using.
  • The GitLab Runner executing this pipeline needs to have SSH access configured to the target machine. This might involve setting up SSH keys and ensuring the runner's user has permission to use SSH.

This is a basic template to get you started. Depending on your specific requirements, environment, and security policies, you may need to make adjustments.

To create a GitLab CI/CD pipeline that runs an OpenSCAP scan against a Windows target using WinRM (Windows Remote Management) and Ansible, you'll need to set up a few things first. Ansible will be used to manage the Windows target remotely, and WinRM is the protocol Ansible will use for the connection.

Prerequisites:

  • Ansible: Ensure Ansible is installed on the GitLab Runner or any machine where the GitLab Runner is executing the pipeline jobs.
  • Windows Target Configuration: The Windows target must be configured to allow WinRM connections. Microsoft provides guidance on setting up WinRM.
  • Ansible Inventory: Set up an Ansible inventory file with your Windows target's details, including its WinRM connection information.

Step 1: Creating Ansible Playbook for OpenSCAP Scan

Create an Ansible playbook (openscap_scan.yml) to run the OpenSCAP scan on your Windows target. Since OpenSCAP is not natively supported on Windows, this example assumes you're running it within a Linux environment or using WSL. You might need a custom script or setup to execute OpenSCAP commands in your environment.

- name: Run OpenSCAP scan on Windows target
  hosts: windows
  tasks:
    - name: Execute OpenSCAP scan command
      win_command: wsl oscap xccdf eval --profile xccdf_org.ssgproject.content_profile_standard --report C:\\path\\to\\report.html /usr/share/xml/scap/ssg/content/ssg-windows-ds.xml
      args:
        chdir: C:\\path\\to\\wsl
      register: scan_result

    - name: Fetch the report to runner
      fetch:
        src: C:\\path\\to\\report.html
        dest: "./report.html"
        flat: yes

Step 2: Writing the .gitlab-ci.yml File

Next, integrate the Ansible playbook into your GitLab CI/CD pipeline by editing the .gitlab-ci.yml file in your GitLab repository.

stages:
  - scan
  - publish

scan_windows_via_ansible:
  stage: scan
  script:
    - ansible-playbook -i inventory.yml openscap_scan.yml
  artifacts:
    paths:
      - report.html
    expire_in: 1 week
  only:
    - main

publish:
  stage: publish
  dependencies:
    - scan_windows_via_ansible
  script:
    - mkdir public
    - mv report.html public/
  artifacts:
    paths:
      - public
    expire_in: 1 week
  only:
    - main
  pages:
    stage: publish
    script:
      - mv report.html public/
    artifacts:
      paths:
        - public

Explanation:

  • Stages: Defined two stages, scan for running the OpenSCAP scan and publish for publishing the results on GitLab Pages.
  • scan_windows_via_ansible Job: Executes the Ansible playbook which runs the OpenSCAP scan on the Windows target. The playbook assumes you have set up WSL for OpenSCAP scans. Adjust the inventory.yml path as needed.
  • publish Job: Moves the scan report into the public/ directory and publishes it on GitLab Pages.

Final Setup:

  • Ensure Ansible and all necessary dependencies are installed where the GitLab Runner is executed.
  • Configure your Windows target for WinRM as required by Ansible.
  • Update the paths, inventory, and playbook commands based on your specific setup and requirements.

This setup assumes a level of familiarity with Ansible, WinRM, and GitLab CI/CD configurations. Depending on your specific Windows environment and how OpenSCAP is installed (especially if using WSL or a different Linux compatibility layer), you may need to adjust the commands and paths accordingly.