Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: defenseunicorns/pepr
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.18.1
Choose a base ref
...
head repository: defenseunicorns/pepr
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: v0.19.0
Choose a head ref
  • 6 commits
  • 17 files changed
  • 4 contributors

Commits on Dec 5, 2023

  1. feat: create a library of helper functions that make working with pep…

    …r easier (#415)
    
    ## Description
    
    Added module-helpers.ts and module-helpers.spec.ts.
    
    module-helpers.ts has a containers function that accepts a request
    parameter and an optional containerTypes parameter. The request is a
    PeprValidateRequest<a.Pod> that identifies the pod from which a list of
    containers should be returned.
    
    If no containerTypes parameter is included, all containers in the pod
    will be returned. If "containers" is passed in for the containerTypes,
    then only spec.containers will be returned. If "initContainers" is
    passed in for the containerTypes, then only spec.initContainers will be
    returned. If ephemeralContainers is passed in for the containerTypes,
    then only spec.ephemeralContainers will be returned.
    
    In order to keep the flexibility of pulling the module-helpers into a
    separate module in the future, the containers function was put into the
    new module-helpers.ts file instead of modifying the PeprValidateRequest
    class.
    
    ## Related Issue
    
    Fixes #
    <!-- or -->
    Relates to #
    
    ## Type of change
    
    - [ ] Bug fix (non-breaking change which fixes an issue)
    - [x] New feature (non-breaking change which adds functionality)
    - [ ] Other (security config, docs update, etc)
    
    ## Checklist before merging
    
    - [x] Test, docs, adr added or updated as needed
    - [x] [Contributor Guide
    Steps](https://github.com/defenseunicorns/pepr/blob/main/CONTRIBUTING.md#submitting-a-pull-request)
    followed
    schaeferka authored Dec 5, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    b060889 View commit details
  2. feat: updated containers function to work with mutate requests (#418)

    ## Description
    
    Updated the containers function in module-helpers.ts to work with both
    validate and mutate blocks.
    
    ## Related Issue
    
    Fixes #417
    Relates to #
    
    ## Type of change
    
    - [ ] Bug fix (non-breaking change which fixes an issue)
    - [X] New feature (non-breaking change which adds functionality)
    - [ ] Other (security config, docs update, etc)
    
    ## Checklist before merging
    
    - [X] Test, docs, adr added or updated as needed
    - [X] [Contributor Guide
    Steps](https://github.com/defenseunicorns/pepr/blob/main/CONTRIBUTING.md#submitting-a-pull-request)
    followed
    schaeferka authored Dec 5, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    ea2a37c View commit details
  3. fix: watch does not respect ns testing (#398)

    ## Description
    
    Watch is not respecting namespace criteria. This PR is to make watch
    respect the ignoredNamespaces and the capability namespaces. If those
    two criteria are not respected, a warning is given to the user.
    
    Bindings must respect ignoreNamespace and capability namespace, if not
    the build will not occur.
    
    The `alwaysIgnore.namespaces` is the first priority, then capability
    namespaces
    
    ## Related Issue
    
    Fixes #395 
    <!-- or -->
    Relates to #
    
    ## Type of change
    
    - [x] Bug fix (non-breaking change which fixes an issue)
    - [ ] New feature (non-breaking change which adds functionality)
    - [ ] Other (security config, docs update, etc)
    
    ## Checklist before merging
    
    - [x] Test, docs, adr added or updated as needed
    - [x] [Contributor Guide
    Steps](https://github.com/defenseunicorns/pepr/blob/main/CONTRIBUTING.md#submitting-a-pull-request)
    followed
    
    ---------
    
    Signed-off-by: Case Wylie <cmwylie19@defenseunicorns.com>
    Co-authored-by: Barrett <81570928+btlghrants@users.noreply.github.com>
    cmwylie19 and btlghrants authored Dec 5, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    34e0525 View commit details

Commits on Dec 6, 2023

  1. chore: fix PeprStore rendering where multiple capabilities are in play (

    #422)
    
    ## Description
    
    Fixes PeprStore not deployed and functions as expected when there are
    multiple capabilities
    
    
    
    ## Related Issue
    
    Fixes #421 
    <!-- or -->
    Relates to #
    
    ## Type of change
    
    - [x] Bug fix (non-breaking change which fixes an issue)
    - [ ] New feature (non-breaking change which adds functionality)
    - [ ] Other (security config, docs update, etc)
    
    ## Checklist before merging
    
    - [x] Test, docs, adr added or updated as needed
    - [x] [Contributor Guide
    Steps](https://github.com/defenseunicorns/pepr/blob/main/CONTRIBUTING.md#submitting-a-pull-request)
    followed
    
    Signed-off-by: Case Wylie <cmwylie19@defenseunicorns.com>
    cmwylie19 authored Dec 6, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    db50856 View commit details
  2. chore: update logo image in header (#420)

    ## Description
    
    Updated the logo image used in the header to an svg file that includes
    the word mark.
    
    ## Related Issue
    
    Fixes #342
    
    ## Type of change
    
    - [ ] Bug fix (non-breaking change which fixes an issue)
    - [ ] New feature (non-breaking change which adds functionality)
    - [X] Other (security config, docs update, etc)
    
    ## Checklist before merging
    
    - [X] Test, docs, adr added or updated as needed
    - [X] [Contributor Guide
    Steps](https://github.com/defenseunicorns/pepr/blob/main/CONTRIBUTING.md#submitting-a-pull-request)
    followed
    
    ---------
    
    Co-authored-by: Case Wylie <cmwylie19@defenseunicorns.com>
    schaeferka and cmwylie19 authored Dec 6, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    2032ce4 View commit details
  3. feat: add pepr monitor command (#411)

    ## Description
    
    For discussion: adds a simple `npx pepr monitor` command to summarize
    in-cluster logs. More of an idea to think through.
    
    ![Screenshot 2023-12-04 at 3 02
    23 AM](https://github.com/defenseunicorns/pepr/assets/882485/d4f06ab0-82c0-458b-8e22-9f8151a83e7f)
    
    
    ## Type of change
    
    - [ ] Bug fix (non-breaking change which fixes an issue)
    - [x] New feature (non-breaking change which adds functionality)
    - [ ] Other (security config, docs update, etc)
    
    ## Checklist before merging
    
    - [ ] Test, docs, adr added or updated as needed
    - [ ] [Contributor Guide
    Steps](https://github.com/defenseunicorns/pepr/blob/main/CONTRIBUTING.md#submitting-a-pull-request)
    followed
    
    ---------
    
    Signed-off-by: Case Wylie <cmwylie19@defenseunicorns.com>
    Co-authored-by: Case Wylie <cmwylie19@defenseunicorns.com>
    Co-authored-by: Barrett <81570928+btlghrants@users.noreply.github.com>
    3 people authored Dec 6, 2023

    Verified

    This commit was created on GitHub.com and signed with GitHub’s verified signature.
    Copy the full SHA
    ef6b756 View commit details
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Version Releaes
name: Version Release

on:
release:
16 changes: 15 additions & 1 deletion docs/cli.md
Original file line number Diff line number Diff line change
@@ -49,6 +49,20 @@ Deploy the current module into a Kubernetes cluster, useful for CI systems. Not

---

## pepr monitor

Monitor Validations for a given Pepr Module.

Usage:
```bash
npx pepr monitor [options] <module-uuid>
```

**Options:**
- `-l, --log-level [level]` - Log level: debug, info, warn, error (default: "info")
- `-h, --help` - Display help for command

---
## `pepr build`

Create a [zarf.yaml](https://zarf.dev) and K8s manifest for the current module. This includes everything needed to deploy Pepr and the current module into production environments.
@@ -60,4 +74,4 @@ Create a [zarf.yaml](https://zarf.dev) and K8s manifest for the current module.
- `-n, --no-embed` - Disables embedding of deployment files into output module. Useful when creating library modules intended solely for reuse/distribution via NPM
- `-r, --registry-info [<registry>/<username>]` - Registry Info: Image registry and username. Note: You must be signed into the registry
- `-o, --output-dir [output directory]` - Define where to place build output
- `--rbac-mode [admin|scoped]` - Rbac Mode: admin, scoped (default: admin) (choices: "admin", "scoped", default: "admin")
- `--rbac-mode [admin|scoped]` - Rbac Mode: admin, scoped (default: admin) (choices: "admin", "scoped", default: "admin")
2 changes: 2 additions & 0 deletions src/cli.ts
Original file line number Diff line number Diff line change
@@ -8,6 +8,7 @@ import build from "./cli/build";
import deploy from "./cli/deploy";
import dev from "./cli/dev";
import format from "./cli/format";
import monitor from "./cli/monitor";
import init from "./cli/init/index";
import { version } from "./cli/init/templates";
import { RootCmd } from "./cli/root";
@@ -39,5 +40,6 @@ deploy(program);
dev(program);
update(program);
format(program);
monitor(program);

program.parse();
87 changes: 87 additions & 0 deletions src/cli/monitor.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
// SPDX-License-Identifier: Apache-2.0
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors

import { Log as K8sLog, KubeConfig } from "@kubernetes/client-node";
import { K8s, kind } from "kubernetes-fluent-client";
import stream from "stream";
import { ResponseItem } from "../lib/types";
import { RootCmd } from "./root";

export default function (program: RootCmd) {
program
.command("monitor <module-uuid>")
.description("Monitor a Pepr Module")
.action(async uuid => {
if (!uuid) {
console.error("Module UUID is required");
process.exit(1);
}

// Get the logs for the `app=pepr-${module}` pod selector
const pods = await K8s(kind.Pod)
.InNamespace("pepr-system")
.WithLabel("app", `pepr-${uuid}`)
.Get();

const podNames = pods.items.flatMap(pod => pod.metadata!.name) as string[];

if (podNames.length < 1) {
console.error(`No pods found for module ${uuid}`);
process.exit(1);
}

const kc = new KubeConfig();
kc.loadFromDefault();

const log = new K8sLog(kc);

const logStream = new stream.PassThrough();

logStream.on("data", chunk => {
const respMsg = `"msg":"Check response"`;
// Split the chunk into lines
const lines = chunk.toString().split("\n");

for (const line of lines) {
// Check for `"msg":"Hello Pepr"`
if (line.includes(respMsg)) {
try {
const payload = JSON.parse(line);
const isMutate = payload.res.patchType || payload.res.warnings;

const name = `${payload.namespace}${payload.name}`;
const uid = payload.uid;

if (isMutate) {
const allowOrDeny = payload.res.allowed ? "✅" : "❌";
console.log(`\n${allowOrDeny} MUTATE ${name} (${uid})`);
} else {
const failures = Array.isArray(payload.res) ? payload.res : [payload.res];

const filteredFailures = failures
.filter((r: ResponseItem) => !r.allowed)
.map((r: ResponseItem) => r.status.message);
// console.log(`${name} (${uid}) | VALIDATE | ${allow ? "ALLOW" : "DENY"}`);
if (filteredFailures.length > 0) {
console.log(`\n❌ VALIDATE ${name} (${uid})`);
console.debug(filteredFailures);
} else {
console.log(`\n✅ VALIDATE ${name} (${uid})`);
}
}
} catch {
console.warn(`\nIGNORED - Unable to parse line: ${line}.`);
}
}
}
});

for (const podName of podNames) {
await log.log("pepr-system", podName, "server", logStream, {
follow: true,
pretty: false,
timestamps: false,
});
}
});
}
2 changes: 2 additions & 0 deletions src/lib.ts
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ import { PeprModule } from "./lib/module";
import { PeprMutateRequest } from "./lib/mutate-request";
import * as PeprUtils from "./lib/utils";
import { PeprValidateRequest } from "./lib/validate-request";
import { containers } from "./lib/module-helpers";

export {
Capability,
@@ -22,4 +23,5 @@ export {
fetch,
fetchStatus,
kind,
containers,
};
11 changes: 10 additions & 1 deletion src/lib/assets/index.ts
Original file line number Diff line number Diff line change
@@ -6,15 +6,19 @@ import crypto from "crypto";
import { ModuleConfig } from "../module";
import { TLSOut, genTLS } from "../tls";
import { CapabilityExport } from "../types";
import { WebhookIgnore } from "../k8s";
import { deploy } from "./deploy";
import { loadCapabilities } from "./loader";
import { allYaml, zarfYaml } from "./yaml";
import { namespaceComplianceValidator } from "../helpers";

export class Assets {
readonly name: string;
readonly tls: TLSOut;
readonly apiToken: string;
readonly alwaysIgnore!: WebhookIgnore;
capabilities!: CapabilityExport[];

image: string;

constructor(
@@ -23,7 +27,7 @@ export class Assets {
readonly host?: string,
) {
this.name = `pepr-${config.uuid}`;

this.alwaysIgnore = config.alwaysIgnore;
this.image = `ghcr.io/defenseunicorns/pepr/controller:v${config.peprVersion}`;

// Generate the ephemeral tls things
@@ -42,6 +46,11 @@ export class Assets {

allYaml = async (rbacMode: string) => {
this.capabilities = await loadCapabilities(this.path);
// give error if namespaces are not respected
for (const capability of this.capabilities) {
namespaceComplianceValidator(capability, this.alwaysIgnore.namespaces);
}

return allYaml(this, rbacMode);
};
}
33 changes: 20 additions & 13 deletions src/lib/controller/index.ts
Original file line number Diff line number Diff line change
@@ -13,6 +13,7 @@ import { ModuleConfig, isWatchMode } from "../module";
import { mutateProcessor } from "../mutate-processor";
import { validateProcessor } from "../validate-processor";
import { PeprControllerStore } from "./store";
import { ResponseItem } from "../types";

export class Controller {
// Track whether the server is running
@@ -233,34 +234,40 @@ export class Controller {
const responseList: ValidateResponse[] | MutateResponse[] = Array.isArray(response) ? response : [response];
responseList.map(res => {
this.#afterHook && this.#afterHook(res);
// Log the response
Log.debug({ ...reqMetadata, res }, "Check response");
});

// Log the response
Log.debug({ ...reqMetadata, response }, "Outgoing response");
let kubeAdmissionResponse: ValidateResponse[] | MutateResponse | ResponseItem;

if (admissionKind === "Mutate") {
kubeAdmissionResponse = response;
Log.debug({ ...reqMetadata, response }, "Outgoing response");
res.send({
apiVersion: "admission.k8s.io/v1",
kind: "AdmissionReview",
response,
response: kubeAdmissionResponse,
});
} else {
kubeAdmissionResponse = {
uid: responseList[0].uid,
allowed: responseList.filter(r => !r.allowed).length === 0,
status: {
message: (responseList as ValidateResponse[])
.filter(rl => !rl.allowed)
.map(curr => curr.status?.message)
.join("; "),
},
};
res.send({
apiVersion: "admission.k8s.io/v1",
kind: "AdmissionReview",
response: {
uid: responseList[0].uid,
allowed: responseList.filter(r => !r.allowed).length === 0,
status: {
message: (responseList as ValidateResponse[])
.filter(rl => !rl.allowed)
.map(curr => curr.status?.message)
.join("; "),
},
},
response: kubeAdmissionResponse,
});
}

Log.debug({ ...reqMetadata, kubeAdmissionResponse }, "Outgoing response");

this.#metricsCollector.observeEnd(startTime, admissionKind);
} catch (err) {
Log.error(err);
2 changes: 1 addition & 1 deletion src/lib/controller/store.ts
Original file line number Diff line number Diff line change
@@ -31,7 +31,7 @@ export class PeprControllerStore {
for (const { name, registerScheduleStore, hasSchedule } of capabilities) {
// Guard Clause to exit early
if (hasSchedule !== true) {
return;
continue;
}
// Register the scheduleStore with the capability
const { scheduleStore } = registerScheduleStore();
Loading