Compare commits

..

4 Commits

Author SHA1 Message Date
3102c621f0
Add optional IP restriction for nginx site configs 2024-10-19 21:08:15 -04:00
e3f03edf3f
Use file-based preshared keys for WireGuard
- Include proxy role in standard Docker playbook
2024-10-13 22:27:27 -04:00
f481a965dd
Update Samba and WireGuard configuration
- Adjust Samba config file permissions to 644
- Introduce PresharedKey option in WireGuard config template
2024-09-10 22:35:20 -04:00
a0aa289c05
Restrict GitHub Actions to a dedicated branch
- The Vagrant testing setup on macos-latest is broken
- Temporary measure until fixed or abandoned
2024-09-10 22:11:31 -04:00
8 changed files with 65 additions and 71 deletions

View File

@ -3,22 +3,17 @@ name: homelab-ci
on:
push:
branches:
- main
- testing
- github_actions
# - main
# - testing
jobs:
homelab-ci:
runs-on: macos-13
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: Setup tmate session
uses: mxschmitt/action-tmate@v3
with:
detached: true
limit-access-to-actor: true
- name: Cache Vagrant boxes
uses: actions/cache@v3
with:
@ -27,23 +22,19 @@ jobs:
restore-keys: |
${{ runner.os }}-vagrant-
- name: Install Tools
run: brew install nmap tree
- name: Install VirtualBox
run: brew install --cask virtualbox
- name: Install Vagrant
run: brew install --cask vagrant
- name: Install Ansible
run: brew install ansible
run: brew install ansible@7
- name: Software Versions
run: |
printf "VirtualBox "; vboxmanage --version
printf "VirtualBox "
vboxmanage --version
vagrant --version
export PATH="/usr/local/opt/ansible@7/bin:$PATH"
ansible --version
- name: Vagrant Up with Dockerbox Playbook
run: ./scripts/github-vagrant.sh
run: |
export PATH="/usr/local/opt/ansible@7/bin:$PATH"
PLAYBOOK=dockerbox vagrant up
vagrant ssh -c "docker ps"

3
Vagrantfile vendored
View File

@ -36,7 +36,6 @@ Vagrant.configure("2") do |config|
config.vm.provider :virtualbox do |vbox|
vbox.cpus = VAGRANT_CPUS
vbox.memory = VAGRANT_MEM
vbox.gui = true
end
# Provision with Ansible
@ -44,6 +43,6 @@ Vagrant.configure("2") do |config|
ENV['ANSIBLE_ROLES_PATH'] = File.dirname(__FILE__) + "/roles"
ansible.compatibility_mode = "2.0"
ansible.playbook = "dev/" + PLAYBOOK + ".yml"
ansible.raw_arguments = ["--diff", "-vvvv"]
ansible.raw_arguments = ["--diff"]
end
end

View File

@ -4,4 +4,5 @@
roles:
- base
- jenkins
- proxy
- docker

View File

@ -26,7 +26,7 @@
ansible.builtin.template:
src: smb.conf.j2
dest: /etc/samba/smb.conf
mode: "700"
mode: "644"
notify: restart_samba
- name: Start smbd and enable on boot

View File

@ -18,6 +18,28 @@
src: /etc/wireguard/privatekey
register: wgkey
- name: Check if WireGuard preshared key file exists
ansible.builtin.stat:
path: /etc/wireguard/presharedkey-{{ item.name }}
loop: "{{ wireguard.peers }}"
loop_control:
label: "{{ item.name }}"
register: presharedkey_files
- name: Grab WireGuard preshared key for configuration
ansible.builtin.slurp:
src: /etc/wireguard/presharedkey-{{ item.item.name }}
register: wgshared
loop: "{{ presharedkey_files.results }}"
loop_control:
label: "{{ item.item.name }}"
when: item.stat.exists
- name: Grab WireGuard private key for configuration
ansible.builtin.slurp:
src: /etc/wireguard/privatekey
register: wgkey
- name: Install WireGuard configuration
ansible.builtin.template:
src: wireguard.j2

View File

@ -1,4 +1,6 @@
[Interface]
# {{ ansible_managed }}
[Interface] # {{ ansible_hostname }}
PrivateKey = {{ wgkey['content'] | b64decode | trim }}
Address = {{ wireguard.address }}
{% if wireguard.listenport is defined %}
@ -6,8 +8,26 @@ ListenPort = {{ wireguard.listenport }}
{% endif %}
{% for peer in wireguard.peers %}
{% if peer.name is defined %}
[Peer] # {{ peer.name }}
{% else %}
[Peer]
{% endif %}
PublicKey = {{ peer.publickey }}
{% if peer.presharedkey is defined %}
PresharedKey = {{ peer.presharedkey }}
{% else %}
{% set preshared_key = (
wgshared.results
| selectattr('item.item.name', 'equalto', peer.name)
| first
).content
| default(none)
%}
{% if preshared_key is not none %}
PresharedKey = {{ preshared_key | b64decode | trim }}
{% endif %}
{% endif %}
{% if peer.endpoint is defined %}
Endpoint = {{ peer.endpoint }}
{% endif %}

View File

@ -35,7 +35,13 @@ server {
client_max_body_size {{ item.client_max_body_size }};
{% endif %}
location / {
{% if item.restrict is defined and item.restrict %}
{% if item.allowedips is defined %}
{% for ip in item.allowedips %}
allow {{ ip }};
{% endfor %}
deny all;
{% endif %}
{% if item.restrict is defined and item.restrict %}
auth_basic "{{ item.restrict_name | default('Restricted Access') }}";
auth_basic_user_file {{ item.restrict_file | default('/etc/nginx/.htpasswd') }};
proxy_set_header Authorization "";

View File

@ -1,45 +0,0 @@
#!/bin/bash
# Defaults
TIMEOUT=600
ELAPSED=0
INITIAL_SLEEP=60
SLEEP_DURATION=30
SSH_AVAILABLE=0
DEBUG_ID="[homelab-ci]"
# Run Vagrant Up in the background
PLAYBOOK=dockerbox vagrant up &
VAGRANT_UP_PID=$!
# Initial delay
echo "$DEBUG_ID Waiting for VM to start..."
sleep $INITIAL_SLEEP
# Loop until timeout or breaks
while [[ $ELAPSED -lt $TIMEOUT ]]; do
VAGRANT_SSH_CONFIG=$(mktemp)
vagrant ssh-config > "$VAGRANT_SSH_CONFIG"
echo "$DEBUG_ID SSH config at $VAGRANT_SSH_CONFIG"
cat "$VAGRANT_SSH_CONFIG"
echo "$DEBUG_ID Vagrant status"
vagrant status
# SSH attempt
set -x
ssh -vvv -F "$VAGRANT_SSH_CONFIG" default 'cat /etc/os-release' && set +x; break \
|| echo "$DEBUG_ID SSH connection failed, retrying in $SLEEP_DURATION seconds..."
set +x
# Sleep and start again
sleep $SLEEP_DURATION
((ELAPSED+=SLEEP_DURATION))
done
# Success?
if [[ $SSH_AVAILABLE -ne 1 ]]; then
echo "$DEBUG_ID Timeout reached without successful SSH connection."
fi
# Ensure the Vagrant up process completes
wait $VAGRANT_UP_PID