Skip to content

Commit

Permalink
Merge pull request apache#16842 from [BEAM-13932][Playground] Contain…
Browse files Browse the repository at this point in the history
…er's user privileges

* [BEAM-13932][Playground]
Change Dockerfiles

* [BEAM-13932][Playground]
Update proxy and permissions for the container's user

* [BEAM-13932][Playground]
Update permissions for the container's user for scio
  • Loading branch information
Aydar Zainutdinov authored and nancyxu123 committed Mar 9, 2022
1 parent 37f571a commit 346d2e2
Show file tree
Hide file tree
Showing 17 changed files with 68 additions and 137 deletions.
12 changes: 6 additions & 6 deletions playground/backend/containers/go/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ ENV HTTP_PROXY="http://127.0.0.1:8081"
ENV HTTPS_PROXY="http://127.0.0.1:8081"

COPY entrypoint.sh /
COPY proxy.sh /
# Run proxy
RUN sh /proxy.sh

# Create a user group `appgroup` and a user `appuser`
RUN groupadd --gid 20000 appgroup \
&& useradd --uid 20000 --gid appgroup --shell /bin/bash --create-home appuser
# Chown all the files to the app user.
RUN chown -R appuser:appgroup /opt/playground/backend/ && chown -R appuser:appgroup /opt/playground/prepared_folder/ \
&& chmod +x /entrypoint.sh

RUN mkdir -p /opt/playground/backend/executable_files/

# Chown all required files to the `appuser`.
RUN chown -R appuser:appgroup /opt/playground/backend/executable_files/ \
&& chmod -R 777 /usr/local/share/ca-certificates/extra/ && chmod -R 777 /etc/ssl/certs && chmod +x /entrypoint.sh

# Switch to appuser
USER appuser
Expand Down
4 changes: 0 additions & 4 deletions playground/backend/containers/go/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ task copyDockerfileDependencies(type: Copy) {
from 'entrypoint.sh'
into 'build/'
}
copy {
from 'proxy.sh'
into 'build/'
}
copy {
from '../../../infrastructure/proxy/allow_list.py'
into 'build/'
Expand Down
9 changes: 9 additions & 0 deletions playground/backend/containers/go/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

nohup /opt/mitmproxy/mitmdump -s /opt/mitmproxy/allow_list_proxy.py -p 8081 &
while [ ! -f /home/appuser/.mitmproxy/mitmproxy-ca.pem ] ;
do
sleep 2
done
openssl x509 -in /home/appuser/.mitmproxy/mitmproxy-ca.pem -inform PEM -out /home/appuser/.mitmproxy/mitmproxy-ca.crt
cp /home/appuser/.mitmproxy/mitmproxy-ca.crt /usr/local/share/ca-certificates/extra/
update-ca-certificates

/opt/playground/backend/server_go_backend
24 changes: 0 additions & 24 deletions playground/backend/containers/go/proxy.sh

This file was deleted.

13 changes: 7 additions & 6 deletions playground/backend/containers/java/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -88,16 +88,17 @@ ENV HTTP_PROXY="http://127.0.0.1:8081"
ENV HTTPS_PROXY="http://127.0.0.1:8081"

COPY entrypoint.sh /
COPY proxy.sh /
# Run proxy
RUN sh /proxy.sh

# Create a user group `appgroup` and a user `appuser`
RUN groupadd --gid 20000 appgroup \
&& useradd --uid 20000 --gid appgroup --shell /bin/bash --create-home appuser
# Chown all the files to the app user.
RUN chown -R appuser:appgroup /opt/playground/backend/ && chown -R appuser:appgroup /opt/apache/beam/jars/ \
&& chmod +x /entrypoint.sh

RUN mkdir -p /opt/playground/backend/executable_files/

# Chown all required files to the `appuser`.
RUN chown -R appuser:appgroup /opt/playground/backend/executable_files/ && chmod -R 775 /opt/apache/beam/jars/ \
&& chmod -R 777 /usr/local/share/ca-certificates/extra/ && chmod -R 777 /usr/local/openjdk-8/jre/lib/security/ \
&& chmod -R 777 /etc/ssl/certs && chmod +x /entrypoint.sh

# Switch to appuser
USER appuser
Expand Down
4 changes: 0 additions & 4 deletions playground/backend/containers/java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ task copyDockerfileDependencies(type: Copy) {
from 'entrypoint.sh'
into 'build/'
}
copy {
from 'proxy.sh'
into 'build/'
}
copy {
from '../../../infrastructure/proxy/allow_list.py'
into 'build/'
Expand Down
9 changes: 9 additions & 0 deletions playground/backend/containers/java/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

nohup /opt/mitmproxy/mitmdump -s /opt/mitmproxy/allow_list_proxy.py -p 8081 &
while [ ! -f /home/appuser/.mitmproxy/mitmproxy-ca.pem ] ;
do
sleep 2
done
openssl x509 -in /home/appuser/.mitmproxy/mitmproxy-ca.pem -inform PEM -out /home/appuser/.mitmproxy/mitmproxy-ca.crt
cp /home/appuser/.mitmproxy/mitmproxy-ca.crt /usr/local/share/ca-certificates/extra/
update-ca-certificates

/opt/playground/backend/server_java_backend
24 changes: 0 additions & 24 deletions playground/backend/containers/java/proxy.sh

This file was deleted.

12 changes: 7 additions & 5 deletions playground/backend/containers/python/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ ENV HTTP_PROXY="http://127.0.0.1:8081"
ENV HTTPS_PROXY="http://127.0.0.1:8081"

COPY entrypoint.sh /
COPY proxy.sh /
# Run proxy
RUN sh /proxy.sh

# Create a user group `appgroup` and a user `appuser`
RUN groupadd --gid 20000 appgroup \
&& useradd --uid 20000 --gid appgroup --shell /bin/bash --create-home appuser
# Chown all the files to the app user.
RUN chown -R appuser:appgroup /opt/playground/backend/ && chmod +x /entrypoint.sh

RUN mkdir -p /opt/playground/backend/executable_files/

# Chown all required files to the `appuser`.
RUN chown -R appuser:appgroup /opt/playground/backend/executable_files/ \
&& chmod 777 /usr/local/lib/python3.7/site-packages/certifi/cacert.pem \
&& chmod -R 777 /usr/local/share/ca-certificates/extra/ && chmod -R 777 /etc/ssl/certs && chmod +x /entrypoint.sh

# Switch to appuser
USER appuser
Expand Down
4 changes: 0 additions & 4 deletions playground/backend/containers/python/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ task copyDockerfileDependencies(type: Copy) {
from 'entrypoint.sh'
into 'build/'
}
copy {
from 'proxy.sh'
into 'build/'
}
copy {
from '../../../infrastructure/proxy/allow_list.py'
into 'build/'
Expand Down
10 changes: 10 additions & 0 deletions playground/backend/containers/python/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,14 @@
# See the License for the specific language governing permissions and
# limitations under the License.

nohup /opt/mitmproxy/mitmdump -s /opt/mitmproxy/allow_list_proxy.py -p 8081 &
while [ ! -f /home/appuser/.mitmproxy/mitmproxy-ca.pem ] ;
do
sleep 2
done
openssl x509 -in /home/appuser/.mitmproxy/mitmproxy-ca.pem -inform PEM -out /home/appuser/.mitmproxy/mitmproxy-ca.crt
cp /home/appuser/.mitmproxy/mitmproxy-ca.crt /usr/local/share/ca-certificates/extra/
update-ca-certificates
cat /home/appuser/.mitmproxy/mitmproxy-ca.pem >> /usr/local/lib/python3.7/site-packages/certifi/cacert.pem

/opt/playground/backend/server_python_backend
25 changes: 0 additions & 25 deletions playground/backend/containers/python/proxy.sh

This file was deleted.

12 changes: 7 additions & 5 deletions playground/backend/containers/scio/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,17 @@ ENV HTTP_PROXY="http://127.0.0.1:8081"
ENV HTTPS_PROXY="http://127.0.0.1:8081"

COPY entrypoint.sh /
COPY proxy.sh /
# Run proxy
RUN sh /proxy.sh

# Create a user group `appgroup` and a user `appuser`
RUN groupadd --gid 20000 appgroup \
&& useradd --uid 20000 --gid appgroup --shell /bin/bash --create-home appuser
# Chown all the files to the app user.
RUN chown -R appuser:appgroup /opt/playground/backend/ && chmod +x /entrypoint.sh

RUN mkdir -p /opt/playground/backend/executable_files/

# Chown all required files to the `appuser`.
RUN chown -R appuser:appgroup /opt/playground/backend/executable_files/ \
&& chmod -R 777 /usr/local/share/ca-certificates/extra/ && chmod -R 777 /usr/local/openjdk-8/jre/lib/security/ \
&& chmod -R 777 /etc/ssl/certs && chmod +x /entrypoint.sh

# Switch to appuser
USER appuser
Expand Down
4 changes: 0 additions & 4 deletions playground/backend/containers/scio/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,6 @@ task copyDockerfileDependencies(type: Copy) {
from 'entrypoint.sh'
into 'build/'
}
copy {
from 'proxy.sh'
into 'build/'
}
copy {
from '../../../infrastructure/proxy/allow_list.py'
into 'build/'
Expand Down
9 changes: 9 additions & 0 deletions playground/backend/containers/scio/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,13 @@
# See the License for the specific language governing permissions and
# limitations under the License.

nohup /opt/mitmproxy/mitmdump -s /opt/mitmproxy/allow_list_proxy.py -p 8081 &
while [ ! -f /home/appuser/.mitmproxy/mitmproxy-ca.pem ] ;
do
sleep 2
done
openssl x509 -in /home/appuser/.mitmproxy/mitmproxy-ca.pem -inform PEM -out /home/appuser/.mitmproxy/mitmproxy-ca.crt
cp /home/appuser/.mitmproxy/mitmproxy-ca.crt /usr/local/share/ca-certificates/extra/
update-ca-certificates

/opt/playground/backend/server_scio_backend
24 changes: 0 additions & 24 deletions playground/backend/containers/scio/proxy.sh

This file was deleted.

6 changes: 4 additions & 2 deletions playground/infrastructure/proxy/allow_list_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,12 @@

def request(flow: http.HTTPFlow) -> None:
allowed_bucket = flow.request.pretty_host == GCS_HOST and \
flow.request.path.split("/")[1] in ALLOWED_BUCKET_LIST
(flow.request.path.split("/")[1] in ALLOWED_BUCKET_LIST or \
flow.request.path.split("/")[4] in ALLOWED_BUCKET_LIST)
allowed_host = flow.request.pretty_host in ALLOWED_LIST
if not (allowed_bucket or allowed_host):
flow.response = http.Response.make(
status_code=403,
content="Making requests to the hosts that are not listed "
"in the allowed list is forbidden.")
"in the allowed list is forbidden. "
"host:" + flow.request.pretty_host + ", path: " + flow.request.path)

0 comments on commit 346d2e2

Please sign in to comment.