Skip to content

Commit f7154a9

Browse files
committed
add Makefile build and deploy docker image for step-ca
1 parent 6c063d8 commit f7154a9

File tree

4 files changed

+332
-2
lines changed

4 files changed

+332
-2
lines changed

Makefile

+66-2
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Q=$(if $V,,@)
66
PREFIX?=
77
SRC=$(shell find . -type f -name '*.go' -not -path "./vendor/*")
88
GOOS_OVERRIDE ?=
9+
OUTPUT_ROOT=output/
910

1011
# Set shell to bash for `echo -e`
1112
SHELL := /bin/bash
@@ -152,6 +153,70 @@ uninstall:
152153

153154
.PHONY: install uninstall
154155

156+
#########################################
157+
# Building Docker Image
158+
#
159+
# Builds a dockerfile for step by building a linux version of the step-cli and
160+
# then copying the specific binary when building the container.
161+
#
162+
# This ensures the container is as small as possible without having to deal
163+
# with getting access to private repositories inside the container during build
164+
# time.
165+
#########################################
166+
167+
# XXX We put the output for the build in 'output' so we don't mess with how we
168+
# do rule overriding from the base Makefile (if you name it 'build' it messes up
169+
# the wildcarding).
170+
DOCKER_OUTPUT=$(OUTPUT_ROOT)docker/
171+
172+
DOCKER_MAKE=V=$V GOOS_OVERRIDE='GOOS=linux GOARCH=amd64' PREFIX=$(1) make $(1)bin/$(2)
173+
DOCKER_BUILD=$Q docker build -t smallstep/$(1):latest -f docker/$(2) --build-arg BINPATH=$(DOCKER_OUTPUT)bin/$(1) .
174+
175+
docker: docker-make docker/Dockerfile.step-ca
176+
$(call DOCKER_BUILD,step-ca,Dockerfile.step-ca)
177+
178+
docker-make:
179+
mkdir -p $(DOCKER_OUTPUT)
180+
$(call DOCKER_MAKE,$(DOCKER_OUTPUT),step-ca)
181+
182+
.PHONY: docker docker-make
183+
184+
#################################################
185+
# Releasing Docker Images
186+
#
187+
# Using the docker build infrastructure, this section is responsible for
188+
# logging into docker hub and pushing the built docker containers up with the
189+
# appropriate tags.
190+
#################################################
191+
192+
DOCKER_TAG=docker tag smallstep/$(1):latest smallstep/$(1):$(2)
193+
DOCKER_PUSH=docker push smallstep/$(1):$(2)
194+
195+
docker-tag:
196+
$(call DOCKER_TAG,step-ca,$(VERSION))
197+
198+
docker-push-tag: docker-tag
199+
$(call DOCKER_PUSH,step-ca,$(VERSION))
200+
201+
# Rely on DOCKER_USERNAME and DOCKER_PASSWORD being set inside the CI or
202+
# equivalent environment
203+
docker-login:
204+
$Q docker login -u="$(DOCKER_USERNAME)" -p="$(DOCKER_PASSWORD)"
205+
206+
.PHONY: docker-login docker-tag docker-push-tag
207+
208+
#################################################
209+
# Targets for pushing the docker images
210+
#################################################
211+
212+
# For all builds on the master branch, we actually build the container
213+
docker-master: docker
214+
215+
# For all builds on the master branch with an rc tag
216+
docker-release: docker-master docker-login docker-push-tag
217+
218+
.PHONY: docker-master docker-release
219+
155220
#########################################
156221
# Debian
157222
#########################################
@@ -177,7 +242,6 @@ distclean: clean
177242
# Build statically compiled step binary for various operating systems
178243
#################################################
179244

180-
OUTPUT_ROOT=output/
181245
BINARY_OUTPUT=$(OUTPUT_ROOT)binary/
182246
BUNDLE_MAKE=v=$v GOOS_OVERRIDE='GOOS=$(1) GOARCH=$(2)' PREFIX=$(3) make $(3)bin/$(BINNAME)
183247
RELEASE=./.travis-releases
@@ -234,7 +298,7 @@ artifacts-master:
234298
artifacts-release: artifacts-tag
235299

236300
# This command is called by travis directly *after* a successful build
237-
artifacts: artifacts-$(PUSHTYPE)
301+
artifacts: artifacts-$(PUSHTYPE) docker-$(PUSHTYPE)
238302

239303
.PHONY: artifacts-master artifacts-release artifacts
240304

docker/Dockerfile.step-ca

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
FROM smallstep/step-cli:0.0.2-rc.17
2+
3+
ARG BINPATH="bin/step-ca"
4+
5+
ENV PORT=9000
6+
ENV CONFIGPATH="/home/step/.step/config/ca.json"
7+
ENV PWDPATH="/home/step/secrets/password"
8+
9+
COPY $BINPATH "/usr/local/bin/step-ca"
10+
11+
EXPOSE $PORT
12+
VOLUME ["/home/step/.step/secrets"]
13+
VOLUME ["/home/step/.step/config"]
14+
VOLUME ["/home/step/secrets"]
15+
STOPSIGNAL SIGTERM
16+
17+
CMD exec /bin/sh -c "/usr/local/bin/step-ca --password-file $PWDPATH $CONFIGPATH"

docker/ca.json

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
{
2+
"root": "/home/step/.step/secrets/root_ca.crt",
3+
"crt": "/home/step/.step/secrets/intermediate_ca.crt",
4+
"key": "/home/step/.step/secrets/intermediate_ca_key",
5+
"address": ":9000",
6+
"dnsNames": [
7+
"ca.smallstep.com"
8+
],
9+
"logger": {
10+
"format": "text"
11+
},
12+
"authority": {
13+
"provisioners": [
14+
{
15+
"name": "mariano@smallstep.com",
16+
"type": "jwk",
17+
"key": {
18+
"use": "sig",
19+
"kty": "EC",
20+
"kid": "DmAtZt2EhmZr_iTJJ387fr4Md2NbzMXGdXQNW1UWPXk",
21+
"crv": "P-256",
22+
"alg": "ES256",
23+
"x": "jXoO1j4CXxoTC32pNzkVC8l6k2LfP0k5ndhJZmcdVbk",
24+
"y": "c3JDL4GTFxJWHa8EaHdMh4QgwMh64P2_AGWrD0ADXcI"
25+
},
26+
"encryptedKey": "eyJhbGciOiJQQkVTMi1IUzI1NitBMTI4S1ciLCJjdHkiOiJqd2sranNvbiIsImVuYyI6IkEyNTZHQ00iLCJwMmMiOjEwMDAwMCwicDJzIjoiOTFVWjdzRGw3RlNXcldfX1I1NUh3USJ9.FcWtrBDNgrkA33G9Ll9sXh1cPF-3jVXeYe1FLmSDc_Q2PmfLOPvJOA.0ZoN32ayaRWnufJb.WrkffMmDLWiq1-2kn-w7-kVBGW12gjNCBHNHB1hyEdED0rWH1YWpKd8FjoOACdJyLhSn4kAS3Lw5AH7fvO27A48zzvoxZU5EgSm5HG9IjkIH-LBJ-v79ShkpmPylchgjkFhxa5epD11OIK4rFmI7s-0BCjmJokLR_DZBhDMw2khGnsr_MEOfAz9UnqXaQ4MIy8eT52xUpx68gpWFlz2YP3EqiYyNEv0PpjMtyP5lO2i8-p8BqvuJdus9H3fO5Dg-1KVto1wuqh4BQ2JKTauv60QAnM_4sdxRHku3F_nV64SCrZfDvnN2ve21raFROtyXaqHZhN6lyoPxDncy8v4.biaOblEe0N-gMpJyFZ-3-A"
27+
}
28+
]
29+
},
30+
"tls": {
31+
"cipherSuites": [
32+
"TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305",
33+
"TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256"
34+
],
35+
"minVersion": 1.2,
36+
"maxVersion": 1.2,
37+
"renegotiation": false
38+
}
39+
}

docker/k8s

+210
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
#!/bin/sh
2+
3+
CA_NAME="ca"
4+
CA_NAMESPACE="step"
5+
DEMO_NAMESPACE="step-demo"
6+
DEMO_ENVIRONMENT="staging"
7+
8+
9+
# The name of an image pull secret (e.g., for private docker hub images)
10+
# Set to "none" for no pull secret.
11+
IMAGE_PULL_SECRET="none"
12+
13+
while getopts "c:d:n:e:h:t:p:i:" opt; do
14+
case "$opt" in
15+
h)
16+
show_help
17+
exit 0
18+
;;
19+
c)
20+
CA_NAMESPACE=$OPTARG
21+
;;
22+
n)
23+
CA_NAME=$OPTARG
24+
;;
25+
e)
26+
DEMO_ENVIRONMENT=$OPTARG
27+
;;
28+
d)
29+
DEMO_NAMESPACE=$OPTARG
30+
;;
31+
t)
32+
INSTALL_TYPE=$OPTARG
33+
;;
34+
p)
35+
PROVISIONER_TYPE=$OPTARG
36+
;;
37+
i)
38+
IMAGE_PULL_SECRET=$OPTARG
39+
;;
40+
esac
41+
done
42+
43+
shift $((OPTIND-1))
44+
45+
46+
# Various container images used throughout the script.
47+
STEP_CA_IMAGE="localhost:5000/smallstep/step-ca:latest"
48+
49+
DIR=`pwd`
50+
PKI="$(dirname "$DIR")/pki"
51+
SECRETS="$PKI/secrets"
52+
53+
##
54+
# Certificate Authority installation (prints yaml to stdout).
55+
##
56+
install_ca()
57+
{
58+
read -p "CA Private Key Password: " -s password
59+
(>&2 echo "")
60+
61+
tmp=$(mktemp -d /tmp/step.XXXXXX)
62+
(
63+
cd "$tmp"
64+
65+
# Bundle up certificates and private key into ConfigMap
66+
mkdir $tmp/certificates
67+
cp $SECRETS/root_ca.crt $tmp/certificates
68+
cp $SECRETS/intermediate_ca.crt $tmp/certificates/
69+
cp $SECRETS/intermediate_ca_key $tmp/certificates/
70+
71+
# ConfigMap for CA configuration
72+
mkdir $tmp/config
73+
cp $DIR/ca.json $tmp/config/ca.json
74+
75+
# Create the namespace
76+
echo "---" > $tmp/step-ca.yml
77+
echo "apiVersion: v1" >> $tmp/step-ca.yml
78+
echo "kind: Namespace" >> $tmp/step-ca.yml
79+
echo "metadata:" >> $tmp/step-ca.yml
80+
echo " name: $CA_NAMESPACE" >> $tmp/step-ca.yml
81+
echo "---" >> $tmp/step-ca.yml
82+
83+
# Create certificates configmap
84+
echo "apiVersion: v1" >> $tmp/step-ca.yml
85+
echo "kind: ConfigMap" >> $tmp/step-ca.yml
86+
kubectl create configmap ca-certificates -n $CA_NAMESPACE --from-file `pwd`/certificates --dry-run -o yaml >> $tmp/step-ca.yml
87+
echo "" >> $tmp/step-ca.yml
88+
echo "---" >> $tmp/step-ca.yml
89+
90+
# Create a CA configuration configmap
91+
echo "" >> $tmp/step-ca.yml
92+
echo "apiVersion: v1" >> $tmp/step-ca.yml
93+
echo "kind: ConfigMap" >> $tmp/step-ca.yml
94+
kubectl create configmap ca-config -n $CA_NAMESPACE --from-file `pwd`/config --dry-run -o yaml >> $tmp/step-ca.yml
95+
echo "" >> $tmp/step-ca.yml
96+
echo "---" >> $tmp/step-ca.yml
97+
98+
# Create a secret with the CA password in it
99+
echo "" >> $tmp/step-ca.yml
100+
echo "apiVersion: v1" >> $tmp/step-ca.yml
101+
echo "kind: Secret" >> $tmp/step-ca.yml
102+
kubectl create secret generic ca-certificate-password -n $CA_NAMESPACE --from-literal=password="$password" --dry-run -o yaml >> $tmp/step-ca.yml
103+
)
104+
105+
echo "" >> $tmp/step-ca.yml
106+
echo "---" >> $tmp/step-ca.yml
107+
echo "" >> $tmp/step-ca.yml
108+
109+
cat <<EOF >> $tmp/step-ca.yml
110+
apiVersion: v1
111+
kind: Service
112+
metadata:
113+
labels:
114+
service: $CA_NAME
115+
name: $CA_NAME
116+
namespace: $CA_NAMESPACE
117+
spec:
118+
type: ClusterIP
119+
ports:
120+
- name: headless
121+
port: 443
122+
targetPort: 9000
123+
selector:
124+
service: $CA_NAME
125+
126+
---
127+
128+
apiVersion: policy/v1beta1
129+
kind: PodDisruptionBudget
130+
metadata:
131+
name: $CA_NAME
132+
spec:
133+
minAvailable: 1
134+
selector:
135+
matchLabels:
136+
service: $CA_NAME
137+
138+
---
139+
140+
apiVersion: extensions/v1beta1
141+
kind: Deployment
142+
metadata:
143+
name: $CA_NAME
144+
namespace: $CA_NAMESPACE
145+
spec:
146+
replicas: 1
147+
strategy:
148+
rollingUpdate:
149+
maxSurge: 25%
150+
maxUnavailable: 25%
151+
type: RollingUpdate
152+
template:
153+
metadata:
154+
creationTimestamp: null
155+
labels:
156+
service: $CA_NAME
157+
spec:
158+
containers:
159+
- name: $CA_NAME
160+
image: $STEP_CA_IMAGE
161+
resources:
162+
requests:
163+
cpu: 100m
164+
memory: 20Mi
165+
readinessProbe:
166+
httpGet:
167+
path: /health
168+
port: 443
169+
scheme: HTTPS
170+
initialDelaySeconds: 3
171+
periodSeconds: 3
172+
livenessProbe:
173+
httpGet:
174+
path: /health
175+
port: 443
176+
scheme: HTTPS
177+
initialDelaySeconds: 5
178+
periodSeconds: 3
179+
volumeMounts:
180+
- name: certificates
181+
mountPath: /home/step/.step/secrets
182+
readOnly: true
183+
- name: config
184+
mountPath: /home/step/.step/config
185+
readOnly: true
186+
- name: secrets
187+
mountPath: /home/step/secrets
188+
readOnly: true
189+
securityContext:
190+
runAsUser: 1000
191+
allowPrivilegeEscalation: false
192+
volumes:
193+
- name: certificates
194+
configMap:
195+
name: ca-certificates
196+
- name: config
197+
configMap:
198+
name: ca-config
199+
- name: secrets
200+
secret:
201+
secretName: ca-certificate-password
202+
EOF
203+
204+
cat $tmp/step-ca.yml
205+
206+
rm -rf "$tmp"
207+
208+
}
209+
210+
install_ca

0 commit comments

Comments
 (0)