-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: expose rbacMode from moduleConfig #1347
Open
cmwylie19
wants to merge
15
commits into
main
Choose a base branch
from
1327
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+142
−34
Open
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
10dad51
wip
cmwylie19 43b22e3
chore: rbacMode from moduleConfig
cmwylie19 66f7348
Merge branch 'main' into 1327
cmwylie19 23ad524
update signature
cmwylie19 37dba68
chore: push all code
cmwylie19 dfee133
chore: testing ci
cmwylie19 767c876
chore: separate files
cmwylie19 25de45d
Update journey/pepr-build.ts
cmwylie19 5fe4605
chore: separate files
cmwylie19 c23f54b
chore: fix journey test
cmwylie19 902c10d
Merge branch 'main' into 1327
btlghrants 8e1a81e
chore: address pr comments
cmwylie19 3f083ab
Update jest.config.json
cmwylie19 abeb3ee
chore: find working dir for test
cmwylie19 1cb0f0a
chore: find working dir for test
cmwylie19 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,35 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors | ||
|
||
import { describe, jest } from "@jest/globals"; | ||
|
||
import { beforeAll, describe, jest } from "@jest/globals"; | ||
import { promises as fs } from "fs"; | ||
import { peprBuild } from "./pepr-build-wasm"; | ||
|
||
import { resolve } from "path"; | ||
import { cwd } from "./entrypoint.test"; | ||
import { execSync } from "child_process"; | ||
|
||
// Unmock unit test things | ||
jest.deepUnmock("pino"); | ||
|
||
|
||
// Allow 5 minutes for the tests to run | ||
jest.setTimeout(1000 * 60 * 5); | ||
export const outputDir = "dist/pepr-test-module/child/folder"; | ||
beforeAll(async () => { | ||
const dir = resolve(cwd); | ||
await fs.mkdir(outputDir, { recursive: true }); | ||
await addScopedRbacMode(); | ||
}); | ||
describe( | ||
"Journey: `npx pepr build -r gchr.io/defenseunicorns -o dist/pepr-test-module/child/folder`", | ||
peprBuild, | ||
); | ||
|
||
describe("Journey: `npx pepr build -r gchr.io/defenseunicorns --rbac-mode scoped -o dist/pepr-test-module/child/folder`", peprBuild); | ||
// Set rbacMode in the Pepr Module Config and write it back to disk | ||
async function addScopedRbacMode() { | ||
const dir = execSync("ls -la", { cwd, stdio: "inherit" }).toString().trim(); | ||
console.log("DIR", dir); | ||
const packageJson = await fs.readFile(resolve(cwd, "package.json"), "utf8"); | ||
const packageJsonObj = JSON.parse(packageJson); | ||
packageJsonObj.pepr.rbacMode = "scoped"; | ||
await fs.writeFile(resolve(cwd, "package.json"), JSON.stringify(packageJsonObj, null, 2)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
rbac: | ||
- apiGroups: | ||
- 'pepr.dev' | ||
resources: | ||
- 'peprstores' | ||
verbs: | ||
- 'create' | ||
- 'get' | ||
- 'patch' | ||
- 'watch' | ||
- apiGroups: | ||
- 'apiextensions.k8s.io' | ||
resources: | ||
- 'customresourcedefinitions' | ||
verbs: | ||
- 'patch' | ||
- 'create' | ||
- apiGroups: | ||
- '' | ||
resources: | ||
- 'namespaces' | ||
verbs: | ||
- 'watch' | ||
- apiGroups: | ||
- '' | ||
resources: | ||
- 'configmaps' | ||
verbs: | ||
- 'watch' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// SPDX-FileCopyrightText: 2023-Present The Pepr Authors | ||
|
||
import { determineRbacMode } from "./build"; | ||
|
||
import { expect, describe, test } from "@jest/globals"; | ||
|
||
describe("determineRbacMode", () => { | ||
test("should allow CLI options to overwrite module config", () => { | ||
const opts = { rbacMode: "admin" }; | ||
const cfg = { pepr: { rbacMode: "scoped" } }; | ||
const result = determineRbacMode(opts, cfg); | ||
expect(result).toBe("admin"); | ||
}); | ||
|
||
test('should return "admin" when cfg.pepr.rbacMode is provided and not "scoped"', () => { | ||
const opts = {}; | ||
const cfg = { pepr: { rbacMode: "admin" } }; | ||
const result = determineRbacMode(opts, cfg); | ||
expect(result).toBe("admin"); | ||
}); | ||
|
||
test('should return "scoped" when cfg.pepr.rbacMode is "scoped"', () => { | ||
const opts = {}; | ||
const cfg = { pepr: { rbacMode: "scoped" } }; | ||
const result = determineRbacMode(opts, cfg); | ||
expect(result).toBe("scoped"); | ||
}); | ||
|
||
test("should default to admin when neither option is provided", () => { | ||
const opts = {}; | ||
const cfg = { pepr: {} }; | ||
const result = determineRbacMode(opts, cfg); | ||
expect(result).toBe("admin"); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// determineRbacMode determines the RBAC mode to use based on the cli and the module's config | ||
export function determineRbacMode(opts: { rbacMode?: string }, cfg: { pepr: { rbacMode?: string } }): string { | ||
// CLI overrides the module's config | ||
if (opts.rbacMode) { | ||
return opts.rbacMode; | ||
} | ||
|
||
// if rbacMode is defined and not scoped, return admin | ||
if (cfg.pepr.rbacMode && cfg.pepr.rbacMode !== "scoped") { | ||
return "admin"; | ||
} | ||
|
||
// if nothing is defined return admin, else return scoped | ||
return cfg.pepr.rbacMode || "admin"; | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the relationship between
rbacMode
andpepr-build-wasm.ts
..? I would have never thought to look for our RBAC mode tests in a-wasm
file. 🤔 Are they bound together in some way?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can't (apparently) comment on lines of code that weren't changed, but... just saw that line 15 says "dst folder" -- should probably say something like "/dist folder" instead (since that's what'll actually be there).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For some reason the rbac tests were in the -wasm file when I started working on the rbac mode stuff. I have no idea why they were put there.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
line 15 only makes a folder. This probably should be live in an
it()
block. I will move this below the where the module is being built.rbacMode is being set through the CLI in
pepr-build.ts
, we need a module to build so this is the other option.