Skip to content

Commit 99fec92

Browse files
committed
contrib: add sample overlay for authentication.
Signed-off-by: Krisztian Litkey <[email protected]>
1 parent 7b902de commit 99fec92

File tree

4 files changed

+81
-0
lines changed

4 files changed

+81
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# Containerized Plugins With Authentication
2+
3+
This example uses the template plugin to demonstrate a kustomize overlay
4+
to enable authentication for our containerized sample plugins.
5+
6+
> [!NOTE] In addition to the kustomize overlay here, you will need a runtime
7+
> with support for NRI plugin authentication to test this.
8+
9+
## Generate And Store Plugin Keys in a Secret
10+
11+
```bash
12+
$ mkdir tmp
13+
$ wget https://raw.githubusercontent.com/klihub/nri/refs/heads/hacking/plugin-authentication/examples/keygen/keygen.go
14+
$ go run ./keygen.go > plugin-key
15+
$ private=$(head -2 plugin-key | tail -1)
16+
$ public=$(tail -1 plugin-key)
17+
$ kubectl -n kube-system create secret generic test-auth \
18+
--from-literal=private="$(echo private)" \--from-literal=public="$(echo public)"
19+
```
20+
21+
> [!NOTE] Now you need to update your runtime's configuration with these
22+
> generated keys.
23+
24+
## Deployment
25+
26+
```bash
27+
$ kubectl apply -k https://github.com/containerd/nri/contrib/kustomize/samples/plugin-authentication
28+
```
29+
30+
If you check the plugin's logs, you should see it getting authenticated:
31+
32+
```bash
33+
[root@n4c16-fedora-42-containerd plugin-auth]# kubectl -n kube-system logs daemonset/nri-plugin-template
34+
time="2025-09-10T17:12:12Z" level=info msg="Created plugin 10-template (plugin, handles RunPodSandbox,StopPodSandbox,RemovePodSandbox,CreateContainer,PostCreateContainer,StartContainer,PostStartContainer,UpdateContainer,PostUpdateContainer,StopContainer,RemoveContainer)"
35+
time="2025-09-10T17:12:12Z" level=info msg="Authenticated with role test1 (tags: map[role:test1])..."
36+
time="2025-09-10T17:12:12Z" level=info msg="Registering plugin 10-template..."
37+
time="2025-09-10T17:12:12Z" level=info msg="Configuring plugin 10-template for runtime containerd/v2.1.0-372-g7b052529d.m..."
38+
```
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
apiVersion: apps/v1
2+
kind: DaemonSet
3+
metadata:
4+
name: nri-plugin-template
5+
spec:
6+
template:
7+
spec:
8+
containers:
9+
- name: plugin
10+
env:
11+
- name: NRI_PLUGIN_AUTH_KEYDIR
12+
value: /etc/containers/nri/auth
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
apiVersion: kustomize.config.k8s.io/v1beta1
2+
kind: Kustomization
3+
resources:
4+
- ../../template/unstable
5+
patches:
6+
- path: volumes-patch.yaml
7+
- path: env-patch.yaml
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
apiVersion: apps/v1
2+
kind: DaemonSet
3+
metadata:
4+
name: nri-plugin-template
5+
spec:
6+
template:
7+
spec:
8+
containers:
9+
- name: plugin
10+
volumeMounts:
11+
- name: plugin-auth
12+
mountPath: /etc/containers/nri/auth
13+
volumes:
14+
# Inject authentication keys from secret.
15+
- name: plugin-auth
16+
projected:
17+
sources:
18+
- secret:
19+
name: test-auth
20+
items:
21+
- key: private
22+
path: private
23+
- key: public
24+
path: public

0 commit comments

Comments
 (0)