-
Notifications
You must be signed in to change notification settings - Fork 0
/
mongo-validate.pkr.hcl
134 lines (122 loc) · 3.91 KB
/
mongo-validate.pkr.hcl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
packer {
required_plugins {
docker = {
version = " >= 1.0.8"
source = "github.com/hashicorp/docker"
}
ansible = {
source = "github.com/hashicorp/ansible"
version = "~> 1"
}
}
}
# Specifies the hardened image to be used as an input.
variable "input_hardened_image" {
type = map(string)
default = {
"name" = "mongo-hardened"
"tag" = "latest"
}
}
variable "scan" {
type = map(string)
default = {
"inspec_profile" = "https://github.com/mitre/mongodb-enterprise-advanced-4-stig-baseline.git",
"report_dir" = "reports",
"inspec_report_filename" = "mongo_inspec_results.json",
"inspec_input_file" = "spec/mongo-inspec-profile/inputs.yml"
}
}
variable "report" {
type = map(string)
description = "Configuration for reporting to Heimdall"
}
variable "attestation" {
type = map(string)
description = "Configuration for attesting InSpec results"
}
variable "mongo" {
type = map(string)
description = "Configuration for connecting to MongoDB"
}
# Hardened docker container to be validated
source "docker" "hardened" {
image = "${var.input_hardened_image.name}:${var.input_hardened_image.tag}"
commit = false
pull = false
discard = true
run_command = [
"-d",
"--name", "${var.input_hardened_image.name}",
"-p", "27017:27017",
"-v", "mongodb_configdb:/data/configdb",
"-v", "mongodb_db:/data/db",
"-e", "PATH=/usr/local/src/openssl-3.1.0/apps:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"-e", "LD_LIBRARY_PATH=/usr/local/src/openssl-3.1.0",
"{{.Image}}",
"mongod", "--config", "/etc/mongod.conf"
]
}
# Run validation process
build {
name = "validate"
sources = ["source.docker.hardened"]
### SCAN
provisioner "shell-local" {
environment_vars = [
"PROFILE=${var.scan.inspec_profile}",
"CONTAINER_ID=${var.input_hardened_image.name}",
"REPORT_DIR=${var.scan.report_dir}",
"REPORT_FILE=${var.scan.inspec_report_filename}",
"INPUT_FILE=${var.scan.inspec_input_file}",
"TARGET_IMAGE=${var.input_hardened_image.name}"
]
valid_exit_codes = [0, 100, 101] # inspec has multiple valid exit codes
script = "spec/scripts/scan.sh"
}
### ATTEST
provisioner "shell-local" {
environment_vars = [
"INSPEC_FILE=${var.attestation.inspec_report_filename}",
"REPORT_DIR=${var.attestation.report_dir}",
"ATTESTATION_FILE=${var.attestation.attestation_filename}",
"ATTESTED_FILE=${var.attestation.attested_inspec_filename}"
]
script = "spec/scripts/attestation.sh"
}
### REPORT
provisioner "shell-local" {
environment_vars = [
"REPORT_DIR=${var.scan.report_dir}",
"REPORT_TO_HEIMDALL=${var.report.report_to_heimdall}",
"HEIMDALL_URL=${var.report.heimdall_url}",
"HEIMDALL_API_KEY=${var.report.heimdall_api_key}"
]
script = "spec/scripts/report.sh"
}
### VERIFY
provisioner "shell-local" {
environment_vars = [
"TARGET_IMAGE=${var.input_hardened_image.name}",
"REPORT_DIR=${var.scan.report_dir}",
"ATTESTED_FILE=${var.attestation.attested_inspec_filename}"
]
valid_exit_codes = [0, 1] # the threshold checks return 1 if the thresholds aren't met
# this does not mean we want to halt the run
script = "spec/scripts/verify_threshold.sh"
}
### CLEANUP
provisioner "shell-local" {
environment_vars = [
"CONTAINER_NAME=${var.mongo.container_name}",
"MONGO_DBA=${var.mongo.mongo_dba}",
"MONGO_DBA_PASSWORD=${var.mongo.mongo_dba_password}",
"MONGO_HOST=${var.mongo.mongo_host}",
"MONGO_PORT=${var.mongo.mongo_port}",
"CA_FILE=${var.mongo.ca_file}",
"CERTIFICATE_KEY_FILE=${var.mongo.certificate_key_file}",
"AUTH_MECHANISM=${var.mongo.auth_mechanism}"
]
script = "spec/scripts/cleanup.sh"
}
}