AAF non-root 89/103789/11
authorChrisC <christophe.closset@intl.att.com>
Tue, 17 Mar 2020 13:23:42 +0000 (14:23 +0100)
committerChrisC <christophe.closset@intl.att.com>
Tue, 24 Mar 2020 12:37:37 +0000 (13:37 +0100)
update AAF service dockerfiles to run as user AAF, reusing existing script infra

Issue-ID: AAF-1102
Signed-off-by: ChrisC <christophe.closset@intl.att.com>, JulienBe <jb3179x@att.com>
Change-Id: I2d9feef65a98d4545e407825533cd1741f891b45

17 files changed:
auth/auth-cass/cass_init/cmd.sh
auth/auth-cass/cass_init/restore.sh
auth/auth-cass/docker/Dockerfile.cass
auth/auth-cass/docker/dbuild.sh
auth/auth-cass/docker/dcqlsh.sh
auth/docker/Dockerfile.agent
auth/docker/Dockerfile.config
auth/docker/Dockerfile.core
auth/docker/Dockerfile.hello
auth/helm/aaf-hello/templates/aaf-hello.yaml
auth/helm/aaf/templates/aaf-cass.yaml
auth/helm/aaf/templates/aaf-cm.yaml
auth/helm/aaf/templates/aaf-fs.yaml
auth/helm/aaf/templates/aaf-gui.yaml
auth/helm/aaf/templates/aaf-locate.yaml
auth/helm/aaf/templates/aaf-oauth.yaml
auth/helm/aaf/templates/aaf-service.yaml

index 7569440..f605a47 100644 (file)
@@ -24,6 +24,7 @@
 DIR="/opt/app/aaf/status"
 INSTALLED_VERSION=/var/lib/cassandra/AAF_VERSION
 AAF_INIT_DATA=/var/lib/cassandra/AAF_INIT_DATA
+CQLSH=${CQLSH:=/opt/cassandra/bin/cqlsh}
 
 if [ ! -e /aaf_cmd ]; then
   ln -s /opt/app/aaf/cass_init/cmd.sh /aaf_cmd
@@ -71,7 +72,7 @@ function wait_start {
 function wait_cql {
    status wait for keyspace to be initialized
    for CNT in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15; do
-     if [ -n "$(cqlsh -e 'describe keyspaces' | grep authz)"  ]; then
+     if [ -n "$($CQLSH -e 'describe keyspaces' | grep authz)"  ]; then
        break
      else
         echo "Waiting for Keyspaces to be loaded... Sleep 10"
@@ -96,11 +97,11 @@ function wait_ready {
 function install_cql {
     wait_start cassandra responsive   
     # Now, make sure data exists
-    if [ ! -e $INSTALLED_VERSION ] && [ -n "$(cqlsh -e 'describe keyspaces' | grep authz)" ]; then
-      cqlsh --request-timeout=60 -e 'DROP KEYSPACE authz' 
+    if [ ! -e $INSTALLED_VERSION ] && [ -n "$($CQLSH -e 'describe keyspaces' | grep authz)" ]; then
+      $CQLSH --request-timeout=60 -e 'DROP KEYSPACE authz'
     fi
 
-    if [ -z "`cqlsh --request-timeout 60 -e 'describe keyspaces' | grep authz`" ]; then
+    if [ -z "$($CQLSH --request-timeout 60 -e 'describe keyspaces' | grep authz)" ]; then
         status install 
         echo "Initializing Cassandra DB" 
         echo "Docker Installed Basic Cassandra on aaf.cass.  Executing the following "
@@ -109,10 +110,10 @@ function install_cql {
         echo " cd /opt/app/aaf/cass_init"
         cd /opt/app/aaf/cass_init
         echo " cqlsh -f keyspace.cql"
-        cqlsh --request-timeout=100 -f keyspace.cql
+        $CQLSH --request-timeout=100 -f keyspace.cql
        status keyspace installed
         echo " cqlsh -f init.cql"
-        cqlsh --request-timeout=100 -f init.cql
+        $CQLSH --request-timeout=100 -f init.cql
        status data initialized
         echo ""
         echo "The following will give you a temporary identity with which to start working, or emergency"
index abc6a7c..ba2c49e 100644 (file)
@@ -4,7 +4,7 @@
 echo `date`
 ENV=DOCKER
 
-CQLSH="cqlsh -k authz"
+CQLSH="${CQLSH:=/opt/cassandra/bin/cqlsh} -k authz"
 
 cd dats
 if [ "$*" = "" ]; then
index 0f12d8c..5d9c3db 100644 (file)
@@ -32,11 +32,16 @@ COPY aaf-auth-batch-*-full.jar /opt/app/aaf/cass_init/
 COPY cass_data/*.dat /opt/app/aaf/cass_init/dats/
 COPY sample.identities.dat /opt/app/aaf/cass_init/data/identites.dat
 
-RUN mkdir -p /opt/app/aaf/status && chmod 777 /opt/app/aaf/status && \
-    addgroup ${USER} && adduser --no-create-home --ingroup ${USER} --disabled-password --gecos "" --shell /bin/bash ${USER} && \
-    chown -R ${USER}:${USER} /opt/app/aaf/cass_init
-
+RUN mkdir -p /opt/app/aaf/status &&\
+    chmod 777 /opt/app/aaf/status && \
+    addgroup ${DUSER} && adduser --ingroup cassandra --disabled-password --gecos "" --shell /bin/bash ${DUSER} && \
+    chown -R ${DUSER}:cassandra /opt/app/aaf/cass_init &&\
+    chown -R ${DUSER}:cassandra /etc/cassandra &&\
+    mkdir -p /var/lib/cassandra/data && chown -R ${DUSER}:cassandra /var/lib/cassandra &&\
+    chown -R ${DUSER}:cassandra /var/log/cassandra &&\
+    ln -s /opt/app/aaf/cass_init/cmd.sh /aaf_cmd && chmod a+x /aaf_cmd
 
+USER ${DUSER}
 ENTRYPOINT ["/bin/bash","/opt/app/aaf/cass_init/cmd.sh"]
 CMD ["start"]
 # Default is to start up with CQL setup only
index 7e2ac7c..6a1ae1c 100644 (file)
@@ -25,7 +25,7 @@ if [ -e ../../docker/d.props ]; then
   . ../../docker/d.props
 fi
 DOCKER=${DOCKER:-docker}
+
 function SCP() {
   SANS=${1/-SNAPSHOT/}
   echo $1 = $SANS
@@ -52,7 +52,7 @@ echo "$0: DOCKER_PULL_REGISTRY=${DOCKER_REGISTRY}"
 DIR=$(pwd)
 cd ..
 sed -e 's/${AAF_VERSION}/'${VERSION/-SNAPSHOT/}'/g' \
-    -e 's/${USER}/'${USER}'/g' \
+    -e 's/${DUSER}/'${DUSER}'/g' \
     -e 's/${REGISTRY}/'${DOCKER_PULL_REGISTRY}'/g' \
     $DIR/Dockerfile.cass > Dockerfile
 cd ..
index 2518eb9..c8708d7 100644 (file)
@@ -22,5 +22,5 @@
 if [ -e ../../docker/d.props ]; then
   . ../../docker/d.props
 fi
-${DOCKER:=docker} exec -it aaf-cass /usr/bin/cqlsh -k authz
+${DOCKER:=docker} exec -it aaf-cass ${CQLSH:=/usr/bin/cqlsh} -k authz
 
index ec5f24e..e974dc4 100644 (file)
@@ -31,5 +31,5 @@ COPY bin/aaf-cadi-servlet-sample-*-sample.jar /opt/app/aaf_config/bin/
 COPY cert/*trust*.b64 /opt/app/aaf_config/cert/
 RUN chmod 755 /opt/app/aaf_config/bin/* &&\
     if [ -n "${DUSER}" ]; then chown -R ${DUSER}:${DUSER} /opt/app/aaf_config; fi
-
+USER ${DUSER}
 CMD []
index 4bb7a94..b2263ec 100644 (file)
@@ -39,5 +39,5 @@ COPY bin/aaf-auth-batch-${JAR_VERSION}-full.jar /opt/app/aaf_config/bin/
 RUN mkdir -p /opt/app/osaaf &&\
     chmod 755 /opt/app/aaf_config/bin/*.sh &&\
     if [ -n "${DUSER}" ]; then chown ${DUSER}:${DUSER} /opt/app/osaaf && chown -R ${DUSER}:${DUSER} /opt/app/aaf_config; fi
-
+USER ${DUSER}
 CMD ["/bin/bash","/opt/app/aaf_config/bin/agent.sh"]
index 5c66c8c..4179c5e 100644 (file)
@@ -37,4 +37,4 @@ RUN mkdir -p /opt/app/osaaf &&\
       && chown ${DUSER}:${DUSER} /opt/app/osaaf \
       && chown -R ${DUSER}:${DUSER} /opt/app/aaf;\
     fi
-
+USER ${DUSER}
index 4b12a6f..82d9a9f 100644 (file)
@@ -37,5 +37,5 @@ RUN mkdir -p /opt/app/osaaf &&\
       && chown ${DUSER}:${DUSER} /opt/app/osaaf \
       && chown -R ${DUSER}:${DUSER} /opt/app/aaf;\
     fi
-
+USER ${DUSER}
 CMD []
index 3ff9a57..a79f39e 100644 (file)
@@ -56,6 +56,18 @@ spec:
           persistentVolumeClaim:
             claimName: aaf-hello-pvc
       initContainers:
+        - command:
+            - /bin/sh
+            - -c
+            - |
+              chmod -R 775 /opt/app/osaaf
+              chown -R 1000:1000 /opt/app/osaaf
+          image: busybox:1.28
+          imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
+          name: init-sysctl
+          volumeMounts:
+            - mountPath: /opt/app/osaaf
+              name: aaf-hello-vol
         - name: aaf-hello-config
           image: "{{ .Values.image.repository }}{{ .Values.service.agentImage }}"
           imagePullPolicy: IfNotPresent
index f795dfe..ace2181 100644 (file)
@@ -68,6 +68,23 @@ spec:
       - name: aaf-status-vol
         persistentVolumeClaim:
           claimName: aaf-status-pvc
+      initContainers:
+        - command:
+            - /bin/sh
+            - -c
+            - |
+              chmod -R 775 /opt/app/aaf/status
+              chown -R 1000:1000 /opt/app/aaf/status
+              chmod -R 775 /var/lib/cassandra
+              chown -R 1000:1000 /var/lib/cassandra
+          image: busybox:1.28
+          imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
+          name: init-sysctl
+          volumeMounts:
+            - mountPath: /opt/app/aaf/status
+              name: aaf-status-vol
+            - mountPath: /var/lib/cassandra
+              name: aaf-cass-vol
       containers:
 ###
 ### AAF-CASS
index ebb4983..e64da6c 100644 (file)
@@ -59,6 +59,22 @@ spec:
         persistentVolumeClaim:
           claimName: aaf-status-pvc
       initContainers:
+        - command:
+            - /bin/sh
+            - -c
+            - |
+              chmod -R 775 /opt/app/aaf/status
+              chown -R 1000:1000 /opt/app/aaf/status
+              chmod -R 775 /opt/app/osaaf
+              chown -R 1000:1000 /opt/app/osaaf
+          image: busybox:1.28
+          imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
+          name: init-sysctl
+          volumeMounts:
+            - mountPath: /opt/app/aaf/status
+              name: aaf-status-vol
+            - mountPath: /opt/app/osaaf
+              name: aaf-config-vol
         - name: aaf-config-container
           image: {{ .Values.image.repository }}onap/aaf/aaf_config:{{ .Values.image.version }}
           imagePullPolicy: IfNotPresent
index 479447d..e3973af 100644 (file)
@@ -59,6 +59,22 @@ spec:
         persistentVolumeClaim:
           claimName: aaf-status-pvc
       initContainers:
+        - command:
+            - /bin/sh
+            - -c
+            - |
+              chmod -R 775 /opt/app/aaf/status
+              chown -R 1000:1000 /opt/app/aaf/status
+              chmod -R 775 /opt/app/osaaf
+              chown -R 1000:1000 /opt/app/osaaf
+          image: busybox:1.28
+          imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
+          name: init-sysctl
+          volumeMounts:
+            - mountPath: /opt/app/osaaf
+              name: aaf-config-vol
+            - mountPath: /opt/app/aaf/status
+              name: aaf-status-vol
         - name: aaf-config-container
           image: {{ .Values.image.repository }}onap/aaf/aaf_config:{{ .Values.image.version }}
           imagePullPolicy: IfNotPresent
index 14c4259..93c1473 100644 (file)
@@ -60,6 +60,22 @@ spec:
         persistentVolumeClaim:
           claimName: aaf-status-pvc
       initContainers:
+        - command:
+            - /bin/sh
+            - -c
+            - |
+              chmod -R 775 /opt/app/aaf/status
+              chown -R 1000:1000 /opt/app/aaf/status
+              chmod -R 775 /opt/app/osaaf
+              chown -R 1000:1000 /opt/app/osaaf
+          image: busybox:1.28
+          imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
+          name: init-sysctl
+          volumeMounts:
+            - mountPath: /opt/app/osaaf
+              name: aaf-config-vol
+            - mountPath: /opt/app/aaf/status
+              name: aaf-status-vol
         - name: aaf-config-container
           image: {{ .Values.image.repository }}onap/aaf/aaf_config:{{ .Values.image.version }}
           imagePullPolicy: IfNotPresent
index d4f2bf6..57ba43d 100644 (file)
@@ -59,6 +59,22 @@ spec:
         persistentVolumeClaim:
           claimName: aaf-status-pvc
       initContainers:
+        - command:
+            - /bin/sh
+            - -c
+            - |
+              chmod -R 775 /opt/app/aaf/status
+              chown -R 1000:1000 /opt/app/aaf/status
+              chmod -R 775 /opt/app/osaaf
+              chown -R 1000:1000 /opt/app/osaaf
+          image: busybox:1.28
+          imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
+          name: init-sysctl
+          volumeMounts:
+            - mountPath: /opt/app/aaf/status
+              name: aaf-status-vol
+            - mountPath: /opt/app/osaaf
+              name: aaf-config-vol
         - name: aaf-config-container
           image: {{ .Values.image.repository }}onap/aaf/aaf_config:{{ .Values.image.version }}
           imagePullPolicy: IfNotPresent
index 4d5ac75..ab21e3a 100644 (file)
@@ -59,6 +59,22 @@ spec:
         persistentVolumeClaim:
           claimName: aaf-status-pvc
       initContainers:
+        - command:
+            - /bin/sh
+            - -c
+            - |
+              chmod -R 775 /opt/app/aaf/status
+              chown -R 1000:1000 /opt/app/aaf/status
+              chmod -R 775 /opt/app/osaaf
+              chown -R 1000:1000 /opt/app/osaaf
+          image: busybox:1.28
+          imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
+          name: init-sysctl
+          volumeMounts:
+            - mountPath: /opt/app/aaf/status
+              name: aaf-status-vol
+            - mountPath: /opt/app/osaaf
+              name: aaf-config-vol
         - name: aaf-config-container
           image: {{ .Values.image.repository }}onap/aaf/aaf_config:{{ .Values.image.version }}
           imagePullPolicy: IfNotPresent
index 96efa75..f4772d6 100644 (file)
@@ -58,6 +58,22 @@ spec:
         persistentVolumeClaim:
           claimName: aaf-status-pvc
       initContainers:
+        - command:
+            - /bin/sh
+            - -c
+            - |
+              chmod -R 775 /opt/app/aaf/status
+              chown -R 1000:1000 /opt/app/aaf/status
+              chmod -R 775 /opt/app/osaaf
+              chown -R 1000:1000 /opt/app/osaaf
+          image: busybox:1.28
+          imagePullPolicy: {{ .Values.global.pullPolicy | default .Values.pullPolicy }}
+          name: init-sysctl
+          volumeMounts:
+          - mountPath: /opt/app/aaf/status
+            name: aaf-status-vol
+          - mountPath: /opt/app/osaaf
+            name: aaf-config-vol
         - name: aaf-config-container
           image: {{ .Values.image.repository }}onap/aaf/aaf_config:{{ .Values.image.version }}
           imagePullPolicy: IfNotPresent