Skip to content

Commit 552dbc0

Browse files
authored
clush: add support for run modes (clush --mode) (#492)
Add support for configuration-based run modes for clush. Run modes are disabled by default because they rely on external tools that we don't want to depend on. They can easily be enabled if needed by installing the corresponding .conf files in clush.conf.d (clush.conf's confdir). sudo support is provided via an example run mode, by defining two variables command_prefix and password_prompt: [mode:sudo] password_prompt: yes command_prefix: /usr/bin/sudo -S -p "''" Then, the sudo mode is activated with --mode or -m: $ clush -w nodes -m sudo command Also added an example of run mode for password-auth based auth with sshpass. Main changes: clush.conf: - add confdir to define paths to config files for run modes - add command_prefix - add password_prompt - removed sudo_command clush.conf.d: - add sshpass.conf.example - add sudo.conf.example clush: - added --mode - removed --sudo Closes #198. Closes #423. Fixes #234.
1 parent 788b1e1 commit 552dbc0

File tree

21 files changed

+739
-178
lines changed

21 files changed

+739
-178
lines changed

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ include README.md
33
include COPYING.LGPLv2.1
44
include conf/*.conf
55
include conf/*.example
6+
include conf/clush.conf.d/README
7+
include conf/clush.conf.d/*.example
68
include conf/groups.d/README
79
include conf/groups.d/*.cfg
810
include conf/groups.d/*.example

clustershell.spec.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,12 +218,15 @@ rm -rf %{buildroot}
218218
%{_mandir}/man5/clush.conf.5*
219219
%{_mandir}/man5/groups.conf.5*
220220
%dir %{_sysconfdir}/clustershell
221+
%dir %{_sysconfdir}/clustershell/clush.conf.d
221222
%dir %{_sysconfdir}/clustershell/groups.d
222223
%dir %{_sysconfdir}/clustershell/groups.conf.d
223224
%config(noreplace) %{_sysconfdir}/clustershell/clush.conf
224225
%config(noreplace) %{_sysconfdir}/clustershell/groups.conf
225226
%ghost %{_sysconfdir}/clustershell/groups
226227
%config(noreplace) %{_sysconfdir}/clustershell/groups.d/local.cfg
228+
%doc %{_sysconfdir}/clustershell/clush.conf.d/README
229+
%doc %{_sysconfdir}/clustershell/clush.conf.d/*.conf.example
227230
%doc %{_sysconfdir}/clustershell/groups.conf.d/README
228231
%doc %{_sysconfdir}/clustershell/groups.conf.d/*.conf.example
229232
%doc %{_sysconfdir}/clustershell/groups.d/README

conf/clush.conf

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,9 @@ history_size: 100
1313
maxrc: no
1414
node_count: yes
1515
verbosity: 1
16+
confdir: /etc/clustershell/clush.conf.d $CFGDIR/clush.conf.d
1617

1718
# Add always all remote hosts to known_hosts without confirmation
1819
#ssh_user: root
1920
#ssh_path: /usr/bin/ssh
2021
#ssh_options: -oStrictHostKeyChecking=no
21-
22-
# Non-interactively performing password authentication with SSH's so called
23-
# "interactive keyboard password authentication".
24-
#ssh_user: root
25-
#ssh_path: /usr/bin/sshpass -f /root/remotepasswordfile /usr/bin/ssh
26-
#scp_path: /usr/bin/sshpass -f /root/remotepasswordfile /usr/bin/scp
27-
#ssh_options: -oBatchMode=no -oStrictHostKeyChecking=no
28-
29-
# sudo command used for --sudo
30-
#sudo_command: /usr/bin/sudo -S -p "''" -k

conf/clush.conf.d/README

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
clush.conf.d/README
2+
3+
Default directory for additional clush configuration files.
4+
clush scans the directory set by the confdir variable, defined
5+
in /etc/clustershell/clush.conf, loading all files of the form *.conf.
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Example configuration file for ssh password auth support with sshpass.
2+
#
3+
# Copy as sshpass.conf to enable and edit the paths below as needed.
4+
# sshpass needs to be installed on your operating system.
5+
#
6+
# To activate sshpass mode, use clush -m sshpath ...
7+
8+
[mode:sshpass]
9+
password_prompt: yes
10+
ssh_path: /usr/bin/sshpass /usr/bin/ssh
11+
scp_path: /usr/bin/sshpass /usr/bin/scp
12+
ssh_options: -oBatchMode=no -oStrictHostKeyChecking=no
13+
14+
# Another mode that reads the password from a local file instead
15+
[mode:sshpass-file]
16+
password_prompt: no
17+
ssh_path: /usr/bin/sshpass -f /root/remotepasswordfile /usr/bin/ssh
18+
scp_path: /usr/bin/sshpass -f /root/remotepasswordfile /usr/bin/scp
19+
ssh_options: -oBatchMode=no -oStrictHostKeyChecking=no
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Example configuration file for sudo support.
2+
#
3+
# Copy as sudo.conf to enable and edit sudo's path as needed
4+
# (sudo needs to be installed on your operating system).
5+
#
6+
# To activate sudo mode, use clush -m sudo ...
7+
8+
[mode:sudo]
9+
password_prompt: yes
10+
command_prefix: /usr/bin/sudo -S -p "''"

doc/extras/vim/ftdetect/clustershell.vim

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@
22
" Installed As: vim/ftdetect/clustershell.vim
33
"
44
au BufNewFile,BufRead *clush.conf setlocal filetype=clushconf
5+
au BufNewFile,BufRead *clush.conf.d/*.conf setlocal filetype=clushconf
56
au BufNewFile,BufRead *groups.conf setlocal filetype=groupsconf
67
au BufNewFile,BufRead *groups.conf.d/*.conf setlocal filetype=groupsconf

doc/extras/vim/syntax/clushconf.vim

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,19 @@ endif
1212
" shut case off
1313
syn case ignore
1414

15-
syn match clushComment "#.*$"
16-
syn match clushComment ";.*$"
17-
syn match clushHeader "\[\w\+\]"
15+
syn match clushComment "#.*$"
16+
syn match clushComment ";.*$"
17+
syn match clushHeader "\[\w\+\]$"
18+
syn match clushHeaderMode "\[mode:\S\+\]$"
19+
syn match confDirGroup "^confdir\(:\|=\).*$" contains=confDirKeys,confDirVars
20+
syn match confDirVars "$CFGDIR" contained
21+
syn match confDirKeys "^\w\+\(:\|=\)"me=e-1 contained
1822

1923
syn keyword clushKeys fanout command_timeout connect_timeout color fd_max history_size node_count maxrc verbosity
2024
syn keyword clushKeys ssh_user ssh_path ssh_options
2125
syn keyword clushKeys scp_user scp_path scp_options
2226
syn keyword clushKeys rsh_path rcp_path rcp_options
23-
syn keyword clushKeys sudo_command
27+
syn keyword clushKeys command_prefix password_prompt
2428

2529
" Define the default highlighting.
2630
" For version 5.7 and earlier: only when not done already
@@ -33,10 +37,13 @@ if version >= 508 || !exists("did_clushconf_syntax_inits")
3337
command -nargs=+ HiLink hi def link <args>
3438
endif
3539

36-
HiLink clushHeader Special
37-
HiLink clushComment Comment
38-
HiLink clushLabel Type
39-
HiLink clushKeys Identifier
40+
HiLink clushHeader Special
41+
HiLink clushHeaderMode Constant
42+
HiLink clushComment Comment
43+
HiLink clushLabel Type
44+
HiLink clushKeys Identifier
45+
HiLink confDirKeys Identifier
46+
HiLink confDirVars Keyword
4047

4148
delcommand HiLink
4249
endif

doc/man/man1/clush.1

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
.\" Man page generated from reStructuredText.
22
.
3-
.TH CLUSH 1 "2022-06-29" "1.8.4" "ClusterShell User Manual"
3+
.TH CLUSH 1 "2022-11-18" "1.8.4" "ClusterShell User Manual"
44
.SH NAME
55
clush \- execute shell commands on a cluster
66
.
@@ -289,6 +289,9 @@ limit time to connect to a node
289289
.BI \-u \ COMMAND_TIMEOUT\fP,\fB \ \-\-command_timeout\fB= COMMAND_TIMEOUT
290290
limit time for command to run on the node
291291
.TP
292+
.BI \-m \ MODE\fP,\fB \ \-\-mode\fB= MODE
293+
run mode; define MODEs in \fB<confdir>/*.conf\fP
294+
.TP
292295
.BI \-R \ WORKER\fP,\fB \ \-\-worker\fB= WORKER
293296
worker name to use for connection (\fBexec\fP, \fBssh\fP, \fBrsh\fP, \fBpdsh\fP, or the name of a Python worker module), default is \fBssh\fP
294297
.TP
@@ -384,8 +387,9 @@ Copy \fI/etc/motd\fP from remote nodes node[3\-5,62] to local \fI/tmp\fP directo
384387
.SH FILES
385388
.INDENT 0.0
386389
.TP
387-
.B \fI/etc/clustershell/clush.conf\fP
388-
System\-wide clush configuration file.
390+
.B \fI$CLUSTERSHELL_CFGDIR/clush.conf\fP
391+
Global clush configuration file. If $CLUSTERSHELL_CFGDIR is not defined,
392+
\fI/etc/clustershell/clush.conf\fP is used instead.
389393
.TP
390394
.B \fI$XDG_CONFIG_HOME/clustershell/clush.conf\fP
391395
User configuration file for clush. If $XDG_CONFIG_HOME is not defined,

doc/man/man5/clush.conf.5

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ user configuration file (\fI$XDG_CONFIG_HOME/clustershell/clush.conf\fP)
4444
.IP 3. 3
4545
local pip user installation (\fI$HOME/.local/etc/clustershell/clush.conf\fP)
4646
.IP 4. 3
47-
system\-wide configuration file (\fI/etc/clustershell/clush.conf\fP)
47+
global configuration file (\fI$CLUSTERSHELL_CFGDIR/clush.conf\fP, defaults to
48+
\fI/etc/clustershell/clush.conf\fP)
4849
.UNINDENT
4950
.UNINDENT
5051
.UNINDENT
@@ -71,10 +72,26 @@ used on the head node and on each gateway (the \fIfanout\fP value is propagated)
7172
That is, if the \fIfanout\fP is \fB16\fP on the head node, each gateway will
7273
initate up to \fB16\fP connections to their target nodes at the same time.
7374
.TP
75+
.B confdir
76+
Optional list of directory paths where clush should look for \fI\&.conf\fP files
77+
which define run modes that can then be activated with \fB\-\-mode\fP\&. All other
78+
clush config file settings defined here might be overriden in a run mode.
79+
Each mode section should have a name prefixed by "mode:" to clearly identify
80+
a section defining a mode. Duplicate modes are not allowed in those files.
81+
Configuration files that are not readable by the current user are ignored.
82+
The variable \fI$CFGDIR\fP is replaced by the path of the highest priority
83+
configuration directory found (where clush.conf resides). The default confdir
84+
value enables both system\-wide and any installed user configuration (thanks
85+
to \fI$CFGDIR\fP). Duplicate directory paths are ignored.
86+
.TP
7487
.B connect_timeout
7588
Timeout in seconds to allow a connection to establish. This parameter is
7689
passed to ssh. If set to \fI0\fP, no timeout occurs.
7790
.TP
91+
.B command_prefix
92+
Command prefix. Generally used for specific run modes, for example to
93+
implement \fBsudo\fP(8) support.
94+
.TP
7895
.B command_timeout
7996
Timeout in seconds to allow a command to complete since the connection has
8097
been established. This parameter is passed to ssh. In addition, the
@@ -110,6 +127,11 @@ header? (\fIyes\fP/\fIno\fP)
110127
.B maxrc
111128
Should \fBclush\fP return the largest of command return codes? (yes/no)
112129
.TP
130+
.B password_prompt
131+
Enable password prompt and password forwarding to stdin? (yes/no) Generally
132+
used for specific run modes, for example to implement interactive
133+
\fBsudo\fP(8) support.
134+
.TP
113135
.B verbosity
114136
Set the verbosity level: \fI0\fP (quiet), \fI1\fP (default), \fI2\fP (verbose) or more
115137
(debug).
@@ -139,10 +161,21 @@ Same a rsh_path for rcp command. (Default is \fIrcp\fP)
139161
.TP
140162
.B rsh_options
141163
Set additional options to pass to the underlying rsh/rcp command.
142-
.TP
143-
.B sudo_command
144-
sudo command for use with \fI\-\-sudo\fP
145164
.UNINDENT
165+
.SS Run modes
166+
.sp
167+
Since version 1.9, clush has support for run modes, which are special
168+
\fBclush.conf\fP(5) settings with a given name. Two run modes are provided in
169+
example configuration files that can be copied and modified. They implement
170+
password\-based authentication with \fBsshpass\fP(1) and support of interactive
171+
\fBsudo\fP(8) with password.
172+
.sp
173+
To use a run mode with \fBclush \-\-mode\fP, install a configuration file in one of
174+
\fBclush.conf\fP(5)\(aqs \fIconfdir\fP (usually \fBclush.conf.d\fP). Only configuration
175+
files ending in \fI\&.conf\fP are scanned. If the user running \fBclush\fP(1) doesn\(aqt
176+
have read access to a configuration file, is it ignored. When \fB\-\-mode\fP is
177+
specified, you can display all available run modes for the current user by
178+
enabling debug mode (\fB\-d\fP).
146179
.SH EXAMPLES
147180
.sp
148181
Simple configuration file.
@@ -157,14 +190,16 @@ color: auto
157190
fd_max: 10240
158191
maxrc: no
159192
node_count: yes
193+
confdir: /etc/clustershell/clush.conf.d
160194

161195
.fi
162196
.sp
163197
.SH FILES
164198
.INDENT 0.0
165199
.TP
166-
.B \fI/etc/clustershell/clush.conf\fP
167-
System\-wide clush configuration file.
200+
.B \fI$CLUSTERSHELL_CFGDIR/clush.conf\fP
201+
Global clush configuration file. If $CLUSTERSHELL_CFGDIR is not defined,
202+
\fI/etc/clustershell/clush.conf\fP is used instead.
168203
.TP
169204
.B \fI$XDG_CONFIG_HOME/clustershell/clush.conf\fP
170205
User configuration file for clush. If $XDG_CONFIG_HOME is not defined,
@@ -184,7 +219,7 @@ from \fIclush.conf\fP\&. External commands whose outputs were used by \fBclush\
184219
\fBgroups.conf\fP(5).
185220
.SH SEE ALSO
186221
.sp
187-
\fBclush\fP(1), \fBgroups.conf\fP(5).
222+
\fBclush\fP(1), \fBgroups.conf\fP(5), \fBsshpass\fP(1), \fBsudo\fP(8).
188223
.sp
189224
\fI\%http://clustershell.readthedocs.org/\fP
190225
.SH AUTHOR

0 commit comments

Comments
 (0)