Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initiating Workload Identity with Spire #84

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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: "true"
- name: CLIENT_PROXY_ADDRESS
value: resource-backend-controller-grpc-svc.backend-system.svc.cluster.local:9999
image: docker.io/nephio/nephio-operator:latest
- name: SPIFFE_ENDPOINT_SOCKET
value: unix:///spiffe-workload-api/spire-agent.sock
# Temporary image
image: docker.io/nephio/nephio-operator:ubuntu
imagePullPolicy: Never
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: {}
26 changes: 26 additions & 0 deletions nephio/optional/spire-agent/Kptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
apiVersion: kpt.dev/v1
kind: Kptfile
metadata:
name: spire-agent
namespace: spire
packageMetadata:
shortDescription: "Kpt package for deploying spire-agent"
keywords:
- spire
- agent
- security
- identity
site: "https://spiffe.io"
maintainers:
- name: "Maintainer Name"
email: "[email protected]"
licenses:
- Apache-2.0
categories:
- security
- identity
version: "1.0.0"
inventory:
namespace: spire
inventoryID: 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
143 changes: 143 additions & 0 deletions nephio/optional/spire-agent/spire-agent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
# 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


---

# ConfigMap for the SPIRE agent featuring:
# 1) PSAT node attestation
# 2) K8S Workload Attestation over the secure kubelet port
apiVersion: v1
kind: ConfigMap
metadata:
name: spire-agent
namespace: spire
data:
agent.conf: |
agent {
data_dir = "/run/spire"
log_level = "DEBUG"
server_address = "spire-server"
server_port = "8081"
socket_path = "/run/spire/sockets/spire-agent.sock"
trust_bundle_path = "/run/spire/bundle/bundle.crt"
trust_domain = "example.org"
}

plugins {
NodeAttestor "k8s_psat" {
plugin_data {
cluster = "kind"
}
}

KeyManager "memory" {
plugin_data {
}
}

WorkloadAttestor "k8s" {
plugin_data {
skip_kubelet_verification = true
}
}
}

---

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/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