Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8pZO-0000NH-CE for pgsql-general@arkaria.postgresql.org; Tue, 26 Mar 2019 17:09:02 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h8pZN-00032p-4S for pgsql-general@arkaria.postgresql.org; Tue, 26 Mar 2019 17:09:01 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8pZL-0002xQ-R9 for pgsql-general@lists.postgresql.org; Tue, 26 Mar 2019 17:09:00 +0000 Received: from out3-smtp.messagingengine.com ([66.111.4.27]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h8pZI-0004JD-5x for pgsql-general@postgresql.org; Tue, 26 Mar 2019 17:08:59 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id DB337221E9; Tue, 26 Mar 2019 13:08:54 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Tue, 26 Mar 2019 13:08:54 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= subject:to:references:from:message-id:date:mime-version :in-reply-to:content-type:content-transfer-encoding; s=fm2; bh=7 PPEXJaJGBe9JAkscJvkprtlHmLOweOw4yWLZ0wrUro=; b=saJg9UYnDIJ+ru7V1 KT4U1P3/HLcNapmKDnIjw43lu6mWd8udti2dVPZROtXlM4EngPnEuXLkvG6KUd1W dFpHlDAGZXFjDqp6fIxhprXL8Nsx3Z1sIAuELi0YEL+tS5VatHY8dnpV+Rz+B2Kv Q5No7a+KksKQwEC6glcK8PnFA6B5vdSSzEsAj8h+igFJ23nx2C2tnYYEfMy87QXH 1jdJyOyXQW3et0i9uqukZ1NH8Er+04CumTxyq6GH9yp+EOcfPKB6RdNDXnRzR+XV t+yeSXkGI7Rvk6IAS90vx8cjP2jUCPRJB8fxEwMqcTdyLAdwlf/j0axPT6v4Z/C2 5jwaA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=7PPEXJaJGBe9JAkscJvkprtlHmLOweOw4yWLZ0wrU ro=; b=K/kV63UzKGwm6ZvroJ+4pGcWKD7bNN4aJnGIdk8TeA2t7IrA98s1PV88U RXSmPE3/yjCUQOglMc3932MmzCGx2wRDogv55dLJww/+DmDECaWrHI6lkANsQOfm IMMPRHsZcACMiZWdQvz4Pr/Ta2OVz5XXFhYqW6JWfYFX8JgSa6EDkN9aQwC99p6c X4u0EonAA4TFiwG5vO7qMsWV1KtOLeu9Tpe33qpb/KUITPXafgEeAArHEkvf+jWM lwo3D9jObff5wGy06bn4cgxctgaYEFyBLRxZ1qO8ZC3EWZErulmwiYu5fcWO3ESW ZpG3OvkBRuKEEpyy18MG+eto1c1VQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedutddrkedtgdeltdcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefuvfhfhffkffgfgggjtgfgsehtkeertddtfeelnecuhfhrohhmpeetughrihgr nhcumfhlrghvvghruceorggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdrtghomh eqnecuffhomhgrihhnpehpohhsthhgrhgvshhqlhdrohhrghenucfkphephedtrdduleej rdektddrvdenucfrrghrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrh esrghklhgrvhgvrhdrtghomhenucevlhhushhtvghrufhiiigvpedt X-ME-Proxy: Received: from ranger.suse (50-197-80-2-static.hfc.comcastbusiness.net [50.197.80.2]) by mail.messagingengine.com (Postfix) with ESMTPA id 8FF42E49FB; Tue, 26 Mar 2019 13:08:53 -0400 (EDT) Subject: Re: Key encryption and relational integrity To: Moreno Andreo , PostgreSQL mailing lists References: <094bf875-5b49-8d3c-1fa3-97c07246b890@evolu-s.it> <082fdd45-a12b-161b-8386-70ee8528361e@aklaver.com> <514fb642-bba4-7a14-b412-d953f1b8b7e7@evolu-s.it> From: Adrian Klaver Message-ID: <3f88c83d-23b0-537f-8325-5b1d19ca77f7@aklaver.com> Date: Tue, 26 Mar 2019 10:08:52 -0700 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1 MIME-Version: 1.0 In-Reply-To: <514fb642-bba4-7a14-b412-d953f1b8b7e7@evolu-s.it> Content-Type: text/plain; charset=iso-8859-15; format=flowed Content-Language: en-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 3/26/19 9:08 AM, Moreno Andreo wrote: > Il 26/03/2019 15:24, Adrian Klaver ha scritto: >> On 3/26/19 7:19 AM, Moreno Andreo wrote: >>> Hello folks :-) >>> >>> Is there any workaround to implement key encryption without breaking >>> relational integrity? >> >> This is going to need more information. > OK, I'll try to be as clearer as I can >> For starters 'key' has separate meanings for encryption and RI. I >> could make some guesses about what you want, but to avoid false >> assumptions a simple example would be helpful. > In a master-detail relation, I need to encrypt one of master table PK or > detail table FK, in order to achieve pseudonimization, required by GDPR > in Europe when managing particular data > Imagine I have > Table users > id   surname    last name > 1    John            Doe > 2    Jane            Doe > 3    Foo             Bar > > Table medications > id    user_id    med > 1     1                Medication > 2     1                Ear check > ... > ... > medications.user_id is FK on users.id > we should achieve > > Table medications > id    user_id        med > 1    sgkighs98    Medication > 2    sghighs98    Ear check > > or the opposite (users.id encryption and medications.user_id kept plain) > > At a first glance, it IS breaking relational integrity, so is there a > way to manage this encryption internally so RI is kept safe? Not that I know of. RI is based on maintaining a link between parent and child. So by definition you would be able to get to the parent record via the child. A quick search on pseudonymisation found a boatload of interpretations of how to implement this: "Pseudonymisation' means the processing of personal data in such a manner that the personal data can no longer be attributed to a specific data subject without the use of additional information, provided that such additional information is kept separately and is subject to technical and organisational measures to ensure that the personal data are not attributed to an identified or identifiable natural person." To me it would seem something like: Table medications id user_id med 1 sgkighs98 Medication 2 sghighs98 Ear check Table users id surname last name sgkighs98 John Doe jkopkl1 Jane Doe uepoti21 Foo Bar Where there is no direct link between the two. Instead permissions would prevent linking from medications to users even via a SELECT. One could also use pgcrypto: https://www.postgresql.org/docs/10/pgcrypto.html on the users table to further hide the personal info. *NOTE* I am not a lawyer so any advice on my part as to meeting legal requirements are just me thinking out loud. I would suggest, if not already done, getting proper legal advice on what the section quoted above actually means. > > Thanks > > Moreno.- > > -- Adrian Klaver adrian.klaver@aklaver.com