Skip to content

Commit 95a6af1

Browse files
authored
Use toolhive service account for MCP server pods (#274)
1 parent f5d260c commit 95a6af1

File tree

4 files changed

+67
-1
lines changed

4 files changed

+67
-1
lines changed

cmd/thv-operator/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ kubectl apply -f deploy/operator/namespace.yaml
3838

3939
```bash
4040
kubectl apply -f deploy/operator/rbac.yaml
41+
kubectl apply -f deploy/operator/toolhive_rbac.yaml
4142
```
4243

4344
4. Deploy the operator:

cmd/thv-operator/controllers/mcpserver_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ func (r *MCPServerReconciler) deploymentForMCPServer(m *mcpv1alpha1.MCPServer) *
323323
Labels: ls,
324324
},
325325
Spec: corev1.PodSpec{
326+
ServiceAccountName: "toolhive",
326327
Containers: []corev1.Container{{
327328
Image: getToolhiveRunnerImage(),
328329
Name: "toolhive",
@@ -530,6 +531,11 @@ func deploymentNeedsUpdate(deployment *appsv1.Deployment, mcpServer *mcpv1alpha1
530531
}
531532
}
532533

534+
// Check if the service account name has changed
535+
if deployment.Spec.Template.Spec.ServiceAccountName != "toolhive" {
536+
return true
537+
}
538+
533539
return false
534540
}
535541

deploy/operator/operator.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ spec:
2020
serviceAccountName: toolhive-operator
2121
containers:
2222
- name: manager
23-
image: ko://github.com/StacklokLabs/toolhive/cmd/thv-operator
23+
image: ghcr.io/stackloklabs/toolhive/operator:latest
2424
args:
2525
- --leader-elect
2626
resources:

deploy/operator/toolhive_rbac.yaml

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
---
2+
apiVersion: v1
3+
kind: ServiceAccount
4+
metadata:
5+
name: toolhive
6+
namespace: toolhive-system
7+
labels:
8+
app: toolhive
9+
app.kubernetes.io/name: toolhive
10+
---
11+
apiVersion: rbac.authorization.k8s.io/v1
12+
kind: Role
13+
metadata:
14+
name: toolhive
15+
namespace: toolhive-system
16+
labels:
17+
app: toolhive
18+
app.kubernetes.io/name: toolhive
19+
rules:
20+
# StatefulSet management
21+
- apiGroups: ["apps"]
22+
resources: ["statefulsets"]
23+
verbs: ["get", "list", "watch", "create", "update", "patch", "delete", "apply"]
24+
25+
# Service management
26+
- apiGroups: [""]
27+
resources: ["services"]
28+
verbs: ["get", "list", "watch", "create", "update", "patch", "delete", "apply"]
29+
30+
# Pod management
31+
- apiGroups: [""]
32+
resources: ["pods"]
33+
verbs: ["get", "list", "watch"]
34+
35+
# Pod logs
36+
- apiGroups: [""]
37+
resources: ["pods/log"]
38+
verbs: ["get"]
39+
40+
# Pod attach (for attaching to containers)
41+
- apiGroups: [""]
42+
resources: ["pods/attach"]
43+
verbs: ["create", "get"]
44+
---
45+
apiVersion: rbac.authorization.k8s.io/v1
46+
kind: RoleBinding
47+
metadata:
48+
name: toolhive
49+
namespace: toolhive-system
50+
labels:
51+
app: toolhive
52+
app.kubernetes.io/name: toolhive
53+
subjects:
54+
- kind: ServiceAccount
55+
name: toolhive
56+
roleRef:
57+
kind: Role
58+
name: toolhive
59+
apiGroup: rbac.authorization.k8s.io

0 commit comments

Comments
 (0)