DEV Community

丁久
丁久

Posted on • Originally published at dingjiu1989-hue.github.io

Secure Configuration Management

This article was originally published on AI Study Room. For the full version with working code examples and related articles, visit the original post.

Secure Configuration Management

Secure Configuration Management

Secure Configuration Management

Secure Configuration Management

Secure Configuration Management

Secure Configuration Management

Secure Configuration Management

Secure Configuration Management

Secure Configuration Management

Introduction

Configuration drift — when actual system configuration diverges from the intended secure baseline — is a leading cause of security incidents. Secure configuration management ensures that systems remain in a known, compliant state throughout their lifecycle. This requires automation at every stage: validation at build time, enforcement at deploy time, and detection at runtime.

Infrastructure as Code Scanning

IaC scanning catches misconfigurations before they reach production.

Checkov: scan Terraform for security issues

checkov -d terraform/environments/production

tfsec: Terraform security scanner

tfsec terraform/environments/production --config-file tfsec.yaml

kics: Keep Infrastructure as Code Secure

kics scan -p kubernetes/deployments --output-path kics-report.json

checkov policy: S3 bucket must have encryption enabled

resource "aws_s3_bucket" "data" {

bucket = "my-data-bucket"

This will fail checkov check CKV_AWS_21

Missing: server_side_encryption_configuration

}

Custom Checkov policy

from checkov.common.models.enums import CheckResult

from checkov.terraform.checks.resource.base_resource_check import BaseResourceCheck

class S3EncryptionCheck(BaseResourceCheck):

def init(self):

name = "Ensure S3 bucket has encryption enabled"

id = "CKV_CUSTOM_001"

supported_resources = ['aws_s3_bucket']

super().init(name=name, id=id, supported_resources=supported_resources)

def scan_resource_conf(self, conf):

if 'server_side_encryption_configuration' in conf:

return CheckResult.PASSED

return CheckResult.FAILED

Drift Detection

Drift detection identifies when live infrastructure differs from the declared configuration.

Terraform plan detects drift

terraform plan -refresh-only # Check for manual changes

Terraform drift detection with AWS Config

resource "aws_config_config_rule" "s3_bucket_ssl" {

name = "s3-bucket-ssl-requests-only"

source {


Read the full article on AI Study Room for complete code examples, comparison tables, and related resources.

Found this useful? Check out more developer guides and tool comparisons on AI Study Room.

Top comments (0)