Skip to content
This repository was archived by the owner on Oct 7, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
68 commits
Select commit Hold shift + click to select a range
5071736
Merge pull request #2654 from codeenigma/Gitlab-stop-fix-PR-2.x
drazenCE Sep 2, 2025
a8ba8e4
Fixing-email-title-for-backup-validation (#2657)
matej5 Sep 4, 2025
057138d
Adding-task-to-create-aurora-cluster (#2659)
matej5 Sep 8, 2025
2b30a78
Fixing truthy variable mistakes. (#2662)
gregharvey Sep 10, 2025
cb63668
feat(php): Add FPM slow logrotate (#2625)
klausi Sep 10, 2025
9f05b90
r73458-install-php-gmp-by-default2 (#2667)
nfawbert Sep 10, 2025
a89ae45
Wazuh-mitre-report-setup (#2588)
drazenCE Sep 11, 2025
71278e9
Wazuh mitre report setup pr 2.x (#2669)
drazenCE Sep 11, 2025
65a6a0d
pin_ansible_version (#2671)
tymofiisobchenko Sep 12, 2025
854a245
Fixing-ce-provision-vars (#2678)
drazenCE Sep 16, 2025
1850230
Updating-string (#2507)
matej5 Sep 17, 2025
d62d4e6
Added-tasks-to-backup-Aurora-and-copy-AMI-to-safe-region (#2682)
matej5 Sep 18, 2025
6717286
SG-creation-update (#2605)
matej5 Sep 18, 2025
3bcee17
Fixing-copy-AMI-to-backup-region (#2684)
matej5 Sep 18, 2025
7bd773f
Fixing-ami-copy-task (#2686)
matej5 Sep 19, 2025
88851ce
Bug fixes pr 2.x (#2690)
gregharvey Sep 22, 2025
cf6129b
73569 allowing webp nginx pr 2.x (#2692)
filiprupic Sep 22, 2025
72021af
extending provision.sh to support tags in plays (#2431)
filiprupic Sep 24, 2025
e783690
Adding-option-for-Aurora-RDS-for-backup-validation (#2635)
matej5 Sep 24, 2025
572f4b0
Fixing-aws_vpc-override (#2688)
matej5 Sep 24, 2025
ef10642
Updating-pam-ldap-condition (#2695)
drazenCE Sep 24, 2025
3dff078
Fixing-when-statement
Sep 24, 2025
b1ec3ad
Resolving-conflicts
Sep 24, 2025
35b0a59
Updating-LE-tasks
Sep 24, 2025
2f7b7b5
Merge branch 'Aurora-backup-validation' into Aurora-backup-validation…
Sep 24, 2025
ca7175a
Adding-from_json-for-systemd-timers
Sep 24, 2025
d3434d2
Merge branch 'Aurora-backup-validation' into Aurora-backup-validation…
Sep 24, 2025
aee0f46
Adding-from_json-for-systemd-timers-2
Sep 24, 2025
bba6d37
Merge branch 'Aurora-backup-validation' into Aurora-backup-validation…
Sep 24, 2025
862663c
Removin-from_json-for-systemd-timers
Sep 24, 2025
e986dd1
Merge branch 'Aurora-backup-validation' into Aurora-backup-validation…
Sep 24, 2025
faf8ed0
Updating-pam_ldap-when-statements
Sep 24, 2025
de7ba9e
Merge branch 'Aurora-backup-validation' into Aurora-backup-validation…
Sep 24, 2025
fa34c8e
Updating-pam_ldap-when-statements-2
Sep 24, 2025
20bd36c
Merge branch 'Aurora-backup-validation' into Aurora-backup-validation…
Sep 24, 2025
654b69b
Updated-Backup-validation-role
Sep 26, 2025
1beea9a
Merge branch 'Aurora-backup-validation' into Aurora-backup-validation…
Sep 26, 2025
db71e46
Updated-trusted-entity-file-name
Sep 26, 2025
d2e48d7
Updated-event-patterns
Sep 26, 2025
b5bea0c
Dropped-default-aurora-retention-to-1
Sep 27, 2025
3c7d745
Bug-fixes
Sep 27, 2025
71c186a
Moving-iam-policy
Sep 27, 2025
b705a69
Updating-tasks
Sep 27, 2025
d2ea04d
Updating-tasks-2
Sep 27, 2025
f0231f8
Updating-return-value
Sep 27, 2025
9b2c2dc
Updating-file-names
Sep 27, 2025
f932bf3
Updating-file-names-2
Sep 27, 2025
0fa1eb7
Updating-file-names-3
Sep 27, 2025
46ffe46
Updating-file-names-4
Sep 27, 2025
b0125e1
Adding-debug
Sep 27, 2025
416fafd
Adding-debug-2
Sep 27, 2025
4939cef
Adding-debug-3
Sep 27, 2025
c191226
Updating-source-for-iam
Sep 27, 2025
a79ea43
Removing-handle-zip-for-lambda
Sep 27, 2025
b951838
Updating-regex-search
Sep 27, 2025
8d89020
Updating-regex-search
Sep 27, 2025
ffd1c66
Updating-lambda-function-handling
Sep 27, 2025
23ba8fd
Updating-lambda-function-handling
Sep 27, 2025
47b6655
Updating-lambda-function-handling-2
Sep 27, 2025
e00bb10
Updating-event-bridge-role-arn
Sep 27, 2025
96bdf86
Moving-functions-to-gitlab
Sep 28, 2025
6c44758
Updating-event-pattern
Sep 29, 2025
64fea93
Updating-iam-role
Sep 29, 2025
e1975ce
Updating-defaults
Sep 29, 2025
5b472f2
Reverting-wazuh-changes
Sep 30, 2025
edb4acf
Merge branch 'devel-2.x' into Aurora-backup-validation-PR-devel-2.x
matej5 Sep 30, 2025
51b3222
Removing-files
Sep 30, 2025
8ea6072
Adding-LE-vars-for-apache
Sep 30, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 0 additions & 48 deletions roles/aws/aws_admin_tools/templates/api_get_list_of_ec2.py.j2

This file was deleted.

1 change: 0 additions & 1 deletion roles/aws/aws_admin_tools/templates/default_s3_object.j2

This file was deleted.

44 changes: 42 additions & 2 deletions roles/aws/aws_backup_validation/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,46 @@ aws_backup_validation:
runtime: "python3.12"
handler: "lambda_handler"
resources:
- EC2
- RDS
- name: ec2_test_instance
git_url: git@gitlab.dummy-infra1.codeenigma.net:functions/ec2_test_instance.git
type: EC2
lambda_policy:
- "backup:PutRestoreValidationResult"
- "ssm:GetCommandInvocation"
- "ssm:GetConnectionStatus"
- "ssm:SendCommand"
- "ec2:DescribeInstances"
- name: rds_test_instance
git_url: git@gitlab.dummy-infra1.codeenigma.net:functions/rds_test_instance.git
type: RDS
lambda_policy:
- "backup:PutRestoreValidationResult"
- "ssm:GetCommandInvocation"
- "ssm:SendCommand"
- "ec2:DescribeInstances"
- "rds:DescribeDBInstances"
- name: aurora_create_instance
git_url: git@gitlab.dummy-infra1.codeenigma.net:functions/aurora_create_instance.git
type: Aurora
lambda_policy:
- "lambda:InvokeFunction"
- name: aurora_test_instance
git_url: git@gitlab.dummy-infra1.codeenigma.net:functions/aurora_test_instance.git
type: Aurora
event_pattern: '{ "source": ["aws.rds"], "detail-type": ["RDS DB Instance Event"], "resources": [{ "prefix": "arn:aws:rds:eu-west-1:{{ _acc_id }}:db:restoretest" }], "detail": { "EventID": ["RDS-EVENT-0005"] } }'
lambda_policy:
- "backup:PutRestoreValidationResult"
- "ec2:DescribeInstances"
- "rds:DescribeDBInstances"
- "rds:DescribeDBClusters"
- "rds:DeleteDBInstance"
- name: validation_report
git_url: git@gitlab.example.codeenigmma.net:functions/validation_report.git
type: Schedule
schedule: "cron(0 0 ? * MON *)"
lambda_policy:
- "backup:ListRestoreJobs"
- "ses:SendEmail"
- "ec2:DescribeImages"
- "rds:DescribeDbSnapshots"
#- EFS
12 changes: 0 additions & 12 deletions roles/aws/aws_backup_validation/files/trusted_entitites.j2

This file was deleted.

177 changes: 107 additions & 70 deletions roles/aws/aws_backup_validation/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,36 +1,100 @@
---
- name: Create a role and attach policies for Lambda backup validation.
- name: Get account ID for ARN.
ansible.builtin.command: >-
aws sts get-caller-identity
--query Account
--output text
register: _acc_id

- name: Setting previous command output into variable.
ansible.builtin.set_fact:
_acc_id: "{{ _acc_id.stdout | from_json }}"

# Passing Api throug the resource ( triger )

- name: Configure API Gateway if defined.
ansible.builtin.include_tasks: create_mock.yml
when: _api_index | length == 0

- name: Create a role and attach policies for events.
ansible.builtin.include_role:
name: aws/aws_iam_role
vars:
aws_iam_role:
name: LambdaBackupRestoreRole
name: "{{ item.name }}_event"
source: "{{ item.name}}"
aws_profile: "{{ _aws_profile }}"
inline_policies:
name: "{{ item.name }}_event"
resource: "arn:aws:lambda:{{ _aws_region }}:{{ _acc_id }}:function:{{ item.name }}"
action:
- "lambda:InvokeFunction"
policy_document: "{{ lookup('template', 'event_document_policy.json.j2') }}"
loop: "{{ aws_backup_validation.resources }}"
loop_control:
extended: true
extended_allitems: false

- name: Create a role and attach policies for Lambda functions.
ansible.builtin.include_role:
name: aws/aws_iam_role
vars:
aws_iam_role:
name: "{{ item.name}}_lambda"
source: "{{ item.name}}"
aws_profile: "{{ _aws_profile }}"
managed_policies:
- arn:aws:iam::aws:policy/AmazonEC2FullAccess
- arn:aws:iam::aws:policy/AWSBackupFullAccess
- arn:aws:iam::aws:policy/AmazonRDSFullAccess
- arn:aws:iam::aws:policy/CloudWatchLogsFullAccess
- arn:aws:iam::aws:policy/AmazonSSMFullAccess
- arn:aws:iam::aws:policy/AmazonSESFullAccess
policy_document: "{{ lookup('file', 'trusted_entitites.j2') }}"
inline_policies:
name: "{{ item.name }}_lambda"
resource: "*"
action: "{{ item.lambda_policy }}"
policy_document: "{{ lookup('template', 'trusted_entitites.json.j2') }}"
loop: "{{ aws_backup_validation.resources }}"
loop_control:
extended: true
extended_allitems: false

- name: Get info about newly created restore testing plan.
ansible.builtin.command: >
aws backup list-restore-testing-plans --region {{ _aws_region }}
register: _testing_plans

- name: Create Lambda functions from templates.
ansible.builtin.include_role:
name: aws/aws_lambda
vars:
aws_lambda:
name: "{{ item.name }}"
description: "Lambda functions for {{ item.type }} validation."
timeout: "{{ aws_backup_validation.timeout }}"
role: "{{ aws_iam_role._result[item.name + '_lambda'] }}"
runtime: "{{ aws_backup_validation.runtime }}"
function_file: "{{ lookup('template', item.name + '.py.j2') }}"
s3_bucket: "{{ aws_backup_validation.s3_bucket }}"
s3_bucket_prefix: "lambda-functions"
tags:
Name: "{{ item.name }}"
loop: "{{ aws_backup_validation.resources }}"
when: item.git_url is not defined

- name: Create backup validation Lambda functions.
- name: Create Lambda functions from git url.
ansible.builtin.include_role:
name: aws/aws_lambda
vars:
aws_lambda:
name: "{{ aws_backup_validation.name }}_{{ item }}"
description: "{{ aws_backup_validation.description }}"
name: "{{ item.name }}"
description: "Lambda functions for {{ item.type }} validation."
timeout: "{{ aws_backup_validation.timeout }}"
role: "{{ aws_iam_role._result['LambdaBackupRestoreRole'] }}"
role: "{{ aws_iam_role._result[item.name + '_lambda'] }}"
runtime: "{{ aws_backup_validation.runtime }}"
function_file: "{{ lookup('template', item + '_validation.py.j2') }}"
function_file: "{{ item.git_url }}"
s3_bucket: "{{ aws_backup_validation.s3_bucket }}"
s3_bucket_prefix: "lambda-functions"
tags:
Name: "{{ item }}_backup_validation"
Name: "{{ item.name }}"
loop: "{{ aws_backup_validation.resources }}"
when: item.git_url is defined

- name: Create an IAM Managed Policy for passing roles and setup IAM role.
ansible.builtin.include_role:
Expand All @@ -53,79 +117,52 @@
#- name: Get verified domain.
# ansible.builtin.include_tasks: get_valid_email.yml

- name: Get info about newly created restore testing plan.
ansible.builtin.command: >
aws backup list-restore-testing-plans --region {{ _aws_region }}
register: _testing_plans

- name: Create validation report function.
ansible.builtin.include_role:
name: aws/aws_lambda
vars:
aws_lambda:
name: "validation_report"
description: "{{ aws_backup_validation.description }}"
timeout: "30"
role: "{{ aws_iam_role._result['LambdaBackupRestoreRole'] }}"
runtime: "{{ aws_backup_validation.runtime }}"
function_file: "{{ lookup('template', 'validation_report.py.j2') }}"
s3_bucket: "{{ aws_backup_validation.s3_bucket }}"
s3_bucket_prefix: "lambda-functions"
tags:
Name: "validation_report"

- name: Get account ID for ARN.
ansible.builtin.command: >-
aws sts get-caller-identity
--query Account
--output text
register: _acc_id

- name: Setting previous command output into variable.
ansible.builtin.set_fact:
_acc_id: "{{ _acc_id.stdout | from_json }}"

- name: Create EventBridge for validation functions.
- name: Create EventBridge with lambda functions.
amazon.aws.cloudwatchevent_rule:
name: "RestoreValidation_{{ item }}"
name: "{{ item.name }}"
description: "{{ aws_backup_validation.description }}"
state: present
region: "{{ _aws_region }}"
event_pattern: '{ "source": ["aws.backup"], "detail-type": ["Restore Job State Change"], "detail": { "resourceType": ["{{ item }}"], "status": ["COMPLETED"] } }'
role_arn: "arn:aws:iam::{{ _acc_id }}:role/{{ item.name }}_event"
event_pattern: >-
{{ item.event_pattern | default(
{
"source": ["aws.backup"],
"detail-type": ["Restore Job State Change"],
"detail": {
"resourceType": [ item.type ],
"status": ["COMPLETED"]
}
} | to_json
) }}
targets:
- id: "RestoreValidation_{{ item }}"
arn: "arn:aws:lambda:{{ _aws_region }}:{{ _acc_id }}:function:RestoreValidation_{{ item }}"
- id: "{{ item.name }}"
arn: "arn:aws:lambda:{{ _aws_region }}:{{ _acc_id }}:function:{{ item.name }}"
loop: "{{ aws_backup_validation.resources }}"
when: item.type != "Schedule"
register: _event_bridges

- name: Create schedule for validation reports.
amazon.aws.cloudwatchevent_rule:
name: validation_report
schedule_expression: "cron(0 0 ? * MON *)"
description: Run validation reporting
name: "{{ item.name }}"
schedule_expression: "{{ item.schedule }}"
description: "Run validation reporting."
region: "{{ _aws_region }}"
role_arn: "arn:aws:iam::{{ _acc_id }}:role/{{ item.name }}_event"
targets:
- id: validation_report
arn: "{{ (aws_lambda._result['validation_report'].configuration.function_arn.split(':') | map('trim'))[:-1] | join(':') }}" # Remove the version number from ARN
arn: "arn:aws:lambda:{{ _aws_region }}:{{ _acc_id }}:function:{{ item.name }}"
loop: "{{ aws_backup_validation.resources }}"
when: item.type == "Schedule"
register: _validation_event

- name: Update Lambda policy.
- name: Update Lambda policies.
amazon.aws.lambda_policy:
state: present
function_name: "{{ item.rule.name }}"
statement_id: "{{ item.rule.name }}"
function_name: "{{ item.name }}"
statement_id: "{{ item.name }}"
action: lambda:InvokeFunction
principal: events.amazonaws.com
source_arn: "{{ item.rule.arn }}"
region: "{{ _aws_region }}"
loop: "{{ _event_bridges.results }}"

- name: Update lambda validation report policy.
amazon.aws.lambda_policy:
state: present
function_name: "validation_report"
statement_id: "validation_report"
action: lambda:InvokeFunction
principal: events.amazonaws.com
source_arn: "{{ _validation_event.rule.arn }}"
source_arn: "arn:aws:events:{{ _aws_region }}:{{ _acc_id }}:rule/{{ item.name }}"
region: "{{ _aws_region }}"
loop: "{{ aws_backup_validation.resources }}"
18 changes: 5 additions & 13 deletions roles/aws/aws_backup_validation/tasks/testing_resources.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,34 +68,26 @@
instance: "EC2"
file-system: "EFS"
db: "RDS"
cluster: "AURORA"
cluster: "Aurora"

- name: Set instance type for template.
ansible.builtin.set_fact:
_instance_type_restore: "{{ instance_type[backup.resource_type] }}"
_template_prefix: "{{ instance_type[backup.resource_type] }}"
when: backup.resource_type != 'file-system'

- name: Set instance type to Aurora if defined.
ansible.builtin.set_fact:
_instance_type_restore: "Aurora"
when:
- backup.resource_type == 'db'
- "'aurora' in aws_rds.engine"

- name: Create restore testing query file.
ansible.builtin.template:
src: "{{ _template_prefix }}_restore_testing.j2"
src: "{{ _instance_type_restore }}_restore_testing.j2"
dest: /tmp/restore_testing.json
register: _restore_testing_query
when: _template_prefix is defined
when: _instance_type_restore is defined

- name: Check if protected reource exist.
ansible.builtin.command: >
aws backup list-protected-resources --query "Results[?ResourceArn=='{{ _resource_arn }}']" --region {{ _aws_region }}
register: _protected_res

- name: Assign {{ _template_prefix }} resource to AWS restore testing plan.
- name: Assign {{ _instance_type_restore }} resource to AWS restore testing plan.
ansible.builtin.command: >
aws backup create-restore-testing-selection --cli-input-json file:///tmp/restore_testing.json --region {{ _aws_region }}
when: _template_prefix is defined and _testing_plan_info.stdout != "null" and _testing_selection_exists.stdout | length == 0 and _protected_res.stdout | length != 0
when: _instance_type_restore is defined and _testing_plan_info.stdout != "null" and _testing_selection_exists.stdout | length == 0 and _protected_res.stdout | length != 0
Loading
Loading