pepr 0.14.1 → 0.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (62) hide show
  1. package/dist/cli.js +110 -43
  2. package/dist/controller.js +1 -1
  3. package/dist/lib/assets/deploy.d.ts.map +1 -1
  4. package/dist/lib/assets/index.d.ts +1 -1
  5. package/dist/lib/assets/index.d.ts.map +1 -1
  6. package/dist/lib/assets/rbac.d.ts +2 -1
  7. package/dist/lib/assets/rbac.d.ts.map +1 -1
  8. package/dist/lib/assets/yaml.d.ts +1 -1
  9. package/dist/lib/assets/yaml.d.ts.map +1 -1
  10. package/dist/lib/helpers.d.ts +11 -0
  11. package/dist/lib/helpers.d.ts.map +1 -0
  12. package/dist/lib/included-files.d.ts +2 -0
  13. package/dist/lib/included-files.d.ts.map +1 -0
  14. package/package.json +16 -14
  15. package/src/lib/assets/deploy.ts +4 -3
  16. package/src/lib/assets/index.ts +2 -2
  17. package/src/lib/assets/rbac.ts +27 -11
  18. package/src/lib/assets/yaml.ts +2 -2
  19. package/src/lib/helpers.ts +39 -0
  20. package/src/lib/included-files.ts +19 -0
  21. package/src/templates/capabilities/hello-pepr.ts +16 -11
  22. package/src/templates/package.json +2 -1
  23. package/website/.linkinator.config.json +8 -0
  24. package/website/.markdownlint.json +6 -0
  25. package/website/.prettierignore +12 -0
  26. package/website/LICENSE +201 -0
  27. package/website/README.md +50 -0
  28. package/website/archetypes/default.md +6 -0
  29. package/website/assets/img/doug.svg +345 -0
  30. package/website/assets/img/pepr.svg +212 -0
  31. package/website/assets/scss/_styles_project.scss +3 -0
  32. package/website/assets/scss/_variables_project.scss +1 -0
  33. package/website/content/en/docs/_index.md +9 -0
  34. package/website/content/en/docs/cli.md +64 -0
  35. package/website/content/en/docs/codeSample.txt +31 -0
  36. package/website/content/en/docs/concepts.md +238 -0
  37. package/website/content/en/docs/customresources.md +167 -0
  38. package/website/content/en/docs/diagrams.txt +18 -0
  39. package/website/content/en/docs/metrics.md +74 -0
  40. package/website/content/en/docs/rbac.md +153 -0
  41. package/website/content/en/docs/webassembly.md +189 -0
  42. package/website/go.mod +8 -0
  43. package/website/go.sum +4 -0
  44. package/website/package-lock.json +3907 -0
  45. package/website/package.json +30 -0
  46. package/website/renovate.json +16 -0
  47. package/website/static/favicons/android-144x144.png +0 -0
  48. package/website/static/favicons/android-192x192.png +0 -0
  49. package/website/static/favicons/android-36x36.png +0 -0
  50. package/website/static/favicons/android-48x48.png +0 -0
  51. package/website/static/favicons/android-72x72.png +0 -0
  52. package/website/static/favicons/android-96x96.png +0 -0
  53. package/website/static/favicons/android-chrome-192x192.png +0 -0
  54. package/website/static/favicons/android-chrome-512x512.png +0 -0
  55. package/website/static/favicons/android-chrome-maskable-192x192.png +0 -0
  56. package/website/static/favicons/android-chrome-maskable-512x512.png +0 -0
  57. package/website/static/favicons/apple-touch-icon-180x180.png +0 -0
  58. package/website/static/favicons/apple-touch-icon.png +0 -0
  59. package/website/static/favicons/favicon-16x16.png +0 -0
  60. package/website/static/favicons/favicon-32x32.png +0 -0
  61. package/website/static/favicons/favicon.ico +0 -0
  62. package/website/static/img/how-to-use.png +0 -0
@@ -0,0 +1,153 @@
1
+ ---
2
+ title: RBAC
3
+ linkTitle: RBAC
4
+ ---
5
+
6
+ # RBAC Modes
7
+
8
+ During the build phase of Pepr (`npx pepr build --rbac-mode [admin|scoped]`), you have the option to specify the desired RBAC mode through specific flags. This allows fine-tuning the level of access granted based on requirements and preferences.
9
+
10
+ ## Modes
11
+
12
+ **admin**
13
+
14
+ ```bash
15
+ npx pepr build --rbac-mode admin
16
+ ```
17
+
18
+ **Description:** The service account is given cluster-admin permissions, granting it full, unrestricted access across the entire cluster. This can be useful for administrative tasks where broad permissions are necessary. However, use this mode with caution, as it can pose security risks if misused. This is the default mode.
19
+
20
+ **scoped**
21
+
22
+ ```bash
23
+ npx pepr build --rbac-mode scoped
24
+ ```
25
+
26
+ **Description:** The service account is provided just enough permissions to perform its required tasks, and no more. This mode is recommended for most use cases as it limits potential attack vectors and aligns with best practices in security. _The admission controller's primary mutating or validating action doesn't require a ClusterRole (as the request is not persisted or executed while passing through admission control), if you have a use case where the admission controller's logic involves reading other Kubernetes resources or taking additional actions beyond just validating, mutating, or watching the incoming request, appropriate RBAC settings should be reflected in the ClusterRole. See how in [Updating the ClusterRole](#updating-the-clusterrole)._
27
+
28
+ ## Debugging RBAC Issues
29
+
30
+ If encountering unexpected behaviors in Pepr while running in scoped mode, check to see if they are related to RBAC.
31
+
32
+ 1. Check Deployment logs for RBAC errors:
33
+
34
+ ```bash
35
+ kubectl logs -n pepr-system -l app | jq
36
+
37
+ # example output
38
+ {
39
+ "level": 50,
40
+ "time": 1697983053758,
41
+ "pid": 16,
42
+ "hostname": "pepr-static-test-watcher-745d65857d-pndg7",
43
+ "data": {
44
+ "kind": "Status",
45
+ "apiVersion": "v1",
46
+ "metadata": {},
47
+ "status": "Failure",
48
+ "message": "configmaps \"pepr-ssa-demo\" is forbidden: User \"system:serviceaccount:pepr-system:pepr-static-test\" cannot patch resource \"configmaps\" in API group \"\" in the namespace \"pepr-demo-2\"",
49
+ "reason": "Forbidden",
50
+ "details": {
51
+ "name": "pepr-ssa-demo",
52
+ "kind": "configmaps"
53
+ },
54
+ "code": 403
55
+ },
56
+ "ok": false,
57
+ "status": 403,
58
+ "statusText": "Forbidden",
59
+ "msg": "Dooes the ServiceAccount permissions to CREATE and PATCH this ConfigMap?"
60
+ }
61
+ ```
62
+
63
+ 2. Verify ServiceAccount Permissions with `kubectl auth can-i`
64
+
65
+ ```bash
66
+ SA=$(kubectl get deploy -n pepr-system -o=jsonpath='{range .items[0]}{.spec.template.spec.serviceAccountName}{"\n"}{end}')
67
+
68
+ # Can i create configmaps as the service account in pepr-demo-2?
69
+ kubectl auth can-i create cm --as=system:serviceaccount:pepr-system:$SA -n pepr-demo-2
70
+
71
+ # example output: no
72
+ ```
73
+
74
+ 3. Describe the ClusterRole
75
+
76
+ ```bash
77
+ SA=$(kubectl get deploy -n pepr-system -o=jsonpath='{range .items[0]}{.spec.template.spec.serviceAccountName}{"\n"}{end}')
78
+
79
+ kubectl describe clusterrole $SA
80
+
81
+ # example output:
82
+ Name: pepr-static-test
83
+ Labels: <none>
84
+ Annotations: <none>
85
+ PolicyRule:
86
+ Resources Non-Resource URLs Resource Names Verbs
87
+ --------- ----------------- -------------- -----
88
+ peprstores.pepr.dev [] [] [create delete get list patch update watch]
89
+ configmaps [] [] [watch]
90
+ namespaces [] [] [watch]
91
+ ```
92
+
93
+ ## Updating the ClusterRole
94
+
95
+ As discussed in the [Modes](#modes) section, the admission controller's primary mutating or validating action doesn't require a ClusterRole (as the request is not persisted or executed while passing through admission control), if you have a use case where the admission controller's logic involves reading other Kubernetes resources or taking additional actions beyond just validating, mutating, or watching the incoming request, appropriate RBAC settings should be reflected in the ClusterRole.
96
+
97
+ Step 1: Figure out the desired permissions. (`kubectl create clusterrole --help` is a good place to start figuring out the syntax)
98
+
99
+ ```bash
100
+ kubectl create clusterrole configMapApplier --verb=create,patch --resource=configmap --dry-run=client -oyaml
101
+
102
+ # example output
103
+ apiVersion: rbac.authorization.k8s.io/v1
104
+ kind: ClusterRole
105
+ metadata:
106
+ creationTimestamp: null
107
+ name: configMapApplier
108
+ rules:
109
+ - apiGroups:
110
+ - ""
111
+ resources:
112
+ - configmaps
113
+ verbs:
114
+ - create
115
+ - patch
116
+ ```
117
+
118
+ Step 2: Update the ClusterRole in the `dist` folder.
119
+
120
+ ```yaml
121
+ ...
122
+ apiVersion: rbac.authorization.k8s.io/v1
123
+ kind: ClusterRole
124
+ metadata:
125
+ name: pepr-static-test
126
+ rules:
127
+ - apiGroups:
128
+ - pepr.dev
129
+ resources:
130
+ - peprstores
131
+ verbs:
132
+ - create
133
+ - get
134
+ - patch
135
+ - watch
136
+ - apiGroups:
137
+ - ''
138
+ resources:
139
+ - namespaces
140
+ verbs:
141
+ - watch
142
+ - apiGroups:
143
+ - ''
144
+ resources:
145
+ - configmaps
146
+ verbs:
147
+ - watch
148
+ - create # New
149
+ - patch # New
150
+ ...
151
+ ```
152
+
153
+ Step 3: Apply the updated configuration
@@ -0,0 +1,189 @@
1
+ ---
2
+ title: WebAssembly
3
+ linkTitle: WebAssembly
4
+ ---
5
+
6
+ # WASM Support: Running WebAssembly in Pepr Guide
7
+
8
+ Pepr fully supports WebAssembly. Depending on the language used to generate the WASM, certain files can be too large to fit into a `Secret` or `ConfigMap`. Due to this limitation, users have the ability to incorporate `*.wasm` and any other essential files during the build phase, which are then embedded into the Pepr Controller container. This is achieved through adding an array of files to the `includedFiles` section under `pepr` in the `package.json`.
9
+
10
+ > **NOTE -** In order to instantiate the WebAsembly module in TypeScript, you need the WebAssembly type. This is accomplished through add the "DOM" to the `lib` array in the `compilerOptions` section of the `tsconfig.json`. Ex: `"lib": ["ES2022", "DOM"]`. Be aware that adding the DOM will add a lot of extra types to your project and your developer experience will be impacted in terms of the intellisense.
11
+
12
+
13
+ ## High-Level Overview
14
+
15
+ WASM support is achieved through adding files as layers atop the Pepr controller image, these files are then able to be read by the individual capabilities. The key components of WASM support are:
16
+
17
+ - Add files to the **base** of the Pepr module.
18
+ - Reference the files in the `includedFiles` section of the `pepr` block of the `package.json`
19
+ - Run `npx pepr build` with the `-r ` option specifying registry info. Ex: `npx pepr build -r docker.io/cmwylie19`
20
+ - Pepr builds and pushes a custom image that is used in the `Deployment`.
21
+
22
+ ## Using WASM Support
23
+
24
+ ### Creating a WASM Module in Go
25
+
26
+ Create a simple Go function that you want to call from your Pepr module
27
+
28
+ ```go
29
+ package main
30
+
31
+ import (
32
+ "fmt"
33
+ "syscall/js"
34
+ )
35
+
36
+ func concats(this js.Value, args []js.Value) interface{} {
37
+ fmt.Println("PeprWASM!")
38
+ stringOne := args[0].String()
39
+ stringTwo := args[1].String()
40
+ return fmt.Sprintf("%s%s", stringOne, stringTwo)
41
+ }
42
+
43
+ func main() {
44
+ done := make(chan struct{}, 0)
45
+ js.Global().Set("concats", js.FuncOf(concats))
46
+ <-done
47
+ }
48
+ ```
49
+
50
+ Compile it to a wasm target and move it to your Pepr module
51
+
52
+ ```bash
53
+ GOOS=js GOARCH=wasm go build -o main.wasm
54
+ cp main.wasm $YOUR_PEPR_MODULE/
55
+ ```
56
+
57
+ Copy the `wasm_exec.js` from `GOROOT` to your Pepr Module
58
+
59
+ ```bash
60
+ cp "$(go env GOROOT)/misc/wasm/wasm_exec.js" $YOUR_PEPR_MODULE/
61
+ ```
62
+
63
+ Update the polyfill to add `globalThis.crypto` in the `wasm_exec.js` since we are not running in the browser. This is needed directly under: `(() => {`
64
+
65
+
66
+ ```javascript
67
+ // Initialize the polyfill
68
+ if (typeof globalThis.crypto === 'undefined') {
69
+ globalThis.crypto = {
70
+ getRandomValues: (array) => {
71
+ for (let i = 0; i < array.length; i++) {
72
+ array[i] = Math.floor(Math.random() * 256);
73
+ }
74
+ },
75
+ };
76
+ }
77
+ ```
78
+
79
+
80
+ ### Configure Pepr to use WASM
81
+
82
+ After adding the files to the root of the Pepr module, reference those files in the `package.json`:
83
+
84
+ ```json
85
+ {
86
+ "name": "pepr-test-module",
87
+ "version": "0.0.1",
88
+ "description": "A test module for Pepr",
89
+ "keywords": [
90
+ "pepr",
91
+ "k8s",
92
+ "policy-engine",
93
+ "pepr-module",
94
+ "security"
95
+ ],
96
+ "engines": {
97
+ "node": ">=18.0.0"
98
+ },
99
+ "pepr": {
100
+ "name": "pepr-test-module",
101
+ "uuid": "static-test",
102
+ "onError": "ignore",
103
+ "alwaysIgnore": {
104
+ "namespaces": [],
105
+ "labels": []
106
+ },
107
+ "includedFiles":[
108
+ "main.wasm",
109
+ "wasm_exec.js"
110
+ ]
111
+ },
112
+ ...
113
+ }
114
+ ```
115
+
116
+ Update the `tsconfig.json` to add "DOM" to the `compilerOptions` lib:
117
+
118
+ ```json
119
+ {
120
+ "compilerOptions": {
121
+ "allowSyntheticDefaultImports": true,
122
+ "declaration": true,
123
+ "declarationMap": true,
124
+ "emitDeclarationOnly": true,
125
+ "esModuleInterop": true,
126
+ "lib": [
127
+ "ES2022",
128
+ "DOM" // <- Add this
129
+ ],
130
+ "module": "CommonJS",
131
+ "moduleResolution": "node",
132
+ "outDir": "dist",
133
+ "resolveJsonModule": true,
134
+ "rootDir": ".",
135
+ "strict": false,
136
+ "target": "ES2022",
137
+ "useUnknownInCatchVariables": false
138
+ },
139
+ "include": [
140
+ "**/*.ts"
141
+ ]
142
+ }
143
+ ```
144
+
145
+ ### Call WASM functions from TypeScript
146
+
147
+ Import the `wasm_exec.js` in the `pepr.ts`
148
+
149
+ ```javascript
150
+ import "./wasm_exec.js";
151
+ ```
152
+
153
+ Create a helper function to load the wasm file in a capability and call it during an event of your choice
154
+
155
+ ```typescript
156
+ async function callWASM(a,b) {
157
+ const go = new globalThis.Go();
158
+
159
+ const wasmData = readFileSync("main.wasm");
160
+ var concated: string;
161
+
162
+ await WebAssembly.instantiate(wasmData, go.importObject).then(wasmModule => {
163
+ go.run(wasmModule.instance);
164
+
165
+ concated = global.concats(a,b);
166
+ });
167
+ return concated;
168
+ }
169
+
170
+ When(a.Pod)
171
+ .IsCreated()
172
+ .Mutate(async pod => {
173
+ try {
174
+ let label_value = await callWASM("loves","wasm")
175
+ pod.SetLabel("pepr",label_value)
176
+ }
177
+ catch(err) {
178
+ Log.error(err);
179
+ }
180
+ });
181
+ ```
182
+
183
+ ### Run Pepr Build
184
+
185
+ Build your Pepr module with the registry specified.
186
+
187
+ ```bash
188
+ npx pepr build -r docker.io/defenseunicorns
189
+ ```
package/website/go.mod ADDED
@@ -0,0 +1,8 @@
1
+ module main
2
+
3
+ go 1.20
4
+
5
+ require (
6
+ github.com/defenseunicorns/defense-unicorns-hugo-theme v0.3.9 // indirect
7
+ github.com/defenseunicorns/defense-unicorns-hugo-theme/dependencies v0.3.9 // indirect
8
+ )
package/website/go.sum ADDED
@@ -0,0 +1,4 @@
1
+ github.com/defenseunicorns/defense-unicorns-hugo-theme v0.3.9 h1:o2ptq0ozp8x5R61Ik0E08YI3VEBjJGwUvKs8sRleUC8=
2
+ github.com/defenseunicorns/defense-unicorns-hugo-theme v0.3.9/go.mod h1:qOBlMoMnovWO8PwmHAlpR7WfPLOJiiq4+XIrVblRb8g=
3
+ github.com/defenseunicorns/defense-unicorns-hugo-theme/dependencies v0.3.9 h1:nz4Aiu+ISXKESXgTjPyDyR9L708XjszH6lnQAGFAAVI=
4
+ github.com/defenseunicorns/defense-unicorns-hugo-theme/dependencies v0.3.9/go.mod h1:zQT7gnRyPnVCNxREasYkyewPJLhemxlOGZhbu+9mcfQ=