简体   繁体   English

存储数据库密码的最佳实践

[英]Best practice for storing database password

I am developing a custom server application that will access a database. 我正在开发一个将访问数据库的自定义服务器应用程序。 I need to decide where I will store the credentials (and to address) to that server. 我需要决定将凭据(和地址)存储到该服务器的位置。

A common solution is to put the credential in a config file. 常见的解决方案是将凭证放在配置文件中。 However, I do not want a compromised server to mean that the hacker has access to the DB (which is hosted on a separate server). 但是,我不希望受感染的服务器意味着黑客可以访问数据库(托管在单独的服务器上)。

I could store the credentials in the environment, but that is just security through obscurity. 我可以将凭据存储在环境中,但这只是通过默默无闻的安全性。 Mr. Evil can just look in the environment to find it. Evil先生可以在环境中寻找它。

Someone suggested encryption. 有人建议加密。 However, if I store the key in the executable, a quick de-compile (we are using Java) and I am still doomed. 但是,如果我将密钥存储在可执行文件中,快速解编译(我们正在使用Java),我仍然注定要失败。

I also want to avoid having to enter a paraphrase every time I start the server. 我还想避免每次启动服务器时都输入一个释义。

Any suggestions? 有什么建议? I feel like I'm missing something simple. 我觉得我错过了一些简单的事情。

Thanks 谢谢

I don't think you're missing something simple. 我不认为你错过了一些简单的东西。 Either the server in question can connect to the database without your help, in which case it has to have the credentials; 有问题的服务器可以在没有您的帮助的情况下连接到数据库,在这种情况下,它必须具有凭据; or it cannot connect without your supplying them. 或者没有你提供它就无法连接。 You can take various steps like the ones you've listed to make it harder for a compromised server to reveal the credentials to the database, but at the end of the day, if it has to have those credentials and supply them to the DB server to connect, they'll have to be stored on it somewhere — or at least, it will have to have some means of getting them, and so will be hackable in that sense. 您可以采取各种步骤,例如您列出的步骤,使受感染的服务器更难以向数据库显示凭据,但是在一天结束时,是否必须拥有这些凭据并将其提供给数据库服务器要连接,它们必须存储在某个地方 - 或者至少,它必须有一些获取它们的方法,因此在这个意义上是可以破解的。

Your best bet is to focus on finding out about intrusions (compromised servers) as quickly as possible, keeping good off-site, off-line backups for the worst case, putting up lots of barriers to intrusion in the first place, etc. 您最好的选择是尽可能快地找出入侵(受损服务器),为最坏情况保留良好的异地,离线备份,首先为入侵设置许多障碍,等等。

I am sharing, the way I had solved this. 我正在分享,我解决这个问题的方式。

  • Build API, to query the authentication details from a foreign domain. 构建API,以从外部域查询身份验证详细信息。
  • Use public key, and private key to read through the details. 使用公钥和私钥来读取详细信息。

But, honestly the only thing this did was over complicate simple things. 但是,老实说,这样做的唯一原因就是复杂的简单事情。 After that, I created several users to the database, with different privileges. 之后,我使用不同的权限为数据库创建了多个用户。

Like 喜欢

  • guest can only to SELECT guest只能SELECT
  • mod can only CREATE , INSERT , UPDATE , DELETE mod只能CREATEINSERTUPDATEDELETE

etc and switched the user, whenever authenticated users appeared. 等等,并在认证用户出现时切换用户。

With the combination of users and session, I have been able to escape the threats so far. 通过用户和会话的组合,我已经能够逃脱目前的威胁。 But ofcourse the code vulnerability have to be tested thoroughly. 但当然,必须彻底测试代码漏洞。

Lock it down. 锁定它。 Prevent Mr. Evil from gaining root. 防止Evil先生获得成功。 I know, easy right? 我知道,对吗?

Write a secure application and keep your application server locked down. 编写安全的应用程序并锁定应用程序服务器。 Follow best practices there, and that's most of the work. 遵循那里的最佳实践,这是大部分工作。

When I've setup databases in a secure environment, the only server that was on the same physical network with the database server was the application server. 当我在安全环境中设置数据库时,与数据库服务器位于同一物理网络上的唯一服务器是应用程序服务器。 There were two ways to access the database server: 有两种方法可以访问数据库服务器:

  1. Application server 应用服务器
  2. Console 安慰

Therefore, in order to compromise the database server, they'd have to compromise the application server. 因此,为了破坏数据库服务器,他们必须妥协应用程序服务器。

So, lock down the application server. 因此,锁定应用程序服务器。 Of course the only thing worse than being compromised is being compromised and not knowing about it. 当然,唯一比受到损害的更糟糕的事情就是妥协而不知道。 If you do discover a compromise, you need to fix the vulnerability if there was one. 如果您确实发现了泄密,则需要修复漏洞(如果存在漏洞)。 Forensics are important here (enable logs and monitor them). 取证在这里很重要(启用日志并监控它们)。 You also need a recovery plan in place. 您还需要制定恢复计划。

Prevention, detection, correction, and recovery are paramount. 预防,检测,纠正和恢复至关重要。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM