Skip to content

Commit f8f8841

Browse files
authored
Merge pull request #3 from PatternAtlas/feature/read-only
Read-only user
2 parents 47dad7d + cadd359 commit f8f8841

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

Dockerfile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ ENV POSTGRES_PASSWORD postgres
1111
ENV POSTGRES_USER postgres
1212
ENV JDBC_DATABASE_PORT 5060
1313
ENV POSTGRES_DB db
14+
ENV READ_ONLY false
1415

1516
# install dependencies (git)
1617
RUN apt-get update \
@@ -22,8 +23,12 @@ RUN apt-get update \
2223
EXPOSE 5060
2324

2425
COPY clone-data-repo.sh clone-data-repo.sh
26+
COPY create-read-only-user.sh create-read-only-user.sh
27+
2528

2629
# if ssh key is set, clone data repo with the sql scripts for initalization and start postgres afterwards
2730
CMD chmod 700 clone-data-repo.sh \
2831
&& ./clone-data-repo.sh \
32+
&& chmod 700 create-read-only-user.sh \
33+
&& ./create-read-only-user.sh \
2934
&& su postgres -c "/usr/local/bin/docker-entrypoint.sh postgres -p ${JDBC_DATABASE_PORT}"

create-read-only-user.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/bash
2+
if [ "$READ_ONLY" = true ] ; then
3+
4+
echo "Create SQL script for read-only-user"
5+
6+
user_name="$POSTGRES_USER"
7+
user_name+="_read"
8+
cat >./99-read-only-user.sql <<EOL
9+
CREATE ROLE readaccess;
10+
GRANT CONNECT ON DATABASE $POSTGRES_DB TO readaccess;
11+
GRANT USAGE ON SCHEMA public TO readaccess;
12+
GRANT SELECT ON ALL TABLES IN SCHEMA public TO readaccess;
13+
CREATE USER $user_name WITH PASSWORD '$POSTGRES_PASSWORD';
14+
GRANT readaccess TO $user_name;
15+
EOL
16+
17+
mv ./99-read-only-user.sql /docker-entrypoint-initdb.d/
18+
19+
fi

0 commit comments

Comments
 (0)