Skip to content

Commit b8ec681

Browse files
authored
Merge pull request #99 from ansible-lockdown/devel
devel to main release
2 parents 2d7b319 + d20a938 commit b8ec681

25 files changed

+423
-412
lines changed

.ansible-lint

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ skip_list:
1111
- 'name[casing]'
1212
- 'name[template]'
1313
- 'key-order[task]'
14+
- 'yaml[line-length]'
1415
- '204'
1516
- '305'
1617
- '303'

.config/.gitleaks-report.json

-1
This file was deleted.

.config/.secrets.baseline

-119
This file was deleted.

.github/workflows/devel_pipeline_validation.yml

+54-34
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,21 @@
1313
- '**.j2'
1414
- '**.ps1'
1515
- '**.cfg'
16+
# Allow manual running of workflow
17+
workflow_dispatch:
18+
19+
# Allow permissions for AWS auth
20+
permissions:
21+
id-token: write
22+
contents: read
23+
pull-requests: read
1624

1725
# A workflow run is made up of one or more jobs
1826
# that can run sequentially or in parallel
1927
jobs:
2028
# This will create messages for first time contributers and direct them to the Discord server
2129
welcome:
22-
runs-on: ubuntu-latest
30+
runs-on: self-hosted
2331

2432
steps:
2533
- uses: actions/first-interaction@main
@@ -32,76 +40,94 @@
3240
# This workflow contains a single job that tests the playbook
3341
playbook-test:
3442
# The type of runner that the job will run on
35-
runs-on: ubuntu-latest
43+
runs-on: self-hosted
3644
env:
3745
ENABLE_DEBUG: ${{ vars.ENABLE_DEBUG }}
3846
# Imported as a variable by terraform
3947
TF_VAR_repository: ${{ github.event.repository.name }}
48+
AWS_REGION: "us-east-1"
49+
ANSIBLE_VERSION: ${{ vars.ANSIBLE_RUNNER_VERSION }}
4050
defaults:
4151
run:
4252
shell: bash
4353
working-directory: .github/workflows/github_linux_IaC
54+
# working-directory: .github/workflows
4455

4556
steps:
46-
- name: Clone ${{ github.event.repository.name }}
57+
58+
- name: Git clone the lockdown repository to test
4759
uses: actions/checkout@v4
4860
with:
4961
ref: ${{ github.event.pull_request.head.sha }}
5062

63+
- name: If a variable for IAC_BRANCH is set use that branch
64+
working-directory: .github/workflows
65+
run: |
66+
if [ ${{ vars.IAC_BRANCH }} != '' ]; then
67+
echo "IAC_BRANCH=${{ vars.IAC_BRANCH }}" >> $GITHUB_ENV
68+
echo "Pipeline using the following IAC branch ${{ vars.IAC_BRANCH }}"
69+
else
70+
echo IAC_BRANCH=main >> $GITHUB_ENV
71+
fi
72+
73+
5174
# Pull in terraform code for linux servers
5275
- name: Clone GitHub IaC plan
5376
uses: actions/checkout@v4
5477
with:
5578
repository: ansible-lockdown/github_linux_IaC
5679
path: .github/workflows/github_linux_IaC
80+
ref: ${{ env.IAC_BRANCH }}
5781

58-
- name: Add_ssh_key
59-
working-directory: .github/workflows
60-
env:
61-
SSH_AUTH_SOCK: /tmp/ssh_agent.sock
62-
PRIVATE_KEY: "${{ secrets.SSH_PRV_KEY }}"
63-
run: |
64-
mkdir .ssh
65-
chmod 700 .ssh
66-
echo $PRIVATE_KEY > .ssh/github_actions.pem
67-
chmod 600 .ssh/github_actions.pem
82+
# Uses dedicated restricted role and policy to enable this only for this task
83+
# No credentials are part of github for AWS auth
84+
- name: configure aws credentials
85+
uses: aws-actions/configure-aws-credentials@main
86+
with:
87+
role-to-assume: ${{ secrets.AWS_ASSUME_ROLE }}
88+
role-session-name: ${{ secrets.AWS_ROLE_SESSION }}
89+
aws-region: ${{ env.AWS_REGION }}
6890

6991
- name: DEBUG - Show IaC files
7092
if: env.ENABLE_DEBUG == 'true'
7193
run: |
7294
echo "OSVAR = $OSVAR"
7395
echo "benchmark_type = $benchmark_type"
96+
echo "PRIVSUBNET_ID = $AWS_PRIVSUBNET_ID"
97+
echo "VPC_ID" = $AWS_VPC_SECGRP_ID"
7498
pwd
7599
ls
76100
env:
77101
# Imported from GitHub variables this is used to load the relevant OS.tfvars file
78102
OSVAR: ${{ vars.OSVAR }}
79103
benchmark_type: ${{ vars.BENCHMARK_TYPE }}
104+
PRIVSUBNET_ID: ${{ secrets.AWS_PRIVSUBNET_ID }}
105+
VPC_ID: ${{ secrets.AWS_VPC_SECGRP_ID }}
80106

81-
- name: Terraform_Init
107+
- name: Tofu init
82108
id: init
83-
run: terraform init
109+
run: tofu init
84110
env:
85111
# Imported from GitHub variables this is used to load the relevant OS.tfvars file
86112
OSVAR: ${{ vars.OSVAR }}
87113
TF_VAR_benchmark_type: ${{ vars.BENCHMARK_TYPE }}
88114

89-
- name: Terraform_Validate
115+
- name: Tofu validate
90116
id: validate
91-
run: terraform validate
117+
run: tofu validate
92118
env:
93119
# Imported from GitHub variables this is used to load the relevant OS.tfvars file
94120
OSVAR: ${{ vars.OSVAR }}
95121
TF_VAR_benchmark_type: ${{ vars.BENCHMARK_TYPE }}
96122

97-
- name: Terraform_Apply
123+
- name: Tofu apply
98124
id: apply
99125
env:
100-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
101-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
102126
OSVAR: ${{ vars.OSVAR }}
103127
TF_VAR_benchmark_type: ${{ vars.BENCHMARK_TYPE }}
104-
run: terraform apply -var-file "github_vars.tfvars" -var-file "${OSVAR}.tfvars" --auto-approve -input=false
128+
TF_VAR_privsubnet_id: ${{ secrets.AWS_PRIVSUBNET_ID }}
129+
TF_VAR_vpc_secgrp_id: ${{ secrets.AWS_VPC_SECGRP_ID }}
130+
run: tofu apply -var-file "${OSVAR}.tfvars" --auto-approve -input=false
105131

106132
## Debug Section
107133
- name: DEBUG - Show Ansible hostfile
@@ -110,30 +136,24 @@
110136

111137
# Aws deployments taking a while to come up insert sleep or playbook fails
112138

113-
- name: Sleep for 60 seconds
139+
- name: Sleep to allow system to come up
114140
run: sleep ${{ vars.BUILD_SLEEPTIME }}
115141

116142
# Run the Ansible playbook
117143
- name: Run_Ansible_Playbook
118-
uses: arillso/action.playbook@master
119-
with:
120-
playbook: site.yml
121-
inventory: .github/workflows/github_linux_IaC/hosts.yml
122-
galaxy_file: collections/requirements.yml
123-
private_key: ${{ secrets.SSH_PRV_KEY }}
124-
# verbose: 3
125144
env:
126145
ANSIBLE_HOST_KEY_CHECKING: "false"
127146
ANSIBLE_DEPRECATION_WARNINGS: "false"
128-
ANSIBLE_INJECT_FACT_VARS: "false"
147+
run: |
148+
/opt/ansible_${{ env.ANSIBLE_VERSION }}_venv/bin/ansible-playbook -i hosts.yml --private-key ~/.ssh/le_runner ../../../site.yml
129149
130150
# Remove test system - User secrets to keep if necessary
131151

132-
- name: Terraform_Destroy
152+
- name: Tofu Destroy
133153
if: always() && env.ENABLE_DEBUG == 'false'
134154
env:
135-
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
136-
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
137155
OSVAR: ${{ vars.OSVAR }}
138156
TF_VAR_benchmark_type: ${{ vars.BENCHMARK_TYPE }}
139-
run: terraform destroy -var-file "github_vars.tfvars" -var-file "${OSVAR}.tfvars" --auto-approve -input=false
157+
TF_VAR_privsubnet_id: ${{ secrets.AWS_PRIVSUBNET_ID }}
158+
TF_VAR_vpc_secgrp_id: ${{ secrets.AWS_VPC_SECGRP_ID }}
159+
run: tofu destroy -var-file "${OSVAR}.tfvars" --auto-approve -input=false

0 commit comments

Comments
 (0)