-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* zymbit first draft. * aws kms getkey example. * fix bug in aws key generation. * google kms example. * add zymkey getkey script. * add a sleep to suppress anoying connect error on faster computer.
- Loading branch information
Showing
12 changed files
with
215 additions
and
64 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,4 +31,6 @@ | |
# Debug files | ||
*.dSYM/ | ||
*.su | ||
*~ | ||
*~ | ||
|
||
pgsodium_encrypted_root.key |
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,28 @@ | ||
ARG version | ||
FROM postgres:${version} | ||
ARG version | ||
|
||
# RUN apt-get update && apt-get install -y make git postgresql-server-dev-${version} curl build-essential gdb | ||
RUN apt-get update && apt-get install -y make git curl build-essential gdb libreadline-dev bison flex zlib1g-dev tmux zile zip gawk | ||
|
||
RUN git clone --branch REL_${version}_STABLE https://github.com/postgres/postgres.git --depth=1 && \ | ||
cd postgres && ./configure \ | ||
--prefix=/usr/ \ | ||
--enable-debug \ | ||
--enable-depend --enable-cassert --enable-profiling \ | ||
CFLAGS="-ggdb -Og -g3 -fno-omit-frame-pointer" \ | ||
# CFLAGS="-O3" \ | ||
&& make -j 4 && make install | ||
|
||
RUN curl -s -L https://github.com/theory/pgtap/archive/v1.1.0.tar.gz | tar zxvf - && cd pgtap-1.1.0 && make && make install | ||
RUN curl -s -L https://download.libsodium.org/libsodium/releases/libsodium-1.0.18.tar.gz | tar zxvf - && cd libsodium-1.0.18 && ./configure && make check && make install | ||
RUN mkdir "/pgsodium" | ||
WORKDIR "/pgsodium" | ||
COPY . . | ||
RUN make && make install | ||
RUN ldconfig | ||
RUN curl -O https://raw.githubusercontent.com/tvondra/gdbpg/master/gdbpg.py | ||
RUN cd `pg_config --sharedir`/extension/ | ||
RUN cp getkey_scripts/pgsodium_getkey.sample `pg_config --sharedir`/extension/pgsodium_getkey | ||
RUN sed -i 's/exit//g' `pg_config --sharedir`/extension/pgsodium_getkey | ||
RUN chmod +x `pg_config --sharedir`/extension/pgsodium_getkey |
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
File renamed without changes.
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,13 @@ | ||
#!/bin/bash | ||
|
||
HERE=`pwd` | ||
KEY_ID=${KEY_ID:-alias/pgsodium} | ||
ENCRYPTED_ROOT_KEY_FILE=${ENCRYPTED_ROOT_KEY_FILE:-$HERE/pgsodium_encrypted_root.key} | ||
|
||
if [[ -f "$ENCRYPTED_ROOT_KEY_FILE" ]]; then | ||
aws kms decrypt --ciphertext-blob fileb://$ENCRYPTED_ROOT_KEY_FILE --query Plaintext --output text | base64 --decode | hex | ||
else | ||
aws kms generate-data-key --number-of-bytes=32 --key-id=$KEY_ID --query CiphertextBlob --output text | base64 --decode > $ENCRYPTED_ROOT_KEY_FILE | ||
aws kms decrypt --ciphertext-blob fileb://$ENCRYPTED_ROOT_KEY_FILE --query Plaintext --output text | base64 --decode | hex | ||
fi | ||
|
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,40 @@ | ||
#!/bin/bash | ||
|
||
HERE=`pwd` | ||
KEY=${KEY:-pgsodium} | ||
KEYRING=${KEYRING:-pgsodium} | ||
LOCATION=${LOCATION:-global} | ||
ROOT_KEY_FILE=${ROOT_KEY_FILE:-$HERE/pgsodium_encrypted_root.key} | ||
|
||
if [[ -f "$ROOT_KEY_FILE" ]]; then | ||
gcloud kms decrypt \ | ||
--key $KEY \ | ||
--keyring $KEYRING \ | ||
--location $LOCATION \ | ||
--plaintext-file - \ | ||
--ciphertext-file $ROOT_KEY_FILE | ||
else | ||
>&2 cat <<EOF | ||
No root key file found at $ROOT_KEY_FILE for pgsodium to load. | ||
See | ||
https://cloud.google.com/kms/docs/creating-keys#kms-create-key-ring-cli | ||
to create a keyring and key. Then encrypt a secret 32 byte payload | ||
with that key and save it to $ROOT_KEY_FILE. For example, create a | ||
new keyring and key: | ||
gcloud kms keyrings create pgsodium --location global | ||
gcloud kms keys create pgsodium --keyring pgsodium --location global --purpose "encryption" | ||
Then encrypt a strong random key generated with pwgen into $ROOT_KEY_FILE: | ||
pwgen 64 -s -1 -A -r ghijklmnopqrstuvwxyz | gcloud kms encrypt \\ | ||
--key pgsodium \\ | ||
--keyring pgsodium \\ | ||
--location global \\ | ||
--plaintext-file - --ciphertext-file $ROOT_KEY_FILE | ||
Now restart postgres to initialize pgsodium with the new key. | ||
EOF | ||
exit 1 | ||
fi |
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,32 @@ | ||
#!/bin/bash | ||
|
||
HERE=`pwd` | ||
KEY=${KEY:-pgsodium} | ||
ROOT_KEY_FILE=${ROOT_KEY_FILE:-$HERE/pgsodium_encrypted_root.key} | ||
|
||
if [[ -f "$ROOT_KEY_FILE" ]]; then | ||
python3 <<EOF | ||
from zymkey import Zymkey | ||
z = Zymkey() | ||
with open('$ROOT_KEY_FILE', 'rb') as f: | ||
z.unlock(f.read()).hex() | ||
EOF | ||
|
||
else | ||
>&2 cat <<EEOF | ||
No root key file found at $ROOT_KEY_FILE for pgsodium to load. | ||
Using the zymkey API, encrypt (lock) a secret 32 byte payload and save | ||
it to $ROOT_KEY_FILE. For example: | ||
pwgen 64 -s -1 -A -r ghijklmnopqrstuvwxyz | python3 <<EOF | ||
import zymkey, sys | ||
z = zymkey.Zymkey() | ||
with open('$ROOT_KEY_FILE', 'wb') as f: | ||
f.write(z.lock(bytes.fromhex(sys.stdin.read()))) | ||
EOF | ||
Now restart postgres to initialize pgsodium with the new key. | ||
EEOF | ||
exit 1 | ||
fi |
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
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