forked from cloudposse/bastion
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Dockerfile
154 lines (119 loc) · 3.54 KB
/
Dockerfile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
##
## Base builder image
##
FROM alpine:3.8 as builder
RUN apk --update add --virtual .build-deps build-base automake autoconf libtool git linux-pam-dev openssl-dev wget
##
## Duo builder image
##
FROM builder as duo-builder
ARG DUO_VERSION=1.10.5
RUN wget https://dl.duosecurity.com/duo_unix-${DUO_VERSION}.tar.gz && \
mkdir -p src && \
tar -zxf duo_unix-${DUO_VERSION}.tar.gz --strip-components=1 -C src
RUN cd src && \
./configure \
--with-pam \
--prefix=/dist/usr && \
make && \
make install
##
## Google Authenticator PAM module builder image
##
FROM builder as google-authenticator-libpam-builder
ARG AUTHENTICATOR_LIBPAM_VERSION=1.05
RUN git clone --branch ${AUTHENTICATOR_LIBPAM_VERSION} --single-branch https://github.com/google/google-authenticator-libpam src
RUN cd src && \
./bootstrap.sh && \
./configure \
--prefix=/dist && \
make && \
make install
##
## OpenSSH Portable builder image
##
FROM builder as openssh-portable-builder
ARG OPENSSH_VERSION=V_7_8_P1
RUN git clone --branch ${OPENSSH_VERSION} --single-branch https://github.com/openssh/openssh-portable src
COPY patches/ /patches/
RUN cd src && \
find ../patches/openssh/** -type f -exec patch -p1 -i {} \; && \
autoreconf && \
./configure \
--prefix=/dist/usr \
--sysconfdir=/etc/ssh \
--datadir=/dist/usr/share/openssh \
--libexecdir=/dist/usr/lib/ssh \
--mandir=/dist/usr/share/man \
--with-pid-dir=/run \
--with-mantype=man \
--with-privsep-path=/var/empty \
--with-privsep-user=sshd \
--with-md5-passwords \
--with-ssl-engine \
--disable-wtmp \
--with-pam && \
make && \
make install
##
## Bastion image
##
FROM alpine:3.8
LABEL maintainer="erik@cloudposse.com"
USER root
## Install dependencies
RUN apk --update add curl drill groff util-linux bash xauth gettext openssl-dev shadow sudo && \
rm -rf /etc/ssh/ssh_host_*_key* && \
rm -f /usr/bin/ssh-agent && \
rm -f /usr/bin/ssh-keyscan && \
touch /var/log/lastlog && \
mkdir -p /var/run/sshd && \
mv /etc/profile.d/color_prompt /etc/profile.d/color_prompt.sh
## Install sudosh
ENV SUDOSH_VERSION=0.1.3
RUN wget https://github.com/cloudposse/sudosh/releases/download/${SUDOSH_VERSION}/sudosh_linux_386 -O /usr/bin/sudosh && \
chmod 755 /usr/bin/sudosh
## Install Duo
COPY --from=duo-builder dist/ /
## Install Google Authenticator PAM module
COPY --from=google-authenticator-libpam-builder dist/ /
## Install OpenSSH Portable
COPY --from=openssh-portable-builder dist/ /
## System
ENV TIMEZONE="Etc/UTC" \
TERM="xterm" \
HOSTNAME="bastion"
ENV MFA_PROVIDER="duo"
ENV UMASK="0022"
## Duo
ENV DUO_IKEY="" \
DUO_SKEY="" \
DUO_HOST="" \
DUO_FAILMODE="secure" \
DUO_AUTOPUSH="yes" \
DUO_PROMPTS="1"
## Enforcer
ENV ENFORCER_ENABLED="true" \
ENFORCER_CLEAN_HOME_ENABLED="true"
## Enable Rate Limiting
ENV RATE_LIMIT_ENABLED="true"
## Tolerate 5 consecutive fairues
ENV RATE_LIMIT_MAX_FAILURES="5"
## Lock accounts out for 300 seconds (5 minutes) after repeated failures
ENV RATE_LIMIT_LOCKOUT_TIME="300"
## Sleep N microseconds between failed attempts
ENV RATE_LIMIT_FAIL_DELAY="3000000"
## Slack
ENV SLACK_ENABLED="false" \
SLACK_HOOK="sshrc" \
SLACK_WEBHOOK_URL="" \
SLACK_USERNAME="" \
SLACK_TIMEOUT="2" \
SLACK_FATAL_ERRORS="true"
## SSH
ENV SSH_AUDIT_ENABLED="true" \
SSH_AUTHORIZED_KEYS_COMMAND="none" \
SSH_AUTHORIZED_KEYS_COMMAND_USER="nobody"
ADD rootfs/ /
EXPOSE 22
ENTRYPOINT ["/init"]