Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/minio file upload #125

Merged
merged 29 commits into from
Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
83245b2
Update minio chart with new image and better configs
sandstromviktor Dec 20, 2023
ab0fb8a
revert to minio image
sandstromviktor Dec 20, 2023
4ea77b5
New minio image, with postStartHook that creates user, bucket add add…
sandstromviktor Jan 3, 2024
8124307
update
sandstromviktor Jan 3, 2024
682d800
update charts with ftp service using nodeport
sandstromviktor Jan 4, 2024
b178c2a
mounting TLS cert
sandstromviktor Jan 4, 2024
cef6de4
update
sandstromviktor Jan 8, 2024
9dab4f2
Working minio chart with logic for activating s3 and console
sandstromviktor Jan 9, 2024
650f563
updated task to automatically delete minio apps
sandstromviktor Jan 9, 2024
4e63c6a
removed manage files if not superuser
sandstromviktor Jan 9, 2024
d37b501
Fixed ingress proxy body size and minio permission error
sandstromviktor Jan 10, 2024
c510817
added password reveal function
sandstromviktor Jan 10, 2024
a2f8c5b
limit proxy-body-size to 10 gigs
sandstromviktor Jan 10, 2024
b8ceebf
added admin command to add user to db - draft
sandstromviktor Jan 10, 2024
1e491ec
added copied info
sandstromviktor Jan 11, 2024
6f0a162
update
sandstromviktor Jan 11, 2024
a0d1f8b
Added admin commands to create stuff for locust tests
sandstromviktor Jan 11, 2024
c301748
Pre commit fix
sandstromviktor Jan 11, 2024
03b69e6
quotify proxy-body-size
sandstromviktor Jan 11, 2024
a6b7272
fixed ingress indentation error and command enumeration
sandstromviktor Jan 11, 2024
2146658
sorting users in admin command + adding link to documentation
sandstromviktor Jan 11, 2024
ba82f7a
added new app called minio-admin that should cover other use cases
sandstromviktor Jan 11, 2024
04b2e2e
show password in settings
sandstromviktor Jan 11, 2024
eff8cbc
Merge branch 'develop' into feature/minio-file-upload
sandstromviktor Jan 12, 2024
4269e1a
fix pre-commit
sandstromviktor Jan 12, 2024
cbac487
Up pillow version
sandstromviktor Jan 12, 2024
e05beae
pre commit run
sandstromviktor Jan 12, 2024
2527ca1
Fix view for empty case
sandstromviktor Jan 12, 2024
4fae835
allowing minio to use flavor and set to public
sandstromviktor Jan 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ RUN apk add --update --no-cache \
# Installing Pillow separate from the packages in requirements
# greatly speeds up the docker build.
RUN python3 -m pip install --upgrade pip \
&& python3 -m pip install Pillow==10.1.0 --global-option="build_ext" --global-option="--disable-tiff" --global-option="--disable-freetype" --global-option="--disable-lcms" --global-option="--disable-webp" --global-option="--disable-webpmux" --global-option="--disable-imagequant" --global-option="--disable-xcb"
&& python3 -m pip install Pillow==10.2.0 --global-option="build_ext" --global-option="--disable-tiff" --global-option="--disable-freetype" --global-option="--disable-lcms" --global-option="--disable-webp" --global-option="--disable-webpmux" --global-option="--disable-imagequant" --global-option="--disable-xcb"

FROM bitnami/kubectl:1.28.2 as kubectl
FROM alpine/helm:3.12.3 as helm
Expand Down
16 changes: 11 additions & 5 deletions apps/tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def post_create_hooks(instance):
print("TASK - POST CREATE HOOK...")
# hard coded hooks for now, we can make this dynamic
# and loaded from the app specs
if instance.app.slug == "minio":
if instance.app.slug == "minio-admin":
# Create project S3 object
# TODO: If the instance is being updated,
# update the existing S3 object.
Expand Down Expand Up @@ -491,11 +491,17 @@ def delete_old_objects():

TODO: Make this a variable in settings.py and use the same number in templates
"""
threshold = 7
threshold_time = timezone.now() - timezone.timedelta(days=threshold)

old_apps = AppInstance.objects.filter(created_on__lt=threshold_time, app__category__name="Develop")
for app_ in old_apps:
def get_old_apps(threshold, category):
threshold_time = timezone.now() - timezone.timedelta(days=threshold)
return AppInstance.objects.filter(created_on__lt=threshold_time, app__category__name=category)

old_develop_apps = get_old_apps(threshold=7, category="Develop")
old_minio_apps = get_old_apps(threshold=1, category="Manage Files")
for app_ in old_develop_apps:
delete_resource.delay(app_.pk)

for app_ in old_minio_apps:
delete_resource.delay(app_.pk)


Expand Down
13 changes: 13 additions & 0 deletions apps/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import re
import secrets
import string

import requests
from django.apps import apps
Expand Down Expand Up @@ -421,6 +423,17 @@ def get(self, request, user, project, app_slug, data=[], wait=False, call=False)
if not user_can_create:
return HttpResponseForbidden()

if app.slug == "minio":

def generate_password(len: int) -> str:
return "".join(
secrets.choice(string.octdigits + string.ascii_uppercase + string.ascii_lowercase + string.digits)
for i in range(len)
)
Comment on lines +428 to +432
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why aren't you using django's password generator? I believe, that this way is most probably insecure and exploitable


MINIO_USERNAME = generate_password(8)
MINIO_PASSWORD = generate_password(8)

do_display_description_field = app.category is not None and app.category.name.lower() == "serve"

form = generate_form(app_settings, project, app, user, [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,24 +27,21 @@ spec:
pod: minio
spec:
automountServiceAccountToken: false
{{- if .Values.securityContext.enabled }}
securityContext:
seccompProfile:
type: RuntimeDefault
fsGroup: {{ .Values.securityContext.fsGroup }}
{{- end }}
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Release.Name }}-minio
image: minio/minio:14128-5ee91dc
image: {{ .Values.appconfig.image }}
imagePullPolicy: IfNotPresent
command:
- "/bin/sh"
- "-ce"
- "/usr/bin/docker-entrypoint.sh minio server {{ .Values.bucketRoot }} --console-address :{{ .Values.minioConsolePort }}"
- /bin/sh
- -ce
- |
/usr/bin/docker-entrypoint.sh minio server {{ .Values.bucketRoot }} --console-address :{{ .Values.appconfig.uiConsolePort }}
args:
{{- range $key, $value := .Values.apps.volumeK8s }}
- server
- /home/stackn/{{ $key }}
- /home/{{ $key }}
{{- end }}
env:
- name: MINIO_ROOT_USER
Expand All @@ -57,49 +54,36 @@ spec:
secretKeyRef:
name: {{ .Release.Name }}-minio
key: secretkey
{{- if .Values.securityContext.enabled }}
securityContext:
runAsUser: {{ .Values.securityContext.runAsUser }}
runAsGroup: {{ .Values.securityContext.runAsGroup }}
allowPrivilegeEscalation: {{ .Values.securityContext.allowPrivilegeEscalation }}
privileged: {{ .Values.securityContext.privileged }}
capabilities:
drop:
- all
{{- end }}
{{- toYaml .Values.securityContext | nindent 10 }}
ports:
- containerPort: 9000
- containerPort: {{ .Values.appconfig.apiServerPort }}
name: api-server
- containerPort: 9001
- containerPort: {{ .Values.appconfig.uiConsolePort }}
name: ui-console
- containerPort: {{ .Values.appconfig.ftpPort }}
name: ftp
resources: {}
volumeMounts:
{{- range $key, $value := .Values.apps.volumeK8s }}
- name: {{ $key }}
mountPath: /data
{{- end }}

- name: {{ .Release.Name }}-minio-sidecar
image: alpine:3.18.3
imagePullPolicy: IfNotPresent
command: ["sh", "-c", "while true; do sleep 3600; done;"]
{{- if .Values.securityContext.enabled }}
securityContext:
runAsUser: {{ .Values.securityContext.runAsUser }}
runAsGroup: {{ .Values.securityContext.runAsGroup }}
allowPrivilegeEscalation: {{ .Values.securityContext.allowPrivilegeEscalation }}
privileged: {{ .Values.securityContext.privileged }}
capabilities:
drop:
- all
{{- end }}
resources: {}
volumeMounts:
{{- range $key, $value := .Values.apps.volumeK8s }}
- name: {{ $key }}
mountPath: /data
{{- end }}

- name: tls-secret
mountPath: /home
readOnly: true
lifecycle:
postStart:
exec:
command:
- /bin/sh
- -ce
- |
sleep 5
mc alias set local http://127.0.0.1:9000 ${MINIO_ROOT_USER} ${MINIO_ROOT_PASSWORD}
mc admin user add local {{ .Values.credentials.access_key }} {{ .Values.credentials.secret_key }}
mc mb /data/data-bucket
mc admin policy attach local readwrite --user {{ .Values.credentials.access_key }} || true
hostname: {{ .Release.Name }}-minio
restartPolicy: Always
volumes:
Expand All @@ -108,4 +92,7 @@ spec:
persistentVolumeClaim:
claimName: {{ $value.release }}
{{- end }}
- name: tls-secret
secret:
secretName: prod-ingress
status: {}
34 changes: 34 additions & 0 deletions charts/apps/minio/chart/templates/ingress.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
annotations:
nginx.ingress.kubernetes.io/proxy-body-size: "10000M"
name: {{ .Release.Name }}-minio
namespace: {{ .Values.namespace }}
spec:
rules:
- host: {{ .Release.Name }}.{{ .Values.global.domain }}
http:
paths:
- path: /
backend:
service:
name: {{ .Values.service.name }}
port:
name: console
pathType: ImplementationSpecific
- host: api-{{ .Release.Name }}.{{ .Values.global.domain }}
http:
paths:
- path: /
backend:
service:
name: {{ .Values.service.name }}
port:
name: api
pathType: ImplementationSpecific

tls:
- secretName: {{ .Values.ingress.secretName }}
hosts:
- {{ .Values.global.domain }}
53 changes: 0 additions & 53 deletions charts/apps/minio/chart/templates/project-s3-ingress.yaml

This file was deleted.

4 changes: 2 additions & 2 deletions charts/apps/minio/chart/templates/secret.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@ metadata:
type: secret
type: Opaque
data:
accesskey: {{ if .Values.credentials.access_key }}{{ .Values.credentials.access_key | b64enc | quote }}{{ else }}{{ randAlphaNum 20 | b64enc | quote }}{{ end }}
secretkey: {{ if .Values.credentials.secret_key }}{{ .Values.credentials.secret_key | b64enc | quote }}{{ else }}{{ randAlphaNum 40 | b64enc | quote }}{{ end }}
accesskey: {{ randAlphaNum 20 | b64enc | quote }}
secretkey: {{ randAlphaNum 40 | b64enc | quote }}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ spec:
ports:
- name: api
protocol: TCP
port: 9000
targetPort: 9000
port: {{ .Values.appconfig.apiServerPort }}
targetPort: {{ .Values.appconfig.apiServerPort }}
- name: console
protocol: TCP
port: 9001
targetPort: 9001
port: {{ .Values.appconfig.uiConsolePort }}
targetPort: {{ .Values.appconfig.uiConsolePort }}

selector:
release: {{ .Release.Name }}
24 changes: 16 additions & 8 deletions charts/apps/minio/chart/values.yaml
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
namespace: default
volumes: {}

## Port number for MinIO S3 API Access
minioAPIPort: "9000"

## Port number for MinIO Browser COnsole Access
minioConsolePort: "9001"


## Path where PV would be mounted on the MinIO Pod
mountPath: ""
Expand All @@ -20,14 +14,28 @@ credentials:
access_key: minio-access-key
secret_key: minio-secret-key


ingress:
v1beta1: false
secretName: prod-ingress

appconfig:
apiServerPort: 9000
uiConsolePort: 9001
ftpPort: 8022
image: minio/minio:latest

podSecurityContext:
seccompProfile:
type: RuntimeDefault
fsGroup: 1000

securityContext:
enabled: true
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
fsGroup: 1000
allowPrivilegeEscalation: false
privileged: false
capabilities:
drop:
- all
31 changes: 0 additions & 31 deletions charts/apps/rstudio/chart/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,34 +43,3 @@ securityContext:
capabilities:
drop:
- all







service:
name: customapp-svc

imagePullSecrets:
- name: regcred

ingress:
v1beta1: false
secretName: prod-ingress

podSecurityContext:
seccompProfile:
type: RuntimeDefault
fsGroup: 1000

securityContext:
runAsNonRoot: true
runAsUser: 1000
runAsGroup: 1000
allowPrivilegeEscalation: false
privileged: false
capabilities:
drop:
- all
Empty file added common/management/__init__.py
Empty file.
Empty file.
26 changes: 26 additions & 0 deletions common/management/commands/add_locust_users.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
from django.contrib.auth import get_user_model
from django.core.management.base import BaseCommand, CommandError
from django.db.utils import IntegrityError

User = get_user_model()


class Command(BaseCommand):
help = "Adds user to database"

def add_arguments(self, parser):
parser.add_argument("num_users", type=int)

def handle(self, *args, **options):
for i in range(1, options["num_users"] + 1):
username = f"locust_test_user_{i}"
email = f"locust_test_user_{i}@test.uu.net"
password = "password123"
try:
user = User.objects.create_user(username, email, password)
user.is_active = True
user.save()
except IntegrityError:
self.stdout.write(self.style.WARNING("User with the given username or email already exists."))

self.stdout.write(self.style.SUCCESS(f"Successfully created {i} users"))
Comment on lines +23 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If IntegrityError is raised, then there should be less successful creations of users

Loading