Exports added by :with are ineffective when :user is specified
还没有人认领这个 Issue。
评估
调研方向
首先定位 issue 中所示的 with 和 user builder 方法,并检查在同时使用这两个选项时,它们如何组合生成的 shell 命令。当 with builder 不再为用户命令添加 export 子 shell,而 user builder 仍然提供环境变量时,此更改即完成。
由索引模型根据 Issue 内容生成。
描述
When a command is mapped, (:should_map?), both :with and :user are invoked.
In both builder methods, the environment variables specified are intended to be inherited by the subshell.
Say that we have the env var MYVAR=myvar, and the command mycommand, which needs to be run as the user myuser. The relevant builder methods are:
def with(&_block)
env_string = environment_string
return yield if env_string.empty?
"( export #{env_string} ; #{yield} )"
end
def user(&_block)
return yield unless options[:user]
env_string = environment_string
"sudo -u #{options[:user].to_s.shellescape} #{env_string + " " unless env_string.empty?}-- sh -c #{yield.shellescape}"
end
this will generate something like:
( export MYVAR=myvar ; sudo -u myuser MYVAR=myvar -- sh -c command )
The problem is that the export is ineffective, because exports are not inherited by the sudo subshell.
While this is harmless, it clutters the generated commands, and it's also semantically incorrect (because it's ineffective) and confusing.
This could be avoided by just yielding the the builder block if options[:user] is set:
def with(&_block)
> # Exports are ineffective on non-login (sudo) shells; in this case, the :user builder takes
> # care of setting them.
> return yield if options[:user]
env_string = environment_string
return yield if env_string.empty?
"( export #{env_string} ; #{yield} )"
end
This makes the (internal) commands output more readable (and understandable). While this has no effect on the end users, it helps understanding those who approach Capistrano/Sshkit development (at least, it did it for me 😬).
If this is approved (either in this form or another), I can easily open a PR.
- 主要语言
- Ruby
- 星标
- 1.2k
- 派生
- 257
- PR 合并指标
- 30 天内没有已合并 PR
环境准备
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
capistrano/sshkit 的其他 Issue
-
难度 5/5 一周以上 新手友好度 35/100
capistrano/sshkit#563 · 6 个 reaction ·
-
难度 2/5 1-3 小时 新手友好度 45/100
capistrano/sshkit#562 ·
-
难度 3/5 1-2 天 新手友好度 48/100
capistrano/sshkit#554 · 3 条评论 ·
-
难度 3/5 1-2 天 新手友好度 35/100
capistrano/sshkit#543 · 2 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 45/100
capistrano/sshkit#518 · 1 条评论 ·
查看 capistrano/sshkit 的全部 Issue
相似的 Issue
-
security
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
Mend: dependency security vulnerability
难度 2/5 1-3 小时 新手友好度 68/100
维护者通常 1 天内回复
-
Mend: dependency security vulnerability
难度 2/5 1-3 小时 新手友好度 62/100
-
难度 2/5 1-3 小时 新手友好度 75/100
维护者通常 1 天内回复
-
难度 1/5 1 小时以内 新手友好度 88/100
bradygaster/squad#2082 ·
维护者通常 1 天内回复