Skip to content
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

sql: support more functions from pgcrypto module #21001

Closed
10 of 22 tasks
robert-s-lee opened this issue Dec 21, 2017 · 22 comments · Fixed by #110107
Closed
10 of 22 tasks

sql: support more functions from pgcrypto module #21001

robert-s-lee opened this issue Dec 21, 2017 · 22 comments · Fixed by #110107
Assignees
Labels
A-sql-builtins SQL built-in functions and semantics thereof. A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-community Originated from the community O-support Would prevent or help troubleshoot a customer escalation - bugs, missing observability/tooling, docs T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)

Comments

@robert-s-lee
Copy link
Contributor

robert-s-lee commented Dec 21, 2017

FEATURE REQUEST

https://vernemq.com/docs/configuration/db-auth.html

is there an equivalent crypt(x.password, x.salt) available?

#19368 has reference to pgcrypt. crypt is a part of the pgcrypto module.


Update on 2023-05-09: Here is a list showing the currently supported functions. We are working on adding support for the remaining ones.

  • digest
  • hmac
  • crypt
  • gen_salt
  • encrypt
  • decrypt
  • encrypt_iv
  • decrypt_iv
  • gen_random_bytes
  • gen_random_uuid

pgcrypto also has PGP functions which we may or may not add, since the security community is generally moving away from openpgp. These are also tracked in #73869.

  • pgp_sym_encrypt
  • pgp_pub_encrypt_bytea
  • pgp_sym_decrypt
  • pgp_sym_decrypt_bytea
  • pgp_pub_encrypt
  • pgp_pub_encrypt_bytea
  • pgp_pub_decrypt
  • pgp_pub_decrypt_bytea
  • pgp_key_id
  • armor
  • dearmor
  • pgp_armor_headers

Jira issue: CRDB-5904

Epic CRDB-10655

@robert-s-lee robert-s-lee added the C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) label Dec 21, 2017
@awoods187
Copy link
Contributor

Who requested this?

@mberhault
Copy link
Contributor

mberhault commented Feb 15, 2018

It seems Bxxx did in the linked issue. It's a reasonable ask to make password storage easier (passwords from the end-user application, not ours). We'd have to gauge demand and figure out exactly which algorithms to support (only one out of the four supported by pgcrypto is acceptable for security purposes), as well as what else to support from pgcrypto.

@mberhault
Copy link
Contributor

See also: #22878 for pgp functions from pgcrypto.

@dianasaur323
Copy link
Contributor

Ok, apparently I'm supposed to take this on, so I'll do some research on this.

@knz knz added the O-support Would prevent or help troubleshoot a customer escalation - bugs, missing observability/tooling, docs label Apr 27, 2018
@knz knz added the A-sql-pgcompat Semantic compatibility with PostgreSQL label May 14, 2018
@knz knz changed the title support crypt function from pgcrypto module sql: support crypt function from pgcrypto module May 14, 2018
@knz knz added the A-sql-builtins SQL built-in functions and semantics thereof. label May 14, 2018
@knz knz added the O-community Originated from the community label May 14, 2018
@cmnstmntmn
Copy link

cmnstmntmn commented Jul 8, 2018

@robert-s-lee did you manage to auth?

i set the password to null, but i'm getting this warning

2018-07-08 16:51:40.103 [warning] <0.483.0>@vmq_mqtt_fsm:check_user:555 can't authenticate client {[],<<"ctin">>} due to chain_exhausted

@knz
Copy link
Contributor

knz commented Jul 12, 2018

@cmnstmntmn I have investigated the issue by looking at the source code of VerneMQ, which thankfully is open source.

The issue can be addressed either by

  • providing the built-in functions crypt() and gen_salt() as initially identified,

  • or by providing an additional vmq_diversity plugin to handle authentication using CockroachDB that you would use instead of auth_postgres

I am not yet certain which one is the easiest for us but I'll investigate.

@cmnstmntmn
Copy link

@knz thank you for your time and interest!

@cmnstmntmn
Copy link

cmnstmntmn commented Jul 12, 2018

a specific VerneMQ auth plugin would be great;
i do belive there's a win-win situation for both crdb and verne.

@knz
Copy link
Contributor

knz commented Jul 12, 2018

@awoods187 can you pick this up for roadmapping?

@awoods187
Copy link
Contributor

As discussed, we will handle this through Ops & Tools planning

@MrOffline77
Copy link

What is the state of pgcrypto with cockroachdb ?

@knz
Copy link
Contributor

knz commented Dec 14, 2018

@MrOffline77 thank you for your interest in CockroachDB!

we are approaching this by looking at individual use cases and applications and providing answers on a per-case basis. It is unlikely that we will aim supporting the entirety of pgcrypto any time soon, because it has a very large scope and also includes functionality that is rarely used (if at all) by modern applications.

The proper next step for you here is to tell us more about your specific needs to see how we can help you.

@MrOffline77
Copy link

MrOffline77 commented Dec 14, 2018

@knz Thank you !
As far as i know pgcrypto is used for encryption of tables / columns inside the database for customer sensitive data like credit card information and so on. Is this possible with cockroachdb "core" at the moment, or is this a enterprise license thing ?

@knz
Copy link
Contributor

knz commented Dec 14, 2018

@MrOffline77 we provide a separate feature which is systematic on-disk encryption for all the data (not just table data: also metadata and user authentication details). This is an enterprise feature.

@MrOffline77
Copy link

Ok. Did I get you right that there is no alternative for a mysql query type like this:

INSERT INTO users (username, password) VALUES ('root', AES_ENCRYPT('somepassword', 'key12346123'));
SELECT AES_DECRYPT(password, 'key12346123') FROM users WHERE username = 'root';

I guess this is an interesting thing for other people too.

@knz
Copy link
Contributor

knz commented Dec 14, 2018

This is a similar request as the one from a previous commenter. In this case we advise to run the AES encrypt and decrypt functions using a client-side library.

We understand this need well and will consider this for a future extension of CockroachDB.

Note however that the performance profile of such a facility is not ideal, and if performance is important to you you will want to run the encryption/decryption client-side in a streaming fashion, or use a storage encryption facility on the database side (which can also operate in streaming fashion).

@tim-o
Copy link
Contributor

tim-o commented Mar 21, 2019

Zendesk ticket #3212 has been linked to this issue.

@polikeiji
Copy link

Hello!
What's the status of the pgcrypto module support? The issue was closed as completed, but has it been already supported by CockroachDB? I found #73869, and it looks not be finished, so I'm a little bit confused.

We're currently looking into CockroachDB and YugaByte DB as the distributed SQL for our internal projects. Some projects might be required column-based encryption at rest for specific data to follow our data privacy policy. Of course, we can encrypt them on the application side with some libraries, but I think the encryption approach using PGP_SYM_ENCRYPT, PGP_SYM_DECRYPT, PGP_PUB_ENCRYPT, and PGP_PUB_DECRYPT such as ones in the YugaByte DB document might be one of the attractive options for the engineers.

@ajwerner
Copy link
Contributor

I don't think we meant to close this.

@ajwerner ajwerner reopened this Oct 21, 2022
@dvasdekis
Copy link

This is also a hurdle for supporting Hasura's Metadata database, meaning that Hasura needs a separate Postgres database to work with Cockroach (given cockroach's lack of support for pg_crypto). Discussion here: https://discord.com/channels/407792526867693568/428469959530643466/1035501924541267968

@jordanlewis
Copy link
Member

Hi @dvasdekis, that Discord link isn't accessible to me.

Can you please provide a list of the missing functionality that Hasura needs from pg_crypto?

@exalate-issue-sync exalate-issue-sync bot added the T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions) label May 9, 2023
@andyyang890 andyyang890 self-assigned this May 15, 2023
craig bot pushed a commit that referenced this issue May 17, 2023
103211: upgradeinterlockccl: shard interlock test cases into separate tests r=rickystewart a=healthy-pod

`TestTenantUpgradeInterlock` is composed of 14 test cases and they take around 10 minutes to run. This is a bottleneck on both current CI and future remote test execution CI.

This code change shards `TestTenantUpgradeInterlock` into 14 different tests. The code generation logic lives under `pkg/ccl/kvccl/kvtenantccl/upgradeinterlockccl/testgen`.

Release note: None
Epic: CRDB-17165

Closes DEVINF-751

103446: deps: upgrade golang.org/x/{crypto,mod,net,sys,text,tools,term} r=rafiss,knz a=andyyang890

This patch updates the following core dependencies as follows:
* golang.org/x/crypto from v0.6.0 to v0.7.0
* golang.org/x/mod from v0.7.0 to v0.8.0
* golang.org/x/net from v0.7.0 to v0.8.0
* golang.org/x/sys from v0.5.0 to v0.6.0
* golang.org/x/text from v0.7.0 to v0.8.0
* golang.org/x/tools from v0.1.12 to v0.6.0
* golang.org/x/term from v0.5.0 to v0.6.0

Also update `rules_go` to a compatible version (0.38).

Informs #21001

Release note: None

Co-authored-by: healthy-pod <[email protected]>
Co-authored-by: Andy Yang <[email protected]>
craig bot pushed a commit that referenced this issue Jun 5, 2023
104058: pgcrypto: add helper functions for PKCS padding r=rafiss a=andyyang890

This patch adds helper functions for PKCS padding/unpadding, which is
needed for pgcrypto's raw encryption functions.

Informs #21001 

Release note: None

104111: kvserver: add cross-region snapshot byte metrics to StoreMetrics r=kvoli,andrewbaptist a=wenyihu6

**kvserver: refactor getSnapshotBytesMetrics**

This commit refactors `getSnapshotBytesMetrics` in `replica_learner_test`
to return a `map[string]snapshotBytesMetrics` instead of
`map[SnapShotRequest_Priority]snapshotBytesMetrics`. This allows us to include
and compare different types of snapshot metrics, removing the constraint of
being limited to `SnapShotRequest_Priority`. This commit does not change any
existing functionality, and the main purpose is to make future commits cleaner.

Part of: #104124
Release note: none

---
 
**kvserver: add cross-region snapshot byte metrics to StoreMetrics**

Previously, there were no metrics to observe cross-region snapshot traffic
between stores within a cluster.

To improve this issue, this commit adds two new store metrics -
`range.snapshots.cross-region.sent-bytes` and
`range.snapshots.cross-region.rcvd-bytes`. These metrics track the aggregate of
snapshot bytes sent from and received at a store across different regions.

Resolves: #104124

Release note (ops change): Two new store metrics -
`range.snapshots.cross-region.sent-bytes` and
`range.snapshots.cross-region.rcvd-bytes` - are now added to track the aggregate
of snapshot bytes sent from and received at a store across different regions.
Note that these metrics require nodes’ localities to include a “region” tier
key. If a node lacks this key but is involved in cross-region batch activities,
an error message will be logged.



Co-authored-by: Andy Yang <[email protected]>
Co-authored-by: Wenyi <[email protected]>
craig bot pushed a commit that referenced this issue Jun 26, 2023
105301: pgcryptocipher: add helper function for parsing cipher method r=rafiss a=andyyang890

**pgcryptocipher: create new package for pgcrypto cipher functions**

This patch creates a new package that will contain the implementation
of pgcrypto cipher functions, along with related helpers.

Release note: None

----

**pgcryptocipher: add helper function for parsing cipher method**

This patch adds a helper function for parsing the cipher method string
passed to pgcrypto cipher functions.

Release note: None

----

Informs #21001

105559: testccl/sqlccl: unskip TestExplainRedactDDL r=mgartner a=michae2

`TestExplainRedactDDL` is a randomized SQL test which runs variants of `EXPLAIN (REDACT)` on random SQL statements and checks that an injected poison string is always redacted in the output. It is very similar to another randomized test, `TestExplainRedact`, but also includes DDL in the random statements.

During development of v23.1 this test was skipped because the random DDL statements were running into other bugs unrelated to redaction. Now that things are more stable, let's unskip this test.

Fixes: #99005

Epic: None

Release note: None

Co-authored-by: Andy Yang <[email protected]>
Co-authored-by: Michael Erickson <[email protected]>
craig bot pushed a commit that referenced this issue Sep 5, 2023
105654: builtins: implement encrypt and decrypt pgcrypto functions r=rafiss a=andyyang890

This patch implements `encrypt`, `encrypt_iv`, `decrypt`,
and `decrypt_iv` from pgcrypto. These functions require an
enterprise license on a CCL distribution.

Informs #21001

Release note (enterprise change): The pgcrypto functions `encrypt`,
`encrypt_iv`, `decrypt`, and `decrypt_iv` are now implemented.
These functions require an enterprise license on a CCL distribution.

109782: server,sql: add status server endpoint to request profiler details r=dt a=adityamaru

This change introduces a new status server endpoint to
request job profiler details. This endpoint will redirect
the request to the current coordinator node of the job in
question. This will be useful because in a followup we will
load the resumer from the coordinator node's job registry
and trigger its specific job profiler detail collection logic.

This is the first step of a few to move to a "fetch model" rather
than have each resumer dump their execution details at some
arbitrary cadence.

The core logic involved in collecting profiler details has not changed,
it has been moved in its entirety from pkg/sql to pkg/server. The
`crdb_internal.request_job_execution_details` builtin now resolves
the job's coordinator ID and calls the new status server endpoint.

Informs: #109671
Release note: None

Co-authored-by: Andy Yang <[email protected]>
Co-authored-by: adityamaru <[email protected]>
@craig craig bot closed this as completed in cd2e060 Sep 7, 2023
craig bot pushed a commit that referenced this issue Sep 13, 2023
110380: pgcryptocipherccl: add FuzzEncryptDecryptAESNoPadding test r=chrisseto a=andyyang890

This patch adds another fuzz test for testing that a round trip of
`Encrypt` and `Decrypt` returns the original input when used with
the no padding option.

Informs #21001

Release note: None

Co-authored-by: Andy Yang <[email protected]>
craig bot pushed a commit that referenced this issue Sep 15, 2023
110408: pgcryptocipherccl: don't panic when passed invalid padding size r=rafiss a=andyyang890

This patch modifies `zeroPadOrTruncate` to return an error instead of panicking
when it is passed an invalid (i.e. negative) padding size. Note that this is
currently only possible as the result of programmer error.

We also add a unit test to validate the function's expected behavior.

Informs #21001 

Release note: None

110580: tree: fix formatting of SHOW BACKUP WITH OPTIONS r=rafiss a=rafiss

This avoids an ambiguity when formatting the statement.

fixes #110411
Release note: None

Co-authored-by: Andy Yang <[email protected]>
Co-authored-by: Rafi Shamim <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-sql-builtins SQL built-in functions and semantics thereof. A-sql-pgcompat Semantic compatibility with PostgreSQL C-enhancement Solution expected to add code/behavior + preserve backward-compat (pg compat issues are exception) O-community Originated from the community O-support Would prevent or help troubleshoot a customer escalation - bugs, missing observability/tooling, docs T-sql-foundations SQL Foundations Team (formerly SQL Schema + SQL Sessions)
Projects
None yet
Development

Successfully merging a pull request may close this issue.