在我们的产品中,我们使用daemontools创建了服务。我的服务之一是这样的,
/service/test/run
/service/test/log/run (has multilog command to log into ./main dir)
/service/test/log/main/..所有进程及其目录都由根用户拥有。现在有一个安全要求要像这样改变,
1. Service should run in non-root user.
2. Log main directory should be readable only to user and groups.为此,我必须更改“log”目录下的“run”文件。另外,我需要更改它下的'main‘目录的权限。
请注意,“/service”下的所有这些文件都属于test-1.0-0.rpm。当我更新rpm时,它会覆盖现有的运行文件并得到这样的错误,
multilog: fatal: unable to lock directory ./main: access denied我知道我们不应该在运行时覆盖“run”文件。我计划在rpm脚本%post部分执行这些步骤,
//Stop service
svc -d /service/test/log
//Moving the main directory
mv /service/test/log/main /service/test/log/main_old
//Updated run file has code to create main with limited permissions.
//Start service
svc -u /service/test/log在一些文章中,他们建议在“log/main”下重新创建“lock”文件。在不移动“主”目录的情况下,还有其他更干净的方法吗?如果没有,按照上述步骤进行安全吗?
发布于 2015-04-27 22:57:12
1. Service should run in non-root user.很简单。您将将服务定义复制到“用户”所在的服务目录中。例如,假设您创建了一个用户,我们将称之为niftyuser。也可以说,您的服务名为niftyservice。因此,您可以将您的服务定义复制到由该用户控制的目录中;为了便于讨论(不一定要这样做),假设您将使用niftyuser的S主目录。
cp -Rav /etc/service/niftyservice /home/niftyuser/service/niftyservice将创建服务定义。然后,您必须在该用户的目录上启动服务扫描,但是使用用户的凭据启动。如果你把它写成一个脚本,它看起来会有点像:
#!/bin/sh
exec setuidgid niftyuser svscan /home/niftyuser/service结果将是由该用户控制的服务树。注意,通过编写脚本,您可以将用户控制进程的子树插入主进程树中.您可以看到这看起来像什么的runit示例,因为runit是受daemontools启发的。
2. Log main directory should be readable only to user and groups.坦率地说,我只是将/service/(service-name)/log/main作为一个指向实际目录的符号链接,即/service/niftyservice/log/main指向/var/log/niftyservice。在日志目录的运行脚本中,将其指向./main作为目标;这意味着您只需更改符号链接就可以设置定义一次并移动日志记录。最后,为了解决问题(2),您将根据需要为/var/log/niftyservice设置用户和组权限,并将模式设置为775。这将允许任何人读取文件,但只允许用户或组向其写入文件。
https://serverfault.com/questions/622126
复制相似问题