Skip to content

Commit

Permalink
增加[可选]OS安全加固脚本
Browse files Browse the repository at this point in the history
  • Loading branch information
gjmzj committed May 19, 2018
1 parent a0d3ac6 commit 58ccd3b
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 80 deletions.
5 changes: 5 additions & 0 deletions 01.prepare.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# [可选]操作系统安全加固 https://github.com/dev-sec/ansible-os-hardening
- hosts: all
roles:
- { role: os-harden, when: "OS_HARDEN is defined and OS_HARDEN == 'yes'" }

# 在deploy节点生成CA相关证书,以及kubedns.yaml配置文件
- hosts: deploy
roles:
Expand Down
1 change: 1 addition & 0 deletions 11.harbor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- hosts: harbor
roles:
- { role: os-harden, when: "OS_HARDEN is defined and OS_HARDEN == 'yes'" }
- prepare
- docker
- harbor
Expand Down
1 change: 1 addition & 0 deletions 20.addnode.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
- hosts: new-node
roles:
- { role: os-harden, when: "OS_HARDEN is defined and OS_HARDEN == 'yes'" }
- prepare
- docker
- kube-node
Expand Down
1 change: 1 addition & 0 deletions 21.addmaster.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

- hosts: new-master
roles:
- { role: os-harden, when: "OS_HARDEN is defined and OS_HARDEN == 'yes'" }
- prepare
- docker
- kube-master
Expand Down
5 changes: 5 additions & 0 deletions 90.setup.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# [可选]操作系统安全加固 https://github.com/dev-sec/ansible-os-hardening
- hosts: all
roles:
- { role: os-harden, when: "OS_HARDEN is defined and OS_HARDEN == 'yes'" }

# 在deploy节点生成CA相关证书,以供整个集群使用
# 以及初始化kubedns.yaml配置文件
- hosts: deploy
Expand Down
3 changes: 3 additions & 0 deletions example/hosts.allinone.example
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ BASIC_AUTH_USER="admin"
BASIC_AUTH_PASS="test1234"

# ---------附加参数--------------------
#是否对操作系统进行安全加固 "yes"/"no"
OS_HARDEN="no"

#默认二进制文件目录
bin_dir="/opt/kube/bin"

Expand Down
3 changes: 3 additions & 0 deletions example/hosts.m-masters.example
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ BASIC_AUTH_USER="admin"
BASIC_AUTH_PASS="test1234"

# ---------附加参数--------------------
#是否对操作系统进行安全加固 "yes"/"no"
OS_HARDEN="no"

#默认二进制文件目录
bin_dir="/opt/kube/bin"

Expand Down
3 changes: 3 additions & 0 deletions example/hosts.s-master.example
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ BASIC_AUTH_USER="admin"
BASIC_AUTH_PASS="test1234"

# ---------附加参数--------------------
#是否对操作系统进行安全加固 "yes"/"no"
OS_HARDEN="no"

#默认二进制文件目录
bin_dir="/opt/kube/bin"

Expand Down
4 changes: 0 additions & 4 deletions os-harden.yml

This file was deleted.

7 changes: 2 additions & 5 deletions roles/kube-node/tasks/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,19 +53,16 @@
copy: src=/etc/kubernetes/kube-proxy.kubeconfig dest=/etc/kubernetes/kube-proxy.kubeconfig

- name: 创建kube-proxy 服务文件
tags: reload-kube-proxy
tags: reload-kube-proxy, upgrade_k8s
template: src=kube-proxy.service.j2 dest=/etc/systemd/system/kube-proxy.service
tags: upgrade_k8s

- name: 开机启用kube-proxy 服务
shell: systemctl enable kube-proxy
ignore_errors: true

- name: 开启kube-proxy 服务
shell: systemctl daemon-reload && systemctl restart kube-proxy
tags:
- reload-kube-proxy
- upgrade_k8s
tags: reload-kube-proxy, upgrade_k8s

# 批准 node 节点,首先轮询等待kubelet启动完成
- name: 轮询等待kubelet启动
Expand Down
70 changes: 0 additions & 70 deletions roles/os-harden/default.yml

This file was deleted.

2 changes: 1 addition & 1 deletion roles/os-harden/defaults/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ ufw_ipt_modules: 'nf_conntrack_ftp nf_nat_ftp nf_conntrack_netbios_ns'

sysctl_config:
# Disable IPv4 traffic forwarding. | sysctl-01
net.ipv4.ip_forward: 0
net.ipv4.ip_forward: 1

# Disable IPv6 traffic forwarding. | sysctl-19
net.ipv6.conf.all.forwarding: 0
Expand Down
7 changes: 7 additions & 0 deletions roles/os-harden/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
---
- name: 缓存ansilbe setup信息
setup: gather_subset=all

- name: apt更新缓存刷新
apt: update_cache=yes cache_valid_time=72000
when: ansible_os_family == 'Debian'

- name: Set OS family dependent variables
include_vars: '{{ ansible_os_family }}.yml'
tags: always
Expand Down

0 comments on commit 58ccd3b

Please sign in to comment.