-
Notifications
You must be signed in to change notification settings - Fork 150
feat: rekey only specific identity #295
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -13,7 +13,7 @@ function show_help () { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo '-h, --help show help' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| # shellcheck disable=SC2016 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo '-e, --edit FILE edits FILE using $EDITOR' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo '-r, --rekey re-encrypts all secrets with specified recipients' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo '-r, --rekey [PUBLIC_KEY] re-encrypts all secrets with specified recipients' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo '-d, --decrypt FILE decrypts FILE to STDOUT' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo '-i, --identity identity to use when decrypting' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| echo '-v, --verbose verbose output' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -46,6 +46,7 @@ function err() { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| test $# -eq 0 && (show_help && exit 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REKEY=0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REKEY_PUBLIC_KEY= | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Since the shebang is already bash it makes perfect sense to use an array here to be able to provide multiple keys IMHO.
Suggested change
nit (outside the scope of this PR tho): these are variables, not environment variables, they shouldn't be uppercase |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DECRYPT_ONLY=0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DEFAULT_DECRYPT=(--decrypt) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -77,6 +78,10 @@ while test $# -gt 0; do | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -r|--rekey) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shift | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if test $# -gt 0; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TODO: Fix e.g. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could just keep the Basically: -r|--rekey)
shift
REKEY=1
;;
# […]
-*)
show_help
exit 1
*)
if test 1 = "$REKEY"; then
REKEY_PUBLIC_KEY+=( "$1" )
shift
else
show_help
exit 1
fi
;; |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REKEY_PUBLIC_KEY="$1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| shift | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| REKEY=1 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ;; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| -d|--decrypt) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -189,7 +194,22 @@ function edit { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| function rekey { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FILES=$( (@nixInstantiate@ --json --eval -E "(let rules = import $RULES; in builtins.attrNames rules)" | @jqBin@ -r .[]) || exit 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if test ! -z "$REKEY_PUBLIC_KEY"; then | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FILTER_EXPRESSION="builtins.elem \"$REKEY_PUBLIC_KEY\" rules.\${file}.publicKeys"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FILTER_EXPRESSION="true"; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| fi | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| RULES_EXPRESSION=$(cat <<EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does using a here document make sense here? I tried fitting it all in the single line but that isn't pretty. |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| let | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| rules = import $RULES; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| filter = file: $FILTER_EXPRESSION; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| builtins.filter filter (builtins.attrNames rules) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| EOF | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| FILES=$( (@nixInstantiate@ --json --eval -E "$RULES_EXPRESSION" | @jqBin@ -r .[]) || exit 1) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+197
to
+212
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. With the other changes from my review this should use a loop over the keys.
Suggested change
Not sure if the extra parens around the instantiate are needed give that pipefail is set. nit (outside the scope of this PR): someone should clean up the indents in this file, choose: either two or four spaces, or ideally if you want people to be able to use their preferred width (and also aid accessibility for screen readers and such) use hard tabs instead, but choose one of those |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for FILE in $FILES | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| do | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
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.
Not sure if this makes sense here.
It makes parsing harder e.g.
--rekey -vis currently broken.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.
If you choose to take the other changes from this review:
However that extends the length beyond the current space available so the entire thing needs fresh spacing.