Fix bug 1709 - Adding non-root user to run Keystone
[osm/devops.git] / docker / Keystone / Dockerfile
1 #######################################################################################
2 # Copyright ETSI Contributors and Others.
3 #
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7 #
8 #    http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
13 # implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #######################################################################################
17 FROM ubuntu:20.04
18
19 ARG APT_PROXY
20 RUN if [ ! -z $APT_PROXY ] ; then \
21     echo "Acquire::http::Proxy \"$APT_PROXY\";" > /etc/apt/apt.conf.d/proxy.conf ;\
22     echo "Acquire::https::Proxy \"$APT_PROXY\";" >> /etc/apt/apt.conf.d/proxy.conf ;\
23     fi
24
25 EXPOSE 5000
26
27 WORKDIR /app
28
29 COPY scripts/start.sh /app/start.sh
30
31 RUN DEBIAN_FRONTEND=noninteractive apt-get update && \
32     DEBIAN_FRONTEND=noninteractive apt-get upgrade -y && \
33     DEBIAN_FRONTEND=noninteractive apt-get autoremove -y && \
34     DEBIAN_FRONTEND=noninteractive apt-get install -y software-properties-common && \
35     add-apt-repository -y cloud-archive:victoria && \
36     DEBIAN_FRONTEND=noninteractive apt-get update && \
37     DEBIAN_FRONTEND=noninteractive apt-get dist-upgrade -y && \
38     DEBIAN_FRONTEND=noninteractive apt-get install -y \
39     apache2=2.4.* \
40     keystone=2:18.0.* \
41     libapache2-mod-wsgi-py3=4.6.* \
42     python3-pip=20.0.* \
43     build-essential=12.8* \
44     python3-dev=3.8.* \
45     libldap2-dev=2.4.* \
46     libsasl2-dev=2.1.* \
47     libssl-dev=1.1.* \
48     libffi-dev=3.3* \
49     libxml2-dev=2.9.* \
50     libxslt1-dev=1.1.* \
51     zlib1g-dev=1:1.2.* \
52     ldap-utils=2.4.* \
53     curl=7.68.* \
54     net-tools=1.60* \
55     mysql-client=8.0.* \
56     dnsutils=1:9.16.* && \
57     rm -rf /var/lib/apt/lists/* && \
58     chmod +x start.sh
59
60 RUN pip3 install -U pip==21.3.1 && \
61     pip3 install python-ldap==3.2.0 ldappool==3.0.0 python-openstackclient==5.7.0
62
63 # Creating the user for the app
64 RUN groupadd -g 1000 appuser && \
65     useradd -u 1000 -g 1000 -d /app appuser && \
66     usermod -a -G keystone appuser && \
67     usermod -a -G adm appuser && \
68     chown -R appuser:appuser /app && \
69     chown root:keystone /etc/keystone && \
70     chmod 770 /etc/keystone && \
71     chown root:keystone /etc/ssl/certs && \
72     chmod 770 /etc/ssl/certs && \
73     chown root:keystone /etc/apache2/apache2.conf && \
74     chmod 664 /etc/apache2/apache2.conf && \
75     sed -i 's/Listen 80/Listen 8080/g' /etc/apache2/ports.conf && \
76     chown root:keystone /var/spool && \
77     chmod 775 /var/spool && \
78     chmod 770 /var/log/apache2 && \
79     chmod 660 /var/log/apache2/* && \
80     chmod 770 /var/log/keystone && \
81     chown root:keystone /var/run/apache2 && \
82     chmod 775 /var/run/apache2 && \
83     mkdir -p /etc/sudoers.d && \
84     echo "%appuser ALL= NOPASSWD: /sbin/service apache2 *" > /etc/sudoers.d/appuser
85
86 USER appuser
87
88 # database
89 ENV DB_HOST                 keystone-db
90 ENV DB_PORT                 3306
91 ENV ROOT_DB_USER            root
92 ENV ROOT_DB_PASSWORD        admin
93 ENV KEYSTONE_DB_PASSWORD    admin
94 # keystone
95 ENV REGION_ID               RegionOne
96 ENV KEYSTONE_HOST           keystone
97 # admin user
98 ENV ADMIN_USERNAME          admin
99 ENV ADMIN_PASSWORD          admin
100 ENV ADMIN_PROJECT           admin
101 # nbi service user
102 ENV SERVICE_USERNAME        nbi
103 ENV SERVICE_PASSWORD        nbi
104 ENV SERVICE_PROJECT         service
105 # ldap
106 # ENV LDAP_AUTHENTICATION_DOMAIN_NAME     no default
107 # ENV LDAP_URL                            ldap://localhost
108 # ENV LDAP_BIND_USER                      no default
109 # ENV LDAP_BIND_PASSWORD                  no default
110 # ENV LDAP_CHASE_REFERRALS                no default
111 # ENV LDAP_PAGE_SIZE                      0
112 # ENV LDAP_USER_TREE_DN                   no default
113 # ENV LDAP_USER_OBJECTCLASS               inetOrgPerson
114 # ENV LDAP_USER_ID_ATTRIBUTE              cn
115 # ENV LDAP_USER_NAME_ATTRIBUTE            sn
116 # ENV LDAP_USER_PASS_ATTRIBUTE            userPassword
117 # ENV LDAP_USER_FILTER                    no default
118 # ENV LDAP_USER_ENABLED_ATTRIBUTE         enabled
119 # ENV LDAP_USER_ENABLED_MASK              0
120 # ENV LDAP_USER_ENABLED_DEFAULT           true
121 # ENV LDAP_USER_ENABLED_INVERT            false
122 # ENV LDAP_GROUP_OBJECTCLASS              groupOfNames
123 # ENV LDAP_GROUP_TREE_DN                  no default
124 # ENV LDAP_USE_STARTTLS                   false
125 # ENV LDAP_TLS_CACERT_BASE64              no default
126 # ENV LDAP_TLS_REQ_CERT                   demand
127
128 ENTRYPOINT ["./start.sh"]