-
Notifications
You must be signed in to change notification settings - Fork 2
feat(secrets): consume SOPS SDK payload #167
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
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e396763
feat(secrets): consume SOPS SDK payload
altaywtf da5bf03
fix(secrets): make mode check portable
altaywtf bd7f098
fix(secrets): harden ciphertext validation
altaywtf 4c77d98
fix(secrets): harden payload rendering
altaywtf d632bad
fix(secrets): reject unsafe control values
altaywtf 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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,69 @@ | ||
| import { readFileSync, writeFileSync } from "node:fs"; | ||
|
|
||
| const [payloadPath, outputPath] = process.argv.slice(2); | ||
|
|
||
| if (!payloadPath || !outputPath) { | ||
| throw new Error("expected payload and output paths"); | ||
| } | ||
|
|
||
| const expectedKeys = [ | ||
| "PUTIO_CLIENT_ID", | ||
| "PUTIO_CLIENT_ID_FIRST_PARTY", | ||
| "PUTIO_CLIENT_ID_THIRD_PARTY", | ||
| "PUTIO_CLIENT_SECRET_FIRST_PARTY", | ||
| "PUTIO_TEST_PASSWORD", | ||
| "PUTIO_TEST_TOTP_REFERENCE", | ||
| "PUTIO_TEST_USERNAME", | ||
| "PUTIO_TOKEN_FIRST_PARTY", | ||
| "PUTIO_TOKEN_THIRD_PARTY", | ||
| ]; | ||
|
|
||
| const payload = JSON.parse(readFileSync(payloadPath, "utf8")); | ||
|
|
||
| if (!payload || typeof payload !== "object" || Array.isArray(payload)) { | ||
| throw new Error("decrypted payload must be a JSON object"); | ||
| } | ||
|
|
||
| const actualKeys = Object.keys(payload).sort(); | ||
| if (JSON.stringify(actualKeys) !== JSON.stringify(expectedKeys)) { | ||
| throw new Error("decrypted payload key inventory does not match the SDK contract"); | ||
| } | ||
|
|
||
| for (const value of Object.values(payload)) { | ||
| if (typeof value !== "string" || value.length === 0) { | ||
| throw new Error("decrypted payload contains an empty or non-string value"); | ||
| } | ||
|
|
||
| if ( | ||
|
cubic-dev-ai[bot] marked this conversation as resolved.
|
||
| (value.startsWith('"') && value.endsWith('"')) || | ||
| (value.startsWith("'") && value.endsWith("'")) | ||
| ) { | ||
| throw new Error("decrypted payload contains a quote-wrapped value"); | ||
| } | ||
|
|
||
| if (value.includes("\0") || value.includes("\n") || value.includes("\r")) { | ||
| throw new Error("decrypted payload contains an unsafe control character"); | ||
| } | ||
| } | ||
|
|
||
| for (const key of [ | ||
| "PUTIO_CLIENT_ID", | ||
| "PUTIO_CLIENT_ID_FIRST_PARTY", | ||
| "PUTIO_CLIENT_ID_THIRD_PARTY", | ||
| ]) { | ||
| if (!/^[0-9]+$/.test(payload[key])) { | ||
| throw new Error("decrypted payload contains an invalid numeric identifier"); | ||
| } | ||
| } | ||
|
|
||
| const delimiters = ['"', "'", "`"]; | ||
| const render = (value) => { | ||
| const delimiter = delimiters.find((candidate) => !value.includes(candidate)); | ||
| if (!delimiter) { | ||
| throw new Error("decrypted payload contains a value that cannot be rendered safely"); | ||
| } | ||
| return `${delimiter}${value}${delimiter}`; | ||
| }; | ||
|
|
||
| const dotenv = actualKeys.map((key) => `${key}=${render(payload[key])}`).join("\n"); | ||
| writeFileSync(outputPath, `${dotenv}\n`, { mode: 0o600 }); | ||
This file contains hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.