Skip to content

Commit 538940a

Browse files
authored
feat: enable Kubernetes API server audit logs in the DA by default. [Learn more](https://cloud.ibm.com/docs/containers?topic=containers-health-audit#audit-api-server) (#719)
1 parent 56e8b79 commit 538940a

File tree

11 files changed

+145
-7
lines changed

11 files changed

+145
-7
lines changed

ibm_catalog.json

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,10 @@
5555
{
5656
"title": "Observability",
5757
"description": "This solution can leverage [Cloud automation for Observability](https://cloud.ibm.com/catalog/7a4d68b4-cf8b-40cd-a3d1-f49aff526eb3/architecture/deploy-arch-ibm-observability-a3137d28-79e0-479d-8a24-758ebd5a0eab-global) that supports configuring resources for logging, monitoring and activity tracker event routing (optional)."
58+
},
59+
{
60+
"title": "Kube Audit",
61+
"description": "Deploys the Kube Audit solution to monitor and log Kubernetes API server activity. It captures events such as user actions, configuration changes, and access attempts, helping meet security and compliance requirements through centralized [audit logging](https://cloud.ibm.com/docs/containers?topic=containers-health-audit#audit-api-server)."
5862
}
5963
],
6064
"support_details": "This product is in the community registry, as such support is handled through the originated repo. If you experience issues, please open an issue in the repository [here](https://github.com/terraform-ibm-modules/terraform-ibm-base-ocp-vpc/issues). Please note this product is not supported via the IBM Cloud Support Center.",
@@ -770,6 +774,34 @@
770774
}
771775
],
772776
"hidden": true
777+
},
778+
{
779+
"key":"enable_kube_audit"
780+
},
781+
{
782+
"key": "audit_deployment_name"
783+
},
784+
{
785+
"key": "audit_log_policy",
786+
"options": [
787+
{
788+
"displayname": "Default",
789+
"value": "default"
790+
},
791+
{
792+
"displayname": "Write Request Bodies",
793+
"value": "WriteRequestBodies"
794+
}
795+
]
796+
},
797+
{
798+
"key": "audit_namespace"
799+
},
800+
{
801+
"key": "audit_webhook_listener_image"
802+
},
803+
{
804+
"key": "audit_webhook_listener_image_tag_digest"
773805
}
774806
],
775807
"dependencies": [

modules/kube-audit/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ No modules.
8484
| <a name="input_audit_log_policy"></a> [audit\_log\_policy](#input\_audit\_log\_policy) | Specify the amount of information that is logged to the API server audit logs by choosing the audit log policy profile to use. Supported values are `default` and `WriteRequestBodies`. | `string` | `"default"` | no |
8585
| <a name="input_audit_namespace"></a> [audit\_namespace](#input\_audit\_namespace) | The name of the namespace where log collection service and a deployment will be created. | `string` | `"ibm-kube-audit"` | no |
8686
| <a name="input_audit_webhook_listener_image"></a> [audit\_webhook\_listener\_image](#input\_audit\_webhook\_listener\_image) | The audit webhook listener image reference in the format of `[registry-url]/[namespace]/[image]`.The sub-module uses the `icr.io/ibm/ibmcloud-kube-audit-to-ibm-cloud-logs` image to forward logs to IBM Cloud Logs. This image is for demonstration purposes only. For a production solution, configure and maintain your own log forwarding image. | `string` | `"icr.io/ibm/ibmcloud-kube-audit-to-ibm-cloud-logs"` | no |
87-
| <a name="input_audit_webhook_listener_image_version"></a> [audit\_webhook\_listener\_image\_version](#input\_audit\_webhook\_listener\_image\_version) | The tag or digest for the audit webhook listener image to deploy. If changing the value, ensure it is compatible with `audit_webhook_listener_image`. | `string` | `"deaabcb8225e800385413ba420cf3f819d3b0671@sha256:acf123f4dba63534cbc104c6886abedff9d25a22a34ab7b549ede988ed6e7144"` | no |
87+
| <a name="input_audit_webhook_listener_image_tag_digest"></a> [audit\_webhook\_listener\_image\_tag\_digest](#input\_audit\_webhook\_listener\_image\_tag\_digest) | The tag or digest for the audit webhook listener image to deploy. If changing the value, ensure it is compatible with `audit_webhook_listener_image`. | `string` | `"deaabcb8225e800385413ba420cf3f819d3b0671@sha256:acf123f4dba63534cbc104c6886abedff9d25a22a34ab7b549ede988ed6e7144"` | no |
8888
| <a name="input_cluster_config_endpoint_type"></a> [cluster\_config\_endpoint\_type](#input\_cluster\_config\_endpoint\_type) | Specify which type of endpoint to use for for cluster config access: 'default', 'private', 'vpe', 'link'. 'default' value will use the default endpoint of the cluster. | `string` | `"default"` | no |
8989
| <a name="input_cluster_id"></a> [cluster\_id](#input\_cluster\_id) | The ID of the cluster to deploy the log collection service in. | `string` | n/a | yes |
9090
| <a name="input_cluster_resource_group_id"></a> [cluster\_resource\_group\_id](#input\_cluster\_resource\_group\_id) | The resource group ID of the cluster. | `string` | n/a | yes |

modules/kube-audit/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ resource "helm_release" "kube_audit" {
6868
set {
6969
name = "image.tag"
7070
type = "string"
71-
value = var.audit_webhook_listener_image_version
71+
value = var.audit_webhook_listener_image_tag_digest
7272
}
7373

7474
provisioner "local-exec" {

modules/kube-audit/variables.tf

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,14 @@ variable "audit_webhook_listener_image" {
9191
default = "icr.io/ibm/ibmcloud-kube-audit-to-ibm-cloud-logs"
9292
}
9393

94-
variable "audit_webhook_listener_image_version" {
94+
variable "audit_webhook_listener_image_tag_digest" {
9595
type = string
9696
description = "The tag or digest for the audit webhook listener image to deploy. If changing the value, ensure it is compatible with `audit_webhook_listener_image`."
9797
nullable = false
98-
default = "deaabcb8225e800385413ba420cf3f819d3b0671@sha256:acf123f4dba63534cbc104c6886abedff9d25a22a34ab7b549ede988ed6e7144" # See, https://github.ibm.com/GoldenEye/issues/issues/13371
98+
default = "deaabcb8225e800385413ba420cf3f819d3b0671@sha256:acf123f4dba63534cbc104c6886abedff9d25a22a34ab7b549ede988ed6e7144"
99+
99100
validation {
100-
condition = can(regex("^[a-f0-9]{40}@sha256:[a-f0-9]{64}$", var.audit_webhook_listener_image_version))
101+
condition = can(regex("^[a-f0-9]{40}@sha256:[a-f0-9]{64}$", var.audit_webhook_listener_image_tag_digest))
101102
error_message = "The value of the audit webhook listener image version must match the tag and sha256 image digest format"
102103
}
103104
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# Ignore everything
2+
*
3+
4+
# But not these files...
5+
!.gitignore
6+
!README.md
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
This directory must exist in source control so the `ibm_container_cluster_config` data lookup can use it to place the
2+
config.yml used to connect to a kubernetes cluster.

solutions/fully-configurable/main.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,3 +284,28 @@ module "secret_group" {
284284
secret_group_description = "Secret group for storing ingress certificates for cluster ${var.cluster_name} with id: ${module.ocp_base.cluster_id}"
285285
endpoint_type = var.secrets_manager_endpoint_type
286286
}
287+
288+
data "ibm_container_cluster_config" "cluster_config" {
289+
count = var.enable_kube_audit ? 1 : 0
290+
cluster_name_id = module.ocp_base.cluster_id
291+
config_dir = "${path.module}/kubeconfig"
292+
admin = true
293+
resource_group_id = module.ocp_base.resource_group_id
294+
endpoint_type = var.cluster_config_endpoint_type != "default" ? var.cluster_config_endpoint_type : null
295+
}
296+
297+
module "kube_audit" {
298+
count = var.enable_kube_audit ? 1 : 0
299+
ibmcloud_api_key = var.ibmcloud_api_key
300+
source = "../../modules/kube-audit"
301+
cluster_id = module.ocp_base.cluster_id
302+
cluster_resource_group_id = module.ocp_base.resource_group_id
303+
region = module.ocp_base.region
304+
use_private_endpoint = var.use_private_endpoint
305+
cluster_config_endpoint_type = var.cluster_config_endpoint_type
306+
audit_log_policy = var.audit_log_policy
307+
audit_namespace = var.audit_namespace
308+
audit_deployment_name = var.audit_deployment_name
309+
audit_webhook_listener_image = var.audit_webhook_listener_image
310+
audit_webhook_listener_image_tag_digest = var.audit_webhook_listener_image_tag_digest
311+
}

solutions/fully-configurable/provider.tf

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,17 @@ provider "ibm" {
2424
visibility = var.provider_visibility
2525
private_endpoint_type = (var.provider_visibility == "private" && local.vpc_region == "ca-mon") ? "vpe" : null
2626
}
27+
28+
provider "helm" {
29+
kubernetes {
30+
host = data.ibm_container_cluster_config.cluster_config[0].host
31+
token = data.ibm_container_cluster_config.cluster_config[0].token
32+
cluster_ca_certificate = data.ibm_container_cluster_config.cluster_config[0].ca_certificate
33+
}
34+
}
35+
36+
provider "kubernetes" {
37+
host = data.ibm_container_cluster_config.cluster_config[0].host
38+
token = data.ibm_container_cluster_config.cluster_config[0].token
39+
cluster_ca_certificate = data.ibm_container_cluster_config.cluster_config[0].ca_certificate
40+
}

solutions/fully-configurable/variables.tf

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -556,3 +556,53 @@ variable "skip_ocp_secrets_manager_iam_auth_policy" {
556556
description = "To skip creating auth policy that allows OCP cluster 'Manager' role access in the existing Secrets Manager instance for managing ingress certificates."
557557
default = false
558558
}
559+
560+
##############################################################
561+
# Kube Audit
562+
##############################################################
563+
564+
variable "enable_kube_audit" {
565+
type = bool
566+
description = "Kubernetes audit logging provides a chronological record of operations performed on the cluster, including by users, administrators, and system components. It is useful for compliance, and security monitoring. Set true to enable kube audit by default. [Learn more](https://cloud.ibm.com/docs/containers?topic=containers-health-audit#audit-api-server)"
567+
default = true
568+
}
569+
570+
variable "audit_log_policy" {
571+
type = string
572+
description = "Specify the amount of information that is logged to the API server audit logs by choosing the audit log policy profile to use. Supported values are `default` and `WriteRequestBodies`."
573+
default = "default"
574+
575+
validation {
576+
error_message = "Invalid Audit log policy Type! Valid values are 'default' or 'WriteRequestBodies'"
577+
condition = contains(["default", "WriteRequestBodies"], var.audit_log_policy)
578+
}
579+
}
580+
581+
variable "audit_namespace" {
582+
type = string
583+
description = "The name of the namespace where log collection service and a deployment will be created."
584+
default = "ibm-kube-audit"
585+
}
586+
587+
variable "audit_deployment_name" {
588+
type = string
589+
description = "The name of log collection deployement and service."
590+
default = "ibmcloud-kube-audit"
591+
}
592+
593+
variable "audit_webhook_listener_image" {
594+
type = string
595+
description = "The audit webhook listener image reference in the format of `[registry-url]/[namespace]/[image]`. This solution uses the `icr.io/ibm/ibmcloud-kube-audit-to-ibm-cloud-logs` image to forward logs to IBM Cloud Logs. This image is for demonstration purposes only. For a production solution, configure and maintain your own log forwarding image."
596+
default = "icr.io/ibm/ibmcloud-kube-audit-to-ibm-cloud-logs"
597+
}
598+
599+
variable "audit_webhook_listener_image_tag_digest" {
600+
type = string
601+
description = "The tag or digest for the audit webhook listener image to deploy. If changing the value, ensure it is compatible with `audit_webhook_listener_image`."
602+
default = "deaabcb8225e800385413ba420cf3f819d3b0671@sha256:acf123f4dba63534cbc104c6886abedff9d25a22a34ab7b549ede988ed6e7144"
603+
604+
validation {
605+
condition = can(regex("^[a-f0-9]{40}@sha256:[a-f0-9]{64}$", var.audit_webhook_listener_image_tag_digest))
606+
error_message = "The value of the audit webhook listener image version must match the tag and sha256 image digest format"
607+
}
608+
}

solutions/fully-configurable/version.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,13 @@ terraform {
77
source = "IBM-Cloud/ibm"
88
version = "1.80.4"
99
}
10+
helm = {
11+
source = "hashicorp/helm"
12+
version = "2.17.0"
13+
}
14+
kubernetes = {
15+
source = "hashicorp/kubernetes"
16+
version = "2.37.1"
17+
}
1018
}
1119
}

0 commit comments

Comments
 (0)