mirror of https://github.com/k3s-io/k3s
cluster/gce: Add env var to enable apiserver basic audit log.
For now, this is focused on a fixed set of flags that makes the audit log show up under /var/log/kube-apiserver-audit.log and behave similarly to /var/log/kube-apiserver.log. Allowing other customization would require significantly more complex changes. Audit log rotation is handled externally by the wildcard /var/log/*.log already configured in configure-helper.sh.pull/6/head
parent
da8f68e013
commit
7500746e7f
|
@ -663,6 +663,7 @@ MULTIZONE: $(yaml-quote ${MULTIZONE:-})
|
||||||
NON_MASQUERADE_CIDR: $(yaml-quote ${NON_MASQUERADE_CIDR:-})
|
NON_MASQUERADE_CIDR: $(yaml-quote ${NON_MASQUERADE_CIDR:-})
|
||||||
KUBE_UID: $(yaml-quote ${KUBE_UID:-})
|
KUBE_UID: $(yaml-quote ${KUBE_UID:-})
|
||||||
ENABLE_DEFAULT_STORAGE_CLASS: $(yaml-quote ${ENABLE_DEFAULT_STORAGE_CLASS:-})
|
ENABLE_DEFAULT_STORAGE_CLASS: $(yaml-quote ${ENABLE_DEFAULT_STORAGE_CLASS:-})
|
||||||
|
ENABLE_APISERVER_BASIC_AUDIT: $(yaml-quote ${ENABLE_APISERVER_BASIC_AUDIT:-})
|
||||||
EOF
|
EOF
|
||||||
if [ -n "${KUBELET_PORT:-}" ]; then
|
if [ -n "${KUBELET_PORT:-}" ]; then
|
||||||
cat >>$file <<EOF
|
cat >>$file <<EOF
|
||||||
|
|
|
@ -760,6 +760,7 @@ function remove-salt-config-comments {
|
||||||
function start-kube-apiserver {
|
function start-kube-apiserver {
|
||||||
echo "Start kubernetes api-server"
|
echo "Start kubernetes api-server"
|
||||||
prepare-log-file /var/log/kube-apiserver.log
|
prepare-log-file /var/log/kube-apiserver.log
|
||||||
|
prepare-log-file /var/log/kube-apiserver-audit.log
|
||||||
|
|
||||||
# Calculate variables and assemble the command line.
|
# Calculate variables and assemble the command line.
|
||||||
local params="${API_SERVER_TEST_LOG_LEVEL:-"--v=2"} ${APISERVER_TEST_ARGS:-} ${CLOUD_CONFIG_OPT}"
|
local params="${API_SERVER_TEST_LOG_LEVEL:-"--v=2"} ${APISERVER_TEST_ARGS:-} ${CLOUD_CONFIG_OPT}"
|
||||||
|
@ -799,6 +800,21 @@ function start-kube-apiserver {
|
||||||
params+=" --etcd-quorum-read=${ETCD_QUORUM_READ}"
|
params+=" --etcd-quorum-read=${ETCD_QUORUM_READ}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "${ENABLE_APISERVER_BASIC_AUDIT:-}" == "true" ]]; then
|
||||||
|
# We currently only support enabling with a fixed path and with built-in log
|
||||||
|
# rotation "disabled" (large value) so it behaves like kube-apiserver.log.
|
||||||
|
# External log rotation should be set up the same as for kube-apiserver.log.
|
||||||
|
params+=" --audit-log-path=/var/log/kube-apiserver-audit.log"
|
||||||
|
params+=" --audit-log-maxage=0"
|
||||||
|
params+=" --audit-log-maxbackup=0"
|
||||||
|
# Lumberjack doesn't offer any way to disable size-based rotation. It also
|
||||||
|
# has an in-memory counter that doesn't notice if you truncate the file.
|
||||||
|
# 2000000000 (in MiB) is a large number that fits in 31 bits. If the log
|
||||||
|
# grows at 10MiB/s (~30K QPS), it will rotate after ~6 years if apiserver
|
||||||
|
# never restarts. Please manually restart apiserver before this time.
|
||||||
|
params+=" --audit-log-maxsize=2000000000"
|
||||||
|
fi
|
||||||
|
|
||||||
local admission_controller_config_mount=""
|
local admission_controller_config_mount=""
|
||||||
local admission_controller_config_volume=""
|
local admission_controller_config_volume=""
|
||||||
local image_policy_webhook_config_mount=""
|
local image_policy_webhook_config_mount=""
|
||||||
|
|
|
@ -817,6 +817,7 @@ function remove-salt-config-comments {
|
||||||
function start-kube-apiserver {
|
function start-kube-apiserver {
|
||||||
echo "Start kubernetes api-server"
|
echo "Start kubernetes api-server"
|
||||||
prepare-log-file /var/log/kube-apiserver.log
|
prepare-log-file /var/log/kube-apiserver.log
|
||||||
|
prepare-log-file /var/log/kube-apiserver-audit.log
|
||||||
|
|
||||||
# Calculate variables and assemble the command line.
|
# Calculate variables and assemble the command line.
|
||||||
local params="${API_SERVER_TEST_LOG_LEVEL:-"--v=2"} ${APISERVER_TEST_ARGS:-} ${CLOUD_CONFIG_OPT}"
|
local params="${API_SERVER_TEST_LOG_LEVEL:-"--v=2"} ${APISERVER_TEST_ARGS:-} ${CLOUD_CONFIG_OPT}"
|
||||||
|
@ -860,6 +861,21 @@ function start-kube-apiserver {
|
||||||
params+=" --etcd-quorum-read=${ETCD_QUORUM_READ}"
|
params+=" --etcd-quorum-read=${ETCD_QUORUM_READ}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "${ENABLE_APISERVER_BASIC_AUDIT:-}" == "true" ]]; then
|
||||||
|
# We currently only support enabling with a fixed path and with built-in log
|
||||||
|
# rotation "disabled" (large value) so it behaves like kube-apiserver.log.
|
||||||
|
# External log rotation should be set up the same as for kube-apiserver.log.
|
||||||
|
params+=" --audit-log-path=/var/log/kube-apiserver-audit.log"
|
||||||
|
params+=" --audit-log-maxage=0"
|
||||||
|
params+=" --audit-log-maxbackup=0"
|
||||||
|
# Lumberjack doesn't offer any way to disable size-based rotation. It also
|
||||||
|
# has an in-memory counter that doesn't notice if you truncate the file.
|
||||||
|
# 2000000000 (in MiB) is a large number that fits in 31 bits. If the log
|
||||||
|
# grows at 10MiB/s (~30K QPS), it will rotate after ~6 years if apiserver
|
||||||
|
# never restarts. Please manually restart apiserver before this time.
|
||||||
|
params+=" --audit-log-maxsize=2000000000"
|
||||||
|
fi
|
||||||
|
|
||||||
local admission_controller_config_mount=""
|
local admission_controller_config_mount=""
|
||||||
local admission_controller_config_volume=""
|
local admission_controller_config_volume=""
|
||||||
local image_policy_webhook_config_mount=""
|
local image_policy_webhook_config_mount=""
|
||||||
|
|
|
@ -573,6 +573,7 @@ remove_salt_config_comments() {
|
||||||
# DOCKER_REGISTRY
|
# DOCKER_REGISTRY
|
||||||
start_kube_apiserver() {
|
start_kube_apiserver() {
|
||||||
prepare_log_file /var/log/kube-apiserver.log
|
prepare_log_file /var/log/kube-apiserver.log
|
||||||
|
prepare_log_file /var/log/kube-apiserver-audit.log
|
||||||
# Load the docker image from file.
|
# Load the docker image from file.
|
||||||
echo "Try to load docker image file kube-apiserver.tar"
|
echo "Try to load docker image file kube-apiserver.tar"
|
||||||
timeout 30 docker load -i /home/kubernetes/kube-docker-files/kube-apiserver.tar
|
timeout 30 docker load -i /home/kubernetes/kube-docker-files/kube-apiserver.tar
|
||||||
|
@ -612,6 +613,21 @@ start_kube_apiserver() {
|
||||||
params="${params} --etcd-quorum-read=${ETCD_QUORUM_READ}"
|
params="${params} --etcd-quorum-read=${ETCD_QUORUM_READ}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
if [[ "${ENABLE_APISERVER_BASIC_AUDIT:-}" == "true" ]]; then
|
||||||
|
# We currently only support enabling with a fixed path and with built-in log
|
||||||
|
# rotation "disabled" (large value) so it behaves like kube-apiserver.log.
|
||||||
|
# External log rotation should be set up the same as for kube-apiserver.log.
|
||||||
|
params="${params} --audit-log-path=/var/log/kube-apiserver-audit.log"
|
||||||
|
params="${params} --audit-log-maxage=0"
|
||||||
|
params="${params} --audit-log-maxbackup=0"
|
||||||
|
# Lumberjack doesn't offer any way to disable size-based rotation. It also
|
||||||
|
# has an in-memory counter that doesn't notice if you truncate the file.
|
||||||
|
# 2000000000 (in MiB) is a large number that fits in 31 bits. If the log
|
||||||
|
# grows at 10MiB/s (~30K QPS), it will rotate after ~6 years if apiserver
|
||||||
|
# never restarts. Please manually restart apiserver before this time.
|
||||||
|
params="${params} --audit-log-maxsize=2000000000"
|
||||||
|
fi
|
||||||
|
|
||||||
local admission_controller_config_mount=""
|
local admission_controller_config_mount=""
|
||||||
local admission_controller_config_volume=""
|
local admission_controller_config_volume=""
|
||||||
local image_policy_webhook_config_mount=""
|
local image_policy_webhook_config_mount=""
|
||||||
|
|
|
@ -31,6 +31,12 @@
|
||||||
- group: root
|
- group: root
|
||||||
- mode: 644
|
- mode: 644
|
||||||
|
|
||||||
|
/var/log/kube-apiserver-audit.log:
|
||||||
|
file.managed:
|
||||||
|
- user: root
|
||||||
|
- group: root
|
||||||
|
- mode: 644
|
||||||
|
|
||||||
# Copy kube-apiserver manifest to manifests folder for kubelet.
|
# Copy kube-apiserver manifest to manifests folder for kubelet.
|
||||||
# Current containervm image by default has both docker and kubelet
|
# Current containervm image by default has both docker and kubelet
|
||||||
# running. But during cluster creation stage, docker and kubelet
|
# running. But during cluster creation stage, docker and kubelet
|
||||||
|
|
|
@ -170,7 +170,12 @@
|
||||||
{% set etcd_quorum_read = "--etcd_quorum_read=" + pillar['etcd_quorum_read'] -%}
|
{% set etcd_quorum_read = "--etcd_quorum_read=" + pillar['etcd_quorum_read'] -%}
|
||||||
{% endif -%}
|
{% endif -%}
|
||||||
|
|
||||||
{% set params = address + " " + storage_backend + " " + etcd_servers + " " + etcd_servers_overrides + " " + cloud_provider + " " + cloud_config + " " + runtime_config + " " + feature_gates + " " + admission_control + " " + max_requests_inflight + " " + target_ram_mb + " " + service_cluster_ip_range + " " + client_ca_file + basic_auth_file + " " + min_request_timeout + " " + enable_garbage_collector + " " + etcd_quorum_read -%}
|
{% set audit_log = "" -%}
|
||||||
|
{% if pillar['enable_apiserver_basic_audit'] is defined and pillar['enable_apiserver_basic_audit'] in ['true'] -%}
|
||||||
|
{% set audit_log = "--audit-log-path=/var/log/kube-apiserver-audit.log --audit-log-maxage=0 --audit-log-maxbackup=0 --audit-log-maxsize=2000000000" -%}
|
||||||
|
{% endif -%}
|
||||||
|
|
||||||
|
{% set params = address + " " + storage_backend + " " + etcd_servers + " " + etcd_servers_overrides + " " + cloud_provider + " " + cloud_config + " " + runtime_config + " " + feature_gates + " " + admission_control + " " + max_requests_inflight + " " + target_ram_mb + " " + service_cluster_ip_range + " " + client_ca_file + basic_auth_file + " " + min_request_timeout + " " + enable_garbage_collector + " " + etcd_quorum_read + " " + audit_log -%}
|
||||||
{% set params = params + " " + cert_file + " " + key_file + " " + kubelet_cert_file + " " + kubelet_key_file + " --secure-port=" + secure_port + token_auth_file + " " + bind_address + " " + log_level + " " + advertise_address + " " + proxy_ssh_options + authz_mode + abac_policy_file + webhook_authentication_config + webhook_authorization_config + image_review_config -%}
|
{% set params = params + " " + cert_file + " " + key_file + " " + kubelet_cert_file + " " + kubelet_key_file + " --secure-port=" + secure_port + token_auth_file + " " + bind_address + " " + log_level + " " + advertise_address + " " + proxy_ssh_options + authz_mode + abac_policy_file + webhook_authentication_config + webhook_authorization_config + image_review_config -%}
|
||||||
|
|
||||||
# test_args has to be kept at the end, so they'll overwrite any prior configuration
|
# test_args has to be kept at the end, so they'll overwrite any prior configuration
|
||||||
|
@ -235,6 +240,9 @@
|
||||||
{ "name": "logfile",
|
{ "name": "logfile",
|
||||||
"mountPath": "/var/log/kube-apiserver.log",
|
"mountPath": "/var/log/kube-apiserver.log",
|
||||||
"readOnly": false},
|
"readOnly": false},
|
||||||
|
{ "name": "auditlogfile",
|
||||||
|
"mountPath": "/var/log/kube-apiserver-audit.log",
|
||||||
|
"readOnly": false},
|
||||||
{ "name": "etcssl",
|
{ "name": "etcssl",
|
||||||
"mountPath": "/etc/ssl",
|
"mountPath": "/etc/ssl",
|
||||||
"readOnly": true},
|
"readOnly": true},
|
||||||
|
@ -271,6 +279,10 @@
|
||||||
"hostPath": {
|
"hostPath": {
|
||||||
"path": "/var/log/kube-apiserver.log"}
|
"path": "/var/log/kube-apiserver.log"}
|
||||||
},
|
},
|
||||||
|
{ "name": "auditlogfile",
|
||||||
|
"hostPath": {
|
||||||
|
"path": "/var/log/kube-apiserver-audit.log"}
|
||||||
|
},
|
||||||
{ "name": "etcssl",
|
{ "name": "etcssl",
|
||||||
"hostPath": {
|
"hostPath": {
|
||||||
"path": "/etc/ssl"}
|
"path": "/etc/ssl"}
|
||||||
|
|
|
@ -2,7 +2,7 @@ logrotate:
|
||||||
pkg:
|
pkg:
|
||||||
- installed
|
- installed
|
||||||
|
|
||||||
{% set logrotate_files = ['kube-scheduler', 'kube-proxy', 'kubelet', 'kube-apiserver', 'kube-controller-manager', 'kube-addons', 'docker'] %}
|
{% set logrotate_files = ['kube-scheduler', 'kube-proxy', 'kubelet', 'kube-apiserver', 'kube-apiserver-audit', 'kube-controller-manager', 'kube-addons', 'docker'] %}
|
||||||
{% for file in logrotate_files %}
|
{% for file in logrotate_files %}
|
||||||
/etc/logrotate.d/{{ file }}:
|
/etc/logrotate.d/{{ file }}:
|
||||||
file:
|
file:
|
||||||
|
|
|
@ -63,7 +63,7 @@ cluster/saltbase/salt/cluster-autoscaler/cluster-autoscaler.manifest:{% set para
|
||||||
cluster/saltbase/salt/etcd/etcd.manifest: "value": "{{ pillar.get('storage_backend', 'etcd3') }}"
|
cluster/saltbase/salt/etcd/etcd.manifest: "value": "{{ pillar.get('storage_backend', 'etcd3') }}"
|
||||||
cluster/saltbase/salt/etcd/etcd.manifest:{% if pillar.get('storage_backend', 'etcd3') == 'etcd3' -%}
|
cluster/saltbase/salt/etcd/etcd.manifest:{% if pillar.get('storage_backend', 'etcd3') == 'etcd3' -%}
|
||||||
cluster/saltbase/salt/kube-admission-controls/init.sls:{% if 'LimitRanger' in pillar.get('admission_control', '') %}
|
cluster/saltbase/salt/kube-admission-controls/init.sls:{% if 'LimitRanger' in pillar.get('admission_control', '') %}
|
||||||
cluster/saltbase/salt/kube-apiserver/kube-apiserver.manifest:{% set params = address + " " + storage_backend + " " + etcd_servers + " " + etcd_servers_overrides + " " + cloud_provider + " " + cloud_config + " " + runtime_config + " " + feature_gates + " " + admission_control + " " + max_requests_inflight + " " + target_ram_mb + " " + service_cluster_ip_range + " " + client_ca_file + basic_auth_file + " " + min_request_timeout + " " + enable_garbage_collector + " " + etcd_quorum_read -%}
|
cluster/saltbase/salt/kube-apiserver/kube-apiserver.manifest:{% set params = address + " " + storage_backend + " " + etcd_servers + " " + etcd_servers_overrides + " " + cloud_provider + " " + cloud_config + " " + runtime_config + " " + feature_gates + " " + admission_control + " " + max_requests_inflight + " " + target_ram_mb + " " + service_cluster_ip_range + " " + client_ca_file + basic_auth_file + " " + min_request_timeout + " " + enable_garbage_collector + " " + etcd_quorum_read + " " + audit_log -%}
|
||||||
cluster/saltbase/salt/kube-controller-manager/kube-controller-manager.manifest:{% if pillar.get('enable_hostpath_provisioner', '').lower() == 'true' -%}
|
cluster/saltbase/salt/kube-controller-manager/kube-controller-manager.manifest:{% if pillar.get('enable_hostpath_provisioner', '').lower() == 'true' -%}
|
||||||
cluster/saltbase/salt/kube-controller-manager/kube-controller-manager.manifest:{% set params = "--master=127.0.0.1:8080" + " " + cluster_name + " " + cluster_cidr + " " + allocate_node_cidrs + " " + service_cluster_ip_range + " " + terminated_pod_gc + " " + enable_garbage_collector + " " + cloud_provider + " " + cloud_config + " " + service_account_key + " " + log_level + " " + root_ca_file -%}
|
cluster/saltbase/salt/kube-controller-manager/kube-controller-manager.manifest:{% set params = "--master=127.0.0.1:8080" + " " + cluster_name + " " + cluster_cidr + " " + allocate_node_cidrs + " " + service_cluster_ip_range + " " + terminated_pod_gc + " " + enable_garbage_collector + " " + cloud_provider + " " + cloud_config + " " + service_account_key + " " + log_level + " " + root_ca_file -%}
|
||||||
cluster/saltbase/salt/kube-controller-manager/kube-controller-manager.manifest:{% set params = params + " " + feature_gates -%}
|
cluster/saltbase/salt/kube-controller-manager/kube-controller-manager.manifest:{% set params = params + " " + feature_gates -%}
|
||||||
|
|
Loading…
Reference in New Issue