first functional commit

This commit is contained in:
Pin
2022-10-02 12:31:34 -04:00
parent d367398766
commit 46d46a4e36
52 changed files with 1216 additions and 0 deletions

18
.gitignore vendored Normal file
View File

@@ -0,0 +1,18 @@
**/*.swp
**/*.lock.hcl
download/
kybus.conf
.kybusenv
.terraform/
**/*.tfstate
**/*.tfstate.backup
vars.tf
main.tf
**/*.tar.gz
src/download/
venv/

View File

@@ -1 +1,34 @@
# Kybus
Kybus is a repository
## Requirements
Docker, or podman with appropriate aliases is required to be installed.
Docker version `20.10.21` is the version using during testing; however, most version should work.
Python3 is required for certain support functions; version `3.10.8` was used during testing.
Libvirt is used for VM deployment; version `8.9.0` was used during testing.
All versions mentioned above are only what was used during testing, other versions will mostly work.
### Quick Reference
- Docker or podman with appropriate aliases
- Python3
- libvirt/virt-manager
## Getting Started
Running `setup.sh` will ensure requisites are installed and download needed VM images.
The Kybus container image will also be generated during this process
## Writing a Plugin
Initial plugin structure can be generated using `ansible-galaxy role init {plugin name}`.
Plugin names are suggested to be the relavent CVE record; however, certain plugins exist as helpers and may deviate.
Once the plugin is created
##

84
_libs/libbase.sh Normal file
View File

@@ -0,0 +1,84 @@
#!/bin/bash
set -e
# Function: EnsureRoot
# Ensures that commands are being executed as root.
function EnsureRoot {
if (( EUID != 0 )); then
echo "[X] Must run as root"
exit 100
fi
}
# Function: EchoBlanks
# Echo number of blank lines indicated by input
#
# Parameters:
# ${1} - The number of blank lines to echo
function EchoBlanks {
local num_lines
# Strip non-numbers from input
num_lines="${1//[^0-9]/}"
if [[ -z "${num_lines}" ]]; then
num_lines=0
fi
if [[ "${num_lines}" -ne 0 ]]; then
for ((i = 0; i < num_lines; i++)); do
echo ""
done
fi
}
# Function: StatusEcho
# Echos out provided text in inverted colors so it stands out
#
# Parameters:
# ${1} - The text to send
# ${2} - The number of leading empty lines before the echo
# ${3} - The number of trailing empty lines after the echo
function StatusEcho {
EchoBlanks "${2}"
echo -e "\e[7m${1} \e[0m"
EchoBlanks "${3}"
}
# Function: WarningEcho
# Echos out provided text as white letters on a red background so it stands out.
#
# Parameters:
# ${1} - The text to send
# ${2} - The number of leading empty lines before the echo
# ${3} - The number of trailing empty lines after the echo
function WarningEcho {
EchoBlanks "${2}"
echo -e "\e[97m\e[41m${1} \e[0m"
EchoBlanks "${3}"
}
# Function: CyanEcho
# Echos out provided text as Light Cyan letters on a black background so it stands out.
#
# Parameters:
# ${1} - The text to send
# ${2} - The number of leading empty lines before the echo
# ${3} - The number of trailing empty lines after the echo
function CyanEcho {
EchoBlanks "${2}"
echo -e "\e[96m\e[40m${1} \e[0m"
EchoBlanks "${3}"
}
# Function: pushd
# Overrides default pushd functionatlity to suppress console messages.
function pushd {
command pushd "$@" >/dev/null
}
# Function: popd
# Overrides default popd functionatlity to suppress console messages.
function popd {
command popd >/dev/null
}

6
localImages/Dockerfile Normal file
View File

@@ -0,0 +1,6 @@
FROM alpine:3.16
RUN apk update && \
apk add --no-cache terraform python3 libvirt-qemu qemu xorriso ansible gettext
COPY init.sh /

14
localImages/init.sh Executable file
View File

@@ -0,0 +1,14 @@
#!/bin/sh
cd /mnt || exit 1
envsubst < templates/site.temp > site.yml
envsubst < templates/vars.temp > vars.tf
terraform init
terraform destroy -auto-approve
terraform apply -auto-approve
rm site.yml

74
main.tf Normal file
View File

@@ -0,0 +1,74 @@
terraform {
required_providers {
libvirt = {
source = "dmacvicar/libvirt"
}
}
}
provider "libvirt" {
uri = "qemu:///system"
}
data "template_file" "user_data" {
template = "${file("${path.module}/templates/cloud_init.cfg")}"
vars = {
init_ssh_auth_key = var.init_ssh_auth_key
init_user_name = var.init_user_name
}
}
resource "libvirt_cloudinit_disk" "kybus_commoninit" {
name = "kybus_commoninit.iso"
pool = "default"
user_data = "${data.template_file.user_data.rendered}"
}
resource "libvirt_volume" "kybus_kybus" {
name = "kybus_kybus"
pool = "default"
source = var.kybus_source
format = "qcow2"
}
resource "libvirt_volume" "kybus_kybus_resized" {
name = "kybus_kybus_resized"
base_volume_id = libvirt_volume.kybus_kybus.id
pool = "default"
size = var.base_disk_size
}
resource "libvirt_domain" "kybus_kybus_vm" {
name = "kybus_kybus"
memory = var.base_ram_size
vcpu = 2
network_interface {
network_name = "default"
wait_for_lease = true
}
disk {
volume_id = "${libvirt_volume.kybus_kybus_resized.id}"
}
cloudinit = "${libvirt_cloudinit_disk.kybus_commoninit.id}"
console {
type = "pty"
target_type = "serial"
target_port = "0"
}
graphics {
type = "spice"
listen_type = "address"
autoport = true
}
provisioner "local-exec" {
command = "sleep 10 && ANSIBLE_STDOUT_CALLBACK=yaml ANSIBLE_HOST_KEY_CHECKING=False ansible-playbook -u '${var.init_user_name}' --private-key /root/.ssh/key -i '${self.network_interface[0].addresses[0]},' site.yml"
}
}

7
requierments.txt Normal file
View File

@@ -0,0 +1,7 @@
args==0.1.0
certifi==2022.6.15.2
charset-normalizer==2.1.1
clint==0.5.1
idna==3.4
requests==2.28.1
urllib3==1.26.12

View File

@@ -0,0 +1,29 @@
---
language: python
python: "2.7"
# Use the new container infrastructure
sudo: false
# Install ansible
addons:
apt:
packages:
- python-pip
install:
# Install ansible
- pip install ansible
# Check ansible version
- ansible --version
# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@@ -0,0 +1,38 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

View File

@@ -0,0 +1,2 @@
---
# defaults file for CVE-2011-2523

View File

@@ -0,0 +1,114 @@
# Example config file /etc/vsftpd.conf
#
# The default compiled in settings are fairly paranoid. This sample file
# loosens things up a bit, to make the ftp daemon more usable.
# Please see vsftpd.conf.5 for all compiled in defaults.
#
# READ THIS: This example file is NOT an exhaustive list of vsftpd options.
# Please read the vsftpd.conf.5 manual page to get a full idea of vsftpd's
# capabilities.
#
# Allow anonymous FTP? (Beware - allowed by default if you comment this out).
anonymous_enable=NO
#
# Uncomment this to allow local users to log in.
local_enable=YES
#
# Uncomment this to enable any form of FTP write command.
#write_enable=YES
#
# Default umask for local users is 077. You may wish to change this to 022,
# if your users expect that (022 is used by most other ftpd's)
#local_umask=022
#
# Uncomment this to allow the anonymous FTP user to upload files. This only
# has an effect if the above global write enable is activated. Also, you will
# obviously need to create a directory writable by the FTP user.
#anon_upload_enable=YES
#
# Uncomment this if you want the anonymous FTP user to be able to create
# new directories.
#anon_mkdir_write_enable=YES
#
# Activate directory messages - messages given to remote users when they
# go into a certain directory.
dirmessage_enable=YES
#
# Activate logging of uploads/downloads.
xferlog_enable=YES
#
# Make sure PORT transfer connections originate from port 20 (ftp-data).
connect_from_port_20=YES
#
# If you want, you can arrange for uploaded anonymous files to be owned by
# a different user. Note! Using "root" for uploaded files is not
# recommended!
#chown_uploads=YES
#chown_username=whoever
#
# You may override where the log file goes if you like. The default is shown
# below.
#xferlog_file=/var/log/vsftpd.log
#
# If you want, you can have your log file in standard ftpd xferlog format.
# Note that the default log file location is /var/log/xferlog in this case.
#xferlog_std_format=YES
#
# You may change the default value for timing out an idle session.
#idle_session_timeout=600
#
# You may change the default value for timing out a data connection.
#data_connection_timeout=120
#
# It is recommended that you define on your system a unique user which the
# ftp server can use as a totally isolated and unprivileged user.
#nopriv_user=ftpsecure
#
# Enable this and the server will recognise asynchronous ABOR requests. Not
# recommended for security (the code is non-trivial). Not enabling it,
# however, may confuse older FTP clients.
#async_abor_enable=YES
#
# By default the server will pretend to allow ASCII mode but in fact ignore
# the request. Turn on the below options to have the server actually do ASCII
# mangling on files when in ASCII mode.
# Beware that on some FTP servers, ASCII support allows a denial of service
# attack (DoS) via the command "SIZE /big/file" in ASCII mode. vsftpd
# predicted this attack and has always been safe, reporting the size of the
# raw file.
# ASCII mangling is a horrible feature of the protocol.
#ascii_upload_enable=YES
#ascii_download_enable=YES
#
# You may fully customise the login banner string:
#ftpd_banner=Welcome to blah FTP service.
#
# You may specify a file of disallowed anonymous e-mail addresses. Apparently
# useful for combatting certain DoS attacks.
#deny_email_enable=YES
# (default follows)
#banned_email_file=/etc/vsftpd.banned_emails
#
# You may specify an explicit list of local users to chroot() to their home
# directory. If chroot_local_user is YES, then this list becomes a list of
# users to NOT chroot().
#chroot_local_user=YES
#chroot_list_enable=YES
# (default follows)
#chroot_list_file=/etc/vsftpd.chroot_list
#
# You may activate the "-R" option to the builtin ls. This is disabled by
# default to avoid remote users being able to cause excessive I/O on large
# sites. However, some broken FTP clients such as "ncftp" and "mirror" assume
# the presence of the "-R" option, so there is a strong case for enabling it.
#ls_recurse_enable=YES
#
# When "listen" directive is enabled, vsftpd runs in standalone mode and
# listens on IPv4 sockets. This directive cannot be used in conjunction
# with the listen_ipv6 directive.
listen=YES
#
# This directive enables listening on IPv6 sockets. To listen on IPv4 and IPv6
# sockets, you must run two copies of vsftpd with two configuration files.
# Make sure, that one of the listen options is commented !!
#listen_ipv6=YES

View File

@@ -0,0 +1,10 @@
[Unit]
Description=Vsftpd ftp daemon
After=network.target
[Service]
ExecStart=/usr/local/sbin/vsftpd /etc/vsftpd.conf
[Install]
WantedBy=multi-user.target

View File

@@ -0,0 +1,7 @@
---
- name: VSFTPD Service
ansible.builtin.service:
name: vsftpd
enabled: "yes"
state: restarted
...

View File

@@ -0,0 +1,4 @@
---
image: ubuntu-20.04-server-cloudimg-amd64.img
holding: bad var
...

View File

@@ -0,0 +1,52 @@
galaxy_info:
author: Spencer
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

View File

@@ -0,0 +1,73 @@
---
- name: Install build deps
ansible.builtin.package:
name:
- make
- gcc
state: present
- name: Create libcrypt symlink
ansible.builtin.file:
src: /lib/x86_64-linux-gnu/libcrypt.so.1
dest: /lib/libcrypt.so
owner: root
group: root
state: link
- name: Create Build Directory
ansible.builtin.file:
path: /tmp/vsftpd_build
state: directory
mode: '0755'
- name: Unarchive VSFTPD
ansible.builtin.unarchive:
src: vsftpd-2.3.4.tar.gz
dest: /tmp/vsftpd_build
- name: Create install reqs
ansible.builtin.file:
path: "{{ install_dir }}"
state: directory
loop:
- /usr/local/man/man8
- /usr/local/man/man5
- /usr/share/empty
loop_control:
loop_var: install_dir
- name: Make build and install
make:
chdir: /tmp/vsftpd_build/vsftpd-2.3.4
target: "{{ make_target }}"
loop:
- vsftpd
- install
loop_control:
loop_var: make_target
- name: Copy configuration file
ansible.builtin.copy:
src: vsftpd.conf
dest: /etc/vsftpd.conf
owner: root
group: root
mode: '0644'
- name: Create FTP user
ansible.builtin.user:
name: ftp
home: "/usr/share/empty"
create_home: no
- name: Copy service file
ansible.builtin.copy:
src: vsftpd.service
dest: /etc/systemd/system/vsftpd.service
owner: root
group: root
mode: '0644'
notify:
- VSFTPD Service
...
# tasks file for CVE-2011-2523

View File

@@ -0,0 +1,2 @@
localhost

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- CVE-2011-2523

View File

@@ -0,0 +1,2 @@
---
# vars file for CVE-2011-2523

View File

@@ -0,0 +1,38 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

View File

@@ -0,0 +1,2 @@
---
# defaults file for CVE-2019-10149

View File

@@ -0,0 +1,2 @@
---
# handlers file for CVE-2019-10149

View File

@@ -0,0 +1,4 @@
---
image: ubuntu-20.04-server-cloudimg-amd64.img
holding: bad var
...

View File

@@ -0,0 +1,52 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

View File

@@ -0,0 +1,7 @@
---
- name:
unarchive:
src: https://downloads.exim.org/exim4/old/exim-4.90.tar.gz
dest: /tmp
remote_src: yes
...

View File

@@ -0,0 +1,2 @@
localhost

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- CVE-2019-10149

View File

@@ -0,0 +1,2 @@
---
# vars file for CVE-2019-10149

View File

@@ -0,0 +1,29 @@
---
language: python
python: "2.7"
# Use the new container infrastructure
sudo: false
# Install ansible
addons:
apt:
packages:
- python-pip
install:
# Install ansible
- pip install ansible
# Check ansible version
- ansible --version
# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

View File

@@ -0,0 +1,38 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

View File

@@ -0,0 +1,2 @@
---
# defaults file for CVE-2021-3156

View File

@@ -0,0 +1,2 @@
---
# handlers file for CVE-2021-3156

View File

@@ -0,0 +1,52 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

View File

@@ -0,0 +1,27 @@
---
- name: Installs Build Deps
package:
name:
- make
- gcc
state: present
- name: Download sudo Package 1.9.5p1
unarchive:
src: https://www.sudo.ws/dist/sudo-1.9.5p1.tar.gz
dest: /tmp/
remote_src: yes
- name: Build Sudo - Configure
command: ./configure
args:
chdir: /tmp/sudo-1.9.5p1
- name: Build Sudo
make:
chdir: /tmp/sudo-1.9.5p1
- name: Build Sudo - Make install
make:
chdir: /tmp/sudo-1.9.5p1
target: install
...

View File

@@ -0,0 +1,2 @@
localhost

View File

@@ -0,0 +1,5 @@
---
- hosts: all
become: "true"
roles:
- CVE-2021-3156

View File

@@ -0,0 +1,2 @@
---
# vars file for CVE-2021-3156

29
roles/test/.travis.yml Normal file
View File

@@ -0,0 +1,29 @@
---
language: python
python: "2.7"
# Use the new container infrastructure
sudo: false
# Install ansible
addons:
apt:
packages:
- python-pip
install:
# Install ansible
- pip install ansible
# Check ansible version
- ansible --version
# Create ansible.cfg with correct roles_path
- printf '[defaults]\nroles_path=../' >ansible.cfg
script:
# Basic role syntax check
- ansible-playbook tests/test.yml -i tests/inventory --syntax-check
notifications:
webhooks: https://galaxy.ansible.com/api/v1/notifications/

38
roles/test/README.md Normal file
View File

@@ -0,0 +1,38 @@
Role Name
=========
A brief description of the role goes here.
Requirements
------------
Any pre-requisites that may not be covered by Ansible itself or the role should be mentioned here. For instance, if the role uses the EC2 module, it may be a good idea to mention in this section that the boto package is required.
Role Variables
--------------
A description of the settable variables for this role should go here, including any variables that are in defaults/main.yml, vars/main.yml, and any variables that can/should be set via parameters to the role. Any variables that are read from other roles and/or the global scope (ie. hostvars, group vars, etc.) should be mentioned here as well.
Dependencies
------------
A list of other roles hosted on Galaxy should go here, plus any details in regards to parameters that may need to be set for other roles, or variables that are used from other roles.
Example Playbook
----------------
Including an example of how to use your role (for instance, with variables passed in as parameters) is always nice for users too:
- hosts: servers
roles:
- { role: username.rolename, x: 42 }
License
-------
BSD
Author Information
------------------
An optional section for the role authors to include contact information, or a website (HTML is not allowed).

View File

@@ -0,0 +1,2 @@
---
# defaults file for test

View File

@@ -0,0 +1,2 @@
---
# handlers file for test

52
roles/test/meta/main.yml Normal file
View File

@@ -0,0 +1,52 @@
galaxy_info:
author: your name
description: your role description
company: your company (optional)
# If the issue tracker for your role is not on github, uncomment the
# next line and provide a value
# issue_tracker_url: http://example.com/issue/tracker
# Choose a valid license ID from https://spdx.org - some suggested licenses:
# - BSD-3-Clause (default)
# - MIT
# - GPL-2.0-or-later
# - GPL-3.0-only
# - Apache-2.0
# - CC-BY-4.0
license: license (GPL-2.0-or-later, MIT, etc)
min_ansible_version: 2.1
# If this a Container Enabled role, provide the minimum Ansible Container version.
# min_ansible_container_version:
#
# Provide a list of supported platforms, and for each platform a list of versions.
# If you don't wish to enumerate all versions for a particular platform, use 'all'.
# To view available platforms and versions (or releases), visit:
# https://galaxy.ansible.com/api/v1/platforms/
#
# platforms:
# - name: Fedora
# versions:
# - all
# - 25
# - name: SomePlatform
# versions:
# - all
# - 1.0
# - 7
# - 99.99
galaxy_tags: []
# List tags for your role here, one per line. A tag is a keyword that describes
# and categorizes the role. Users find roles by searching for tags. Be sure to
# remove the '[]' above, if you add tags to this list.
#
# NOTE: A tag is limited to a single word comprised of alphanumeric characters.
# Maximum 20 tags per role.
dependencies: []
# List your role dependencies here, one per line. Be sure to remove the '[]' above,
# if you add dependencies to this list.

View File

@@ -0,0 +1,6 @@
---
- name: Debug
debug:
var: ansible
...
# tasks file for test

View File

@@ -0,0 +1,2 @@
localhost

View File

@@ -0,0 +1,5 @@
---
- hosts: localhost
remote_user: root
roles:
- test

2
roles/test/vars/main.yml Normal file
View File

@@ -0,0 +1,2 @@
---
# vars file for test

106
run.sh Executable file
View File

@@ -0,0 +1,106 @@
#!/bin/bash
script_file_path="$(realpath "${0}")"
script_dir_path="$(dirname "${script_file_path}")"
pushd "${script_dir_path}" >/dev/null || exit 1
# shellcheck disable=SC1091
source ./_libs/libbase.sh
# shellcheck disable=SC1091
source ./kybus.conf
function initKybus {
StatusEcho "Cleaning up old Environment"
rm -f .kybusenv >/dev/null
}
function parseKybusRole {
metaKybus=$(cat "roles/${1}/meta/kybus.yml")
KYBUS_BASE_IMAGE="download/$(echo "${metaKybus}" | grep "^image:" | cut -d " " -f 2-)"
setKybusVariable "KYBUS_BASE_IMAGE" "${KYBUS_BASE_IMAGE}"
return
}
function setKybusVariable {
if [[ -z "${1}" || -z ${2} ]]; then
WarningEcho "Variables not passed to setKybusVariable correctly"
exit 1
fi
# Create variable file if one does not exist
if [[ ! -e .kybusenv ]]; then
touch .kybusenv
fi
StatusEcho "Setting ${1}"
# Set blank variable if it does not already exist
grep "${1}" .kybusenv >/dev/null || echo "${1}=" >>.kybusenv
# Set variable
sed -i "s|${1}=.*|${1}=${2}|" .kybusenv >/dev/null
return
}
function findCVE {
StatusEcho "Attempting to find ${1}"
ls "roles/${1}" &>/dev/null || failed=1
if (( failed == 1 )); then
WarningEcho "CVE - ${1} not found"
exit 1
fi
return
}
function ArgParse {
while (("${#}")); do
case "${1}" in
--cve | -c)
shift
findCVE "${1}" && setKybusVariable "KYBUS_SELECTED_CVE" "${1}"
export KYBUS_SELECTED_CVE=${1}
shift
;;
--help | -h)
shift
WarningEcho "Not implemented"
;;
--list-roles)
shift
local roles
roles=$(find roles/* -maxdepth 0 | sed 's|roles/||g')
CyanEcho "Available Roles:"
CyanEcho "${roles}"
unset roles
exit 0
;;
--destroy)
terraform destroy -auto-approve
exit 0
shift
;;
*)
shift
;;
esac
done
return
}
#initKybus
ArgParse "${@}"
parseKybusRole "${KYBUS_SELECTED_CVE}"
docker run --rm -v /var/run/libvirt/libvirt-sock:/var/run/libvirt/libvirt-sock -v "$(pwd):/mnt" -v "${SSH_KEY_FILE}:/root/.ssh/key" --env-file kybus.conf --env-file .kybusenv kybus:latest ./init.sh
KYBUS_ADDRESS=$(grep -A 1 addresses <terraform.tfstate | tail -n 1 | sed 's| ||g;s|"||g')
CyanEcho "Kybus IP Address: ${KYBUS_ADDRESS}"
popd || exit 1

42
setup.sh Executable file
View File

@@ -0,0 +1,42 @@
#!/bin/bash
function exitFailure() {
echo "Exiting $1"
exit 1
}
function checkDependencies {
if ! command python3 --version &>/dev/null; then
exitFailure "python3 not installed"
fi
if ! command docker &>/dev/null; then
exitFailure "docker not installed"
fi
if [[ ! -e /var/run/libvirt/libvirt-sock ]]; then
exitFailure "libvirt-socket not detected"
fi
}
function setupEnvironment {
checkDependencies
if [[ ! -d venv ]]; then
python3 -m venv venv
fi
# shellcheck disable=SC1091
. venv/bin/activate
pip3 install -r ./requierments.txt
}
function dockerImageInit {
cd ./localImages || exitFailure "change dir failed"
docker build . -t kybus:latest
}
setupEnvironment
dockerImageInit

39
src/main.py Normal file
View File

@@ -0,0 +1,39 @@
#!/usr/bin/python3
import os
import requests
from clint.textui import progress
def downloadArtifact(artifactURL: str, downloadPath: str):
print("holding")
def downloadImage(imageURL: str):
createDownloadFolder()
# Obtain last segment of URL for file name
fileName = imageURL.split("/")[-1]
if not os.path.exists("download/" + fileName):
print("Downloading - {}".format(imageURL))
r = requests.get(imageURL, stream=True)
with open("download/" + fileName, "wb") as fd:
totalLength = int(r.headers.get('content-length'))
for ch in progress.bar(r.iter_content(chunk_size = 2048), expected_size=(totalLength/2048)):
if ch:
fd.write(ch)
fd.close()
return
def createDownloadFolder():
if not os.path.isdir("download"):
os.mkdir("download")
return
#downloadImage("https://cloud.centos.org/centos/7/images/CentOS-7-x86_64-GenericCloud.qcow2")
#downloadImage("https://cloud-images.ubuntu.com/jammy/current/jammy-server-cloudimg-amd64.img")
#downloadImage("https://cloud-images.ubuntu.com/releases/focal/release/ubuntu-20.04-server-cloudimg-amd64.img")
downloadImage("http://file.pinfosec.local/file/vm-images/CentOS-7-x86_64-GenericCloud.qcow2")
downloadImage("http://file.pinfosec.local/file/vm-images/jammy-server-cloudimg-amd64.img")
downloadImage("http://file.pinfosec.local/file/vm-images/ubuntu-20.04-server-cloudimg-amd64.img")

16
templates/cloud_init.cfg Normal file
View File

@@ -0,0 +1,16 @@
#cloud-config
users:
- name: ${init_user_name}
groups: wheel
sudo: ['ALL=(ALL) NOPASSWD:ALL']
shell: /bin/bash
ssh_authorized_keys:
- ${init_ssh_auth_key}
growpart:
mode: auto
devices: ['/']
package_update: true
package_upgrade: false

6
templates/site.temp Normal file
View File

@@ -0,0 +1,6 @@
---
- hosts: all
become: true
roles:
- ${KYBUS_SELECTED_CVE}
...

22
templates/vars.temp Normal file
View File

@@ -0,0 +1,22 @@
variable "init_ssh_auth_key" {
default = ${SSH_PUB_KEY}
}
variable "init_user_name" {
default = "${SSH_DEFAULT_USER}"
}
# 30GB default (Size in bytes)
variable "base_disk_size" {
default = ${VM_DISK_SIZE}
}
# 4GB of RAM per deployed host (Size in bytes)
variable "base_ram_size" {
default = ${VM_RAM_SIZE}
}
variable "kybus_source" {
default = "${KYBUS_BASE_IMAGE}"
}