Skip to content
Merged
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
16 changes: 7 additions & 9 deletions charts/cainjekt/templates/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ spec:
{{- if .Values.hostNetwork }}
hostNetwork: true
{{- end }}
{{- with .Values.podSecurityContext }}
securityContext:
{{- toYaml . | nindent 8 }}
{{- end }}
{{- with .Values.priorityClassName }}
priorityClassName: {{ . }}
{{- end }}
Expand Down Expand Up @@ -72,8 +76,10 @@ spec:
- name: cainjekt
image: "{{ .Values.image.repository }}:{{ include "cainjekt.imageTag" . }}"
imagePullPolicy: {{ .Values.image.pullPolicy }}
{{- with .Values.securityContext }}
securityContext:
privileged: true
{{- toYaml . | nindent 12 }}
{{- end }}
env:
- name: CAINJEKT_CA_FILE
value: /etc/cainjekt/ca-bundle.pem
Expand Down Expand Up @@ -124,10 +130,6 @@ spec:
- name: plugin-install-dir
mountPath: /opt/cainjekt
readOnly: true
- name: host-root
mountPath: /host
readOnly: true
mountPropagation: HostToContainer
{{- with .Values.resources }}
resources:
{{- toYaml . | nindent 12 }}
Expand All @@ -152,7 +154,3 @@ spec:
hostPath:
path: /opt/cainjekt
type: DirectoryOrCreate
- name: host-root
hostPath:
path: /
type: Directory
3 changes: 0 additions & 3 deletions charts/cainjekt/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ metadata:
labels:
{{- include "cainjekt.labels" . | nindent 4 }}
rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list"]
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["get"]
Expand Down
23 changes: 23 additions & 0 deletions charts/cainjekt/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,29 @@ affinity: {}
## @param priorityClassName Priority class name
priorityClassName: system-node-critical

## @param podSecurityContext Security context of the pod (plugin and installer)
## On SELinux-enforcing nodes (RKE2 with `selinux: true`, SLE Micro, RHEL) the
## default container_t domain may not connect to the NRI socket or write
## /run/cainjekt and /opt/cainjekt, which carry host labels. spc_t lifts only the
## SELinux confinement; capabilities stay dropped. Nodes without SELinux ignore it.
podSecurityContext:
seLinuxOptions:
type: spc_t

## @param securityContext Security context of the plugin container
## The plugin only needs root (uid 0) to reach the NRI socket and write
## /run/cainjekt; the OCI hook is run by the container runtime on the host, not
## in this pod, so it needs no capabilities.
securityContext:
runAsUser: 0
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop:
- ALL
seccompProfile:
type: RuntimeDefault

resources:
## @param resources.requests.cpu CPU request
## @param resources.requests.memory Memory request
Expand Down
21 changes: 12 additions & 9 deletions deploy/kubernetes/daemonset.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ spec:
app: cainjekt
spec:
serviceAccountName: cainjekt
securityContext:
seLinuxOptions:
type: spc_t # SELinux-enforcing nodes: NRI socket and hostPaths carry host labels
priorityClassName: system-node-critical
tolerations:
- operator: Exists
Expand All @@ -45,8 +48,16 @@ spec:
- name: cainjekt
image: cainjekt:latest
imagePullPolicy: IfNotPresent
# Root for the NRI socket and /run/cainjekt; no capabilities needed.
# Use `privileged: true` instead if SELinux blocks hostPath access.
securityContext:
privileged: true
runAsUser: 0
allowPrivilegeEscalation: false
readOnlyRootFilesystem: true
capabilities:
drop: ["ALL"]
seccompProfile:
type: RuntimeDefault
env:
- name: CAINJEKT_CA_FILE
value: /etc/cainjekt/ca-bundle.pem
Expand Down Expand Up @@ -75,10 +86,6 @@ spec:
- name: plugin-install-dir
mountPath: /opt/cainjekt
readOnly: true
- name: host-root
mountPath: /host
readOnly: true
mountPropagation: HostToContainer
resources:
requests:
cpu: 10m
Expand All @@ -103,7 +110,3 @@ spec:
hostPath:
path: /opt/cainjekt
type: DirectoryOrCreate
- name: host-root
hostPath:
path: /
type: Directory
3 changes: 0 additions & 3 deletions deploy/kubernetes/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,6 @@ metadata:
labels:
app: cainjekt
rules:
- apiGroups: [""]
resources: ["nodes"]
verbs: ["get", "list"]
- apiGroups: [""]
resources: ["namespaces"]
verbs: ["get"]
Expand Down
11 changes: 7 additions & 4 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -137,11 +137,14 @@ annotations:

### Privileges

The DaemonSet runs with `privileged: true`. This is required because:
The plugin container runs as root (uid 0) but is **not privileged**: all capabilities are dropped, the root filesystem is read-only, privilege escalation is disabled and the default seccomp profile applies. Root is needed only because:

- **NRI socket access**: The NRI socket at `/var/run/nri` is owned by containerd and requires root access
- **Container rootfs access**: The hook modifies files inside the container's mounted rootfs, which lives under containerd's internal storage
- **File ownership preservation**: When modifying trust stores, cainjekt preserves the original file ownership (uid/gid), which requires root
- **NRI socket access**: The NRI socket at `/var/run/nri` is owned by root
- **Per-container CA staging**: The plugin writes `/run/cainjekt/containers/<id>/` on the host, which is root-owned

The part that modifies container filesystems — the OCI hook — is not run in this pod. containerd runs it on the host as root, as it does all OCI hooks, so the pod needs no capabilities and no access to the host root filesystem. The plugin does not call the Kubernetes nodes API; RBAC grants only `get` on namespaces (for the namespace-label opt-in).

The pod runs in the SELinux type `spc_t`. Under SELinux enforcing (RKE2 with `selinux: true`, SLE Micro, RHEL), the default `container_t` may not connect to the NRI socket or write `/run/cainjekt` and `/opt/cainjekt`, which carry host labels. `spc_t` lifts only the SELinux confinement; capabilities stay dropped. Nodes without SELinux ignore it. If a node still denies access, set `securityContext: {privileged: true}` in the Helm values.

`hostNetwork` and `hostPID` are **not required** — the plugin communicates via Unix socket (hostPath volume), not the network. They are disabled by default in the Helm chart but can be enabled if needed.

Expand Down
9 changes: 9 additions & 0 deletions docs/usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,15 @@ shell or `cat`; for those, inspect the container on the node instead
(`crictl inspect <id> | jq '.info.runtimeSpec.process.args'` shows the cainjekt
wrapper prepended to the entrypoint if injection happened).

### Plugin gets "permission denied" on the NRI socket or /run/cainjekt

The plugin runs as root with all capabilities dropped and without `privileged`. The pod runs in the SELinux type `spc_t` (`podSecurityContext`), so SELinux-enforcing nodes don't block the NRI socket or the hostPaths. If the plugin still gets "permission denied" (check `ausearch -m avc` on the node), fall back to a privileged container:

```bash
helm upgrade cainjekt charts/cainjekt -n kube-system --reuse-values \
--set-json 'securityContext={"privileged":true}'
```

## Limitations

| Scenario | Works? | Details |
Expand Down
3 changes: 2 additions & 1 deletion internal/nri/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package nri
import (
"fmt"
"net/http"
"time"

"github.com/prometheus/client_golang/prometheus/promhttp"
)
Expand All @@ -23,7 +24,7 @@ func newHTTPServer(addr string, metrics *Metrics, isReady func() bool) *http.Ser
_, _ = fmt.Fprint(w, "ok")
})
mux.Handle("GET /metrics", promhttp.HandlerFor(metrics.Registry, promhttp.HandlerOpts{}))
return &http.Server{Addr: addr, Handler: mux}
return &http.Server{Addr: addr, Handler: mux, ReadHeaderTimeout: 5 * time.Second}
}

func handleHealth(w http.ResponseWriter, _ *http.Request) {
Expand Down
Loading