Skip to content

Commit fb4dca3

Browse files
committed
feat(security): devsecops modernization for projects 01-25 (2026 standards)
- IAM & Networking: Enforced Zero Trust across AWS Security Groups (Projects 01, 11) and Azure Network Rules (Project 20). Replaced IAM wildcards with explicit boundaries (Project 22). - Containerization: Remediated root-execution risks. Implemented multi-stage, unprivileged user builds for Docker workloads (Projects 05, 18, 21, 23). - CI/CD & SCA: Purged third-party repository checkout vulnerabilities (Project 19). Parameterized hardcoded images/credentials (Projects 09, 21). Implemented automated Trivy container scanning pre-push. - GitHub Actions: Upgraded legacy Node 12/16 dependent plugins (actions/checkout, upload-artifact) to v4 across Android and .NET pipelines (Projects 14, 24). - Kubernetes: Hardened application pods by defining precise compute resource capabilities (CPU/Mem limits) and dropping all kernel escalations via rigid security contexts (Projects 04, 08, 18, 19, 24). - Documentation: Pushed deprecation warnings for retired cloud features, updated markdown dependencies, and finalized global Security/Contributing policies.
1 parent c96986a commit fb4dca3

File tree

67 files changed

+472
-188
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

67 files changed

+472
-188
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
name: Global Repository Security & Linting
2+
3+
on:
4+
push:
5+
branches: [ "main", "master" ]
6+
pull_request:
7+
branches: [ "main", "master" ]
8+
schedule:
9+
- cron: '0 0 * * 0' # Run weekly on Sunday
10+
11+
jobs:
12+
secret-scanning:
13+
name: Secret Scanning
14+
runs-on: ubuntu-latest
15+
steps:
16+
- name: Checkout code
17+
uses: actions/checkout@v4
18+
with:
19+
fetch-depth: 0
20+
21+
# TruffleHog is a free, powerful secret scanner
22+
- name: TruffleHog Secret Scan
23+
uses: trufflesecurity/trufflehog@main
24+
with:
25+
path: ./
26+
base: ${{ github.event.pull_request.base.sha }}
27+
head: ${{ github.ref }}
28+
extra_args: --debug --only-verified
29+
30+
iac-security:
31+
name: IaC Security Scan (Trivy)
32+
runs-on: ubuntu-latest
33+
steps:
34+
- name: Checkout code
35+
uses: actions/checkout@v4
36+
37+
# Trivy is free and excellent for IaC and container scanning
38+
- name: Run Trivy vulnerability scanner in fs mode
39+
uses: aquasecurity/trivy-action@master
40+
with:
41+
scan-type: 'fs'
42+
scan-ref: '.'
43+
trivy-config: trivy.yaml
44+
format: 'table'
45+
exit-code: '0' # Set to 1 in later phases to block PRs
46+
ignore-unfixed: true
47+
vuln-type: 'os,library'
48+
severity: 'CRITICAL,HIGH'
49+
50+
linting:
51+
name: Super-Linter
52+
runs-on: ubuntu-latest
53+
steps:
54+
- name: Checkout Code
55+
uses: actions/checkout@v4
56+
with:
57+
fetch-depth: 0
58+
59+
# Super-linter supports multiple languages and is free
60+
- name: Lint Code Base
61+
uses: github/super-linter@v5
62+
env:
63+
VALIDATE_ALL_CODEBASE: false
64+
DEFAULT_BRANCH: "main"
65+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
66+
# Disable linters that might be too noisy initially
67+
VALIDATE_JSCPD: false
68+
VALIDATE_KUBERNETES_KUBEVAL: false

β€Ž.gitignoreβ€Ž

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,74 @@
1+
# -------------------------------------------------------------------
2+
# DevOps-Projects Global .gitignore
3+
# -------------------------------------------------------------------
4+
5+
# OS & Environment
6+
.DS_Store
7+
Thumbs.db
8+
.env
9+
.venv/
10+
venv/
11+
ENV/
12+
13+
# IDE & Editors
14+
.vscode/
15+
.idea/
16+
*.swp
17+
*.swo
18+
19+
# Git/Review artifacts
120
IMPROVEMENTS.md
221
REVIEW-PLAN.md
322
REVIEW-UPDATES.md
23+
24+
# Application Dependencies
25+
node_modules/
426
__pycache__/
527
*.pyc
28+
*.pyo
29+
target/
30+
build/
31+
bin/
32+
obj/
33+
dist/
34+
35+
# Terraform / OpenTofu
36+
.terraform/
37+
*.tfstate
38+
*.tfstate.*
39+
crash.log
40+
crash.*.log
41+
*.tfvars
42+
*.tfvars.json
43+
override.tf
44+
override.tf.json
45+
*_override.tf
46+
*_override.tf.json
47+
.terraformrc
48+
terraform.rc
49+
50+
# Credentials & Secrets (NEVER COMMIT)
51+
*.pem
52+
*.key
53+
*.cert
54+
*.cer
55+
*.crt
56+
*.pfx
57+
*.p12
58+
secret*.yaml
59+
credentials
60+
id_rsa
61+
id_rsa.pub
62+
63+
# Build Artifacts & Archives
64+
*.tgz
65+
*.tar.gz
66+
*.zip
67+
*.jar
68+
*.war
69+
*.ear
70+
71+
# Databases
72+
*.sqlite3
73+
db.sqlite3
74+
*.db

β€ŽSECURITY.mdβ€Ž

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Security Policy
2+
3+
## Supported Versions
4+
5+
Currently, the `main` branch of `devops-projects` is the only supported version.
6+
7+
| Version | Supported |
8+
| ------- | ------------------ |
9+
| `main` | :white_check_mark: |
10+
11+
## Reporting a Vulnerability
12+
13+
If you discover a security vulnerability within this repository, please do not disclose it publicly.
14+
15+
Instead, please send an email to the repository owner or open a private security advisory via GitHub. We will address the issue as promptly as possible.
16+
17+
## Security Tools Used in this Repository
18+
19+
This repository serves as a learning resource and implements modern DevSecOps practices. We heavily feature the following **free** security tools that students can use in their own projects:
20+
21+
- **[TruffleHog](https://github.com/trufflesecurity/trufflehog):** Scans for exposed secrets, passwords, and API keys.
22+
- **[Trivy](https://aquasecurity.github.io/trivy/):** A comprehensive and versatile security scanner for containers, Infrastructure as Code (IaC), and software dependencies.
23+
- **[SonarQube Community](https://www.sonarqube.org/):** Used for static application security testing (SAST) and code quality analysis.
24+
- **[Checkov](https://www.checkov.io/):** Static code analysis tool for infrastructure-as-code.
25+
- **[Super-Linter](https://github.com/github/super-linter):** GitHub's versatile linting framework.

β€Žproject-01-java-aws-3tier/README.mdβ€Ž

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ Goal of this project is to deploy scalable, highly available and secured Java ap
2626
3. Migrate Java Source Code to your own GitHub repository
2727
4. Create account in Sonarcloud.
2828
5. Create account in Jfrog cloud.
29+
6. **Security Mandate**: Find your public IP address and replace `YOUR_IP_ADDRESS/32` in `terraform/bastion.tf`, `terraform/apache-ec2.tf`, and `terraform/nginx-ec2.tf` before deploying.
2930

3031
## Pre-Deployment
3132

β€Žproject-01-java-aws-3tier/terraform/apache-ec2.tfβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,14 +85,16 @@ resource "aws_security_group" "tomcat_sg" {
8585
from_port = 22
8686
to_port = 22
8787
protocol = "tcp"
88-
cidr_blocks = ["0.0.0.0/0"]
88+
cidr_blocks = ["YOUR_IP_ADDRESS/32"] # REPLACE THIS with your actual IP address
89+
description = "Allow SSH from administrator IP"
8990
}
9091

9192
egress {
9293
from_port = 0
9394
to_port = 0
9495
protocol = "-1"
9596
cidr_blocks = ["0.0.0.0/0"]
97+
description = "Allow all outbound traffic"
9698
}
9799

98100
tags = {

β€Žproject-01-java-aws-3tier/terraform/bastion.tfβ€Ž

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,18 +81,21 @@ resource "aws_security_group" "bastion_sg" {
8181
description = "Security group for Bastion host"
8282
vpc_id = aws_vpc.bastion_vpc.id
8383

84+
# SECURITY FIX: Removed open 0.0.0.0/0. Recommend standardizing on VPN or explicit admin IP.
8485
ingress {
8586
from_port = 22
8687
to_port = 22
8788
protocol = "tcp"
88-
cidr_blocks = ["0.0.0.0/0"]
89+
cidr_blocks = ["YOUR_IP_ADDRESS/32"] # REPLACE THIS with your actual IP address
90+
description = "Allow SSH from administrator IP"
8991
}
9092

9193
egress {
9294
from_port = 0
9395
to_port = 0
9496
protocol = "-1"
9597
cidr_blocks = ["0.0.0.0/0"]
98+
description = "Allow all outbound traffic"
9699
}
97100

98101
tags = {
@@ -107,4 +110,5 @@ resource "aws_security_group_rule" "bastion_to_rds" {
107110
protocol = "tcp"
108111
cidr_blocks = [aws_vpc.app_vpc.cidr_block]
109112
security_group_id = aws_security_group.bastion_sg.id
113+
description = "Allow Bastion to connect to RDS"
110114
}

β€Žproject-01-java-aws-3tier/terraform/nginx-ec2.tfβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,14 +86,16 @@ resource "aws_security_group" "nginx_sg" {
8686
from_port = 22
8787
to_port = 22
8888
protocol = "tcp"
89-
cidr_blocks = ["0.0.0.0/0"]
89+
cidr_blocks = ["YOUR_IP_ADDRESS/32"] # REPLACE THIS with your actual IP address
90+
description = "Allow SSH from administrator IP"
9091
}
9192

9293
egress {
9394
from_port = 0
9495
to_port = 0
9596
protocol = "-1"
9697
cidr_blocks = ["0.0.0.0/0"]
98+
description = "Allow all outbound traffic"
9799
}
98100

99101
tags = {

β€Žproject-01-java-aws-3tier/terraform/rds.tfβ€Ž

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,21 @@ resource "aws_db_subnet_group" "mysql" {
55
}
66

77
resource "aws_db_instance" "mysql" {
8-
identifier = "myapp-mysql"
9-
engine = "mysql"
10-
engine_version = "8.0"
11-
instance_class = "db.t3.medium"
12-
allocated_storage = 20
13-
storage_type = "gp2"
14-
multi_az = true
15-
db_name = "myapp"
16-
username = "admin"
17-
password = var.db_password
18-
db_subnet_group_name = aws_db_subnet_group.mysql.name
19-
vpc_security_group_ids = [aws_security_group.mysql_sg.id]
20-
skip_final_snapshot = true
8+
identifier = "myapp-mysql"
9+
engine = "mysql"
10+
engine_version = "8.0"
11+
instance_class = "db.t3.medium"
12+
allocated_storage = 20
13+
storage_type = "gp2"
14+
multi_az = true
15+
db_name = "myapp"
16+
username = "admin"
17+
password = var.db_password
18+
db_subnet_group_name = aws_db_subnet_group.mysql.name
19+
vpc_security_group_ids = [aws_security_group.mysql_sg.id]
20+
skip_final_snapshot = true
21+
publicly_accessible = false # SECURITY FIX: Explicitly disable public access
22+
storage_encrypted = true # SECURITY FIX: Enable encryption at rest
2123
}
2224

2325
resource "aws_security_group" "mysql_sg" {
@@ -30,12 +32,14 @@ resource "aws_security_group" "mysql_sg" {
3032
to_port = 3306
3133
protocol = "tcp"
3234
cidr_blocks = [aws_vpc.bastion_vpc.cidr_block, aws_vpc.app_vpc.cidr_block]
35+
description = "Allow MySQL access from App and Bastion VPCs"
3336
}
3437

3538
egress {
3639
from_port = 0
3740
to_port = 0
3841
protocol = "-1"
3942
cidr_blocks = ["0.0.0.0/0"]
43+
description = "Allow all outbound traffic"
4044
}
4145
}

β€Žproject-02-aws-vpc-architecture/VPC Architecture/s3-policy.jsonβ€Ž

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010
"s3:GetBucketLocation"
1111
],
1212
"Resource": [
13-
"arn:aws:s3::: YOUR_BUCKET_NAME/*",
14-
"arn:aws:s3::: YOUR_BUCKET_NAME"
13+
"arn:aws:s3:::YOUR_BUCKET_NAME/*",
14+
"arn:aws:s3:::YOUR_BUCKET_NAME"
1515
]
1616
}
1717
]
Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
1-
# importing base image
2-
FROM python:3.9
1+
# Use slim Python 3.11 image for a smaller, secure footprint
2+
FROM python:3.11-slim
33

4-
# updating docker host or host machine
5-
RUN apt-get update \
6-
&& apt-get install -y --no-install-recommends \
7-
&& rm -rf /var/lib/apt/lists/*
4+
# Prevent Python from writing .pyc files and enable unbuffered output
5+
ENV PYTHONDONTWRITEBYTECODE=1
6+
ENV PYTHONUNBUFFERED=1
7+
8+
# Create a non-root user for security
9+
RUN groupadd -r django && useradd -r -g django django
810

9-
# changing current working directory to /usr/src/app
11+
# Set working directory
1012
WORKDIR /usr/src/app
1113

12-
# copying requirement.txt file to present working directory
13-
COPY requirements.txt ./
14+
# Install system dependencies (clearing cache afterwards)
15+
RUN apt-get update \
16+
&& apt-get install -y --no-install-recommends gcc libpq-dev \
17+
&& rm -rf /var/lib/apt/lists/*
1418

15-
# installing dependency in container
16-
RUN pip install -r requirements.txt
19+
# Copy requirements and install
20+
COPY requirements.txt ./
21+
RUN pip install --no-cache-dir -r requirements.txt gunicorn
1722

18-
# copying all the files to present working directory
23+
# Copy application code
1924
COPY . .
2025

21-
# informing Docker that the container listens on the
22-
# specified network ports at runtime i.e 8000.
26+
# Change ownership to the non-root user
27+
RUN chown -R django:django /usr/src/app /var/log
28+
29+
# Switch to non-root user
30+
USER django
31+
32+
# Expose port
2333
EXPOSE 8000
2434

25-
# running server
26-
CMD ["python", "manage.py", "runserver", "0.0.0.0:8000"]
35+
# Run server using gunicorn instead of the development runserver
36+
CMD ["gunicorn", "--bind", "0.0.0.0:8000", "--workers", "3", "hello_world_django_app.wsgi:application"]

0 commit comments

Comments
Β (0)