Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TES-363: Cleaned up configuration and security issues #20

Merged
merged 1 commit into from
Nov 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
14 changes: 9 additions & 5 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,17 @@ jobs:
- name: Run Terraform validate check
run: terraform validate

- name: Run tfsec
uses: aquasecurity/tfsec-sarif-action@v0.1.4
- name: Run Trivy vulnerability scanner
uses: aquasecurity/trivy-action@master
with:
config_file: tfsec.yml
sarif_file: tfsec.sarif
scan-type: config
trivy-config: trivy.yaml
hide-progress: false
format: sarif
output: trivy.sarif

- name: Upload SARIF file
uses: github/codeql-action/upload-sarif@v2
timeout-minutes: 1
with:
sarif_file: tfsec.sarif
sarif_file: trivy.sarif
3 changes: 3 additions & 0 deletions .trivyignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Rule: Key vault should have purge protection enabled
# Note: There is a variable for controlling the purge protection
AVD-AZU-0016
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
# terraform-azure-graphdb
Terraform module for deploying GraphDB in Azure
# GraphDB Azure Terraform Module

## License

This code is released under the Apache 2.0 License. See [LICENSE](LICENSE) for more details.
9 changes: 7 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ resource "azurerm_subnet" "graphdb-vmss" {
resource_group_name = azurerm_resource_group.graphdb.name
virtual_network_name = azurerm_virtual_network.graphdb.name
address_prefixes = var.graphdb_subnet_address_prefix
service_endpoints = ["Microsoft.KeyVault"]
service_endpoints = ["Microsoft.KeyVault", "Microsoft.Storage"]
}

resource "azurerm_network_security_group" "graphdb-gateway" {
Expand Down Expand Up @@ -149,6 +149,9 @@ module "vault" {
nacl_subnet_ids = [azurerm_subnet.graphdb-gateway.id, azurerm_subnet.graphdb-vmss.id]
nacl_ip_rules = var.management_cidr_blocks

key_vault_enable_purge_protection = var.key_vault_enable_purge_protection
key_vault_retention_days = var.key_vault_retention_days

tags = local.tags
}

Expand Down Expand Up @@ -294,7 +297,9 @@ module "backup" {
location = var.location
resource_group_name = azurerm_resource_group.graphdb.name

identity_name = module.identity.identity_name
nacl_subnet_ids = [azurerm_subnet.graphdb-vmss.id]
nacl_ip_rules = var.management_cidr_blocks

identity_principal_id = module.identity.identity_principal_id
storage_account_tier = var.storage_account_tier
storage_account_replication_type = var.storage_account_replication_type
Expand Down
23 changes: 16 additions & 7 deletions modules/backup/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ locals {

# Create an Azure Storage Account for backups
resource "azurerm_storage_account" "graphdb-backup" {
name = local.storage_account_name
resource_group_name = var.resource_group_name
location = var.location
account_tier = var.storage_account_tier
account_replication_type = var.storage_account_replication_type
enable_https_traffic_only = true
min_tls_version = "TLS1_2"
name = local.storage_account_name
resource_group_name = var.resource_group_name
location = var.location

account_tier = var.storage_account_tier
account_replication_type = var.storage_account_replication_type
enable_https_traffic_only = true
allow_nested_items_to_be_public = false
min_tls_version = "TLS1_2"

network_rules {
bypass = ["AzureServices"]
default_action = "Deny"
virtual_network_subnet_ids = var.nacl_subnet_ids
ip_rules = var.nacl_ip_rules
}

tags = var.tags
}
Expand Down
22 changes: 16 additions & 6 deletions modules/backup/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,22 @@ variable "resource_group_name" {
type = string
}

# Identity
# Networking

variable "identity_name" {
description = "Name of a user assigned identity for assigning permissions"
type = string
variable "nacl_subnet_ids" {
description = "List of subnet identifiers allowed to access the storage account internally over a service link"
type = list(string)
default = []
}

variable "nacl_ip_rules" {
description = "List of CIDR blocks allowed to access the storage account"
type = list(string)
default = []
}

# Identity

variable "identity_principal_id" {
description = "Principal identifier of a user assigned identity for assigning permissions"
type = string
Expand All @@ -36,12 +45,13 @@ variable "identity_principal_id" {
# Storage specifics

variable "storage_account_tier" {
default = "Standard"
description = "Specify the performance and redundancy characteristics of the Azure Storage Account that you are creating"
type = string
default = "Standard"
}

variable "storage_account_replication_type" {
default = "LRS"
description = "Specify the data redundancy strategy for your Azure Storage Account"
type = string
default = "ZRS"
}
25 changes: 15 additions & 10 deletions modules/configuration/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -17,26 +17,29 @@ locals {
resource "azurerm_key_vault_secret" "graphdb-license" {
key_vault_id = var.key_vault_id

name = var.graphdb_license_secret_name
value = filebase64(var.graphdb_license_path)
name = var.graphdb_license_secret_name
value = filebase64(var.graphdb_license_path)
content_type = "text/plain"

tags = var.tags
}

resource "azurerm_key_vault_secret" "graphdb-cluster-token" {
key_vault_id = var.key_vault_id

name = var.graphdb_cluster_token_name
value = base64encode(local.graphdb_cluster_token)
name = var.graphdb_cluster_token_name
value = base64encode(local.graphdb_cluster_token)
content_type = "text/plain"

tags = var.tags
}

resource "azurerm_key_vault_secret" "graphdb-password" {
key_vault_id = var.key_vault_id

name = var.graphdb_password_secret_name
value = base64encode(local.graphdb_password)
name = var.graphdb_password_secret_name
value = base64encode(local.graphdb_password)
content_type = "text/plain"

tags = var.tags
}
Expand All @@ -46,8 +49,9 @@ resource "azurerm_key_vault_secret" "graphdb-properties" {

key_vault_id = var.key_vault_id

name = var.graphdb_properties_secret_name
value = filebase64(var.graphdb_properties_path)
name = var.graphdb_properties_secret_name
value = filebase64(var.graphdb_properties_path)
content_type = "text/plain"

tags = var.tags
}
Expand All @@ -57,8 +61,9 @@ resource "azurerm_key_vault_secret" "graphdb-java-options" {

key_vault_id = var.key_vault_id

name = var.graphdb_java_options_secret_name
value = base64encode(var.graphdb_java_options)
name = var.graphdb_java_options_secret_name
value = base64encode(var.graphdb_java_options)
content_type = "text/plain"

tags = var.tags
}
Expand Down
7 changes: 5 additions & 2 deletions modules/gateway/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ resource "azurerm_application_gateway" "graphdb" {

enable_http2 = true

# TODO: Connection draining?

sku {
name = "Standard_v2"
tier = "Standard_v2"
Expand All @@ -43,6 +41,11 @@ resource "azurerm_application_gateway" "graphdb" {
key_vault_secret_id = var.gateway_tls_certificate_secret_id
}

ssl_policy {
policy_type = "Predefined"
policy_name = var.gateway_ssl_policy_profile
}

gateway_ip_configuration {
name = local.gateway_ip_configuration_name
subnet_id = var.gateway_subnet_id
Expand Down
6 changes: 6 additions & 0 deletions modules/gateway/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,12 @@ variable "gateway_max_capacity" {
default = 2
}

variable "gateway_ssl_policy_profile" {
description = "The predefined SSL policy to use in the Application Gateway"
type = string
default = "AppGwSslPolicy20220101S"
}

variable "gateway_backend_port" {
description = "Backend port for the Application Gateway rules"
type = number
Expand Down
6 changes: 4 additions & 2 deletions modules/vault/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@ resource "azurerm_key_vault" "graphdb" {
location = var.location
tenant_id = data.azurerm_client_config.current.tenant_id

sku_name = "standard"
enable_rbac_authorization = true
sku_name = "standard"
enable_rbac_authorization = true
purge_protection_enabled = var.key_vault_enable_purge_protection
soft_delete_retention_days = var.key_vault_retention_days

network_acls {
bypass = "AzureServices"
Expand Down
15 changes: 15 additions & 0 deletions modules/vault/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,18 @@ variable "nacl_ip_rules" {
type = list(string)
default = []
}

# Key Vault

# Enable only for production
variable "key_vault_enable_purge_protection" {
description = "Prevents purging the key vault and its contents by soft deleting it. It will be deleted once the soft delete retention has passed."
type = bool
default = false
}

variable "key_vault_retention_days" {
description = "Retention period in days during which soft deleted secrets are kept"
type = number
default = 30
}
8 changes: 5 additions & 3 deletions modules/vm/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,10 @@ resource "azurerm_linux_virtual_machine_scale_set" "graphdb" {
upgrade_mode = "Manual"
overprovision = false

computer_name_prefix = "${var.resource_name_prefix}-"
admin_username = "graphdb"
computer_name_prefix = "${var.resource_name_prefix}-"
admin_username = "graphdb"
disable_password_authentication = true
encryption_at_host_enabled = var.encryption_at_host

scale_in {
# In case of re-balancing, remove the newest VM which might have not been IN-SYNC yet with the cluster
Expand Down Expand Up @@ -62,7 +64,7 @@ resource "azurerm_linux_virtual_machine_scale_set" "graphdb" {

tags = var.tags

depends_on = [azurerm_role_assignment.rg-contributor-role]
depends_on = [azurerm_role_assignment.rg-contributor-role, azurerm_role_assignment.rg-reader-role]
}

resource "azurerm_monitor_autoscale_setting" "graphdb-autoscale-settings" {
Expand Down
4 changes: 3 additions & 1 deletion modules/vm/templates/entrypoint.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,9 @@ if [ -z "$existingUnattachedDisk" ]; then
--zone $ZONE_ID \
--os-type Linux \
--disk-iops-read-write $DISK_IOPS \
--disk-mbps-read-write $DISK_THROUGHPUT
--disk-mbps-read-write $DISK_THROUGHPUT \
--public-network-access Disabled \
--network-access-policy DenyAll
fi

# Checks if a managed disk is attached to the instance
Expand Down
6 changes: 6 additions & 0 deletions modules/vm/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,12 @@ variable "custom_user_data" {
default = null
}

variable "encryption_at_host" {
description = "Enables encryption at rest on the VM host"
type = bool
default = true
}

# Managed Data Disks

variable "disk_size_gb" {
Expand Down
7 changes: 7 additions & 0 deletions trivy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
timeout: 5m
exit-code: 1
severity:
- HIGH
- CRITICAL
- MEDIUM
format: table
20 changes: 18 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,21 @@ variable "tls_certificate_password" {
default = null
}

# Key Vault

# Enable only for production
variable "key_vault_enable_purge_protection" {
description = "Prevents purging the key vault and its contents by soft deleting it. It will be deleted once the soft delete retention has passed."
type = bool
default = false
}

variable "key_vault_retention_days" {
description = "Retention period in days during which soft deleted secrets are kept"
type = number
default = 30
}

# GraphDB

variable "graphdb_version" {
Expand Down Expand Up @@ -139,14 +154,15 @@ variable "custom_graphdb_vm_user_data" {
# Storage account

variable "storage_account_tier" {
default = "Standard"
description = "Specify the performance and redundancy characteristics of the Azure Storage Account that you are creating"
type = string
default = "Standard"
}

variable "storage_account_replication_type" {
default = "LRS"
description = "Specify the data redundancy strategy for your Azure Storage Account"
type = string
default = "ZRS"
}

# Backup configurations
Expand Down
Loading