Skip to content

Commit 60d52f5

Browse files
committed
enforce 32-byte key length
1 parent 8b1f835 commit 60d52f5

File tree

5 files changed

+9
-4
lines changed

5 files changed

+9
-4
lines changed

cli/testdata/coder_server_--help.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ These options are only available in the Enterprise Edition.
453453

454454
--external-token-encryption-key string, $CODER_EXTERNAL_TOKEN_ENCRYPTION_KEY
455455
Encrypt OIDC and Git authentication tokens with AES-256-GCM in the
456-
database. The value must be a base64-encoded key.
456+
database. The value must be a base64-encoded key exactly 32 bytes in
457+
length.
457458

458459
--scim-auth-header string, $CODER_SCIM_AUTH_HEADER
459460
Enables SCIM and sets the authentication header for the built-in SCIM

coderd/database/dbcrypt/cipher.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ func IsDecryptFailedError(err error) bool {
3434

3535
// CipherAES256 returns a new AES-256 cipher.
3636
func CipherAES256(key []byte) (Cipher, error) {
37+
if len(key) != 32 {
38+
return nil, xerrors.Errorf("key must be 32 bytes")
39+
}
3740
block, err := aes.NewCipher(key)
3841
if err != nil {
3942
return nil, err

coderd/database/dbcrypt/cipher_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,6 @@ func TestCipherAES256(t *testing.T) {
4040
t.Parallel()
4141

4242
_, err := dbcrypt.CipherAES256(bytes.Repeat([]byte{'a'}, 31))
43-
require.ErrorContains(t, err, "invalid key size")
43+
require.ErrorContains(t, err, "key must be 32 bytes")
4444
})
4545
}

codersdk/deployment.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1580,7 +1580,7 @@ when required by your organization's security policy.`,
15801580
},
15811581
{
15821582
Name: "External Token Encryption Key",
1583-
Description: "Encrypt OIDC and Git authentication tokens with AES-256-GCM in the database. The value must be a base64-encoded key.",
1583+
Description: "Encrypt OIDC and Git authentication tokens with AES-256-GCM in the database. The value must be a base64-encoded key exactly 32 bytes in length.",
15841584
Flag: "external-token-encryption-key",
15851585
Env: "CODER_EXTERNAL_TOKEN_ENCRYPTION_KEY",
15861586
Annotations: clibase.Annotations{}.Mark(annotationEnterpriseKey, "true").Mark(annotationSecretKey, "true"),

enterprise/cli/testdata/coder_server_--help.golden

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -453,7 +453,8 @@ These options are only available in the Enterprise Edition.
453453

454454
--external-token-encryption-key string, $CODER_EXTERNAL_TOKEN_ENCRYPTION_KEY
455455
Encrypt OIDC and Git authentication tokens with AES-256-GCM in the
456-
database. The value must be a base64-encoded key.
456+
database. The value must be a base64-encoded key exactly 32 bytes in
457+
length.
457458

458459
--scim-auth-header string, $CODER_SCIM_AUTH_HEADER
459460
Enables SCIM and sets the authentication header for the built-in SCIM

0 commit comments

Comments
 (0)