大网数据广告活动
服务器运维问答

sudo with Kerberos credentials

· 52CE 我爱测

We are on Oracle Linux 7.9, which is part of a Kerberos realm. I would like account foo to be able to execute (without any password) one command as account bar with Kerberos credentials of bar acquired, but without giving foo she…

问题原文

原帖链接 · Peter G. Horvath · CC BY-SA 4.0

We are on Oracle Linux 7.9, which is part of a Kerberos realm.

I would like account foo to be able to execute (without any password) one command as account bar with Kerberos credentials of bar acquired, but without giving foo shell access, to fully impersonate account bar in an interactive session.

How could I achieve this in a properly? One option I see her is having

  1. a wrapper script that executes the desired command after performing a kinit from a keytab file of bar and
  2. a sudo rule that allows executing the wrapper script to foo.

This approach does not seem to be great to me. What would be a proper solution for this?

已采纳解答

原帖链接 · u1686_grawity · CC BY-SA 4.0

Running the command with sudo or similar is actually a fairly good approach – it provides UID-based separation to prevent the invoker from accessing the temporary tickets.

You could avoid the need for a wrapper script by using either gss-proxy or KRB5_CLIENT_KEYTAB to have libkrb5 automatically acquire tickets on behalf of the user (or by having a cronjob to acquire them with kinit), but otherwise it's going to have to function the same way as you described.

Alternatively, you could keep the wrapper script and have it sudo itself if needed. That is, if /usr/local/bin/cmdbar is invoked as any other user than 'bar' it would sudo -u bar itself, and the invoker wouldn't need to worry about that.

if [ "$(whoami)" != bar ]; then
    exec sudo -u bar -- "$0" "$@" || exit
fi

If it is critical that not even 'bar' has access to the keytab (e.g. if the command being run is one that gives unlimited file access, there are a few options:

  • Use gssproxy (if the command uses standard system libkrb5). The keytab will only need to be accessible by gssproxy while the command's libkrb5 library will ask gssproxy to do all Kerberos operations, similar to the way ssh-agent works. This raises the bar from "read the ticket file" to "talk to gssproxy via socket".

  • Use a yet another account to sudo -u ... kinit, specifying only the necessary service principal (not the krbtgt!), then sudo-chown the resulting ticket cache to bar.

  • Probably, some form of "constrained delegation" where gssproxy can use its machine keytab to impersonate bar and acquire service tickets in a limited way. (The gssproxy docs have an example for doing this with NFS.)

摘自公开归档,保留原文语言,版式经整理,外部媒体与邮箱地址已移除。

资料来源与适用范围

资料来源
Server Fault
适用范围
以原帖系统、软件版本与发布日期为准(2023-10-06)
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 4.0

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。