Skip to content

Commit 93afa93

Browse files
authored
change confd to hbs for unified docker templates (#2434)
* change confd to hbs tool * use new repo owner
1 parent 0795545 commit 93afa93

File tree

7 files changed

+64
-74
lines changed

7 files changed

+64
-74
lines changed

docker-unified/Dockerfile

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,7 @@ RUN apk add --update-cache \
214214
su-exec \
215215
supervisor \
216216
tzdata \
217+
unzip \
217218
&& rm -rf /var/cache/apk/*
218219

219220
# Create non-root user to run app
@@ -261,18 +262,18 @@ COPY docker-unified/nginx/logrotate.sh /
261262
RUN chmod +x /logrotate.sh
262263

263264
# Copy configuration templates
264-
COPY docker-unified/confd/nginx-config.toml /etc/confd/conf.d/
265-
COPY docker-unified/confd/nginx-config.conf.tmpl /etc/confd/templates/
266-
COPY docker-unified/confd/app-id.toml /etc/confd/conf.d/
267-
COPY docker-unified/confd/app-id.conf.tmpl /etc/confd/templates/
268-
269-
# Download confd tool for generating final configurations
270-
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ] ; then curl -L --output confd.tar.gz https://github.com/abtreece/confd/releases/download/v0.19.1/confd-v0.19.1-linux-amd64.tar.gz; fi
271-
RUN if [ "$TARGETPLATFORM" = "linux/arm/v7" ] ; then curl -L --output confd.tar.gz https://github.com/abtreece/confd/releases/download/v0.19.1/confd-v0.19.1-linux-arm7.tar.gz; fi
272-
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ] ; then curl -L --output confd.tar.gz https://github.com/abtreece/confd/releases/download/v0.19.1/confd-v0.19.1-linux-arm64.tar.gz; fi
273-
274-
# Extract confd
275-
RUN tar -xvzo -C /usr/local/bin -f confd.tar.gz && rm confd.tar.gz
265+
COPY docker-unified/hbs/nginx-config.hbs /etc/hbs/
266+
COPY docker-unified/hbs/app-id.hbs /etc/hbs/
267+
COPY docker-unified/hbs/config.yaml /etc/hbs/
268+
269+
# Download hbs tool for generating final configurations
270+
RUN if [ "$TARGETPLATFORM" = "linux/amd64" ] ; then curl -L --output hbs.zip https://github.com/bitwarden/Handlebars.conf/releases/download/v1.2.0/hbs_linux-musl-x64_dotnet.zip; fi
271+
RUN if [ "$TARGETPLATFORM" = "linux/arm/v7" ] ; then curl -L --output hbs.zip https://github.com/bitwarden/Handlebars.conf/releases/download/v1.2.0/hbs_linux-arm_dotnet.zip; fi
272+
RUN if [ "$TARGETPLATFORM" = "linux/arm64" ] ; then curl -L --output hbs.zip https://github.com/bitwarden/Handlebars.conf/releases/download/v1.2.0/hbs_linux-arm64_dotnet.zip; fi
273+
274+
# Extract hbs
275+
RUN unzip hbs.zip -d /usr/local/bin && rm hbs.zip
276+
RUN chmod +x /usr/local/bin/hbs
276277

277278
# Copy entrypoint script and make it executable
278279
COPY docker-unified/entrypoint.sh /entrypoint.sh

docker-unified/confd/app-id.toml

Lines changed: 0 additions & 6 deletions
This file was deleted.

docker-unified/confd/nginx-config.toml

Lines changed: 0 additions & 17 deletions
This file was deleted.

docker-unified/entrypoint.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fi
6666
# Launch a loop to rotate nginx logs on a daily basis
6767
/bin/sh -c "/logrotate.sh loop >/dev/null 2>&1 &"
6868

69-
/usr/local/bin/confd -onetime -backend env
69+
/usr/local/bin/hbs
7070

7171
# Enable/Disable services
7272
sed -i "s/autostart=true/autostart=${BW_ENABLE_ADMIN}/" /etc/supervisor.d/admin.ini

docker-unified/confd/app-id.conf.tmpl renamed to docker-unified/hbs/app-id.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"minor": 0
77
},
88
"ids": [
9-
"{{ getenv "globalSettings__baseServiceUri__vault" "https://localhost" }}",
9+
"{{{String.Coalesce env.globalSettings__baseServiceUri__vault "https://localhost"}}}",
1010
"ios:bundle-id:com.8bit.bitwarden",
1111
"android:apk-key-hash:dUGFzUzf3lmHSLBDBIv+WaFyZMI"
1212
]

docker-unified/hbs/config.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
helper_categories:
2+
- String
3+
templates:
4+
- src: /etc/hbs/app-id.hbs
5+
dest: /app/Web/app-id.json
6+
- src: /etc/hbs/nginx-config.hbs
7+
dest: /etc/nginx/http.d/bitwarden.conf
Lines changed: 42 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,63 @@
11
server {
22
listen 80 default_server;
33
#listen [::]:80 default_server;
4-
server_name {{ getenv "BW_DOMAIN" "localhost" }};
5-
{{ if eq (getenv "BW_ENABLE_SSL") "true" }}
4+
server_name {{{String.Coalesce env.BW_DOMAIN "localhost"}}};
5+
{{#if (String.Equal env.BW_ENABLE_SSL "true")}}
66

7-
return 301 https://{{ getenv "BW_DOMAIN" "localhost" }}$request_uri;
7+
return 301 https://{{{String.Coalesce env.BW_DOMAIN "localhost"}}}$request_uri;
88
}
99

1010
server {
1111
listen 443 ssl http2;
1212
#listen [::]:443 ssl http2;
13-
server_name {{ getenv "BW_DOMAIN" "localhost" }};
13+
server_name {{{String.Coalesce env.BW_DOMAIN "localhost"}}};
1414

15-
ssl_certificate /etc/bitwarden/{{ getenv "BW_SSL_CERT" "ssl.crt" }};
16-
ssl_certificate_key /etc/bitwarden/{{ getenv "BW_SSL_KEY" "ssl.key" }};
15+
ssl_certificate /etc/bitwarden/{{{String.Coalesce env.BW_SSL_CERT "ssl.crt"}}};
16+
ssl_certificate_key /etc/bitwarden/{{{String.Coalesce env.BW_SSL_KEY "ssl.key"}}};
1717
ssl_session_timeout 30m;
1818
ssl_session_cache shared:SSL:20m;
1919
ssl_session_tickets off;
20+
{{#if (String.Equal env.BW_ENABLE_SSL_DH "true")}}
2021

21-
ssl_protocols {{ getenv "BW_SSL_PROTOCOLS" "TLSv1.2" }};
22-
ssl_ciphers "{{ getenv "BW_SSL_CIPHERS" "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256" }}";
22+
# Diffie-Hellman parameter for DHE ciphersuites, recommended 2048 bits
23+
ssl_dhparam /etc/bitwarden/{{{String.Coalesce env.BW_SSL_DH_CERT "dh.pem"}}};
24+
{{/if}}
25+
26+
ssl_protocols {{{String.Coalesce env.BW_SSL_PROTOCOLS "TLSv1.2"}}};
27+
ssl_ciphers "{{{String.Coalesce env.BW_SSL_CIPHERS "ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA256"}}}";
2328
# Enables server-side protection from BEAST attacks
2429
ssl_prefer_server_ciphers on;
25-
{{ if eq (getenv "BW_ENABLE_SSL_CA") "true" }}
30+
{{#if (String.Equal env.BW_ENABLE_SSL_CA "true")}}
2631

2732
# OCSP Stapling ---
2833
# Fetch OCSP records from URL in ssl_certificate and cache them
2934
ssl_stapling on;
3035
ssl_stapling_verify on;
3136

3237
# Verify chain of trust of OCSP response using Root CA and Intermediate certs
33-
ssl_trusted_certificate /etc/bitwarden/{{ getenv "BW_SSL_CA_CERT" "ca.crt" }};
38+
ssl_trusted_certificate /etc/bitwarden/{{{String.Coalesce env.BW_SSL_CA_CERT "ca.crt"}}};
3439
resolver 1.1.1.1 1.0.0.1 9.9.9.9 149.112.112.112 valid=300s;
35-
{{ end }}
40+
{{/if}}
3641

3742
include /etc/nginx/security-headers-ssl.conf;
38-
{{ end }}
43+
{{/if}}
3944
include /etc/nginx/security-headers.conf;
40-
{{ if getenv "BW_REAL_IPS" }}
45+
{{#if (String.IsNotNullOrWhitespace env.BW_REAL_IPS)}}
4146

42-
{{ range (getenv "BW_REAL_IPS") }}
43-
set_real_ip_from {{ .Key }};
44-
{{ end }}
47+
{{#each (String.Split env.BW_REAL_IPS ",")}}
48+
set_real_ip_from {{{String.Trim .}}};
49+
{{/each}}
4550
real_ip_header X-Forwarded-For;
4651
real_ip_recursive on;
47-
{{ end }}
52+
{{/if}}
4853

4954
location / {
5055
root /app/Web;
51-
{{ if eq (getenv "BW_ENABLE_SSL") "true" }}
56+
{{#if (String.Equal env.BW_ENABLE_SSL "true")}}
5257
include /etc/nginx/security-headers-ssl.conf;
53-
{{ end }}
58+
{{/if}}
5459
include /etc/nginx/security-headers.conf;
55-
add_header Content-Security-Policy "{{ getenv "BW_CSP" "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://haveibeenpwned.com https://www.gravatar.com; child-src 'self' https://*.duosecurity.com https://*.duofederal.com; frame-src 'self' https://*.duosecurity.com https://*.duofederal.com; connect-src 'self' https://api.pwnedpasswords.com https://2fa.directory; object-src 'self' blob:;" }}";
60+
add_header Content-Security-Policy "{{{String.Coalesce env.BW_CSP "default-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https://haveibeenpwned.com https://www.gravatar.com; child-src 'self' https://*.duosecurity.com https://*.duofederal.com; frame-src 'self' https://*.duosecurity.com https://*.duofederal.com; connect-src 'self' https://api.pwnedpasswords.com https://2fa.directory; object-src 'self' blob:;"}}}";
5661
add_header X-Frame-Options SAMEORIGIN;
5762
add_header X-Robots-Tag "noindex, nofollow";
5863
}
@@ -64,9 +69,9 @@ server {
6469

6570
location = /app-id.json {
6671
root /app/Web;
67-
{{ if eq (getenv "BW_ENABLE_SSL") "true" }}
72+
{{#if (String.Equal env.BW_ENABLE_SSL "true")}}
6873
include /etc/nginx/security-headers-ssl.conf;
69-
{{ end }}
74+
{{/if}}
7075
include /etc/nginx/security-headers.conf;
7176
proxy_hide_header Content-Type;
7277
add_header Content-Type $fido_content_type;
@@ -81,14 +86,14 @@ server {
8186
}
8287

8388
location /icons/ {
84-
{{ if eq (getenv "BW_ICONS_PROXY_TO_CLOUD") "true" }}
89+
{{#if (String.Equal env.BW_ICONS_PROXY_TO_CLOUD "true")}}
8590
proxy_pass https://icons.bitwarden.net/;
8691
proxy_set_header Host icons.bitwarden.net;
8792
proxy_set_header X-Forwarded-For $remote_addr;
8893
proxy_ssl_server_name on;
89-
{{ else }}
94+
{{else}}
9095
proxy_pass http://localhost:5004/;
91-
{{ end }}
96+
{{/if}}
9297
}
9398

9499
location /notifications/ {
@@ -107,38 +112,38 @@ server {
107112

108113
location /sso {
109114
proxy_pass http://localhost:5007;
110-
{{ if eq (getenv "BW_ENABLE_SSL") "true" }}
115+
{{#if (String.Equal env.BW_ENABLE_SSL "true")}}
111116
include /etc/nginx/security-headers-ssl.conf;
112-
{{ end }}
117+
{{/if}}
113118
include /etc/nginx/security-headers.conf;
114119
add_header X-Frame-Options SAMEORIGIN;
115120
}
116121

117122
location /identity {
118123
proxy_pass http://localhost:5005;
119-
{{ if eq (getenv "BW_ENABLE_SSL") "true" }}
124+
{{#if (String.Equal env.BW_ENABLE_SSL "true")}}
120125
include /etc/nginx/security-headers-ssl.conf;
121-
{{ end }}
126+
{{/if}}
122127
include /etc/nginx/security-headers.conf;
123128
add_header X-Frame-Options SAMEORIGIN;
124129
}
125130

126131
location /admin {
127132
proxy_pass http://localhost:5000;
128-
{{ if eq (getenv "BW_ENABLE_SSL") "true" }}
133+
{{#if (String.Equal env.BW_ENABLE_SSL "true")}}
129134
include /etc/nginx/security-headers-ssl.conf;
130-
{{ end }}
135+
{{/if}}
131136
include /etc/nginx/security-headers.conf;
132137
add_header X-Frame-Options SAMEORIGIN;
133138
}
134139

135-
{{ if eq (getenv "BW_ENABLE_KEY_CONNECTOR") "true" }}
136-
location /key-connector/ {
137-
proxy_pass {{ getenv "BW_KEY_CONNECTOR_INTERNAL_URL"}}/;
138-
}
139-
{{ end }}
140-
141140
location /scim/ {
142141
proxy_pass http://localhost:5002/;
143142
}
143+
{{#if (String.Equal env.BW_ENABLE_KEY_CONNECTOR "true")}}
144+
145+
location /key-connector/ {
146+
proxy_pass {{{env.BW_KEY_CONNECTOR_INTERNAL_URL}}}/;
147+
}
148+
{{/if}}
144149
}

0 commit comments

Comments
 (0)