Skip to content

Commit 1bb08fb

Browse files
committed
fix: address 4 critical security and operational issues from PR review
1. Add Terraform state locking with DynamoDB - Add dynamodb_table to S3 backend configuration - Prevents state corruption from concurrent operations 2. Restrict IAM CloudWatch Logs policy - Change Resource from '*' to 'arn:aws:logs:*:*:log-group:/aws/eks/*' - Limit permissions to EKS log groups only 3. Pin ArgoCD version to v2.10.4 - Replace 'stable' tag with explicit version - Prevent uncontrolled updates and ensure reproducibility 4. Add error handling for terrascan results - Check if terrascan-results.json exists before parsing - Set counts to 0 if file is missing - Add 'if: always()' to parse step - Prevent workflow failure when terrascan doesn't produce output
1 parent 31c35f2 commit 1bb08fb

4 files changed

Lines changed: 29 additions & 19 deletions

File tree

.github/workflows/terraform-scan.yml

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -71,17 +71,24 @@ jobs:
7171
-o human | tee terrascan-human.txt
7272
continue-on-error: true
7373

74-
- name: Parse Results
75-
id: parse
76-
run: |
77-
HIGH_COUNT=$(jq -r '.results.violations | map(select(.severity == "HIGH")) | length' terrascan-results.json || echo "0")
78-
MEDIUM_COUNT=$(jq -r '.results.violations | map(select(.severity == "MEDIUM")) | length' terrascan-results.json || echo "0")
79-
echo "high_severity_count=${HIGH_COUNT}" >> $GITHUB_ENV
80-
echo "medium_severity_count=${MEDIUM_COUNT}" >> $GITHUB_ENV
81-
82-
echo "Summary of findings:"
83-
echo "High severity issues: ${HIGH_COUNT}"
84-
echo "Medium severity issues: ${MEDIUM_COUNT}"
74+
- name: Parse Results
75+
id: parse
76+
if: always()
77+
run: |
78+
if [ -f terrascan-results.json ]; then
79+
HIGH_COUNT=$(jq -r '.results.violations | map(select(.severity == "HIGH")) | length' terrascan-results.json || echo "0")
80+
MEDIUM_COUNT=$(jq -r '.results.violations | map(select(.severity == "MEDIUM")) | length' terrascan-results.json || echo "0")
81+
else
82+
echo "Terrascan results file not found, setting counts to 0"
83+
HIGH_COUNT=0
84+
MEDIUM_COUNT=0
85+
fi
86+
echo "high_severity_count=${HIGH_COUNT}" >> $GITHUB_ENV
87+
echo "medium_severity_count=${MEDIUM_COUNT}" >> $GITHUB_ENV
88+
89+
echo "Summary of findings:"
90+
echo "High severity issues: ${HIGH_COUNT}"
91+
echo "Medium severity issues: ${MEDIUM_COUNT}"
8592
8693
- name: Upload Results
8794
uses: actions/upload-artifact@v4

infra/backend.tf

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,10 @@ terraform {
22
required_version = ">= 1.6.0"
33

44
backend "s3" {
5-
bucket = "my-terraform-state-eks-infra"
6-
key = "simpleApp/terraform.tfstate"
7-
region = "eu-north-1"
8-
encrypt = true
5+
bucket = "my-terraform-state-eks-infra"
6+
key = "simpleApp/terraform.tfstate"
7+
region = "eu-north-1"
8+
encrypt = true
9+
dynamodb_table = "terraform-state-lock"
910
}
1011
}

infra/modules/iam/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ resource "aws_iam_policy" "cloudwatch_logs" {
9797
"logs:DescribeLogStreams"
9898
]
9999
Effect = "Allow"
100-
Resource = "*"
100+
Resource = "arn:aws:logs:*:*:log-group:/aws/eks/*"
101101
}
102102
]
103103
})

platform/bootstrap/install-argocd.sh

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,15 @@
33

44
set -e
55

6+
ARGOCD_VERSION="v2.10.4"
7+
68
echo "Creating argocd namespace..."
79
kubectl create namespace argocd || true
810

9-
echo "Installing Argo CD..."
10-
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
11+
echo "Installing Argo CD ${ARGOCD_VERSION}..."
12+
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/${ARGOCD_VERSION}/manifests/install.yaml
1113

1214
echo "Waiting for Argo CD to be ready..."
1315
kubectl wait --for=condition=available --timeout=300s deployment/argocd-server -n argocd
1416

15-
echo "Argo CD installed successfully."
17+
echo "Argo CD ${ARGOCD_VERSION} installed successfully."

0 commit comments

Comments
 (0)