- Notifications
You must be signed in to change notification settings - Fork914
fix(coderd): ensure that clearing invalid oauth refresh tokens works with dbcrypt#15721
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Uh oh!
There was an error while loading.Please reload this page.
Changes fromall commits
77954e1
e6cdd1f
e2ca180
18837ba
File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading.Please reload this page.
Jump to
Uh oh!
There was an error while loading.Please reload this page.
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Some generated files are not rendered by default. Learn more abouthow customized files appear on GitHub.
Uh oh!
There was an error while loading.Please reload this page.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -43,13 +43,16 @@ UPDATE external_auth_links SET | ||
oauth_extra = $9 | ||
WHERE provider_id = $1 AND user_id = $2 RETURNING *; | ||
-- name: UpdateExternalAuthLinkRefreshToken :exec | ||
UPDATE | ||
external_auth_links | ||
SET | ||
oauth_refresh_token =@oauth_refresh_token, | ||
updated_at = @updated_at | ||
WHERE | ||
provider_id = @provider_id | ||
AND | ||
user_id = @user_id | ||
AND | ||
-- Required for sqlc to generate a parameter for the oauth_refresh_token_key_id | ||
@oauth_refresh_token_key_id :: text = @oauth_refresh_token_key_id :: text; | ||
Comment on lines +57 to +58 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. self-review: this is yuck. We don't actually need this parameter in the query but we need in the params for dbcrypt. This is the 'best' way I could find to set it. 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 feel pretty numb now to these kinda sqlc hacks now it doesn't phase me 🚶 |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -3,6 +3,8 @@ package dbcrypt | ||
import ( | ||
"bytes" | ||
"encoding/base64" | ||
"os" | ||
"strings" | ||
"testing" | ||
"github.com/stretchr/testify/require" | ||
@@ -89,3 +91,35 @@ func TestCiphersBackwardCompatibility(t *testing.T) { | ||
require.NoError(t, err, "decryption should succeed") | ||
require.Equal(t, msg, string(decrypted), "decrypted message should match original message") | ||
} | ||
// If you're looking here, you're probably in trouble. | ||
// Here's what you need to do: | ||
// 1. Get the current CODER_EXTERNAL_TOKEN_ENCRYPTION_KEYS environment variable. | ||
// 2. Run the following command: | ||
// ENCRYPT_ME="<value to encrypt>" CODER_EXTERNAL_TOKEN_ENCRYPTION_KEYS="<secret keys here>" go test -v -count=1 ./enterprise/dbcrypt -test.run='^TestHelpMeEncryptSomeValue$' | ||
// 3. Copy the value from the test output and do what you need with it. | ||
func TestHelpMeEncryptSomeValue(t *testing.T) { | ||
t.Parallel() | ||
t.Skip("this only exists if you need to encrypt a value with dbcrypt, it does not actually test anything") | ||
valueToEncrypt := os.Getenv("ENCRYPT_ME") | ||
t.Logf("valueToEncrypt: %q", valueToEncrypt) | ||
keys := os.Getenv("CODER_EXTERNAL_TOKEN_ENCRYPTION_KEYS") | ||
require.NotEmpty(t, keys, "Set the CODER_EXTERNAL_TOKEN_ENCRYPTION_KEYS environment variable to use this") | ||
base64Keys := strings.Split(keys, ",") | ||
activeKey := base64Keys[0] | ||
decodedKey, err := base64.StdEncoding.DecodeString(activeKey) | ||
require.NoError(t, err, "the active key should be valid base64") | ||
cipher, err := cipherAES256(decodedKey) | ||
require.NoError(t, err) | ||
t.Logf("cipher digest: %+v", cipher.HexDigest()) | ||
encryptedEmptyString, err := cipher.Encrypt([]byte(valueToEncrypt)) | ||
require.NoError(t, err) | ||
t.Logf("encrypted and base64-encoded: %q", base64.StdEncoding.EncodeToString(encryptedEmptyString)) | ||
} | ||
Comment on lines +95 to +125 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. self-review: we could potentially make this a proper CLI function for use in a pinch. 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. Seems pretty reasonable to leave as a test for now |
Uh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.