pepr 0.42.1 → 0.42.3
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.
- package/dist/cli/build.helpers.d.ts +1 -1
- package/dist/cli/build.helpers.d.ts.map +1 -1
- package/dist/cli/deploy.d.ts +15 -0
- package/dist/cli/deploy.d.ts.map +1 -1
- package/dist/cli/dev.d.ts.map +1 -1
- package/dist/cli/format.d.ts.map +1 -1
- package/dist/cli/format.helpers.d.ts +3 -0
- package/dist/cli/format.helpers.d.ts.map +1 -0
- package/dist/cli/init/enums.d.ts +10 -0
- package/dist/cli/init/enums.d.ts.map +1 -0
- package/dist/cli/init/index.d.ts.map +1 -1
- package/dist/cli/init/templates.d.ts +15 -11
- package/dist/cli/init/templates.d.ts.map +1 -1
- package/dist/cli/init/utils.d.ts.map +1 -1
- package/dist/cli/init/walkthrough.d.ts +3 -2
- package/dist/cli/init/walkthrough.d.ts.map +1 -1
- package/dist/cli/kfc.d.ts.map +1 -1
- package/dist/cli/root.d.ts.map +1 -1
- package/dist/cli/update.d.ts.map +1 -1
- package/dist/cli/uuid.d.ts.map +1 -1
- package/dist/cli.js +1073 -1220
- package/dist/controller.js +1 -195
- package/dist/fixtures/loader.d.ts.map +1 -1
- package/dist/lib/assets/assets.d.ts +27 -0
- package/dist/lib/assets/assets.d.ts.map +1 -0
- package/dist/lib/assets/deploy.d.ts +1 -1
- package/dist/lib/assets/deploy.d.ts.map +1 -1
- package/dist/lib/assets/index.d.ts +5 -24
- package/dist/lib/assets/index.d.ts.map +1 -1
- package/dist/lib/assets/pods.d.ts +2 -4
- package/dist/lib/assets/pods.d.ts.map +1 -1
- package/dist/lib/assets/rbac.d.ts.map +1 -1
- package/dist/lib/assets/webhooks.d.ts +1 -1
- package/dist/lib/assets/webhooks.d.ts.map +1 -1
- package/dist/lib/assets/yaml.d.ts +31 -5
- package/dist/lib/assets/yaml.d.ts.map +1 -1
- package/dist/lib/controller/index.d.ts +2 -2
- package/dist/lib/controller/index.d.ts.map +1 -1
- package/dist/lib/controller/store.d.ts +1 -1
- package/dist/lib/controller/store.d.ts.map +1 -1
- package/dist/lib/controller/storeCache.d.ts +1 -1
- package/dist/lib/controller/storeCache.d.ts.map +1 -1
- package/dist/lib/{capability.d.ts → core/capability.d.ts} +1 -1
- package/dist/lib/core/capability.d.ts.map +1 -0
- package/dist/lib/{module.d.ts → core/module.d.ts} +2 -2
- package/dist/lib/core/module.d.ts.map +1 -0
- package/dist/lib/core/queue.d.ts.map +1 -0
- package/dist/lib/{schedule.d.ts → core/schedule.d.ts} +0 -1
- package/dist/lib/core/schedule.d.ts.map +1 -0
- package/dist/lib/core/storage.d.ts.map +1 -0
- package/dist/lib/deploymentChecks.d.ts.map +1 -1
- package/dist/lib/errors.d.ts +0 -5
- package/dist/lib/errors.d.ts.map +1 -1
- package/dist/lib/filesystemService.d.ts.map +1 -1
- package/dist/lib/filter/adjudicators/adjudicators.d.ts +5 -4
- package/dist/lib/filter/adjudicators/adjudicators.d.ts.map +1 -1
- package/dist/lib/filter/filter.d.ts +33 -1
- package/dist/lib/filter/filter.d.ts.map +1 -1
- package/dist/lib/finalizer.d.ts.map +1 -1
- package/dist/lib/helpers.d.ts +4 -9
- package/dist/lib/helpers.d.ts.map +1 -1
- package/dist/lib/included-files.d.ts.map +1 -1
- package/dist/lib/mutate-request.d.ts.map +1 -1
- package/dist/lib/processors/mutate-processor.d.ts +28 -0
- package/dist/lib/processors/mutate-processor.d.ts.map +1 -0
- package/dist/lib/{validate-processor.d.ts → processors/validate-processor.d.ts} +5 -5
- package/dist/lib/processors/validate-processor.d.ts.map +1 -0
- package/dist/lib/{watch-processor.d.ts → processors/watch-processor.d.ts} +2 -2
- package/dist/lib/processors/watch-processor.d.ts.map +1 -0
- package/dist/lib/telemetry/logger.d.ts.map +1 -1
- package/dist/lib/telemetry/metrics.d.ts.map +1 -1
- package/dist/lib/validate-request.d.ts +2 -2
- package/dist/lib/validate-request.d.ts.map +1 -1
- package/dist/lib.d.ts +2 -2
- package/dist/lib.d.ts.map +1 -1
- package/dist/lib.js +383 -243
- package/dist/lib.js.map +4 -4
- package/dist/sdk/heredoc.d.ts.map +1 -1
- package/package.json +9 -9
- package/src/cli/build.helpers.ts +1 -1
- package/src/cli/build.ts +1 -1
- package/src/cli/deploy.ts +114 -75
- package/src/cli/dev.ts +3 -3
- package/src/cli/format.helpers.ts +27 -0
- package/src/cli/format.ts +4 -18
- package/src/cli/init/enums.ts +9 -0
- package/src/cli/init/index.ts +4 -3
- package/src/cli/init/templates.ts +30 -2
- package/src/cli/init/utils.ts +3 -3
- package/src/cli/init/walkthrough.ts +7 -8
- package/src/cli/kfc.ts +1 -1
- package/src/cli/root.ts +1 -1
- package/src/cli/update.ts +1 -1
- package/src/cli/uuid.ts +1 -1
- package/src/fixtures/loader.ts +2 -2
- package/src/lib/assets/assets.ts +176 -0
- package/src/lib/assets/deploy.ts +6 -6
- package/src/lib/assets/index.ts +10 -144
- package/src/lib/assets/pods.ts +2 -2
- package/src/lib/assets/webhooks.ts +32 -56
- package/src/lib/assets/yaml.ts +47 -25
- package/src/lib/controller/index.ts +4 -4
- package/src/lib/controller/store.ts +2 -2
- package/src/lib/controller/storeCache.ts +6 -2
- package/src/lib/{capability.ts → core/capability.ts} +4 -4
- package/src/lib/{module.ts → core/module.ts} +10 -10
- package/src/lib/{queue.ts → core/queue.ts} +1 -1
- package/src/lib/deploymentChecks.ts +2 -2
- package/src/lib/errors.ts +3 -8
- package/src/lib/filesystemService.ts +1 -1
- package/src/lib/filter/adjudicators/adjudicators.ts +40 -9
- package/src/lib/filter/filter.ts +204 -111
- package/src/lib/finalizer.ts +2 -2
- package/src/lib/helpers.ts +20 -133
- package/src/lib/included-files.ts +1 -1
- package/src/lib/processors/mutate-processor.ts +225 -0
- package/src/lib/{validate-processor.ts → processors/validate-processor.ts} +8 -8
- package/src/lib/{watch-processor.ts → processors/watch-processor.ts} +8 -8
- package/src/lib/telemetry/logger.ts +3 -1
- package/src/lib/tls.ts +5 -1
- package/src/lib/validate-request.ts +4 -4
- package/src/lib.ts +2 -2
- package/src/runtime/controller.ts +2 -2
- package/src/sdk/heredoc.ts +1 -1
- package/dist/lib/capability.d.ts.map +0 -1
- package/dist/lib/module.d.ts.map +0 -1
- package/dist/lib/mutate-processor.d.ts +0 -6
- package/dist/lib/mutate-processor.d.ts.map +0 -1
- package/dist/lib/queue.d.ts.map +0 -1
- package/dist/lib/schedule.d.ts.map +0 -1
- package/dist/lib/storage.d.ts.map +0 -1
- package/dist/lib/validate-processor.d.ts.map +0 -1
- package/dist/lib/watch-processor.d.ts.map +0 -1
- package/src/lib/mutate-processor.ts +0 -165
- /package/dist/lib/{queue.d.ts → core/queue.d.ts} +0 -0
- /package/dist/lib/{storage.d.ts → core/storage.d.ts} +0 -0
- /package/src/lib/{schedule.ts → core/schedule.ts} +0 -0
- /package/src/lib/{storage.ts → core/storage.ts} +0 -0
|
@@ -1,165 +0,0 @@
|
|
|
1
|
-
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
-
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors
|
|
3
|
-
|
|
4
|
-
import jsonPatch from "fast-json-patch";
|
|
5
|
-
import { kind } from "kubernetes-fluent-client";
|
|
6
|
-
|
|
7
|
-
import { Capability } from "./capability";
|
|
8
|
-
import { Errors } from "./errors";
|
|
9
|
-
import { shouldSkipRequest } from "./filter/filter";
|
|
10
|
-
import { MutateResponse } from "./k8s";
|
|
11
|
-
import { AdmissionRequest } from "./types";
|
|
12
|
-
import Log from "./telemetry/logger";
|
|
13
|
-
import { ModuleConfig } from "./module";
|
|
14
|
-
import { PeprMutateRequest } from "./mutate-request";
|
|
15
|
-
import { base64Encode, convertFromBase64Map, convertToBase64Map } from "./utils";
|
|
16
|
-
|
|
17
|
-
export async function mutateProcessor(
|
|
18
|
-
config: ModuleConfig,
|
|
19
|
-
capabilities: Capability[],
|
|
20
|
-
req: AdmissionRequest,
|
|
21
|
-
reqMetadata: Record<string, string>,
|
|
22
|
-
): Promise<MutateResponse> {
|
|
23
|
-
const wrapped = new PeprMutateRequest(req);
|
|
24
|
-
const response: MutateResponse = {
|
|
25
|
-
uid: req.uid,
|
|
26
|
-
warnings: [],
|
|
27
|
-
allowed: false,
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// Track whether any capability matched the request
|
|
31
|
-
let matchedAction = false;
|
|
32
|
-
|
|
33
|
-
// Track data fields that should be skipped during decoding
|
|
34
|
-
let skipDecode: string[] = [];
|
|
35
|
-
|
|
36
|
-
// If the resource is a secret, decode the data
|
|
37
|
-
const isSecret = req.kind.version === "v1" && req.kind.kind === "Secret";
|
|
38
|
-
if (isSecret) {
|
|
39
|
-
skipDecode = convertFromBase64Map(wrapped.Raw as unknown as kind.Secret);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
Log.info(reqMetadata, `Processing request`);
|
|
43
|
-
|
|
44
|
-
for (const { name, bindings, namespaces } of capabilities) {
|
|
45
|
-
const actionMetadata = { ...reqMetadata, name };
|
|
46
|
-
for (const action of bindings) {
|
|
47
|
-
// Skip this action if it's not a mutate action
|
|
48
|
-
if (!action.mutateCallback) {
|
|
49
|
-
continue;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
// Continue to the next action without doing anything if this one should be skipped
|
|
53
|
-
const shouldSkip = shouldSkipRequest(action, req, namespaces, config?.alwaysIgnore?.namespaces);
|
|
54
|
-
if (shouldSkip !== "") {
|
|
55
|
-
Log.debug(shouldSkip);
|
|
56
|
-
continue;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
const label = action.mutateCallback.name;
|
|
60
|
-
Log.info(actionMetadata, `Processing mutation action (${label})`);
|
|
61
|
-
matchedAction = true;
|
|
62
|
-
|
|
63
|
-
// Add annotations to the request to indicate that the capability started processing
|
|
64
|
-
// this will allow tracking of failed mutations that were permitted to continue
|
|
65
|
-
const updateStatus = (status: string) => {
|
|
66
|
-
// Only update the status if the request is a CREATE or UPDATE (we don't use CONNECT)
|
|
67
|
-
if (req.operation === "DELETE") {
|
|
68
|
-
return;
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
const identifier = `${config.uuid}.pepr.dev/${name}`;
|
|
72
|
-
wrapped.Raw.metadata = wrapped.Raw.metadata || {};
|
|
73
|
-
wrapped.Raw.metadata.annotations = wrapped.Raw.metadata.annotations || {};
|
|
74
|
-
wrapped.Raw.metadata.annotations[identifier] = status;
|
|
75
|
-
};
|
|
76
|
-
|
|
77
|
-
updateStatus("started");
|
|
78
|
-
|
|
79
|
-
try {
|
|
80
|
-
// Run the action
|
|
81
|
-
await action.mutateCallback(wrapped);
|
|
82
|
-
|
|
83
|
-
// Log on success
|
|
84
|
-
Log.info(actionMetadata, `Mutation action succeeded (${label})`);
|
|
85
|
-
|
|
86
|
-
// Add annotations to the request to indicate that the capability succeeded
|
|
87
|
-
updateStatus("succeeded");
|
|
88
|
-
} catch (e) {
|
|
89
|
-
updateStatus("warning");
|
|
90
|
-
response.warnings = response.warnings || [];
|
|
91
|
-
|
|
92
|
-
const errorMessage = logMutateErrorMessage(e);
|
|
93
|
-
|
|
94
|
-
// Log on failure
|
|
95
|
-
Log.error(actionMetadata, `Action failed: ${errorMessage}`);
|
|
96
|
-
response.warnings.push(`Action failed: ${errorMessage}`);
|
|
97
|
-
|
|
98
|
-
switch (config.onError) {
|
|
99
|
-
case Errors.reject:
|
|
100
|
-
Log.error(actionMetadata, `Action failed: ${errorMessage}`);
|
|
101
|
-
response.result = "Pepr module configured to reject on error";
|
|
102
|
-
return response;
|
|
103
|
-
|
|
104
|
-
case Errors.audit:
|
|
105
|
-
response.auditAnnotations = response.auditAnnotations || {};
|
|
106
|
-
response.auditAnnotations[Date.now()] = `Action failed: ${errorMessage}`;
|
|
107
|
-
break;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
// If we've made it this far, the request is allowed
|
|
114
|
-
response.allowed = true;
|
|
115
|
-
|
|
116
|
-
// If no capability matched the request, exit early
|
|
117
|
-
if (!matchedAction) {
|
|
118
|
-
Log.info(reqMetadata, `No matching actions found`);
|
|
119
|
-
return response;
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
// delete operations can't be mutate, just return before the transformation
|
|
123
|
-
if (req.operation === "DELETE") {
|
|
124
|
-
return response;
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
const transformed = wrapped.Raw;
|
|
128
|
-
|
|
129
|
-
// Post-process the Secret requests to convert it back to the original format
|
|
130
|
-
if (isSecret) {
|
|
131
|
-
convertToBase64Map(transformed as unknown as kind.Secret, skipDecode);
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
// Compare the original request to the modified request to get the patches
|
|
135
|
-
const patches = jsonPatch.compare(req.object, transformed);
|
|
136
|
-
|
|
137
|
-
// Only add the patch if there are patches to apply
|
|
138
|
-
if (patches.length > 0) {
|
|
139
|
-
response.patchType = "JSONPatch";
|
|
140
|
-
// Webhook must be base64-encoded
|
|
141
|
-
// https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#response
|
|
142
|
-
response.patch = base64Encode(JSON.stringify(patches));
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
// Remove the warnings array if it's empty
|
|
146
|
-
if (response.warnings && response.warnings.length < 1) {
|
|
147
|
-
delete response.warnings;
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
Log.debug({ ...reqMetadata, patches }, `Patches generated`);
|
|
151
|
-
|
|
152
|
-
return response;
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
const logMutateErrorMessage = (e: Error): string => {
|
|
156
|
-
try {
|
|
157
|
-
if (e.message && e.message !== "[object Object]") {
|
|
158
|
-
return e.message;
|
|
159
|
-
} else {
|
|
160
|
-
throw new Error("An error occurred in the mutate action.");
|
|
161
|
-
}
|
|
162
|
-
} catch (e) {
|
|
163
|
-
return "An error occurred with the mutate action.";
|
|
164
|
-
}
|
|
165
|
-
};
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|