Last active 1765808095

Revision 91f9008295d92b9de7f3d37577f7b821c3eadd92

StepCA.sh Raw
1#!/bin/sh
2
3set -e
4
5echo '----------Install StepCA!----------'
6apt-get update && apt-get install -y --no-install-recommends curl vim gpg ca-certificates jq
7
8curl -fsSL https://packages.smallstep.com/keys/apt/repo-signing-key.gpg -o /etc/apt/trusted.gpg.d/smallstep.asc && \
9 echo 'deb [signed-by=/etc/apt/trusted.gpg.d/smallstep.asc] https://packages.smallstep.com/stable/debian debs main' \
10 | tee /etc/apt/sources.list.d/smallstep.list
11
12apt-get update && apt-get -y install step-cli step-ca
13
14step ca init
15step ca provisioner add acme --type ACME
16mkdir /etc/step-ca
17mv $(step path)/* /etc/step-ca
18nano /etc/step-ca/password.txt
19cat <<< $(jq '.db.dataSource = "/etc/step-ca/db"' /etc/step-ca/config/ca.json) > /etc/step-ca/config/ca.json
20nano /etc/step-ca/config/defaults.json
21nano /etc/step-ca/config/ca.json
22
23useradd --user-group --system --home /etc/step-ca --shell /bin/false step
24setcap CAP_NET_BIND_SERVICE=+eip $(which step-ca)
25chown -R step:step /etc/step-ca
26
27
28cat <<EOF >>/etc/systemd/system/step-ca.service
29[Unit]
30Description=step-ca service
31Documentation=https://smallstep.com/docs/step-ca
32Documentation=https://smallstep.com/docs/step-ca/certificate-authority-server-production
33After=network-online.target
34Wants=network-online.target
35StartLimitIntervalSec=30
36StartLimitBurst=3
37ConditionFileNotEmpty=/etc/step-ca/config/ca.json
38ConditionFileNotEmpty=/etc/step-ca/password.txt
39
40[Service]
41Type=simple
42User=step
43Group=step
44Environment=STEPPATH=/etc/step-ca
45WorkingDirectory=/etc/step-ca
46ExecStart=/usr/bin/step-ca /etc/step-ca/config/ca.json --password-file password.txt
47ExecReload=/bin/kill --signal HUP $MAINPID
48Restart=on-failure
49RestartSec=5
50TimeoutStopSec=30
51StartLimitInterval=30
52StartLimitBurst=3
53
54; Process capabilities & privileges
55AmbientCapabilities=CAP_NET_BIND_SERVICE
56CapabilityBoundingSet=CAP_NET_BIND_SERVICE
57SecureBits=keep-caps
58NoNewPrivileges=yes
59
60; Sandboxing
61ProtectSystem=full
62ProtectHome=true
63RestrictNamespaces=true
64RestrictAddressFamilies=AF_UNIX AF_INET AF_INET6
65PrivateTmp=true
66PrivateDevices=true
67ProtectClock=true
68ProtectControlGroups=true
69ProtectKernelTunables=true
70ProtectKernelLogs=true
71ProtectKernelModules=true
72LockPersonality=true
73RestrictSUIDSGID=true
74RemoveIPC=true
75RestrictRealtime=true
76SystemCallFilter=@system-service
77SystemCallArchitectures=native
78MemoryDenyWriteExecute=true
79ReadWriteDirectories=/etc/step-ca/db
80
81[Install]
82WantedBy=multi-user.target
83EOF
84
85systemctl daemon-reload
86systemctl enable --now step-ca.service