Add cilium chart

This commit is contained in:
Jonny Ervine
2024-07-15 18:18:16 +08:00
parent 9b2e417702
commit 221e0d5590
159 changed files with 37242 additions and 0 deletions
@@ -0,0 +1,15 @@
{{- if and .Values.authentication.mutual.spire.enabled .Values.authentication.mutual.spire.install.enabled .Values.authentication.mutual.spire.install.agent.serviceAccount.create -}}
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Values.authentication.mutual.spire.install.agent.serviceAccount.name }}
{{- with .Values.authentication.mutual.spire.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
rules:
# Required cluster role to allow spire-agent to query k8s API server
- apiGroups: [ "" ]
resources: [ "pods","nodes","nodes/proxy" ]
verbs: [ "get" ]
{{- end }}
@@ -0,0 +1,19 @@
{{- if and .Values.authentication.mutual.spire.enabled .Values.authentication.mutual.spire.install.enabled .Values.authentication.mutual.spire.install.agent.serviceAccount.create -}}
---
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Values.authentication.mutual.spire.install.agent.serviceAccount.name }}
{{- with .Values.authentication.mutual.spire.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
roleRef:
kind: ClusterRole
name: {{ .Values.authentication.mutual.spire.install.agent.serviceAccount.name }}
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: {{ .Values.authentication.mutual.spire.install.agent.serviceAccount.name }}
namespace: {{ .Values.authentication.mutual.spire.install.namespace }}
{{- end }}
@@ -0,0 +1,53 @@
{{- if and .Values.authentication.mutual.spire.enabled .Values.authentication.mutual.spire.install.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: spire-agent
namespace: {{ .Values.authentication.mutual.spire.install.namespace }}
{{- with .Values.authentication.mutual.spire.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
data:
agent.conf: |
agent {
data_dir = "/run/spire"
log_level = "ERROR"
server_address = "spire-server"
server_port = "8081"
socket_path = {{ .Values.authentication.mutual.spire.agentSocketPath | quote }}
admin_socket_path = {{ .Values.authentication.mutual.spire.adminSocketPath | quote }}
trust_bundle_path = "/run/spire/bundle/bundle.crt"
trust_domain = {{ .Values.authentication.mutual.spire.trustDomain | quote }}
authorized_delegates = [
"spiffe://{{ .Values.authentication.mutual.spire.trustDomain }}/cilium-agent",
]
}
plugins {
NodeAttestor "k8s_psat" {
plugin_data {
cluster = {{ .Values.cluster.name | quote }}
}
}
KeyManager "memory" {
plugin_data {
}
}
WorkloadAttestor "k8s" {
plugin_data {
skip_kubelet_verification = {{ .Values.authentication.mutual.spire.install.agent.skipKubeletVerification }}
}
}
}
health_checks {
listener_enabled = true
bind_address = "0.0.0.0"
bind_port = "4251"
live_path = "/live"
ready_path = "/ready"
}
{{- end }}
+126
View File
@@ -0,0 +1,126 @@
{{- if and .Values.authentication.mutual.spire.enabled .Values.authentication.mutual.spire.install.enabled -}}
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: spire-agent
namespace: {{ .Values.authentication.mutual.spire.install.namespace }}
{{- if or .Values.authentication.mutual.spire.install.server.annotations .Values.authentication.mutual.spire.annotations }}
annotations:
{{- with .Values.authentication.mutual.spire.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.authentication.mutual.spire.install.server.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
labels:
app: spire-agent
{{- with .Values.authentication.mutual.spire.install.agent.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
selector:
matchLabels:
app: spire-agent
template:
metadata:
namespace: {{ .Values.authentication.mutual.spire.install.namespace }}
labels:
app: spire-agent
{{- with .Values.authentication.mutual.spire.install.agent.labels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
hostPID: true
hostNetwork: true
dnsPolicy: ClusterFirstWithHostNet
serviceAccountName: {{ .Values.authentication.mutual.spire.install.agent.serviceAccount.name }}
{{- with .Values.authentication.mutual.spire.install.agent.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
initContainers:
- name: init
image: {{ include "cilium.image" .Values.authentication.mutual.spire.install.initImage | quote }}
imagePullPolicy: {{ .Values.authentication.mutual.spire.install.initImage.pullPolicy }}
command:
- /bin/sh
- -c
- |
{{- tpl (.Files.Get "files/spire/wait-for-spire.bash") . | nindent 14 }}
containers:
- name: spire-agent
{{- if eq (typeOf .Values.authentication.mutual.spire.install.agent.image) "string" }}
image: {{ .Values.authentication.mutual.spire.install.agent.image }}
{{- else }}
image: {{ include "cilium.image" .Values.authentication.mutual.spire.install.agent.image | quote }}
imagePullPolicy: {{ .Values.authentication.mutual.spire.install.agent.image.pullPolicy }}
{{- end }}
args: ["-config", "/run/spire/config/agent.conf"]
{{- with .Values.authentication.mutual.spire.install.agent.securityContext }}
securityContext:
{{- toYaml . | nindent 12 }}
{{- end }}
volumeMounts:
- name: spire-config
mountPath: /run/spire/config
readOnly: true
- name: spire-bundle
mountPath: /run/spire/bundle
- name: spire-agent-socket
mountPath: /run/spire/sockets
readOnly: false
- name: spire-agent
mountPath: /var/run/secrets/tokens
env:
- name: MY_NODE_NAME
valueFrom:
fieldRef:
fieldPath: status.hostIP
livenessProbe:
httpGet:
path: /live
port: 4251
failureThreshold: 2
initialDelaySeconds: 15
periodSeconds: 60
timeoutSeconds: 3
readinessProbe:
httpGet:
path: /ready
port: 4251
initialDelaySeconds: 5
periodSeconds: 5
{{- with .Values.authentication.mutual.spire.install.agent.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.authentication.mutual.spire.install.agent.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
tolerations:
{{- with .Values.authentication.mutual.spire.install.agent.tolerations }}
{{- toYaml . | trim | nindent 8 }}
{{- end }}
- key: {{ .Values.agentNotReadyTaintKey | default "node.cilium.io/agent-not-ready" }}
effect: NoSchedule
volumes:
- name: spire-config
configMap:
name: spire-agent
- name: spire-bundle
configMap:
name: spire-bundle
- name: spire-agent-socket
hostPath:
path: /run/spire/sockets
type: DirectoryOrCreate
- name: spire-agent
projected:
sources:
- serviceAccountToken:
path: spire-agent
expirationSeconds: 600
audience: spire-server
{{- end }}
@@ -0,0 +1,11 @@
{{- if and .Values.authentication.mutual.spire.enabled .Values.authentication.mutual.spire.install.enabled .Values.authentication.mutual.spire.install.agent.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Values.authentication.mutual.spire.install.agent.serviceAccount.name }}
namespace: {{ .Values.authentication.mutual.spire.install.namespace }}
{{- with .Values.authentication.mutual.spire.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
@@ -0,0 +1,11 @@
{{- if and .Values.authentication.mutual.spire.enabled .Values.authentication.mutual.spire.install.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: spire-bundle
namespace: {{ .Values.authentication.mutual.spire.install.namespace }}
{{- with .Values.authentication.mutual.spire.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
+10
View File
@@ -0,0 +1,10 @@
{{- if and .Values.authentication.mutual.spire.enabled .Values.authentication.mutual.spire.install.enabled (not .Values.authentication.mutual.spire.install.existingNamespace) -}}
apiVersion: v1
kind: Namespace
metadata:
name: {{ .Values.authentication.mutual.spire.install.namespace }}
{{- with .Values.authentication.mutual.spire.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
@@ -0,0 +1,26 @@
{{- if and .Values.authentication.mutual.spire.enabled .Values.authentication.mutual.spire.install.enabled .Values.authentication.mutual.spire.install.server.serviceAccount.create -}}
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Values.authentication.mutual.spire.install.server.serviceAccount.name }}
{{- with .Values.authentication.mutual.spire.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
rules:
# ClusterRole to allow spire-server node attestor to query Token Review API
- apiGroups: [ "authentication.k8s.io" ]
resources: [ "tokenreviews" ]
verbs: [ "create" ]
# Required cluster role to allow spire-server to query k8s API server
# for pods for psat attestation
- apiGroups: [ "" ]
resources: [ "pods" ]
verbs: [ "get" ]
# Required cluster role to allow spire-server to query k8s API server
# for nodes for psat attestation
- apiGroups: [ "" ]
resources: [ "nodes","nodes/proxy" ]
verbs: [ "get" ]
{{- end }}
@@ -0,0 +1,18 @@
{{- if and .Values.authentication.mutual.spire.enabled .Values.authentication.mutual.spire.install.enabled .Values.authentication.mutual.spire.install.server.serviceAccount.create -}}
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Values.authentication.mutual.spire.install.server.serviceAccount.name }}
{{- with .Values.authentication.mutual.spire.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
roleRef:
kind: ClusterRole
name: spire-server
apiGroup: rbac.authorization.k8s.io
subjects:
- kind: ServiceAccount
name: {{ .Values.authentication.mutual.spire.install.server.serviceAccount.name }}
namespace: {{ .Values.authentication.mutual.spire.install.namespace }}
{{- end }}
@@ -0,0 +1,72 @@
{{- if and .Values.authentication.mutual.spire.enabled .Values.authentication.mutual.spire.install.enabled -}}
apiVersion: v1
kind: ConfigMap
metadata:
name: spire-server
namespace: {{ .Values.authentication.mutual.spire.install.namespace }}
{{- with .Values.authentication.mutual.spire.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
data:
server.conf: |
server {
bind_address = "0.0.0.0"
bind_port = "8081"
socket_path = "/tmp/spire-server/private/api.sock"
trust_domain = {{ .Values.authentication.mutual.spire.trustDomain | quote }}
data_dir = "/run/spire/data"
log_level = "INFO"
ca_key_type = {{ .Values.authentication.mutual.spire.install.server.ca.keyType | quote }}
ca_subject = {
country = [{{ .Values.authentication.mutual.spire.install.server.ca.subject.country | quote }}],
organization = [{{ .Values.authentication.mutual.spire.install.server.ca.subject.organization | quote }}],
common_name = {{ .Values.authentication.mutual.spire.install.server.ca.subject.commonName | quote }},
}
admin_ids = [
"spiffe://{{ .Values.authentication.mutual.spire.trustDomain }}/cilium-operator",
]
}
plugins {
DataStore "sql" {
plugin_data {
database_type = "sqlite3"
connection_string = "/run/spire/data/datastore.sqlite3"
}
}
NodeAttestor "k8s_psat" {
plugin_data {
clusters = {
{{ .Values.cluster.name | quote }} = {
use_token_review_api_validation = true
service_account_allow_list = ["{{ .Values.authentication.mutual.spire.install.namespace}}:{{ .Values.authentication.mutual.spire.install.agent.serviceAccount.name }}"]
}
}
}
}
KeyManager "disk" {
plugin_data {
keys_path = "/run/spire/data/keys.json"
}
}
Notifier "k8sbundle" {
plugin_data {
namespace = {{ .Values.authentication.mutual.spire.install.namespace | quote }}
}
}
}
health_checks {
listener_enabled = true
bind_address = "0.0.0.0"
bind_port = "8080"
live_path = "/live"
ready_path = "/ready"
}
{{- end }}
+16
View File
@@ -0,0 +1,16 @@
{{- if and .Values.authentication.mutual.spire.enabled .Values.authentication.mutual.spire.install.enabled .Values.authentication.mutual.spire.install.server.serviceAccount.create -}}
kind: Role
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Values.authentication.mutual.spire.install.server.serviceAccount.name }}
namespace: {{ .Values.authentication.mutual.spire.install.namespace }}
{{- with .Values.authentication.mutual.spire.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
rules:
# Role (namespace scoped) to be able to push certificate bundles to a configmap
- apiGroups: [ "" ]
resources: [ "configmaps" ]
verbs: [ "patch", "get", "list" ]
{{- end }}
@@ -0,0 +1,37 @@
{{- if and .Values.authentication.mutual.spire.enabled .Values.authentication.mutual.spire.install.enabled -}}
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Values.authentication.mutual.spire.install.server.serviceAccount.name }}
namespace: {{ .Values.authentication.mutual.spire.install.namespace }}
{{- with .Values.authentication.mutual.spire.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: Role
name: spire-server
subjects:
- kind: ServiceAccount
name: {{ .Values.authentication.mutual.spire.install.server.serviceAccount.name }}
namespace: {{ .Values.authentication.mutual.spire.install.namespace }}
---
kind: RoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: {{ .Values.authentication.mutual.spire.install.server.serviceAccount.name }}-pod
namespace: {{ .Values.authentication.mutual.spire.install.namespace }}
{{- with .Values.authentication.mutual.spire.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: {{ .Values.authentication.mutual.spire.install.server.serviceAccount.name }}-pod
subjects:
- kind: ServiceAccount
name: {{ .Values.authentication.mutual.spire.install.server.serviceAccount.name }}
namespace: {{ .Values.authentication.mutual.spire.install.namespace }}
{{- end }}
@@ -0,0 +1,29 @@
{{- if and .Values.authentication.mutual.spire.enabled .Values.authentication.mutual.spire.install.enabled -}}
apiVersion: v1
kind: Service
metadata:
name: spire-server
namespace: {{ .Values.authentication.mutual.spire.install.namespace }}
{{- if or .Values.authentication.mutual.spire.install.server.service.annotations .Values.authentication.mutual.spire.annotations }}
annotations:
{{- with .Values.authentication.mutual.spire.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.authentication.mutual.spire.install.server.service.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
{{- with .Values.authentication.mutual.spire.install.server.service.labels }}
labels:
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
type: {{ .Values.authentication.mutual.spire.install.server.service.type }}
ports:
- name: grpc
port: 8081
targetPort: grpc
protocol: TCP
selector:
app: spire-server
{{- end }}
@@ -0,0 +1,11 @@
{{- if and .Values.authentication.mutual.spire.enabled .Values.authentication.mutual.spire.install.enabled .Values.authentication.mutual.spire.install.server.serviceAccount.create -}}
apiVersion: v1
kind: ServiceAccount
metadata:
name: {{ .Values.authentication.mutual.spire.install.server.serviceAccount.name }}
namespace: {{ .Values.authentication.mutual.spire.install.namespace }}
{{- with .Values.authentication.mutual.spire.annotations }}
annotations:
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
@@ -0,0 +1,129 @@
{{- if and .Values.authentication.mutual.spire.enabled .Values.authentication.mutual.spire.install.enabled -}}
apiVersion: apps/v1
kind: StatefulSet
metadata:
name: spire-server
namespace: {{ .Values.authentication.mutual.spire.install.namespace }}
{{- if or .Values.authentication.mutual.spire.install.server.annotations .Values.authentication.mutual.spire.annotations }}
annotations:
{{- with .Values.authentication.mutual.spire.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- with .Values.authentication.mutual.spire.install.server.annotations }}
{{- toYaml . | nindent 4 }}
{{- end }}
{{- end }}
labels:
app: spire-server
{{- with .Values.authentication.mutual.spire.install.server.labels }}
{{- toYaml . | nindent 4 }}
{{- end }}
spec:
replicas: 1
selector:
matchLabels:
app: spire-server
serviceName: spire-server
template:
metadata:
labels:
app: spire-server
{{- with .Values.authentication.mutual.spire.install.server.labels }}
{{- toYaml . | nindent 8 }}
{{- end }}
spec:
serviceAccountName: {{ .Values.authentication.mutual.spire.install.server.serviceAccount.name }}
shareProcessNamespace: true
{{- with .Values.authentication.mutual.spire.install.server.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- if gt (len .Values.authentication.mutual.spire.install.server.initContainers) 0 }}
initContainers:
{{- toYaml .Values.authentication.mutual.spire.install.server.initContainers | nindent 8 }}
{{- end }}
containers:
- name: cilium-init
image: {{ include "cilium.image" .Values.authentication.mutual.spire.install.initImage | quote }}
imagePullPolicy: {{ .Values.authentication.mutual.spire.install.initImage.pullPolicy }}
command:
- /bin/sh
- -c
- |
{{- tpl (.Files.Get "files/spire/init.bash") . | nindent 12 }}
- name: spire-server
{{- if eq (typeOf .Values.authentication.mutual.spire.install.server.image) "string" }}
image: {{ .Values.authentication.mutual.spire.install.server.image }}
{{- else }}
image: {{ include "cilium.image" .Values.authentication.mutual.spire.install.server.image | quote }}
imagePullPolicy: {{ .Values.authentication.mutual.spire.install.server.image.pullPolicy }}
{{- end }}
args:
- -config
- /run/spire/config/server.conf
ports:
- name: grpc
containerPort: 8081
volumeMounts:
- name: spire-config
mountPath: /run/spire/config
readOnly: true
{{- if .Values.authentication.mutual.spire.install.server.dataStorage.enabled }}
- name: spire-data
mountPath: /run/spire/data
readOnly: false
{{- end }}
- name: spire-server-socket
mountPath: /tmp/spire-server/private
readOnly: false
livenessProbe:
httpGet:
path: /live
port: 8080
failureThreshold: 2
initialDelaySeconds: 15
periodSeconds: 60
timeoutSeconds: 3
readinessProbe:
httpGet:
path: /ready
port: 8080
initialDelaySeconds: 5
periodSeconds: 5
{{- with .Values.authentication.mutual.spire.install.server.securityContext }}
securityContext:
{{- toYaml . | nindent 10 }}
{{- end }}
{{- with .Values.authentication.mutual.spire.install.server.affinity }}
affinity:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.authentication.mutual.spire.install.server.nodeSelector }}
nodeSelector:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.authentication.mutual.spire.install.server.tolerations }}
tolerations:
{{- toYaml . | trim | nindent 8 }}
{{- end }}
volumes:
- name: spire-config
configMap:
name: spire-server
- name: spire-server-socket
hostPath:
path: /var/run/spire-server/sockets
type: DirectoryOrCreate
{{- if .Values.authentication.mutual.spire.install.server.dataStorage.enabled }}
volumeClaimTemplates:
- metadata:
name: spire-data
spec:
accessModes:
- {{ .Values.authentication.mutual.spire.install.server.dataStorage.accessMode | default "ReadWriteOnce" }}
resources:
requests:
storage: {{ .Values.authentication.mutual.spire.install.server.dataStorage.size }}
storageClassName: {{ .Values.authentication.mutual.spire.install.server.dataStorage.storageClass }}
{{- end }}
{{- end }}