怎么使用PostgreSQL的插件postgresql_anonymizer

本篇內(nèi)容主要講解“怎么使用PostgreSQL的插件postgresql_anonymizer”,感興趣的朋友不妨來看看。本文介紹的方法操作簡單快捷,實用性強。下面就讓小編來帶大家學(xué)習(xí)“怎么使用PostgreSQL的插件postgresql_anonymizer”吧!

站在用戶的角度思考問題,與客戶深入溝通,找到金東網(wǎng)站設(shè)計與金東網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:網(wǎng)站建設(shè)、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名申請、虛擬空間、企業(yè)郵箱。業(yè)務(wù)覆蓋金東地區(qū)。

安裝
依賴tsm_system_rows和ddlx兩個擴展,需提前安裝妥當(dāng)。

[local:/data/pg12]:5432 pg12@testdb=# create extension tsm_system_rows;
CREATE EXTENSION
[local:/data/pg12]:5432 pg12@testdb=# create extension ddlx;
CREATE EXTENSION
[local:/data/pg12]:5432 pg12@testdb=#

clone代碼,編譯安裝

[pg12@localhost contrib]$ git clone https://gitlab.com/dalibo/postgresql_anonymizer.git -b 0.5.0
Cloning into 'postgresql_anonymizer'...
remote: Enumerating objects: 2396, done.
remote: Counting objects: 100% (2396/2396), done.
remote: Compressing objects: 100% (854/854), done.
remote: Total 2396 (delta 1524), reused 2379 (delta 1513)
Receiving objects: 100% (2396/2396), 12.85 MiB | 55.00 KiB/s, done.
Resolving deltas: 100% (1524/1524), done.
Note: checking out 'c108008719a1394b55779ff7115f188511c6ec89'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
  git checkout -b new_branch_name

編譯安裝

[pg12@localhost contrib]$ cd postgresql_anonymizer/
[pg12@localhost postgresql_anonymizer]$ make
mkdir -p anon
cp anon.sql anon/anon--0.5.0.sql
cp data/default/* anon/
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -DOPTIMIZER_DEBUG -g3 -gdwarf-2 -fPIC -I. -I./ -I/appdb/pg12/pg12.1/include/postgresql/server -I/appdb/pg12/pg12.1/include/postgresql/internal  -D_GNU_SOURCE -I/usr/include/libxml2   -c -o anon.o anon.c -MMD -MP -MF .deps/anon.Po
gcc -std=gnu99 -Wall -Wmissing-prototypes -Wpointer-arith -Wdeclaration-after-statement -Werror=vla -Wendif-labels -Wmissing-format-attribute -Wformat-security -fno-strict-aliasing -fwrapv -fexcess-precision=standard -g -O0 -DOPTIMIZER_DEBUG -g3 -gdwarf-2 -fPIC anon.o -L/appdb/pg12/pg12.1/lib   -Wl,--as-needed -Wl,-rpath,'/appdb/pg12/pg12.1/lib',--enable-new-dtags  -shared -o anon.so
[pg12@localhost postgresql_anonymizer]$ make install
mkdir -p anon
cp anon.sql anon/anon--0.5.0.sql
cp data/default/* anon/
/bin/mkdir -p '/appdb/pg12/pg12.1/share/postgresql/extension'
/bin/mkdir -p '/appdb/pg12/pg12.1/share/postgresql/extension/anon'
/bin/mkdir -p '/appdb/pg12/pg12.1/lib/postgresql'
/bin/install -c -m 644 .//anon.control '/appdb/pg12/pg12.1/share/postgresql/extension/'
/bin/install -c -m 644 .//anon/*  '/appdb/pg12/pg12.1/share/postgresql/extension/anon/'
/bin/install -c -m 755  anon.so '/appdb/pg12/pg12.1/lib/postgresql/'
[pg12@localhost postgresql_anonymizer]$

體驗
創(chuàng)建擴展,添加到加載庫中shared_preload_libraries,重啟實例

[local:/data/pg12]:5432 pg12@testdb=# CREATE EXTENSION IF NOT EXISTS anon CASCADE;
CREATE EXTENSION
[local:/data/pg12]:5432 pg12@testdb=# alter system set shared_preload_libraries = 'anon';
ALTER SYSTEM
[local:/data/pg12]:5432 pg12@testdb=# 
[local:/data/pg12]:5432 pg12@testdb=# exit
[pg12@localhost contrib]$ pg_ctl restart
waiting for server to shut down.... done
server stopped
waiting for server to start....2019-11-19 16:41:45.940 CST [15439] LOG:  starting PostgreSQL 12.1 on x86_64-pc-linux-gnu, compiled by gcc (GCC) 4.8.5 20150623 (Red Hat 4.8.5-16), 64-bit
2019-11-19 16:41:45.940 CST [15439] LOG:  listening on IPv4 address "0.0.0.0", port 5432
2019-11-19 16:41:45.940 CST [15439] LOG:  listening on IPv6 address "::", port 5432
2019-11-19 16:41:45.943 CST [15439] LOG:  listening on Unix socket "/data/pg12/.s.PGSQL.5432"
2019-11-19 16:41:46.013 CST [15439] LOG:  redirecting log output to logging collector process
2019-11-19 16:41:46.013 CST [15439] HINT:  Future log output will appear in directory "pg_log".
 done
server started
[pg12@localhost contrib]$

插件提供的函數(shù)

[local:/data/pg12]:5432 pg12@testdb=# select * from pg_namespace where nspname='anon';
  oid  | nspname | nspowner | nspacl 
-------+---------+----------+--------
 17050 | anon    |       10 | 
(1 row)
[local:/data/pg12]:5432 pg12@testdb=# \d pg_proc
                   Table "pg_catalog.pg_proc"
     Column      |     Type     | Collation | Nullable | Default 
-----------------+--------------+-----------+----------+---------
 oid             | oid          |           | not null | 
 proname         | name         |           | not null | 
 pronamespace    | oid          |           | not null | 
 proowner        | oid          |           | not null | 
 prolang         | oid          |           | not null | 
 procost         | real         |           | not null | 
 prorows         | real         |           | not null | 
 provariadic     | oid          |           | not null | 
 prosupport      | regproc      |           | not null | 
 prokind         | "char"       |           | not null | 
 prosecdef       | boolean      |           | not null | 
 proleakproof    | boolean      |           | not null | 
 proisstrict     | boolean      |           | not null | 
 proretset       | boolean      |           | not null | 
 provolatile     | "char"       |           | not null | 
 proparallel     | "char"       |           | not null | 
 pronargs        | smallint     |           | not null | 
 pronargdefaults | smallint     |           | not null | 
 prorettype      | oid          |           | not null | 
 proargtypes     | oidvector    |           | not null | 
 proallargtypes  | oid[]        |           |          | 
 proargmodes     | "char"[]     |           |          | 
 proargnames     | text[]       | C         |          | 
[local:/data/pg12]:5432 pg12@testdb=# select proname from pg_proc where pronamespace = 17050;
           proname            
------------------------------
 dump
 generalize_int4range
 random_date_between
 random_date
 random_int_between
 add_noise_on_numeric_column
 add_noise_on_datetime_column
 shuffle_column
 load
 load
 isloaded
 unload
 random_string
 random_zip
 random_phone
 fake_first_name
 fake_last_name
 fake_email
 fake_city_in_country
 fake_city
 fake_region_in_country
 fake_region
 fake_country
 fake_company
 fake_iban
 fake_siren
 fake_siret
 lorem_ipsum
 random_first_name
 random_last_name
 random_email
 random_city_in_country
 random_city
 random_region_in_country
 random_region
 random_country
 random_company
 random_iban
 random_siren
 random_siret
 partial
 partial_email
 source_schema
 mask_schema
 anonymize_column
 anonymize_table
 anonymize_database
 static_substitution
 hasmask
 mask_columns
 mask_create
 mask_filters
 mask_create_view
 mask_drop_view
 get_copy_statement
 start_dynamic_masking
 mask_init
 stop_dynamic_masking
 mask_trigger
 mask_role
 unmask_role
 mask_enable
 mask_disable
 mask_update
 dump_ddl
 dump_data
 generalize_int8range
 generalize_numrange
 generalize_tsrange
 generalize_tstzrange
 generalize_daterange
 k_anonymity
(72 rows)

下面創(chuàng)建一張”隱私”表,使用該插件實現(xiàn)動態(tài)脫敏

[local:/data/pg12]:5432 pg12@testdb=# drop table t_masking;
ERROR:  table "t_masking" does not exist
[local:/data/pg12]:5432 pg12@testdb=# create table t_masking(id serial,name varchar(20),zipcode varchar(20));
 values('王五','230100');
CREATE TABLE
[local:/data/pg12]:5432 pg12@testdb=# 
[local:/data/pg12]:5432 pg12@testdb=# insert into t_masking(name,zipcode) values('張三','440100');
INSERT 0 1
[local:/data/pg12]:5432 pg12@testdb=# insert into t_masking(name,zipcode) values('李四','420100');
INSERT 0 1
[local:/data/pg12]:5432 pg12@testdb=# insert into t_masking(name,zipcode) values('王五','230100');
INSERT 0 1
[local:/data/pg12]:5432 pg12@testdb=#

啟用動態(tài)脫敏,創(chuàng)建脫敏用戶masking

[local:/data/pg12]:5432 pg12@testdb=# SELECT anon.start_dynamic_masking();
 start_dynamic_masking 
-----------------------
 t
(1 row)
[local:/data/pg12]:5432 pg12@testdb=# 
[local:/data/pg12]:5432 pg12@testdb=# CREATE ROLE masking LOGIN with password 'root';
ERROR:  syntax error at or near "with"
LINE 1: CREATE ROLE masking LOGIN with password 'root';
                                  ^
[local:/data/pg12]:5432 pg12@testdb=# CREATE user masking with password 'root';
CREATE ROLE

打標(biāo)簽

[local:/data/pg12]:5432 pg12@testdb=# SECURITY LABEL FOR anon ON ROLE masking IS 'MASKED';
SECURITY LABEL
[local:/data/pg12]:5432 pg12@testdb=# SECURITY LABEL FOR anon ON COLUMN t_masking.name is 'MASKED WITH FUNCTION anon.fake_last_name()';
SECURITY LABEL
[local:/data/pg12]:5432 pg12@testdb=# SECURITY LABEL FOR anon ON COLUMN t_masking.zipcode is 'MASKED WITH FUNCTION anon.random_zip()';
SECURITY LABEL
[local:/data/pg12]:5432 pg12@testdb=#

t_masking的數(shù)據(jù)

[local:/data/pg12]:5432 pg12@testdb=# select * from t_masking;
 id | name | zipcode 
----+------+---------
  1 | 張三 | 440100
  2 | 李四 | 420100
  3 | 王五 | 230100
(3 rows)
[local:/data/pg12]:5432 pg12@testdb=#

用戶masking登錄查詢得到的數(shù)據(jù)

[pg12@localhost pgddl]$ psql -U masking
Expanded display is used automatically.
psql (12.1)
Type "help" for help.
[local:/data/pg12]:5432 masking@testdb=> select * from t_masking;
 id |   name   | zipcode 
----+----------+---------
  1 | Malagisi | 46864
  2 | Hausner  | 55255
  3 | Degolyer | 82186
(3 rows)
[local:/data/pg12]:5432 masking@testdb=>

可以看到,數(shù)據(jù)已被“脫敏”。

到此,相信大家對“怎么使用PostgreSQL的插件postgresql_anonymizer”有了更深的了解,不妨來實際操作一番吧!這里是創(chuàng)新互聯(lián)網(wǎng)站,更多相關(guān)內(nèi)容可以進入相關(guān)頻道進行查詢,關(guān)注我們,繼續(xù)學(xué)習(xí)!

本文題目:怎么使用PostgreSQL的插件postgresql_anonymizer
網(wǎng)站路徑:http://muchs.cn/article4/jchsoe.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站收錄、虛擬主機用戶體驗、軟件開發(fā)、App設(shè)計、標(biāo)簽優(yōu)化

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都app開發(fā)公司