我在我工作的公司实现了这一点,并简要介绍了它的工作原理=> https://www.youtube.com/watch?v=6vUw6f7KlqI
该视频提供了更多概述,而不是有关如何配置 PAM 的详细信息。但是,我很乐意回答有关我们如何设置 PAM 配置的任何后续问题,但基本上我们让 OPA 在我们的 linux 主机上作为 systemd 服务运行,并添加了对=>的pam_exec
调用/etc/pam.d/sshd
auth sufficient pam_exec.so quiet /some/path/pam_opa_entrypoint.sh ssh
pam_opa_entrypoint.sh 或多或少看起来像:
#!/bin/bash
INPUT_JSON=$(jq -n -c --arg username "$PAM_USER" '{input:{pam_username:$username}}')
OPA_RESULT_JSON=$(curl -s -X POST https://opa.local/v1/data/linux/$1 -H "Content-Type: application/json" -d $INPUT_JSON)
OPA_RESULT=$(jq -r '.result.allowed' <<< "$OPA_RESULT_JSON")
if [[ "$OPA_RESULT" == "true" ]]; then
# Authorization success
exit 0
else
# Authorization failed
exit 1
fi
这种pam_exec.so
方法比 Styra 提供的用 C 编写 PAM 模块的示例更受欢迎。