Agent Mesh
Go a2aa2a-protocolagent-meshagentic-aiinferencemcpmeshmesh-networknetwork-securitynetworking-aip2p-network
feat(deploy): introduce sam-mesh Helm chart and migrate local kind integration
Antonio Ojea63fe69d477be
diff --git a/charts/sam-mesh/Chart.yaml b/charts/sam-mesh/Chart.yamlnew file mode 100644index 00000000..e89a669e--- /dev/null+++ b/charts/sam-mesh/Chart.yaml@@ -0,0 +1,6 @@+apiVersion: v2+name: sam-mesh+description: A Helm chart for deploying the Sovereign Agent Mesh (SAM) Control Plane, Router, and Console+type: application+version: 0.1.0+appVersion: "1.0.0"diff --git a/charts/sam-mesh/templates/_helpers.tpl b/charts/sam-mesh/templates/_helpers.tplnew file mode 100644index 00000000..26c19ec2--- /dev/null+++ b/charts/sam-mesh/templates/_helpers.tpl@@ -0,0 +1,51 @@+{{/*+Expand the name of the chart.+*/}}+{{- define "sam-mesh.name" -}}+{{- default .Chart.Name .Values.nameOverride | trunc 63 | trimSuffix "-" }}+{{- end }}++{{/*+Create a default fully qualified app name.+We truncate at 63 chars because some Kubernetes name fields are limited to this (by the DNS naming spec).+If release name contains chart name it will be used as a full name.+*/}}+{{- define "sam-mesh.fullname" -}}+{{- if .Values.fullnameOverride }}+{{- .Values.fullnameOverride | trunc 63 | trimSuffix "-" }}+{{- else }}+{{- $name := default .Chart.Name .Values.nameOverride }}+{{- if contains $name .Release.Name }}+{{- .Release.Name | trunc 63 | trimSuffix "-" }}+{{- else }}+{{- printf "%s-%s" .Release.Name $name | trunc 63 | trimSuffix "-" }}+{{- end }}+{{- end }}+{{- end }}++{{/*+Create chart name and version as used by the chart label.+*/}}+{{- define "sam-mesh.chart" -}}+{{- printf "%s-%s" .Chart.Name .Chart.Version | replace "+" "_" | trunc 63 | trimSuffix "-" }}+{{- end }}++{{/*+Common labels+*/}}+{{- define "sam-mesh.labels" -}}+helm.sh/chart: {{ include "sam-mesh.chart" . }}+{{ include "sam-mesh.selectorLabels" . }}+{{- if .Chart.AppVersion }}+app.kubernetes.io/version: {{ .Chart.AppVersion | quote }}+{{- end }}+app.kubernetes.io/managed-by: {{ .Release.Service }}+{{- end }}++{{/*+Selector labels+*/}}+{{- define "sam-mesh.selectorLabels" -}}+app.kubernetes.io/name: {{ include "sam-mesh.name" . }}+app.kubernetes.io/instance: {{ .Release.Name }}+{{- end }}diff --git a/charts/sam-mesh/templates/bootstrap-job.yaml b/charts/sam-mesh/templates/bootstrap-job.yamlnew file mode 100644index 00000000..d1f9ebd3--- /dev/null+++ b/charts/sam-mesh/templates/bootstrap-job.yaml@@ -0,0 +1,138 @@+apiVersion: v1+kind: ServiceAccount+metadata:+ name: {{ include "sam-mesh.fullname" . }}-bootstrap-sa+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}+---+apiVersion: rbac.authorization.k8s.io/v1+kind: Role+metadata:+ name: {{ include "sam-mesh.fullname" . }}-bootstrap-role+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}+rules:+- apiGroups: [""]+ resources: ["secrets"]+ verbs: ["get", "create", "delete", "patch", "update"]+---+apiVersion: rbac.authorization.k8s.io/v1+kind: RoleBinding+metadata:+ name: {{ include "sam-mesh.fullname" . }}-bootstrap-rb+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}+subjects:+- kind: ServiceAccount+ name: {{ include "sam-mesh.fullname" . }}-bootstrap-sa+ namespace: {{ .Release.Namespace }}+roleRef:+ kind: Role+ name: {{ include "sam-mesh.fullname" . }}-bootstrap-role+ apiGroup: rbac.authorization.k8s.io+---+apiVersion: batch/v1+kind: Job+metadata:+ name: {{ include "sam-mesh.fullname" . }}-bootstrap+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}+spec:+ activeDeadlineSeconds: 120+ template:+ metadata:+ labels:+ app: {{ include "sam-mesh.fullname" . }}-bootstrap+ spec:+ serviceAccountName: {{ include "sam-mesh.fullname" . }}-bootstrap-sa+ restartPolicy: OnFailure+ containers:+ - name: bootstrap+ image: curlimages/curl:8.6.0+ imagePullPolicy: {{ .Values.global.imagePullPolicy }}+ env:+ - name: NAMESPACE+ value: {{ .Release.Namespace | quote }}+ - name: SECRET_NAME+ value: "{{ include "sam-mesh.fullname" . }}-router-token"+ - name: ADMIN_TOKEN+ valueFrom:+ secretKeyRef:+ name: {{ include "sam-mesh.fullname" . }}-secrets+ key: admin-token+ command: ["/bin/sh", "-c"]+ args:+ - |+ set -e+ CACERT=/var/run/secrets/kubernetes.io/serviceaccount/ca.crt+ K8S_TOKEN=$(cat /var/run/secrets/kubernetes.io/serviceaccount/token)+ CP_URL="http://{{ include "sam-mesh.fullname" . }}-control-plane:8080"++ echo "Waiting for Control Plane to be ready..."+ until curl -s "${CP_URL}/info" > /dev/null; do+ echo "Control plane not ready yet, sleeping..."+ sleep 2+ done++ echo "Seeding default policies..."+ {{- $bindings := .Values.bootstrap.bindings -}}+ {{- if not $bindings -}}+ {{- $defaultRouterSA := printf "user:system:serviceaccount:%s:%s-router-sa" .Release.Namespace (include "sam-mesh.fullname" .) -}}+ {{- $bindings = list+ (dict "role" "sam:role:router" "members" (list "group:routers" $defaultRouterSA))+ (dict "role" "sam-admin" "members" (list (printf "user:system:serviceaccount:%s:node-a-sa" .Release.Namespace) (printf "user:system:serviceaccount:%s:node-b-sa" .Release.Namespace) (printf "user:system:serviceaccount:%s:node-c-sa" .Release.Namespace) (printf "user:system:serviceaccount:%s:local-node-sa" .Release.Namespace)))+ (dict "role" "sam:role:sambox" "members" (list (printf "user:system:serviceaccount:%s:sam-box-sa" .Release.Namespace)))+ -}}+ {{- end }}+ curl -s -X POST \+ -H "Content-Type: application/json" \+ -H "Authorization: Bearer ${ADMIN_TOKEN}" \+ -d '{+ "roles": [+ {"name": "sam-admin", "allowed_services": ["*"], "allowed_targets": ["*"]},+ {"name": "sam:role:sambox", "allowed_services": ["*"], "allowed_targets": ["*"]},+ {"name": "sam:role:router", "allowed_services": ["*"], "allowed_targets": ["*"]}+ ],+ "bindings": {{ toJson $bindings }}+ }' \+ "${CP_URL}/policies" >/dev/null+++ echo "Generating bootstrap token for sam-router..."+ TOKEN_RESP=$(curl -s -X POST \+ -H "Content-Type: application/json" \+ -H "Authorization: Bearer ${ADMIN_TOKEN}" \+ -d '{"role": "sam:role:router", "max_usages": 999999}' \+ "${CP_URL}/admin/bootstrap-tokens")++ ROUTER_TOKEN=$(echo "${TOKEN_RESP}" | grep -o '"token":"[^"]*' | cut -d'"' -f4)+ if [ -z "${ROUTER_TOKEN}" ]; then+ echo "Failed to extract router token from response: ${TOKEN_RESP}"+ exit 1+ fi++ echo "Writing bootstrap token to Kubernetes secret ${SECRET_NAME}..."++ # Delete existing secret first (ignore error if doesn't exist)+ curl -s --cacert $CACERT -X DELETE \+ -H "Authorization: Bearer $K8S_TOKEN" \+ "https://kubernetes.default.svc/api/v1/namespaces/${NAMESPACE}/secrets/${SECRET_NAME}" > /dev/null || true++ # Create new secret+ curl -s --cacert $CACERT -X POST \+ -H "Authorization: Bearer $K8S_TOKEN" \+ -H "Content-Type: application/json" \+ -d '{+ "apiVersion": "v1",+ "kind": "Secret",+ "metadata": {+ "name": "'"${SECRET_NAME}"'"+ },+ "type": "Opaque",+ "stringData": {+ "token": "'"${ROUTER_TOKEN}"'"+ }+ }' \+ "https://kubernetes.default.svc/api/v1/namespaces/${NAMESPACE}/secrets" > /dev/null++ echo "Bootstrap completed successfully!"diff --git a/charts/sam-mesh/templates/console-deployment.yaml b/charts/sam-mesh/templates/console-deployment.yamlnew file mode 100644index 00000000..9e1f8e99--- /dev/null+++ b/charts/sam-mesh/templates/console-deployment.yaml@@ -0,0 +1,37 @@+{{- if .Values.console.enabled -}}+apiVersion: apps/v1+kind: Deployment+metadata:+ name: {{ include "sam-mesh.fullname" . }}-console+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}+spec:+ replicas: {{ .Values.console.replicaCount }}+ selector:+ matchLabels:+ app: {{ include "sam-mesh.fullname" . }}-console+ template:+ metadata:+ labels:+ app: {{ include "sam-mesh.fullname" . }}-console+ spec:+ containers:+ - name: sam-console+ image: "{{ .Values.console.image.repository }}:{{ .Values.global.imageTag }}"+ imagePullPolicy: {{ .Values.global.imagePullPolicy }}+ env:+ - name: ADMIN_TOKEN+ valueFrom:+ secretKeyRef:+ name: {{ include "sam-mesh.fullname" . }}-secrets+ key: admin-token+ ports:+ - containerPort: 8081+ name: http+ protocol: TCP+ args:+ - "--hub=http://{{ include "sam-mesh.fullname" . }}-control-plane:8080"+ - "--bind-addr=:8081"+ - "--static-dir=/app/public"+ - "--admin-token=$(ADMIN_TOKEN)"+{{- end }}diff --git a/charts/sam-mesh/templates/console-service.yaml b/charts/sam-mesh/templates/console-service.yamlnew file mode 100644index 00000000..a2438151--- /dev/null+++ b/charts/sam-mesh/templates/console-service.yaml@@ -0,0 +1,20 @@+{{- if .Values.console.enabled -}}+apiVersion: v1+kind: Service+metadata:+ name: {{ include "sam-mesh.fullname" . }}-console+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}+spec:+ type: {{ .Values.console.service.type }}+ ports:+ - name: http+ port: {{ .Values.console.service.port }}+ targetPort: 8081+ {{- if and (eq .Values.console.service.type "NodePort") .Values.console.service.nodePort }}+ nodePort: {{ .Values.console.service.nodePort }}+ {{- end }}+ protocol: TCP+ selector:+ app: {{ include "sam-mesh.fullname" . }}-console+{{- end }}diff --git a/charts/sam-mesh/templates/control-plane-deployment.yaml b/charts/sam-mesh/templates/control-plane-deployment.yamlnew file mode 100644index 00000000..f97610b4--- /dev/null+++ b/charts/sam-mesh/templates/control-plane-deployment.yaml@@ -0,0 +1,73 @@+apiVersion: apps/v1+kind: Deployment+metadata:+ name: {{ include "sam-mesh.fullname" . }}-control-plane+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}+spec:+ replicas: {{ .Values.controlPlane.replicaCount }}+ selector:+ matchLabels:+ app: {{ include "sam-mesh.fullname" . }}-control-plane+ template:+ metadata:+ labels:+ app: {{ include "sam-mesh.fullname" . }}-control-plane+ spec:+ {{- if .Values.database.postgres.deployInternal }}+ initContainers:+ - name: wait-for-db+ image: busybox:1.36.1+ imagePullPolicy: {{ .Values.global.imagePullPolicy }}+ command: ['sh', '-c', 'until nc -z -w3 {{ include "sam-mesh.fullname" . }}-db 5432; do echo waiting for db; sleep 1; done']+ {{- end }}+ containers:+ - name: sam-control-plane+ image: "{{ .Values.controlPlane.image.repository }}:{{ .Values.global.imageTag }}"+ imagePullPolicy: {{ .Values.global.imagePullPolicy }}+ env:+ - name: DB_PASSWORD+ valueFrom:+ secretKeyRef:+ name: {{ include "sam-mesh.fullname" . }}-secrets+ key: db-password+ - name: ADMIN_TOKEN+ valueFrom:+ secretKeyRef:+ name: {{ include "sam-mesh.fullname" . }}-secrets+ key: admin-token+ ports:+ - containerPort: 8080+ name: http+ protocol: TCP+ readinessProbe:+ httpGet:+ path: /info+ port: http+ periodSeconds: 5+ livenessProbe:+ httpGet:+ path: /info+ port: http+ periodSeconds: 15+ args:+ - "--bind-address=0.0.0.0:8080"+ {{- if eq .Values.database.type "postgres" }}+ - "--db-driver=postgres"+ {{- $dbHost := printf "%s-db" (include "sam-mesh.fullname" .) }}+ {{- if not .Values.database.postgres.deployInternal }}+ {{- $dbHost = .Values.database.postgres.host }}+ {{- end }}+ - "--db-dsn=postgres://{{ .Values.database.postgres.user }}:$(DB_PASSWORD)@{{ $dbHost }}:5432/{{ .Values.database.postgres.database }}?sslmode=disable"+ {{- else }}+ - "--db-driver=sqlite"+ - "--db-dsn=/data/control-plane.db"+ {{- end }}+ - "--issuer={{ .Values.controlPlane.oidcIssuer }}"+ - "--allowed-audiences={{ .Values.controlPlane.allowedAudiences }}"+ - "--admin-token=$(ADMIN_TOKEN)"+ {{- if .Values.controlPlane.autoApproveEnrollment }}+ - "--auto-approve-enrollment"+ {{- end }}+ - "--insecure-skip-tls-verify"+ - "--log-level={{ .Values.controlPlane.logLevel }}"diff --git a/charts/sam-mesh/templates/control-plane-service.yaml b/charts/sam-mesh/templates/control-plane-service.yamlnew file mode 100644index 00000000..183fb86f--- /dev/null+++ b/charts/sam-mesh/templates/control-plane-service.yaml@@ -0,0 +1,18 @@+apiVersion: v1+kind: Service+metadata:+ name: {{ include "sam-mesh.fullname" . }}-control-plane+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}+spec:+ type: {{ .Values.controlPlane.service.type }}+ ports:+ - name: http+ port: {{ .Values.controlPlane.service.port }}+ targetPort: 8080+ {{- if and (eq .Values.controlPlane.service.type "NodePort") .Values.controlPlane.service.nodePort }}+ nodePort: {{ .Values.controlPlane.service.nodePort }}+ {{- end }}+ protocol: TCP+ selector:+ app: {{ include "sam-mesh.fullname" . }}-control-planediff --git a/charts/sam-mesh/templates/db-service.yaml b/charts/sam-mesh/templates/db-service.yamlnew file mode 100644index 00000000..3bb4a09e--- /dev/null+++ b/charts/sam-mesh/templates/db-service.yaml@@ -0,0 +1,17 @@+{{- if .Values.database.postgres.deployInternal -}}+apiVersion: v1+kind: Service+metadata:+ name: {{ include "sam-mesh.fullname" . }}-db+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}+spec:+ type: ClusterIP+ ports:+ - name: postgres+ port: 5432+ targetPort: 5432+ protocol: TCP+ selector:+ app: {{ include "sam-mesh.fullname" . }}-db+{{- end }}diff --git a/charts/sam-mesh/templates/db-statefulset.yaml b/charts/sam-mesh/templates/db-statefulset.yamlnew file mode 100644index 00000000..0705d9b7--- /dev/null+++ b/charts/sam-mesh/templates/db-statefulset.yaml@@ -0,0 +1,48 @@+{{- if .Values.database.postgres.deployInternal -}}+apiVersion: apps/v1+kind: StatefulSet+metadata:+ name: {{ include "sam-mesh.fullname" . }}-db+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}+spec:+ serviceName: {{ include "sam-mesh.fullname" . }}-db+ replicas: 1+ selector:+ matchLabels:+ app: {{ include "sam-mesh.fullname" . }}-db+ template:+ metadata:+ labels:+ app: {{ include "sam-mesh.fullname" . }}-db+ spec:+ containers:+ - name: postgres+ image: "{{ .Values.database.postgres.image.repository }}:{{ .Values.database.postgres.image.tag }}"+ imagePullPolicy: {{ .Values.global.imagePullPolicy }}+ env:+ - name: POSTGRES_DB+ value: {{ .Values.database.postgres.database | quote }}+ - name: POSTGRES_USER+ value: {{ .Values.database.postgres.user | quote }}+ - name: POSTGRES_PASSWORD+ valueFrom:+ secretKeyRef:+ name: {{ include "sam-mesh.fullname" . }}-secrets+ key: db-password+ ports:+ - containerPort: 5432+ name: postgres+ protocol: TCP+ volumeMounts:+ - name: db-data+ mountPath: /var/lib/postgresql/data+ volumeClaimTemplates:+ - metadata:+ name: db-data+ spec:+ accessModes: [ "ReadWriteOnce" ]+ resources:+ requests:+ storage: {{ .Values.database.postgres.storageSize | quote }}+{{- end }}diff --git a/development/kind/13-dex.yaml b/charts/sam-mesh/templates/dex-deployment.yamlsimilarity index 66%rename from development/kind/13-dex.yamlrename to charts/sam-mesh/templates/dex-deployment.yamlindex 64f95ac6..0da5f031 100644--- a/development/kind/13-dex.yaml+++ b/charts/sam-mesh/templates/dex-deployment.yaml@@ -1,8 +1,10 @@+{{- if .Values.dex.enabled -}}apiVersion: v1kind: ConfigMapmetadata:- name: dex-config- namespace: ${NAMESPACE}+ name: {{ include "sam-mesh.fullname" . }}-dex-config+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}data:config.yaml: |issuer: http://dex:5556/dex@@ -30,23 +32,25 @@ data:apiVersion: apps/v1kind: Deploymentmetadata:- name: dex- namespace: ${NAMESPACE}+ name: {{ include "sam-mesh.fullname" . }}-dex+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}spec:replicas: 1selector:matchLabels:- app: dex+ app: {{ include "sam-mesh.fullname" . }}-dextemplate:metadata:labels:- app: dex+ app: {{ include "sam-mesh.fullname" . }}-dexspec:nodeSelector:sam-role: hubcontainers:- name: dex- image: ghcr.io/dexidp/dex:v2.41.1+ image: "{{ .Values.dex.image.repository }}:{{ .Values.dex.image.tag }}"+ imagePullPolicy: {{ .Values.global.imagePullPolicy }}args:- dex- serve@@ -60,19 +64,21 @@ spec:volumes:- name: configconfigMap:- name: dex-config+ name: {{ include "sam-mesh.fullname" . }}-dex-config---apiVersion: v1kind: Servicemetadata:name: dex- namespace: ${NAMESPACE}+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}spec:type: NodePortselector:- app: dex+ app: {{ include "sam-mesh.fullname" . }}-dexports:- name: httpport: 5556targetPort: 5556nodePort: 30556+{{- end }}diff --git a/charts/sam-mesh/templates/router-service.yaml b/charts/sam-mesh/templates/router-service.yamlnew file mode 100644index 00000000..0735681b--- /dev/null+++ b/charts/sam-mesh/templates/router-service.yaml@@ -0,0 +1,24 @@+{{- if .Values.router.enabled -}}+apiVersion: v1+kind: Service+metadata:+ name: {{ include "sam-mesh.fullname" . }}-router+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}+spec:+ type: {{ .Values.router.service.type }}+ ports:+ - name: p2p-tcp+ port: {{ .Values.router.service.port }}+ targetPort: 4501+ {{- if and (eq .Values.router.service.type "NodePort") .Values.router.service.nodePort }}+ nodePort: {{ .Values.router.service.nodePort }}+ {{- end }}+ protocol: TCP+ - name: p2p-udp+ port: {{ .Values.router.service.port }}+ targetPort: 4501+ protocol: UDP+ selector:+ app: {{ include "sam-mesh.fullname" . }}-router+{{- end }}diff --git a/charts/sam-mesh/templates/router-statefulset.yaml b/charts/sam-mesh/templates/router-statefulset.yamlnew file mode 100644index 00000000..f6f520f0--- /dev/null+++ b/charts/sam-mesh/templates/router-statefulset.yaml@@ -0,0 +1,79 @@+{{- if .Values.router.enabled -}}+apiVersion: v1+kind: ServiceAccount+metadata:+ name: {{ include "sam-mesh.fullname" . }}-router-sa+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}+---+apiVersion: apps/v1+kind: StatefulSet+metadata:+ name: {{ include "sam-mesh.fullname" . }}-router+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}+spec:+ serviceName: {{ include "sam-mesh.fullname" . }}-router+ replicas: {{ .Values.router.replicaCount }}+ selector:+ matchLabels:+ app: {{ include "sam-mesh.fullname" . }}-router+ template:+ metadata:+ labels:+ app: {{ include "sam-mesh.fullname" . }}-router+ spec:+ serviceAccountName: {{ include "sam-mesh.fullname" . }}-router-sa+ containers:+ - name: sam-router+ image: "{{ .Values.router.image.repository }}:{{ .Values.global.imageTag }}"+ imagePullPolicy: {{ .Values.global.imagePullPolicy }}+ ports:+ - containerPort: 4501+ name: p2p-tcp+ protocol: TCP+ - containerPort: 4501+ name: p2p-udp+ protocol: UDP+ env:+ {{- if not .Values.router.useOidcToken }}+ - name: BOOTSTRAP_TOKEN+ valueFrom:+ secretKeyRef:+ name: {{ include "sam-mesh.fullname" . }}-router-token+ key: token+ {{- end }}+ args:+ - "--control-plane=http://{{ include "sam-mesh.fullname" . }}-control-plane:8080"+ - "--listen=/ip4/0.0.0.0/tcp/4501"+ - "--listen=/ip4/0.0.0.0/udp/4501/quic-v1"+ - "--external-addr=/dns4/{{ include "sam-mesh.fullname" . }}-router/tcp/4501"+ - "--keys-path=/data/router.key"+ - "--allow-loopback"+ - "--log-level={{ .Values.router.logLevel }}"+ {{- if .Values.router.useOidcToken }}+ - "--jwt-path=/var/run/secrets/tokens/sam-token"+ {{- else }}+ - "--bootstrap-token=$(BOOTSTRAP_TOKEN)"+ {{- end }}+ volumeMounts:+ - name: router-data+ mountPath: /data+ {{- if .Values.router.useOidcToken }}+ - name: sam-token+ mountPath: /var/run/secrets/tokens+ readOnly: true+ {{- end }}+ volumes:+ - name: router-data+ emptyDir: {}+ {{- if .Values.router.useOidcToken }}+ - name: sam-token+ projected:+ sources:+ - serviceAccountToken:+ path: sam-token+ expirationSeconds: 3600+ audience: "sam-hub-audience"+ {{- end }}+{{- end }}diff --git a/charts/sam-mesh/templates/secrets.yaml b/charts/sam-mesh/templates/secrets.yamlnew file mode 100644index 00000000..c7b6e577--- /dev/null+++ b/charts/sam-mesh/templates/secrets.yaml@@ -0,0 +1,10 @@+apiVersion: v1+kind: Secret+metadata:+ name: {{ include "sam-mesh.fullname" . }}-secrets+ labels:+ {{- include "sam-mesh.labels" . | nindent 4 }}+type: Opaque+data:+ admin-token: {{ .Values.controlPlane.adminToken | b64enc | quote }}+ db-password: {{ .Values.database.postgres.password | b64enc | quote }}diff --git a/charts/sam-mesh/values.yaml b/charts/sam-mesh/values.yamlnew file mode 100644index 00000000..d105315e--- /dev/null+++ b/charts/sam-mesh/values.yaml@@ -0,0 +1,68 @@+global:+ imageTag: local+ imagePullPolicy: IfNotPresent++controlPlane:+ replicaCount: 2+ image:+ repository: sam-control-plane+ logLevel: info+ adminToken: super-secret-admin-token+ autoApproveEnrollment: true+ oidcIssuer: "http://dex:5556/dex"+ allowedAudiences: "sam-mesh-audience,sam-hub-audience"+ service:+ type: ClusterIP+ port: 8080+ nodePort: null++database:+ type: postgres+ postgres:+ deployInternal: true+ image:+ repository: postgres+ tag: 16-alpine+ user: sam+ password: sam-secret-password+ database: sam_mesh+ storageSize: 1Gi++router:+ enabled: true+ replicaCount: 1+ image:+ repository: sam-router+ useOidcToken: false+ logLevel: info+ service:+ type: ClusterIP+ port: 4501+ nodePort: null++console:+ enabled: true+ replicaCount: 1+ image:+ repository: sam-console+ service:+ type: ClusterIP+ port: 8081+ nodePort: null++dex:+ enabled: false+ image:+ repository: dexidp/dex+ tag: v2.39.0+ google:+ clientId: ""+ clientSecret: ""+ github:+ clientId: ""+ clientSecret: ""+ cliOAuthSecret: ""++bootstrap:+ bindings: []+diff --git a/development/kind/10-control-plane.yaml b/development/kind/10-control-plane.yamldeleted file mode 100644index 6e66ad14..00000000--- a/development/kind/10-control-plane.yaml+++ /dev/null@@ -1,116 +0,0 @@-apiVersion: v1-kind: Service-metadata:- name: sam-control-plane- namespace: ${NAMESPACE}-spec:- type: ClusterIP- selector:- app: sam-control-plane- ports:- - { name: http, port: 8080, targetPort: 8080, protocol: TCP }-----apiVersion: v1-kind: Service-metadata:- name: sam-db- namespace: ${NAMESPACE}-spec:- type: ClusterIP- selector:- app: sam-db- ports:- - { name: postgres, port: 5432, targetPort: 5432, protocol: TCP }-----apiVersion: apps/v1-kind: StatefulSet-metadata:- name: sam-db- namespace: ${NAMESPACE}-spec:- serviceName: sam-db- replicas: 1- selector:- matchLabels:- app: sam-db- template:- metadata:- labels:- app: sam-db- spec:- containers:- - name: postgres- image: postgres:16-alpine- env:- - name: POSTGRES_DB- value: sam_mesh- - name: POSTGRES_USER- value: sam- - name: POSTGRES_PASSWORD- value: sam-secret-password- ports:- - containerPort: 5432- protocol: TCP- volumeMounts:- - name: db-data- mountPath: /var/lib/postgresql/data- volumeClaimTemplates:- - metadata:- name: db-data- spec:- accessModes: [ "ReadWriteOnce" ]- resources:- requests:- storage: 1Gi-----apiVersion: apps/v1-kind: Deployment-metadata:- name: sam-control-plane- namespace: ${NAMESPACE}-spec:- replicas: 2- selector:- matchLabels:- app: sam-control-plane- template:- metadata:- labels:- app: sam-control-plane- spec:- nodeSelector:- sam-role: hub- containers:- - name: sam-control-plane- image: sam-control-plane:${IMAGE_TAG}- imagePullPolicy: IfNotPresent- args:- - "--bind-address=0.0.0.0:8080"- - "--db-driver=postgres"- - "--db-dsn=postgres://sam:sam-secret-password@sam-db:5432/sam_mesh?sslmode=disable"- - "--issuer=${CONTROL_PLANE_ISSUERS}"- - "--allowed-audiences=${ALLOWED_AUDIENCES}"- - "--insecure-skip-tls-verify"- - "--admin-token=super-secret-admin-token"- ports:- - { containerPort: 8080, name: http, protocol: TCP }- readinessProbe:- httpGet:- path: /info- port: http- periodSeconds: 2------# Host-facing access for a locally-built sam-node. Reachable on the host at-# 127.0.0.1:9090 via the control-plane extraPortMappings.-apiVersion: v1-kind: Service-metadata:- name: sam-control-plane-nodeport- namespace: ${NAMESPACE}-spec:- type: NodePort- selector:- app: sam-control-plane- ports:- - { name: http, port: 8080, targetPort: 8080, nodePort: 30090, protocol: TCP }diff --git a/development/kind/11-router.yaml b/development/kind/11-router.yamldeleted file mode 100644index fe54f7fb..00000000--- a/development/kind/11-router.yaml+++ /dev/null@@ -1,84 +0,0 @@-apiVersion: v1-kind: ServiceAccount-metadata:- name: sam-router-sa- namespace: ${NAMESPACE}-----apiVersion: v1-kind: Service-metadata:- name: sam-router- namespace: ${NAMESPACE}-spec:- type: ClusterIP- selector:- app: sam-router- ports:- - { name: p2p-tcp, port: 4501, targetPort: 4501, protocol: TCP }- - { name: p2p-udp, port: 4501, targetPort: 4501, protocol: UDP }-----apiVersion: apps/v1-kind: StatefulSet-metadata:- name: sam-router- namespace: ${NAMESPACE}-spec:- serviceName: "sam-router"- replicas: 1- selector:- matchLabels:- app: sam-router- template:- metadata:- labels:- app: sam-router- spec:- serviceAccountName: sam-router-sa- nodeSelector:- sam-role: hub- containers:- - name: sam-router- image: sam-router:${IMAGE_TAG}- imagePullPolicy: IfNotPresent- ports:- - { containerPort: 4501, name: p2p-tcp, protocol: TCP }- - { containerPort: 4501, name: p2p-udp, protocol: UDP }- args:- - "--control-plane=http://sam-control-plane.${NAMESPACE}.svc.cluster.local:8080"- - "--listen=/ip4/0.0.0.0/tcp/4501"- - "--listen=/ip4/0.0.0.0/udp/4501/quic-v1"- - "--external-addr=/dns4/sam-router.${NAMESPACE}.svc.cluster.local/tcp/4501"- - "--external-addr=/ip4/127.0.0.1/tcp/4001"- - "--jwt-path=/var/run/secrets/tokens/sam-token"- - "--keys-path=/data/router.key"- - "--allow-loopback"- volumeMounts:- - name: sam-token- mountPath: /var/run/secrets/tokens- readOnly: true- - name: router-data- mountPath: /data- volumes:- - name: sam-token- projected:- sources:- - serviceAccountToken:- path: sam-token- expirationSeconds: 3600- audience: "sam-hub-audience"- - name: router-data- emptyDir: {}-----# Host-facing access for a locally-built sam-node. Reachable on the host at-# 127.0.0.1:4001 via the control-plane extraPortMappings.-apiVersion: v1-kind: Service-metadata:- name: sam-router-nodeport- namespace: ${NAMESPACE}-spec:- type: NodePort- selector:- app: sam-router- ports:- - { name: p2p-tcp, port: 4501, targetPort: 4501, nodePort: 30401, protocol: TCP }diff --git a/development/kind/12-console.yaml b/development/kind/12-console.yamldeleted file mode 100644index 5329710c..00000000--- a/development/kind/12-console.yaml+++ /dev/null@@ -1,52 +0,0 @@-apiVersion: v1-kind: Service-metadata:- name: sam-console- namespace: ${NAMESPACE}-spec:- type: ClusterIP- selector:- app: sam-console- ports:- - { name: http, port: 80, targetPort: 8081, protocol: TCP }-----apiVersion: v1-kind: Service-metadata:- name: sam-console-nodeport- namespace: ${NAMESPACE}-spec:- type: NodePort- selector:- app: sam-console- ports:- - { name: http, port: 8081, targetPort: 8081, nodePort: 30081, protocol: TCP }-----apiVersion: apps/v1-kind: Deployment-metadata:- name: sam-console- namespace: ${NAMESPACE}-spec:- replicas: 1- selector:- matchLabels:- app: sam-console- template:- metadata:- labels:- app: sam-console- spec:- nodeSelector:- sam-role: hub- containers:- - name: sam-console- image: sam-console:${IMAGE_TAG}- imagePullPolicy: IfNotPresent- args:- - "--hub=http://sam-control-plane:8080"- - "--bind-addr=:8081"- - "--static-dir=/app/public"- - "--admin-token=super-secret-admin-token"- ports:- - { containerPort: 8081, name: http, protocol: TCP }diff --git a/development/kind/node.template.yaml b/development/kind/node.template.yamlindex 745b3660..0d96f474 100644--- a/development/kind/node.template.yaml+++ b/development/kind/node.template.yaml@@ -28,7 +28,7 @@ spec:imagePullPolicy: IfNotPresentargs:- "run"- - "--hub=http://sam-control-plane:8080"+ - "--hub=${HUB_URL}"- "--jwt-path=/var/run/secrets/tokens/sam-token"- "--api-token=devtoken"- "--bind-addr=0.0.0.0:8080"diff --git a/development/kind/run.sh b/development/kind/run.shindex 70ac7a52..3237c4ef 100755--- a/development/kind/run.sh+++ b/development/kind/run.sh@@ -8,6 +8,10 @@ NAMESPACE="sam-kind"SESSION="sam-kind"KCTX="kind-${CLUSTER}"IMAGE_TAG="local"+HUB_URL="http://sam-mesh-control-plane:8080"+HELM="helm"++SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"PROJECT_ROOT="$(cd "${SCRIPT_DIR}/../.." && pwd)"@@ -19,6 +23,16 @@ check_prereqs() {for bin in "${bins[@]}"; docommand -v "$bin" >/dev/null 2>&1 || { echo "missing prerequisite: $bin" >&2; exit 1; }done++ if ! command -v helm >/dev/null 2>&1; then+ if [[ -x "${PROJECT_ROOT}/bin/helm" ]]; then+ HELM="${PROJECT_ROOT}/bin/helm"+ else+ echo "missing prerequisite: helm (install helm or run: curl -fsSL https://get.helm.sh/helm-v3.12.0-linux-amd64.tar.gz | tar -xz -C bin/ --strip-components=1 linux-amd64/helm)" >&2+ exit 1+ fi+ fi+if kind get clusters 2>/dev/null | grep -qx "${CLUSTER}"; thenecho "kind cluster '${CLUSTER}' already exists; delete it first: make kind-down" >&2exit 1@@ -44,9 +58,10 @@ render_and_apply() {SIDECAR=$' - name: '"${name}"$'\n image: '"${name}:${IMAGE_TAG}"$'\n imagePullPolicy: IfNotPresent'CONFIG_VOLUME=$' - name: config\n configMap:\n name: '"${node}-config"fi- NODE="$node" CONFIG_ARG="$CONFIG_ARG" CONFIG_MOUNT="$CONFIG_MOUNT" SIDECAR="$SIDECAR" CONFIG_VOLUME="$CONFIG_VOLUME" \- envsubst '${NODE} ${NAMESPACE} ${IMAGE_TAG} ${CONFIG_ARG} ${CONFIG_MOUNT} ${SIDECAR} ${CONFIG_VOLUME}' \+ NODE="$node" HUB_URL="$HUB_URL" CONFIG_ARG="$CONFIG_ARG" CONFIG_MOUNT="$CONFIG_MOUNT" SIDECAR="$SIDECAR" CONFIG_VOLUME="$CONFIG_VOLUME" \+ envsubst '${NODE} ${NAMESPACE} ${HUB_URL} ${IMAGE_TAG} ${CONFIG_ARG} ${CONFIG_MOUNT} ${SIDECAR} ${CONFIG_VOLUME}' \< "${SCRIPT_DIR}/node.template.yaml" | kubectl --context "${KCTX}" apply -f -+}# logs: $1 = pane name (printed in-pane and set as the pane title); $2 = logs target.@@ -58,8 +73,8 @@ tmuxs() { tmux -L samsocket -f /dev/null "$@"; }show_cluster_logs() {tmuxs kill-session -t "${SESSION}" 2>/dev/null || true- tmuxs new-session -d -s "${SESSION}" -n mesh "$(logs control-plane 'deploy/sam-control-plane')" \; set -t "${SESSION}" destroy-unattached off- tmuxs split-window -t "${SESSION}:0" "$(logs router 'statefulset/sam-router')"+ tmuxs new-session -d -s "${SESSION}" -n mesh "$(logs control-plane 'deploy/sam-mesh-control-plane')" \; set -t "${SESSION}" destroy-unattached off+ tmuxs split-window -t "${SESSION}:0" "$(logs router 'statefulset/sam-mesh-router')"for node in "${NODES[@]}"; dotmuxs split-window -t "${SESSION}:0" "$(logs "$node" "deploy/${node} -c sam-node")"tmuxs select-layout -t "${SESSION}:0" tiled@@ -136,52 +151,40 @@ fiexport NAMESPACE ISSUER IMAGE_TAG OIDC_ISSUER OIDC_CLIENT_ID OIDC_CLIENT_SECRET OIDC_REDIRECT_URL CONTROL_PLANE_ISSUERS ALLOWED_AUDIENCES-echo "== Applying control plane and router (issuer: ${CONTROL_PLANE_ISSUERS}) =="-for f in "${SCRIPT_DIR}"/00-*.yaml "${SCRIPT_DIR}"/10-*.yaml "${SCRIPT_DIR}"/11-*.yaml "${SCRIPT_DIR}"/12-*.yaml "${SCRIPT_DIR}"/13-*.yaml; do- envsubst '${NAMESPACE} ${ISSUER} ${IMAGE_TAG} ${OIDC_ISSUER} ${OIDC_CLIENT_ID} ${OIDC_CLIENT_SECRET} ${OIDC_REDIRECT_URL} ${CONTROL_PLANE_ISSUERS} ${ALLOWED_AUDIENCES}' < "$f" | kubectl --context "${KCTX}" apply -f --done+echo "== Applying namespace and RBAC cluster rules =="+envsubst '${NAMESPACE}' < "${SCRIPT_DIR}/00-namespace-rbac.yaml" | kubectl --context "${KCTX}" apply -f -++echo "== Deploying SAM Mesh via Helm =="+"${HELM}" --kube-context "${KCTX}" upgrade --install sam-mesh "${PROJECT_ROOT}/charts/sam-mesh" \+ --namespace "${NAMESPACE}" \+ --set global.imageTag="${IMAGE_TAG}" \+ --set controlPlane.oidcIssuer="${CONTROL_PLANE_ISSUERS//,/\\,}" \+ --set controlPlane.allowedAudiences="${ALLOWED_AUDIENCES//,/\\,}" \+ --set controlPlane.service.type=NodePort \+ --set controlPlane.service.nodePort=30090 \+ --set router.service.type=NodePort \+ --set router.service.nodePort=30401 \+ --set router.useOidcToken=true \+ --set console.service.type=NodePort \+ --set console.service.nodePort=30081 \+ --set dex.enabled=trueecho "== Waiting for database to be ready =="-kubectl --context "${KCTX}" -n "${NAMESPACE}" wait --for=condition=ready --timeout=180s pod -l app=sam-db+kubectl --context "${KCTX}" -n "${NAMESPACE}" wait --for=condition=ready --timeout=180s pod -l app=sam-mesh-dbecho "== Waiting for control plane to be ready =="-kubectl --context "${KCTX}" -n "${NAMESPACE}" wait --for=condition=available --timeout=180s deployment/sam-control-plane+kubectl --context "${KCTX}" -n "${NAMESPACE}" wait --for=condition=available --timeout=180s deployment/sam-mesh-control-plane-echo "== Seeding control plane policies =="-for i in {1..30}; do- if curl -s http://127.0.0.1:9090/info >/dev/null; then- break- fi- sleep 1-done--curl -s -X POST \- -H "Content-Type: application/json" \- -H "Authorization: Bearer super-secret-admin-token" \- -d '{- "roles": [- {"name": "sam-admin", "allowed_services": ["*"], "allowed_targets": ["*"]},- {"name": "sam:role:sambox", "allowed_services": ["*"], "allowed_targets": ["*"]},- {"name": "sam:role:router", "allowed_services": ["*"], "allowed_targets": ["*"]}- ],- "bindings": [- {"role": "sam-admin", "members": [- "user:system:serviceaccount:'"${NAMESPACE}"':node-a-sa",- "user:system:serviceaccount:'"${NAMESPACE}"':node-b-sa",- "user:system:serviceaccount:'"${NAMESPACE}"':node-c-sa",- "user:system:serviceaccount:'"${NAMESPACE}"':local-node-sa"- ]},- {"role": "sam:role:sambox", "members": ["user:system:serviceaccount:'"${NAMESPACE}"':sam-box-sa"]},- {"role": "sam:role:router", "members": ["group:routers", "user:system:serviceaccount:'"${NAMESPACE}"':sam-router-sa"]}- ]- }' \- http://127.0.0.1:9090/policies >/dev/null+# Policy seeding is handled automatically by the Helm chart bootstrap job, we just wait for it to complete.+echo "== Waiting for bootstrap job to complete =="+kubectl --context "${KCTX}" -n "${NAMESPACE}" wait --for=condition=complete --timeout=120s job/sam-mesh-bootstrapecho "== Waiting for router to be ready =="-kubectl --context "${KCTX}" -n "${NAMESPACE}" wait --for=condition=ready --timeout=180s pod -l app=sam-router+kubectl --context "${KCTX}" -n "${NAMESPACE}" wait --for=condition=ready --timeout=180s pod -l app=sam-mesh-routerecho "== Waiting for console to be ready =="-kubectl --context "${KCTX}" -n "${NAMESPACE}" wait --for=condition=available --timeout=180s deployment/sam-console+kubectl --context "${KCTX}" -n "${NAMESPACE}" wait --for=condition=available --timeout=180s deployment/sam-mesh-consoleecho "== Waiting for Dex to be ready =="-kubectl --context "${KCTX}" -n "${NAMESPACE}" wait --for=condition=available --timeout=180s deployment/dex+kubectl --context "${KCTX}" -n "${NAMESPACE}" wait --for=condition=available --timeout=180s deployment/sam-mesh-dex+echo "== Applying sam-nodes =="for line in "${NODE_LINES[@]}"; do