GrowingIO 数据安全实践

{"type":"doc","content":[{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"什么是数据安全","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"根据《中华人民共和国数据安全法》中第三条,给出了数据安全的定义,是指通过采取必要措施,确保数据处于有效保护和合法利用的状态,以及具备保障持续安全状态的能力。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"为什么企业要做数据安全","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在互联网盛行的今天,不法分子可以通过网络攻击,网络欺骗等手段窃取用户的个人信息甚至企业的机密信息。而且在拿到部分用户信息后就可以唯一的锁定具体某一个人,因此数据的保密显得格外重要。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"GrowingIO 数据安全落地","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"为了保证客户数据的安全性, GrowingIO 通过构建一个安全的软件运行时与数据静态存储加密来提高数据生产安全性。下面我们将详细介绍数据安全落地的过程。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"【软件运行安全","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"软件运行安全也就是企业的系统运行安全,这主要包含两个方面: 数据逻辑隔离:系统通过用户的权限与角色,给出专有的数据操作集合。 KMS秘钥管理:系统所依赖的数据库,中间件不会因为秘钥的泄露而造成数据泄露。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"数据逻辑隔离","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"数据逻辑隔离主要是对平台上操作的用户进行身份,角色,权限的认证。 认证流程:","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/2c/2cbc7afdbcb2fe50e5367a9059b0c7f1.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"所有平台的用户通过RBAC 权限模型分配不同的角色和权限。只有拥有对应角色权限的用户才能查看或进行对应的操作。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"KMS 秘钥管理","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"KMS 即(key manage system)秘钥管理系统。目前亚马逊云和阿里云等云产品都有自己的解决方案。KMS 支持多种类型的的数据库,中间件,以及应用秘钥管理等功能。使用KMS 之后所有数据库,中间件等的用户名,密码对产研均不可见,应用静态数据加密对应的秘钥也不可见。 目前支持数据库和中间件以及系统秘钥:","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/2b/2b8fa77c21b501df287bb0dc7f11f1c0.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 【","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"交互流程】","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/29/29dbcbab7e8d8be9511fd826aef7f486.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 【","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"示例展示】","attrs":{}},{"type":"text","text":" 以亚马逊云(AWS)为例: ","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"应用配置","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"kms:\n enabled: false\n aws:\n region: \"\"\n access_key_id: \"\"\n secret_access_key: \"\"\n#应用中添加\nspring:\n redis:\n kms-key: \"test/json/redis\"\n datasource:\n kms-key: \"test/postgresql/accounts\"","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"运行初始化","attrs":{}},{"type":"text","text":" 示例以postgresql 数据库HikariCP 连接池为例:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"@Bean\n@ConditionalOnProperty(value = \"kms.enabled\",havingValue = \"true\")\npublic HikariDataSource dataSource(DataSourceProperties properties, KmsProperties kms,Configs configs) {\n SecretsManagerClient client = SecretsManagerClientBuilder.build(kms.getRegion(),kms.getAwsAccessKeyId(),kms.getAwsSecretAccessKey());\n AwsSecretProvider secretProvider = new AwsSecretProvider(client);\n String secret;\n try{\n secret = secretProvider.getSecret(configs.getDataSourceKmsKey());\n //secret是json格式的链接信息\n final HashMap map = Jackson.readValue(secret, HashMap.class);\n String url = String.format(\"jdbc:postgresql://%s:%s/%s?useUnicode=true&useSSL=false&characterEncoding=utf8\",map.get(\"host\"),map.get(\"port\"),map.get(\"dbname\"));\n properties.setUrl(url);\n properties.setUsername(map.get(\"username\"));\n properties.setPassword(map.get(\"password\"));\n }catch (Exception e) {\n log.error(\"kms database error\",e);\n }\n HikariDataSource dataSource = properties.initializeDataSourceBuilder().type(HikariDataSource.class).build();\n if (StringUtils.hasText(properties.getName())) {\n dataSource.setPoolName(properties.getName());\n }\n return dataSource;\n }","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在实际开发中用到的任何数据库,中间件都可以通过KMS 来管理对应的用户名,密码等敏感信息。","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":2},"content":[{"type":"text","text":"【静态存储安全】","attrs":{}}]},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"PII 管理","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"【什么是PII】","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"PII 即个人身份信息 (Personally identifiable information) 是任何可能识别特定个人的数据。任何可用于将一个人与另一个人区分开来并可用于对以前匿名数据进行去匿名化的信息都可以被视为 PII。 PII 可以单独使用或与其他相关数据一起使用来识别个人,并且包含可以唯一识别个人的直接标识符(例如护照信息)或准标识符(例如种族),可以与其他准标识符结合使用标识符,如出生日期,以成功识别个人。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"【","attrs":{}},{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"PII 意义】","attrs":{}},{"type":"text","text":" ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"保护 PII 对于个人隐私、数据隐私、数据保护、信息隐私和信息安全至关重要。仅凭个人信息的一小部分,窃贼就可以以该人的名义创建虚假账户、产生债务、伪造护照或将个人身份出售给犯罪分子。随着个人的个人数据每天被记录、跟踪和使用——例如在使用指纹的生物识别扫描和用于解锁设备的面部识别系统中——保护个人身份和他们独有的任何识别信息变得越来越重要。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"【PII 加解密】","attrs":{}},{"type":"text","text":" ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"PII 加密: 对于所有入库的用户敏感数据使用加密算法进行加密。 PII 解密:普通用户只能查看加密的密文数据,对于有业务需要的通过授权可以查看明文数据。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"GrowingIO 默认选择AES(AES/CBC/PKCS5Padding) 算法 ,采用256长度的秘钥来作为PII 数据加密的实现。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"执行流程","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"数据加密","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/31/31abeaa3d06a59204d2982a4d831ff2c.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"数据解密","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/00/0059f0d5fef6d7becdbf4aecbfeeb3fd.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"示例展示","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"PII 可以从配置中心或KMS 中来获取加解密需要的秘钥数据。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"秘钥获取:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"// KMS 方式\nSecretsManagerClient client = SecretsManagerClientBuilder.build(kms.getRegion(),kms.getAwsAccessKeyId(),kms.getAwsSecretAccessKey());\nAwsSecretProvider secretProvider = new AwsSecretProvider(client);\nString secret = secretProvider.getSecret(\"test/pii/json\");\n//secret是json格式的链接信息\nfinal HashMap map = Jackson.readValue(secret, HashMap.class);\n\nString algorithmIv = map.getOrElse(\"algorithm_iv\", \"\");\n// 向量\nString iv = DatatypeConverter.parseHexBinary(algorithmIv);\n// 秘钥\nString encryptionKey = DatatypeConverter.parseHexBinary(map(\"encryption_key\"));\nString decryptionKey = DatatypeConverter.parseHexBinary(map(\"decryption_key\"));\n\n// 配置中心方式\n// 向量\nString iv = Hex.decodeHex(Configs.Encry.configCenterIv);\n// 秘钥\nString secret = Hex.decodeHex(Configs.Encry.configCenterSecret);","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"执行加密或者解密操作:","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"通过PII 进行数据处理后,数据库中敏感数据全为加密存储。页面渲染依据用户权限判断是否加密或者解密展示。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"strong","attrs":{}}],"text":"数据存储与渲染","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"数据库数据:","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/bf/bf809aca431830ccaacbae2c469f5a27.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"只有管理员登录后渲染解密后的数据:","attrs":{}}]},{"type":"image","attrs":{"src":"https://static001.geekbang.org/infoq/10/1000b5e81f983bb0728b2825676f555c.png","alt":null,"title":null,"style":[{"key":"width","value":"75%"},{"key":"bordertype","value":"none"}],"href":null,"fromPaste":true,"pastePass":true}},{"type":"heading","attrs":{"align":null,"level":3},"content":[{"type":"text","text":"常见问题","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":" 一、向量IV 的支持","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"italic","attrs":{}}],"text":"在AES 加密算法中:AES_ECB_PKCS5Padding 不支持向量,AES_CBC_PKCS5Padding支持向量且安全性更高。如果原来已经有用到AES 算法要考虑兼容性。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"二、Base 64 编码带来的问题","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"现象:如果加密的字符串比较长,加密后的密文将长度超过76时,密文中会被加入一个换行符,导致后续按行解析异常。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"在JDK1.8 之后Base64 工具类移到了java.util 包中,为了向低版本的JDK 兼容,Base64 中 MimeEncode,采用的方式:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"private static final int MIMELINEMAX = 76;\nprivate static final byte[] CRLF = new byte[] {'\\r', '\\n'};\nstatic final Encoder RFC2045 = new Encoder(false, CRLF, MIMELINEMAX, true);","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"也就是说在加密串的长度超过76时会加上 '\\r' 或者 '\\n',这就导致如果按行进行数据的某些操作将会发生致命错误。所以推荐使用Base64中Encode的实现:","attrs":{}}]},{"type":"codeblock","attrs":{"lang":null},"content":[{"type":"text","text":"static final Encoder RFC4648 = new Encoder(false, null, -1, true);\nstatic final Encoder RFC4648_URLSAFE = new Encoder(true, null, -1, true);","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"这样不管加密后的字符串长度有多长都不会发生换行的问题。","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","text":"参考JDK 源码和秘钥标准: ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"italic","attrs":{}}],"text":"RFC 4648","attrs":{}},{"type":"text","text":" ","attrs":{}},{"type":"text","marks":[{"type":"italic","attrs":{}}],"text":"http://www.ietf.org/rfc/rfc4648.txt ","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null},"content":[{"type":"text","marks":[{"type":"italic","attrs":{}}],"text":"RFC 2045 http://www.ietf.org/rfc/rfc2045.txt","attrs":{}}]},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}},{"type":"paragraph","attrs":{"indent":0,"number":0,"align":null,"origin":null}}]}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章