diff --git a/k8s/apps/authelia/Chart.yaml b/k8s/apps/authelia/Chart.yaml new file mode 100644 index 0000000..79c2ed3 --- /dev/null +++ b/k8s/apps/authelia/Chart.yaml @@ -0,0 +1,12 @@ +apiVersion: v2 +name: authella +description: An infra service for homelab +type: application +version: 0.1.0 +dependencies: + - name: authelia + repository: https://charts.authelia.com + version: "0.8.57" + - name: redis + repository: https://charts.bitnami.com/bitnami + version: "17.9.2" diff --git a/k8s/apps/authelia/templates/certificate.yaml b/k8s/apps/authelia/templates/certificate.yaml new file mode 100644 index 0000000..2afcb5c --- /dev/null +++ b/k8s/apps/authelia/templates/certificate.yaml @@ -0,0 +1,15 @@ +{{ if .Values.global.tls.enabled }} +--- +apiVersion: cert-manager.io/v1 +kind: Certificate +metadata: + name: "tls-{{.Values.authelia.ingress.subdomain}}.{{.Values.authelia.domain}}" +spec: + secretName: "{{.Values.authelia.ingress.tls.secret}}" + issuerRef: + kind: ClusterIssuer + name: "{{ .Values.global.tls.issuer }}" + commonName: "{{.Values.authelia.ingress.subdomain}}.{{.Values.authelia.domain}}" + dnsNames: + - "{{.Values.authelia.ingress.subdomain}}.{{.Values.authelia.domain}}" +{{ end }} diff --git a/k8s/apps/authelia/templates/postfix.yaml b/k8s/apps/authelia/templates/postfix.yaml new file mode 100644 index 0000000..def4fd0 --- /dev/null +++ b/k8s/apps/authelia/templates/postfix.yaml @@ -0,0 +1,83 @@ +{{ if .Values.smtp_configs }} +--- +apiVersion: v1 +kind: Secret +metadata: + name: "postfix-smtp-env" +type: Opaque +data: + SERVER_HOSTNAME: "{{ .Values.global.domain | b64enc }}" +{{ range $k, $v := .Values.smtp_configs }} + {{ $k }}: "{{ $v | b64enc }}" +{{ end }} +--- +apiVersion: external-secrets.io/v1beta1 +kind: ExternalSecret +metadata: + name: "postfix-smtp" +spec: + refreshInterval: 1h + secretStoreRef: + kind: ClusterSecretStore + name: secrets + target: + name: "postfix-smtp-env" + creationPolicy: Merge + data: + - secretKey: "SMTP_PASSWORD" + remoteRef: + key: "smtp" + property: password +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postfix + labels: + app: postfix +spec: + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + type: RollingUpdate + selector: + matchLabels: + app: postfix + template: + metadata: + labels: + app: postfix + annotations: + postfix/env-checksum: "{{ .Values.smtp_configs | toJson | sha256sum }}" + spec: + containers: + - image: juanluisbaptiste/postfix:alpine + name: postfix + resources: + requests: + cpu: "20m" + memory: "55M" + limits: + cpu: "20m" + memory: "55M" + envFrom: + - secretRef: + name: postfix-smtp-env + ports: + - containerPort: 25 + name: smtp +--- +kind: Service +apiVersion: v1 +metadata: + name: postfix +spec: + selector: + app: postfix + type: ClusterIP + ports: + - name: smtp + port: 25 + targetPort: 25 +{{ end }} \ No newline at end of file diff --git a/k8s/apps/authelia/templates/secert-authellia.yaml b/k8s/apps/authelia/templates/secert-authellia.yaml new file mode 100644 index 0000000..0895638 --- /dev/null +++ b/k8s/apps/authelia/templates/secert-authellia.yaml @@ -0,0 +1,46 @@ +--- +apiVersion: v1 +kind: Secret +metadata: + name: "{{ .Values.authelia.secret.existingSecret }}" + annotations: + secret-generator.v1.mittwald.de/autogenerate: SESSION_ENCRYPTION_KEY,REDIS_PASSWORD,JWT_TOKEN,STORAGE_ENCRYPTION_KEY +data: + dummy_values: "" +type: Opaque +--- +apiVersion: external-secrets.io/v1beta1 +kind: ExternalSecret +metadata: + name: "{{ .Values.authelia.secret.existingSecret }}-db" +spec: + refreshInterval: 1h + secretStoreRef: + kind: ClusterSecretStore + name: database + target: + name: "{{ .Values.authelia.secret.existingSecret }}" + creationPolicy: Merge + data: + - secretKey: "STORAGE_PASSWORD" + remoteRef: + key: "password.pg.authelia" + property: password +--- +apiVersion: external-secrets.io/v1beta1 +kind: ExternalSecret +metadata: + name: "{{ .Values.authelia.secret.existingSecret }}-smtp" +spec: + refreshInterval: 1h + secretStoreRef: + kind: ClusterSecretStore + name: secrets + target: + name: "{{ .Values.authelia.secret.existingSecret }}" + creationPolicy: Merge + data: + - secretKey: "SMTP_PASSWORD" + remoteRef: + key: "smtp" + property: password diff --git a/k8s/apps/authelia/values-dev.yaml b/k8s/apps/authelia/values-dev.yaml new file mode 100644 index 0000000..e69de29 diff --git a/k8s/apps/authelia/values-prod.yaml b/k8s/apps/authelia/values-prod.yaml new file mode 100644 index 0000000..d7f9bf8 --- /dev/null +++ b/k8s/apps/authelia/values-prod.yaml @@ -0,0 +1,23 @@ +authelia: + configMap: + notifier: + disable_startup_check: false + smtp: + enabled: true + filesystem: + enabled: false + ingress: + enabled: true + certManager: true + tls: + enabled: true + traefikCRD: + enabled: true + disableIngressRoute: true + sticky: true + middlewares: + chains: + ingressRoute: + before: + - name: "https-redirect" + namespace: "apps-ingresses" diff --git a/k8s/apps/authelia/values.yaml b/k8s/apps/authelia/values.yaml new file mode 100644 index 0000000..63c548b --- /dev/null +++ b/k8s/apps/authelia/values.yaml @@ -0,0 +1,234 @@ +authelia: + domain: "changeme" + nameOverride: main-authelia + image: + registry: ghcr.io + repository: authelia/authelia + tag: "" + pullPolicy: IfNotPresent + + ingress: + enabled: true + annotations: {} + certManager: true + className: traefik + subdomain: auth.core + tls: + enabled: false + secret: authelia-tls + traefikCRD: + enabled: true + disableIngressRoute: false + sticky: true + + pod: + kind: DaemonSet + replicas: 1 + revisionHistoryLimit: 1 + env: + - name: TZ + value: America/Toronto + + resources: + limits: + cpu: "4.00" + memory: 125Mi + requests: + cpu: "0.25" + memory: 50Mi + persistence: + enabled: true + readOnly: false + accessModes: + - ReadWriteMany + size: 100Mi + + configMap: + enabled: true + theme: dark + default_2fa_method: totp + + access_control: + secret: + enabled: true + key: configuration.acl.yaml + ## Default policy can either be 'bypass', 'one_factor', 'two_factor' or 'deny'. It is the policy applied to any + default_policy: two_factor + networks: [] + # networks: + # - name: private + # networks: + # - 10.0.0.0/8 + # - 172.16.0.0/12 + # - 192.168.0.0/16 + # - name: vpn + # networks: + # - 10.9.0.0/16 + rules: [] + # rules: + # - domain_regex: '^.*\.example.com$' + # policy: bypass + # - domain: public.example.com + # policy: bypass + # - domain: "*.example.com" + # policy: bypass + # methods: + # - OPTIONS + # - domain: secure.example.com + # policy: one_factor + # networks: + # - private + # - vpn + # - 192.168.1.0/24 + # - 10.0.0.1 + # - domain: + # - secure.example.com + # - private.example.com + # policy: two_factor + # - domain: singlefactor.example.com + # policy: one_factor + # - domain: "mx2.mail.example.com" + # subject: "group:admins" + # policy: deny + # - domain: "*.example.com" + # subject: + # - "group:admins" + # - "group:moderators" + # policy: two_factor + # - domain: dev.example.com + # resources: + # - "^/groups/dev/.*$" + # subject: "group:dev" + # policy: two_factor + # - domain: dev.example.com + # resources: + # - "^/users/john/.*$" + # subject: + # - ["group:dev", "user:john"] + # - "group:admins" + # policy: two_factor + # - domain: "{user}.example.com" + # policy: bypass + + authentication_backend: + ldap: + enabled: false + file: + enabled: true + path: /config/users_database.yml + watch: true + search: + email: true + case_insensitive: true + + storage: + postgres: + enabled: true + host: postgres.chart-database.svc.cluster.local + port: 5432 + database: authelia + schema: public + username: authelia + timeout: 5s + + notifier: + disable_startup_check: true + smtp: + enabled: false + filesystem: + enabled: true + filename: /config/notification.txt + + session: + name: authelia_session + same_site: lax + expiration: 1h + inactivity: 5m + remember_me_duration: 1M + redis: + enabled: true + enabledSecret: true + host: redis-authelia-headless.apps-authelia.svc.cluster.local + port: 6379 + database_index: 0 + maximum_active_connections: 8 + minimum_idle_connections: 0 + + secret: + existingSecret: authelia + mountPath: /secrets + excludeVolumeAndMounts: false + + storage: + key: STORAGE_PASSWORD + session: + key: SESSION_ENCRYPTION_KEY + redis: + key: REDIS_PASSWORD + smtp: + key: SMTP_PASSWORD + jwt: + key: JWT_TOKEN + storageEncryptionKey: + key: STORAGE_ENCRYPTION_KEY +redis: + image: + registry: docker.io + repository: bitnami/redis + tag: 7.0.10-debian-11-r2 + pullPolicy: IfNotPresent + fullnameOverride: "redis-authelia" + architecture: replication + auth: + enabled: true + existingSecret: "authelia" + existingSecretPasswordKey: "REDIS_PASSWORD" + usePasswordFiles: false + + master: + count: 1 + resources: + limits: + cpu: 500m + memory: 1Gi + requests: + cpu: 500m + memory: 1Gi + persistence: + enabled: true + size: "8Gi" + storageClass: "" + accessModes: + - ReadWriteOnce + service: + type: ClusterIP + ports: + redis: 6379 + + replica: + replicaCount: 1 + containerPorts: + redis: 6379 + resources: + limits: + cpu: 250m + memory: 256Mi + requests: + cpu: 250m + memory: 256Mi + persistence: + enabled: true + storageClass: "" + accessModes: + - ReadWriteOnce + size: 8Gi + service: + type: ClusterIP + ports: + redis: 6379 + autoscaling: + enabled: true + minReplicas: 1 + maxReplicas: 4 + targetCPU: "80" + targetMemory: "80" diff --git a/k8s/apps/postfix/Chart.yaml b/k8s/apps/postfix/Chart.yaml new file mode 100644 index 0000000..9883ef1 --- /dev/null +++ b/k8s/apps/postfix/Chart.yaml @@ -0,0 +1,6 @@ +apiVersion: v2 +name: postfix +description: An apps service for homelab +type: application +version: 0.1.0 +dependencies: [] diff --git a/k8s/apps/postfix/templates/postfix.yaml b/k8s/apps/postfix/templates/postfix.yaml new file mode 100644 index 0000000..39e52b4 --- /dev/null +++ b/k8s/apps/postfix/templates/postfix.yaml @@ -0,0 +1,71 @@ +{{ if .Values.smtp_configs }} +--- +apiVersion: v1 +kind: Secret +metadata: + name: "postfix-smtp-env" +type: Opaque +data: + SERVER_HOSTNAME: "{{ .Values.global.domain | b64enc }}" +{{ range $k, $v := .Values.smtp_configs }} + {{ $k }}: "{{ $v | b64enc }}" +{{ end }} +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + name: postfix + labels: + app: postfix +spec: + strategy: + rollingUpdate: + maxSurge: 1 + maxUnavailable: 1 + type: RollingUpdate + selector: + matchLabels: + app: postfix + template: + metadata: + labels: + app: postfix + annotations: + postfix/env-checksum: "{{ .Values.smtp_configs | toJson | sha256sum }}" + spec: + containers: + - image: juanluisbaptiste/postfix:alpine + name: postfix + resources: + requests: + cpu: "20m" + memory: "55M" + limits: + cpu: "20m" + memory: "55M" + env: + - name: "SMTP_PASSWORD" + valueFrom: + secretKeyRef: + name: {{ .Values.smtp_password_secret }} + key: {{ .Values.smtp_password_secret_key }} + envFrom: + - secretRef: + name: postfix-smtp-env + ports: + - containerPort: 25 + name: smtp +--- +kind: Service +apiVersion: v1 +metadata: + name: postfix +spec: + selector: + app: postfix + type: ClusterIP + ports: + - name: smtp + port: 25 + targetPort: 25 +{{ end }} \ No newline at end of file diff --git a/k8s/apps/postfix/values-dev.yaml b/k8s/apps/postfix/values-dev.yaml new file mode 100644 index 0000000..e69de29 diff --git a/k8s/apps/postfix/values-prod.yaml b/k8s/apps/postfix/values-prod.yaml new file mode 100644 index 0000000..e69de29 diff --git a/k8s/apps/postfix/values.yaml b/k8s/apps/postfix/values.yaml new file mode 100644 index 0000000..6712791 --- /dev/null +++ b/k8s/apps/postfix/values.yaml @@ -0,0 +1,5 @@ +global: + domain: changme +smtp_configs: {} +smtp_password_secret: "changeme" +smtp_password_secret_key: "changeme" \ No newline at end of file diff --git a/k8s/argoapps/apps-values/authelia.yaml b/k8s/argoapps/apps-values/authelia.yaml new file mode 100644 index 0000000..bd43834 --- /dev/null +++ b/k8s/argoapps/apps-values/authelia.yaml @@ -0,0 +1,34 @@ +authelia: + domain: "{{ .Values.global.domain }}" + configMap: + default_redirection_url: "https://auth.core.{{ .Values.global.domain }}" + notifier: + disable_startup_check: false + smtp: + host: postfix.email.svc.cluster.local + port: 25 + sender: {{ .Values.global.smtp.email }} + startup_check_address: {{ .Values.global.email }} + disable_require_tls: true + + persistence: + storageClass: "{{ .Values.global.nfs.storageClass }}" + + storage: + postgres: + host: postgres.chart-database.svc.cluster.local + database: authelia + username: authelia + + session: + redis: + host: redis-authelia-headless.apps-authelia.svc.cluster.local + +redis: + master: + persistence: + storageClass: "{{ .Values.global.nfs.storageClass }}" + + replica: + persistence: + storageClass: "{{ .Values.global.nfs.storageClass }}" diff --git a/k8s/argoapps/chart-values/database.yaml b/k8s/argoapps/chart-values/database.yaml new file mode 100644 index 0000000..96550b1 --- /dev/null +++ b/k8s/argoapps/chart-values/database.yaml @@ -0,0 +1,21 @@ +fullnameOverride: "postgres" +image: + tag: 15.1.0-debian-11-r19 + repository: bitnami/postgresql + pullPolicy: IfNotPresent +auth: + secretKeys: + adminPasswordKey: password + existingSecret: "{{ .Values.secrets.database.secrets.dbmain.name }}" +architecture: standalone +postgresqlDataDir: /bitnami/postgresql/data +primary: + persistence: + enabled: true + mountPath: /bitnami/postgresql + storageClass: "{{ .Values.global.nfs.storageClass }}" + existingClaim: "{{ .Values.storage.database.name }}" + accessModes: + - ReadWriteMany +readReplicas: + replicaCount: 0 diff --git a/k8s/argoapps/templates/argoappset-apps.yaml b/k8s/argoapps/templates/argoappset-apps.yaml index 0085b40..3d509ae 100644 --- a/k8s/argoapps/templates/argoappset-apps.yaml +++ b/k8s/argoapps/templates/argoappset-apps.yaml @@ -30,7 +30,14 @@ spec: - values.yaml - values-{{$.Values.global.deployment}}.yaml values: |- - {{- tpl ($appProps.values | default "") $ | nindent 10 }} +{{- $values := ($appProps.values| default "") -}} +{{ if $appProps.valuesFile }} +{{- $valuesFilePath := (printf "chart-values/%s" $appProps.valuesFile) -}} +{{- $values := $.Files.Get $valuesFilePath -}} + {{- tpl $values $ | nindent 10 }} +{{ else }} + {{- tpl $values $ | nindent 10 }} +{{- end }} global: {{- $.Values.global | toYaml | nindent 12 }} releaseName: {{ $appName }} diff --git a/k8s/argoapps/templates/charts-infra.yaml b/k8s/argoapps/templates/charts-infra.yaml index ab080cf..b04fa94 100644 --- a/k8s/argoapps/templates/charts-infra.yaml +++ b/k8s/argoapps/templates/charts-infra.yaml @@ -4,13 +4,15 @@ {{ range $chartName, $chartProps := .Values.infrastructureCharts }} -{{- $namespace := (printf "chart-%s" $chartName) -}} +{{- $namespace := $chartProps.namespace | default (printf "chart-%s" $chartName) -}} +{{ if (not $chartProps.namespace) }} --- apiVersion: v1 kind: Namespace metadata: name: "{{ $namespace }}" +{{ end }} --- apiVersion: argoproj.io/v1alpha1 @@ -25,7 +27,14 @@ spec: targetRevision: {{ $chartProps.targetRevision }} helm: values: |- - {{- tpl ($chartProps.values | default "") $ | nindent 8}} +{{- $values := ($chartProps.values | default "") -}} +{{ if $chartProps.valuesFile }} +{{- $valuesFilePath := (printf "chart-values/%s" $chartProps.valuesFile) -}} +{{- $values := $.Files.Get $valuesFilePath -}} + {{- tpl $values $ | nindent 8 }} +{{ else }} + {{- tpl $values $ | nindent 8 }} +{{ end }} releaseName: {{ $chartName }} destination: server: https://kubernetes.default.svc diff --git a/k8s/argoapps/templates/ns.yaml b/k8s/argoapps/templates/ns.yaml new file mode 100644 index 0000000..1720a78 --- /dev/null +++ b/k8s/argoapps/templates/ns.yaml @@ -0,0 +1,5 @@ +--- +apiVersion: v1 +kind: Namespace +metadata: + name: email \ No newline at end of file diff --git a/k8s/argoapps/templates/secrets.yaml b/k8s/argoapps/templates/secrets.yaml index cd4aa76..4950e90 100644 --- a/k8s/argoapps/templates/secrets.yaml +++ b/k8s/argoapps/templates/secrets.yaml @@ -63,7 +63,12 @@ metadata: annotations: homelab-secret/type: "externally-filled" data: +{{- if $value.data }} + {{- tpl $value.data $ | nindent 4}} +{{ else }} _placeholder: "" {{ end }} {{ end }} + +{{ end }} diff --git a/k8s/argoapps/values.yaml b/k8s/argoapps/values.yaml index e159db7..3d7059d 100644 --- a/k8s/argoapps/values.yaml +++ b/k8s/argoapps/values.yaml @@ -18,6 +18,8 @@ global: additionalShares: torrents: "changeme" familyvideos: "changeme" + smtp: + email: "ariel.sosnovsky@gmail.com" videohosting: linuxserverServices: @@ -87,6 +89,17 @@ apps: namespace: chart-database values: |- postgresSecret: "{{ .Values.secrets.database.secrets.dbmain.name }}" + postfix: + namespace: email + values: |- + smtp_configs: + SMTP_SERVER: "smtp.gmail.com" + SMTP_PORT: "587" + SMTP_USERNAME: "{{.Values.global.smtp.email}}" + smtp_password_secret: {{ .Values.secrets.smtp.secrets.smtp.name }} + smtp_password_secret_key: password + authelia: + valuesFile: authelia.yaml infrastructureCharts: cert-manager: @@ -116,28 +129,7 @@ infrastructureCharts: chart: postgresql repoURL: "https://charts.bitnami.com/bitnami" targetRevision: "12.1.8" - values: |- - fullnameOverride: "postgres" - image: - tag: 15.1.0-debian-11-r19 - repository: bitnami/postgresql - pullPolicy: IfNotPresent - auth: - secretKeys: - adminPasswordKey: password - existingSecret: "{{ .Values.secrets.database.secrets.dbmain.name }}" - architecture: standalone - postgresqlDataDir: /bitnami/postgresql/data - primary: - persistence: - enabled: true - mountPath: /bitnami/postgresql - storageClass: "{{ .Values.global.nfs.storageClass }}" - existingClaim: "{{ .Values.storage.database.name }}" - accessModes: - - ReadWriteMany - readReplicas: - replicaCount: 0 + valuesFile: database.yaml secrets: database: @@ -145,6 +137,13 @@ secrets: secrets: dbmain: name: "pg.password" + smtp: + namespace: email + secrets: + smtp: + name: "smtp.creds" + data: |- + username: "{{.Values.global.smtp.email}}" storage: database: @@ -155,6 +154,16 @@ storage: resources: requests: storage: 8Gi + authelia: + name: authelia + namespace: chart-authelia + accessModes: + - ReadWriteMany + resources: + limits: + storage: 5Gi + requests: + storage: 5Gi nextcloudData: name: nextcloud-data namespace: apps-nextcloud