Политика безопасности модуля - модули не могут создавать файлы
мы пытаемся применить правило безопасности подов, как показано ниже:
apiVersion: policy/v1beta1
kind: PodSecurityPolicy
metadata:
name: taap-restricted-psp
annotations:
# https://docs.docker.com/engine/security/seccomp/
# https://kubernetes.io/docs/concepts/policy/pod-security-policy/
seccomp.security.alpha.kubernetes.io/allowedProfileNames: 'docker/default,runtime/default'
seccomp.security.alpha.kubernetes.io/defaultProfileName: 'runtime/default'
spec:
privileged: false
# Required to prevent escalations to root
allowPrivilegeEscalation: false
requiredDropCapabilities:
- ALL
# Allow core volume types.
volumes:
- 'configMap'
- 'emptyDir'
- 'projected'
- 'secret'
- 'downwardAPI'
# Assume that persistentVolumes set up by the cluster admin are safe to use.
- 'persistentVolumeClaim'
hostNetwork: false
hostIPC: false
hostPID: false
runAsUser:
rule: 'MustRunAs' # Don't allow containers to run as ROOT
ranges:
- max: 65535
min: 1
seLinux:
rule: 'RunAsAny'
supplementalGroups:
rule: 'MustRunAs'
ranges:
# Forbid adding the root group.
- min: 1
max: 65535
fsGroup:
rule: 'MustRunAs'
ranges:
# Forbid adding the root group.
- min: 1
max: 65535
readOnlyRootFilesystem: false # Requires that containers must run with a read-only root filesystem (i.e. no writable layer)
---
apiVersion: rbac.authorization.k8s.io/v1
kind: Role
metadata:
name: taap-restricted-psp-role
namespace: taap-internal-dev
rules:
- apiGroups: ['policy']
resources: ['podsecuritypolicies']
verbs: ['use']
resourceNames:
- taap-restricted-psp
---
apiVersion: rbac.authorization.k8s.io/v1
kind: RoleBinding
metadata:
name: taap-restricted-psp-role-rolebinding
namespace: taap-internal-dev
roleRef:
kind: Role
name: taap-restricted-psp-role
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: Group
apiGroup: rbac.authorization.k8s.io
name: system:serviceaccounts # Authorize all service accounts in the namespace
namespace: taap-internal-dev
и используя изображение докера ниже, где мы даем разрешение пользователю taapuser на доступ к папке '/ app'
FROM maven:3.6-jdk-8-alpine AS builder
# See https://www.docker.com/blog/intro-guide-to-dockerfile-best-practices/
WORKDIR /app
COPY pom.xml .
COPY 3rdparty 3rdparty/
RUN mvn -e -B dependency:resolve
COPY src ./src
COPY trustStore ./trustStore/
RUN mvn -e -B package
FROM openjdk:8-jre-alpine
RUN apk add curl
WORKDIR /app
COPY --from=builder /app/target/taap_Anonymization.jar ./app.jar
# TODO: package .so file with maven in single jar file
COPY 3rdparty/com/voltage/securedata/enterprise/vibesimplejava/6.0.0/libvibesimplejava.so ./libvibesimplejava.so
COPY trustStore ./trustStore/
# Run container in non-privileged mode
RUN addgroup -g 111 -S taapgroup && \
adduser -u 111 -S taapuser -G taapgroup
RUN chown -R taapuser /app /var/log
USER taapuser
EXPOSE 8080
CMD ["java", "-Djava.library.path=/app/", "-jar", "/app/app.jar"]
Но когда мы пытаемся запустить эти модули, модули не могут создать файл в / app.
Я попытался изменить код, как показано ниже, и он начал работать
RUN chown -R 1 /app /var/log USER 1
Я хотел бы знать, нужно ли нам изменить правило безопасности pods, чтобы taapuser получил доступ для создания файлов в папке / app.
'rule: 'MustRunAsNonRoot'