forked from italia/spid-shibboleth-proxy-docker
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsystem-integration.sh
183 lines (165 loc) · 6.18 KB
/
system-integration.sh
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/bin/bash
# Copyright 2018 AgID - Agenzia per l'Italia Digitale
#
# Licensed under the EUPL, Version 1.2 or - as soon they will be approved by
# the European Commission - subsequent versions of the EUPL (the "Licence").
#
# You may not use this work except in compliance with the Licence.
#
# You may obtain a copy of the Licence at:
#
# https://joinup.ec.europa.eu/software/page/eupl
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the Licence is distributed on an "AS IS" basis, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# Licence for the specific language governing permissions and limitations
# under the Licence.
_INSTALL_DIR=${INSTALL_DIR:-"/opt/authproxy"}
if [ ! -d "${_INSTALL_DIR}/spid-auth-docker" ]; then
cat<<EOF
ERROR: INSTALL_DIR must be set to the path where
https://github.com/italia/spid-auth-docker has been
cloned.
For instance, ff you cloned the repository under
"/tmp/spid-auth-docker", INSTALL_DIR must be set
to "/tmp".
EOF
exit 1
fi
_SERVER_NAME=${SERVER_NAME:-"my.auth.proxy.it"}
_ENTITY_ID=${ENTITY_ID:-"https://my.auth.proxy.it"}
_TARGET_BACKEND=${TARGET_BACKEND:-"http://backend_app:8080"}
_TARGET_LOCATION=${TARGET_LOCATION:-"/login"}
_ORGANIZATION=${ORGANIZATION:-"A Company Making Everything"}
_MODE=${MODE:-"dev"}
LOG_DIR="${_INSTALL_DIR}/log"
CERT_DIR="${_INSTALL_DIR}/certs"
LOGROTATE_DIR="${_INSTALL_DIR}/etc/logrotate.d"
SYSTEMD_DIR="${_INSTALL_DIR}/lib/systemd/system"
# create log dirs
mkdir -vp ${LOG_DIR}/{httpd,shibboleth,shibboleth-www}
# create cert dirs
mkdir -vp ${CERT_DIR}/{saml,tls}
# create system dirs
mkdir -vp ${LOGROTATE_DIR} ${SYSTEMD_DIR}
#
# generate docker compose file
#
cat > ${_INSTALL_DIR}/docker-compose.yml <<EOF
version: '3'
services:
authproxy:
image: spid-auth-proxy
restart: always
build:
context: ${_INSTALL_DIR}/spid-auth-docker
dockerfile: Dockerfile
args:
http_proxy: ${http_proxy}
https_proxy: ${https_proxy}
ports:
- '80:80'
- '443:443'
volumes:
- '${CERT_DIR}/saml:/opt/shibboleth-sp/certs'
- '${CERT_DIR}/tls/server.crt:/etc/pki/tls/certs/server.crt:ro'
- '${CERT_DIR}/tls/server.key:/etc/pki/tls/private/server.key:ro'
- '${LOG_DIR}:/var/log'
environment:
MODE: '${_MODE}'
ORGANIZATION: '${_ORGANIZATION}'
SERVER_NAME: '${_SERVER_NAME}'
ENTITY_ID: '${_ENTITY_ID}'
TARGET_BACKEND: '${_TARGET_BACKEND}'
TARGET_LOCATION: '${_TARGET_LOCATION}'
SPID_ACS: |
<md:AttributeConsumingService index="0">
<md:ServiceName xml:lang="it">all SPID attributes</md:ServiceName>
<md:RequestedAttribute Name="address" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
<md:RequestedAttribute Name="companyName" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
<md:RequestedAttribute Name="countyOfBirth" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
<md:RequestedAttribute Name="dateOfBirth" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
<md:RequestedAttribute Name="digitalAddress" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
<md:RequestedAttribute Name="email" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
<md:RequestedAttribute Name="expirationDate" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
<md:RequestedAttribute Name="familyName" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
<md:RequestedAttribute Name="fiscalNumber" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
<md:RequestedAttribute Name="gender" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
<md:RequestedAttribute Name="idCard" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
<md:RequestedAttribute Name="ivaCode" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
<md:RequestedAttribute Name="mobilePhone" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
<md:RequestedAttribute Name="name" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
<md:RequestedAttribute Name="placeOfBirth" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
<md:RequestedAttribute Name="registeredOffice" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
<md:RequestedAttribute Name="spidCode" NameFormat="urn:oasis:names:tc:SAML:2.0:attrname-format:basic"/>
</md:AttributeConsumingService>
networks:
- authproxy
depends_on:
- backend_app
backend_app:
build:
context: ${_INSTALL_DIR}/spid-auth-docker/example
dockerfile: Dockerfile
args:
http_proxy: ${http_proxy}
https_proxy: ${https_proxy}
environment:
SERVER_NAME: ${_SERVER_NAME}
networks:
- authproxy
networks:
authproxy:
driver_opts:
com.docker.network.driver.mtu: 1500
EOF
#
# generate systemd unit file
#
cat > ${SYSTEMD_DIR}/spid-auth-proxy.service <<EOF
[Unit]
Description=SPID Authentication Proxy
Requires=docker.service
After=docker.service
[Service]
Restart=always
WorkingDirectory=${_INSTALL_DIR}
# stop and remove existing containers
ExecStartPre=/usr/local/bin/docker-compose stop
ExecStartPre=/usr/local/bin/docker-compose rm -f
# start
ExecStart=/usr/local/bin/docker-compose up --build
# stop
ExecStop=/usr/local/bin/docker-compose stop
[Install]
WantedBy=multi-user.target
EOF
cat <<EOF
Run the following command to enable the systemd unit file
cd /lib/systemd/system
sudo ln -s ${SYSTEMD_DIR}/spid-auth-proxy.service .
sudo systemctl enable spid-auth-proxy.service
EOF
#
# generate logrotate file
#
cat > ${LOGROTATE_DIR}/spid-auth-proxy <<EOF
${LOG_DIR}/httpd/*_log
${LOG_DIR}/shibboleth/*.log
${LOG_DIR}/shibboleth-www/*.log
{
rotate 4
weekly
missingok
notifempty
compress
delaycompress
sharedscripts
}
EOF
cat <<EOF
Run the following command to enable the logrotate configuration
cd /etc/logrotate.d
sudo ln -s ${LOGROTATE_DIR}/spid-auth-proxy .
EOF