Skip to content

Commit

Permalink
Merge pull request #42 from holaplex/mpw/update-permissions-chart
Browse files Browse the repository at this point in the history
Mpw/update permissions chart
  • Loading branch information
mpwsh authored Mar 22, 2023
2 parents 87280d3 + 80a63ef commit 017de76
Show file tree
Hide file tree
Showing 11 changed files with 265 additions and 9 deletions.
6 changes: 0 additions & 6 deletions charts/hub-permissions/Chart.lock

This file was deleted.

7 changes: 6 additions & 1 deletion charts/hub-permissions/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type: application
# to the chart and its templates, including the app version.
# Versions are expected to follow Semantic Versioning (https://semver.org/)

version: "0.0.1"
version: "0.1.0"

# This is the version number of the application being deployed. This version number should be
# incremented each time you make changes to the application. Versions are not expected to
Expand All @@ -31,5 +31,10 @@ sources:

dependencies:
- name: keto
condition: keto.enabled
version: 0.28.0
repository: https://k8s.ory.sh/helm/charts
- name: opa
condition: opa.enabled
version: 0.1.0
repository: https://charts.holaplex.com
46 changes: 46 additions & 0 deletions charts/hub-permissions/policies/namespaces.keto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,52 @@
import { Namespace, Context } from "@ory/keto-namespace-types"
class User implements Namespace {}

class Customer implements Namespace {
related: {
owners: User[]
editors: User[]
viewers: User[]
parents: Project[]
}

permits = {
view: (ctx: Context): boolean =>
this.related.viewers.includes(ctx.subject) ||
this.related.parents.traverse((parent) => parent.permits.view(ctx)) ||
this.permits.edit(ctx),
edit: (ctx: Context): boolean =>
this.related.editors.includes(ctx.subject) ||
this.related.parents.traverse((parent) => parent.permits.edit(ctx)) ||
this.permits.delete(ctx),
delete: (ctx: Context): boolean =>
this.related.owners.includes(ctx.subject) ||
this.related.parents.traverse((parent) => parent.permits.delete(ctx)),
}
}

class Drop implements Namespace {
related: {
owners: User[]
editors: User[]
viewers: User[]
parents: Project[]
}

permits = {
view: (ctx: Context): boolean =>
this.related.viewers.includes(ctx.subject) ||
this.related.parents.traverse((parent) => parent.permits.view(ctx)) ||
this.permits.edit(ctx),
edit: (ctx: Context): boolean =>
this.related.editors.includes(ctx.subject) ||
this.related.parents.traverse((parent) => parent.permits.edit(ctx)) ||
this.permits.delete(ctx),
delete: (ctx: Context): boolean =>
this.related.owners.includes(ctx.subject) ||
this.related.parents.traverse((parent) => parent.permits.delete(ctx)),
}
}

class Project implements Namespace {
related: {
owners: User[]
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion charts/hub-permissions/templates/configmap.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ metadata:
labels:
{{- include "hub-permissions.labels" $ | nindent 4 }}
data:
{{- with .Values.customNamespaces.files}}
{{- with .Values.ketoNamespaces.files}}
{{- range . }}
{{ (splitList "/" .) | last | nindent 2}}: |-
{{ $.Files.Get . | nindent 8 }}
Expand Down
54 changes: 54 additions & 0 deletions charts/hub-permissions/templates/deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: {{ include "hub-permissions.fullname" . }}
labels:
{{- include "hub-permissions.labels" . | nindent 4 }}
spec:
{{- if not .Values.autoscaling.enabled }}
replicas: {{ .Values.replicaCount }}
{{- end }}
selector:
matchLabels:
{{- include "hub-permissions.selectorLabels" . | nindent 6 }}
template:
metadata:
{{- with .Values.podAnnotations }}
annotations:
{{- toYaml . | nindent 8 }}
{{- end }}
labels:
{{- include "hub-permissions.selectorLabels" . | nindent 8 }}
spec:
{{- with .Values.imagePullSecrets }}
imagePullSecrets:
{{- toYaml . | nindent 8 }}
{{- end }}
serviceAccountName: {{ include "hub-permissions.serviceAccountName" . }}
securityContext:
{{- toYaml .Values.podSecurityContext | nindent 8 }}
containers:
- name: {{ .Chart.Name }}
securityContext:
{{- toYaml .Values.securityContext | nindent 12 }}
image: "{{ .Values.image.repository }}:{{ .Values.image.tag }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
envFrom:
- configMapRef:
name: {{ include "hub-permissions.fullname" . }}
- secretRef:
name: {{ include "hub-permissions.fullname" . }}
resources:
{{- toYaml .Values.resources | nindent 12 }}
{{- with .Values.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.tolerations }}
tolerations:
{{- toYaml . | nindent 8 }}
{{- end }}
12 changes: 12 additions & 0 deletions charts/hub-permissions/templates/environment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: v1
kind: ConfigMap
metadata:
name: {{ include "hub-permissions.fullname" . }}
data:
{{- with .Values.environment }}
RUST_LOG: {{ .logLevel }}
KAFKA_BROKERS: {{ required "must set kafka brokers" .kafkaBrokers | quote }}
KAFKA_SSL: {{ default "false" .kafkaSsl | quote }}
KAFKA_USERNAME: {{ required "must set kafka username" .kafkaUsername | quote }}
KETO_WRITE_URL: {{ required "must set keto write url" .ketoWriteUrl | quote }}
{{- end }}
28 changes: 28 additions & 0 deletions charts/hub-permissions/templates/hpa.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{{- if .Values.autoscaling.enabled }}
apiVersion: autoscaling/v2beta1
kind: HorizontalPodAutoscaler
metadata:
name: {{ include "hub-permissions.fullname" . }}
labels:
{{- include "hub-permissions.labels" . | nindent 4 }}
spec:
scaleTargetRef:
apiVersion: apps/v1
kind: Deployment
name: {{ include "hub-permissions.fullname" . }}
minReplicas: {{ .Values.autoscaling.minReplicas }}
maxReplicas: {{ .Values.autoscaling.maxReplicas }}
metrics:
{{- if .Values.autoscaling.targetCPUUtilizationPercentage }}
- type: Resource
resource:
name: cpu
targetAverageUtilization: {{ .Values.autoscaling.targetCPUUtilizationPercentage }}
{{- end }}
{{- if .Values.autoscaling.targetMemoryUtilizationPercentage }}
- type: Resource
resource:
name: memory
targetAverageUtilization: {{ .Values.autoscaling.targetMemoryUtilizationPercentage }}
{{- end }}
{{- end }}
13 changes: 13 additions & 0 deletions charts/hub-permissions/templates/secrets.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- with .Values.secrets }}
{{- if .enabled }}
apiVersion: v1
kind: Secret
metadata:
name: {{ include "hub-permissions.fullname" $ }}
annotations:
"helm.sh/hook": pre-install
type: Opaque
data:
KAFKA_PASSWORD: {{ required "must set kafka password" .entries.kafkaPassword | b64enc }}
{{- end }}
{{- end }}
12 changes: 12 additions & 0 deletions charts/hub-permissions/templates/serviceaccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{{- if .Values.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ include "hub-permissions.serviceAccountName" . }}
labels:
{{- include "hub-permissions.labels" . | nindent 4 }}
{{- with .Values.serviceAccount.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
94 changes: 93 additions & 1 deletion charts/hub-permissions/values.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,100 @@
customNamespaces:
# Default values for hub-permissions.
# This is a YAML-formatted file.
# Declare variables to be passed into your templates.

replicaCount: 1

image:
repository: holaplex/hub-permissions
pullPolicy: IfNotPresent
# Overrides the image tag whose default is the chart appVersion.
tag: "latest"

imagePullSecrets: []
nameOverride: ""
fullnameOverride: ""

serviceAccount:
# Specifies whether a service account should be created
create: true
# Annotations to add to the service account
annotations: {}
# The name of the service account to use.
# If not set and create is true, a name is generated using the fullname template
name: ""

podAnnotations: {}

podSecurityContext: {}
# fsGroup: 2000

securityContext: {}
# capabilities:
# drop:
# - ALL
# readOnlyRootFilesystem: true
# runAsNonRoot: true
# runAsUser: 1000

resources: {}
# We usually recommend not to specify default resources and to leave this as a conscious
# choice for the user. This also increases chances charts run on environments with little
# resources, such as Minikube. If you do want to specify resources, uncomment the following
# lines, adjust them as necessary, and remove the curly braces after 'resources:'.
# limits:
# cpu: 100m
# memory: 128Mi
# requests:
# cpu: 100m
# memory: 128Mi

autoscaling:
enabled: false
minReplicas: 1
maxReplicas: 100
targetCPUUtilizationPercentage: 80
# targetMemoryUtilizationPercentage: 80

nodeSelector: {}

tolerations: []

affinity: {}

secrets:
enabled: true
entries:
kafkaPassword: ""

environment:
logLevel: "info"
kafkaBrokers: "hub-eventbus-cluster-0.hub-eventbus-cluster.default.svc.cluster.local.:9093"
kafkaSsl: false
kafkaUsername: ""
ketoWriteUrl: http://hub-permissions-keto-write

ketoNamespaces:
files:
- policies/namespaces.keto.ts

opa:
enabled: true
replicaCount: 1
image:
repository: openpolicyagent/opa
tag: 0.48.0-rootless
pullPolicy: IfNotPresent

secrets:
enabled: true
entries:
s3BucketUrl: https://stage-holaplex-hub-policies.s3.us-east-1.amazonaws.com/
s3Region: us-east-1
s3AccessKey: ""
s3SecretKey: ""

keto:
enabled: true
replicaCount: 1
image:
repository: oryd/keto
Expand Down

0 comments on commit 017de76

Please sign in to comment.