Skip to content

Commit

Permalink
Merge pull request #84 from 5GSEC/regis
Browse files Browse the repository at this point in the history
Add SPIRE/SPIFFE Packages for Workload Identity
  • Loading branch information
nephio-prow[bot] authored Feb 19, 2025
2 parents 39deb29 + df2e173 commit 42465a3
Show file tree
Hide file tree
Showing 31 changed files with 1,361 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ rules:
- get
- list
- watch
- apiGroups:
- '*'
resources:
- configmaps
verbs:
- update
- list
- watch
- apiGroups:
- '*'
resources:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ spec:
name: nephio-controller
namespace: nephio-system
spec:
containers:
containers:
- args:
- --secure-listen-address=0.0.0.0:8443
- --upstream=http://127.0.0.1:8080/
Expand Down Expand Up @@ -85,9 +85,19 @@ spec:
value: "true"
- name: ENABLE_NETWORKS
value: "true"
- name: ENABLE_WORKLOADIDENTITY
value: "false"
- name: CLIENT_PROXY_ADDRESS
value: resource-backend-controller-grpc-svc.backend-system.svc.cluster.local:9999
- name: SPIFFE_ENDPOINT_SOCKET
value: unix:///spiffe-workload-api/spire-agent.sock
# Temporary image
image: docker.io/nephio/nephio-operator:latest
imagePullPolicy: Always
volumeMounts:
- name: spiffe-workload-api
mountPath: /spiffe-workload-api
readOnly: true
livenessProbe:
httpGet:
path: /healthz
Expand All @@ -114,4 +124,10 @@ spec:
drop:
- ALL
serviceAccountName: nephio-controller
volumes:
- name: spiffe-workload-api
csi:
driver: "csi.spiffe.io"
readOnly: true

status: {}
8 changes: 8 additions & 0 deletions nephio/optional/spire-agent/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: spire
annotations:
config.kubernetes.io/local-config: "true"
info:
description: spire-agent
133 changes: 133 additions & 0 deletions nephio/optional/spire-agent/spiffe-csi.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
# Source: spire-agent/templates/csi-serviceaccount.yaml
apiVersion: v1
kind: ServiceAccount
metadata:
name: spiffe-csi-driver
namespace: spire

---

# Source: spire-agent/templates/spiffe-csi-driver.yaml
apiVersion: apps/v1
kind: DaemonSet
metadata:
name: spiffe-csi-driver
namespace: spire
labels:
app: spiffe-csi-driver
spec:
selector:
matchLabels:
app: spiffe-csi-driver
template:
metadata:
namespace: spire
labels:
app: spiffe-csi-driver
spec:
serviceAccountName: spiffe-csi-driver
containers:
# This is the container which runs the SPIFFE CSI driver.
- name: spiffe-csi-driver
image: ghcr.io/spiffe/spiffe-csi-driver:0.2.6
imagePullPolicy: IfNotPresent
args: [
"-workload-api-socket-dir", "/spire-agent-socket",
"-csi-socket-path", "/spiffe-csi/csi.sock",
]
env:
# The CSI driver needs a unique node ID. The node name can be
# used for this purpose.
- name: MY_NODE_NAME
valueFrom:
fieldRef:
fieldPath: spec.nodeName
volumeMounts:
# The volume containing the SPIRE agent socket. The SPIFFE CSI
# driver will mount this directory into containers.
- mountPath: /spire-agent-socket
name: spire-agent-socket-dir
readOnly: true
# The volume that will contain the CSI driver socket shared
# with the kubelet and the driver registrar.
- mountPath: /spiffe-csi
name: spiffe-csi-socket-dir
# The volume containing mount points for containers.
- mountPath: /var/lib/kubelet/pods
mountPropagation: Bidirectional
name: mountpoint-dir
securityContext:
readOnlyRootFilesystem: true
capabilities:
drop:
- all
privileged: true
# This container runs the CSI Node Driver Registrar which takes care
# of all the little details required to register a CSI driver with
# the kubelet.
- name: node-driver-registrar
image: registry.k8s.io/sig-storage/csi-node-driver-registrar:v2.6.0
imagePullPolicy: IfNotPresent
args: [
"-csi-address", "/spiffe-csi/csi.sock",
"-kubelet-registration-path", "/var/lib/kubelet/plugins/csi.spiffe.io/csi.sock",
]
volumeMounts:
# The registrar needs access to the SPIFFE CSI driver socket
- mountPath: /spiffe-csi
name: spiffe-csi-socket-dir
# The registrar needs access to the Kubelet plugin registration
# directory
- name: kubelet-plugin-registration-dir
mountPath: /registration
volumes:
# This volume is used to share the Workload API socket between the CSI
# driver and SPIRE agent. Note, an emptyDir volume could also be used
# (if the CSI driver and SPIRE agent shared a pod), however,
# this can lead to broken bind mounts in the workload
# containers if the agent pod is restarted (since the emptyDir
# directory on the node that was mounted into workload containers by
# the CSI driver belongs to the old pod instance and is no longer
# valid).
- name: spire-agent-socket-dir
hostPath:
path: /run/spire/agent-sockets
type: DirectoryOrCreate
# This volume is where the socket for kubelet->driver communication lives
- name: spiffe-csi-socket-dir
hostPath:
path: /var/lib/kubelet/plugins/csi.spiffe.io
type: DirectoryOrCreate
# This volume is where the SPIFFE CSI driver mounts volumes
- name: mountpoint-dir
hostPath:
path: /var/lib/kubelet/pods
type: Directory
# This volume is where the node-driver-registrar registers the plugin
# with kubelet
- name: kubelet-plugin-registration-dir
hostPath:
path: /var/lib/kubelet/plugins_registry
type: Directory
---

apiVersion: storage.k8s.io/v1
kind: CSIDriver
metadata:
name: "csi.spiffe.io"
spec:
# Only ephemeral, inline volumes are supported. There is no need for a
# controller to provision and attach volumes.
attachRequired: false

# Request the pod information which the CSI driver uses to verify that an
# ephemeral mount was requested.
podInfoOnMount: true

# Don't change ownership on the contents of the mount since the Workload API
# Unix Domain Socket is typically open to all (i.e. 0777).
fsGroupPolicy: None

# Declare support for ephemeral volumes only.
volumeLifecycleModes:
- Ephemeral
102 changes: 102 additions & 0 deletions nephio/optional/spire-agent/spire-agent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
# ServiceAccount for the SPIRE agent
apiVersion: v1
kind: ServiceAccount
metadata:
name: spire-agent
namespace: spire

---

# Required cluster role to allow spire-agent to query k8s API server
kind: ClusterRole
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: spire-agent-cluster-role
rules:
- apiGroups: [""]
resources: ["pods","nodes","nodes/proxy"]
verbs: ["get"]

---

# Binds above cluster role to spire-agent service account
kind: ClusterRoleBinding
apiVersion: rbac.authorization.k8s.io/v1
metadata:
name: spire-agent-cluster-role-binding
subjects:
- kind: ServiceAccount
name: spire-agent
namespace: spire
roleRef:
kind: ClusterRole
name: spire-agent-cluster-role
apiGroup: rbac.authorization.k8s.io


---

apiVersion: apps/v1
kind: DaemonSet
metadata:
name: spire-agent
namespace: spire
labels:
app: spire-agent
spec:
selector:
matchLabels:
app: spire-agent
updateStrategy:
type: RollingUpdate
template:
metadata:
namespace: spire
labels:
app: spire-agent
spec:
hostPID: true
hostNetwork: true
dnsPolicy: ClusterFirstWithHostNet
serviceAccountName: spire-agent
containers:
- name: spire-agent
image: ghcr.io/spiffe/spire-agent:1.8.0
imagePullPolicy: IfNotPresent
args: ["-config", "/run/spire/config/agent.conf"]
volumeMounts:
- name: spire-config
mountPath: /run/spire/config
readOnly: true
- name: spire-bundle
mountPath: /run/spire/bundle
readOnly: true
- name: spire-token
mountPath: /var/run/secrets/tokens
- name: spire-agent-socket-dir
mountPath: /run/spire/sockets
volumes:
- name: spire-config
configMap:
name: spire-agent
- name: spire-bundle
configMap:
name: spire-bundle
- name: spire-token
projected:
sources:
- serviceAccountToken:
path: spire-agent
expirationSeconds: 7200
audience: spire-server
# This volume is used to share the Workload API socket between the CSI
# driver and SPIRE agent. Note, an emptyDir volume could also be used,
# however, this can lead to broken bind mounts in the workload
# containers if the agent pod is restarted (since the emptyDir
# directory on the node that was mounted into workload containers by
# the CSI driver belongs to the old pod instance and is no longer
# valid).
- name: spire-agent-socket-dir
hostPath:
path: /run/spire/agent-sockets
type: DirectoryOrCreate
8 changes: 8 additions & 0 deletions nephio/optional/spire-restrictedSA/ClusterRole.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: pod-reader
rules:
- apiGroups: [""]
resources: ["pods", "nodes"]
verbs: ["get"]
25 changes: 25 additions & 0 deletions nephio/optional/spire-restrictedSA/ClusterRoleBinding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: spire-agent-tokenreview-binding
subjects:
- kind: ServiceAccount
name: spirekubeconfig
namespace: spire
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: system:auth-delegator
---
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: spire-agent-pod-reader-binding
subjects:
- kind: ServiceAccount
name: spirekubeconfig
namespace: spire
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: pod-reader
8 changes: 8 additions & 0 deletions nephio/optional/spire-restrictedSA/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: restricted-SA
annotations:
config.kubernetes.io/local-config: "true"
info:
description: restricted-SA
8 changes: 8 additions & 0 deletions nephio/optional/spire-restrictedSA/Secret.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: v1
kind: Secret
metadata:
name: agent-sa-secret
namespace: spire
annotations:
kubernetes.io/service-account.name: spirekubeconfig
type: kubernetes.io/service-account-token
5 changes: 5 additions & 0 deletions nephio/optional/spire-restrictedSA/ServiceAccount.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: spirekubeconfig
namespace: spire
8 changes: 8 additions & 0 deletions nephio/optional/spire/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: spire
annotations:
config.kubernetes.io/local-config: "true"
info:
description: sample description
21 changes: 21 additions & 0 deletions nephio/optional/spire/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# spire

## Description
sample description

## Usage

### Fetch the package
`kpt pkg get REPO_URI[.git]/PKG_PATH[@VERSION] spire`
Details: https://kpt.dev/reference/cli/pkg/get/

### View package content
`kpt pkg tree spire`
Details: https://kpt.dev/reference/cli/pkg/tree/

### Apply the package
```
kpt live init spire
kpt live apply spire --reconcile-timeout=2m --output=table
```
Details: https://kpt.dev/reference/cli/live/
Loading

0 comments on commit 42465a3

Please sign in to comment.