Skip to content

Commit e9ad720

Browse files
committed
Use dedicated role for taking the snapshot
The GithubDeployDataReplicationInfrastructure role has an explicit Deny in the policy for all tagged resources which prevents taking DB snapshots Jira-Issue: MAV-1864
1 parent 1634e73 commit e9ad720

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

.github/workflows/data-replication-pipeline.yml

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ env:
4444
aws_role: ${{ inputs.environment == 'production'
4545
&& 'arn:aws:iam::820242920762:role/GithubDeployDataReplicationInfrastructure'
4646
|| 'arn:aws:iam::393416225559:role/GithubDeployDataReplicationInfrastructure' }}
47+
db_snapshot_role: ${{ inputs.environment == 'production'
48+
&& 'arn:aws:iam::820242920762:role/DatabaseSnapshotRole'
49+
|| 'arn:aws:iam::393416225559:role/DatabaseSnapshotRole' }}
4750

4851
defaults:
4952
run:
@@ -62,10 +65,11 @@ jobs:
6265
steps:
6366
- name: Checkout code
6467
uses: actions/checkout@v5
65-
- name: Configure AWS Credentials
68+
- name: Assume DB Snapshot role
69+
if: inputs.take_db_snapshot
6670
uses: aws-actions/configure-aws-credentials@v4
6771
with:
68-
role-to-assume: ${{ env.aws_role }}
72+
role-to-assume: ${{ env.db_snapshot_role }}
6973
aws-region: eu-west-2
7074
- name: Take DB snapshot
7175
if: inputs.take_db_snapshot
@@ -76,6 +80,11 @@ jobs:
7680
echo "Waiting for snapshot to be available. This can take a while."
7781
aws rds wait db-cluster-snapshot-available --db-cluster-snapshot-identifier $snapshot_identifier
7882
echo "New snapshot is now available"
83+
- name: Configure AWS Credentials
84+
uses: aws-actions/configure-aws-credentials@v4
85+
with:
86+
role-to-assume: ${{ env.aws_role }}
87+
aws-region: eu-west-2
7988
- name: Get latest snapshot
8089
id: get-latest-snapshot
8190
run: |

terraform/account/deployment_permissions.tf

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,28 @@ resource "aws_iam_role_policy_attachment" "data_replication" {
4646
policy_arn = each.value
4747
}
4848

49+
resource "aws_iam_role" "data_replication_snapshot" {
50+
name = "DatabaseSnapshotRole"
51+
description = "Role to be assumed by the data replication workflow for taking on-demand DB snapshots"
52+
assume_role_policy = templatefile("resources/iam_role_github_trust_policy_${var.environment}.json.tftpl", {
53+
account_id = var.account_id
54+
})
55+
}
56+
57+
resource "aws_iam_policy" "db_snapshot_policy" {
58+
name = "DatabaseSnapshotPolicy"
59+
description = "Policy to take DB snapshots"
60+
policy = file("resources/iam_policy_DatabaseSnapshotPolicy.json")
61+
lifecycle {
62+
ignore_changes = [description]
63+
}
64+
}
65+
66+
resource "aws_iam_role_policy_attachment" "db_snapshot" {
67+
role = aws_iam_role.data_replication_snapshot.name
68+
policy_arn = aws_iam_policy.db_snapshot_policy.arn
69+
}
70+
4971
################# Deploy Monitoring ################
5072

5173
resource "aws_iam_role" "monitoring_deploy" {
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"Version": "2012-10-17",
3+
"Statement": [
4+
{
5+
"Sid": "Statement1",
6+
"Effect": "Allow",
7+
"Action": [
8+
"rds:CreateDBClusterSnapshot",
9+
"rds:DescribeDBClusterSnapshots"
10+
],
11+
"Resource": ["*"]
12+
}
13+
]
14+
}

0 commit comments

Comments
 (0)