Skip to content

Commit 8930dd1

Browse files
committed
Add the possibility of comma-separated groups and users
1 parent a104f41 commit 8930dd1

File tree

6 files changed

+50
-23
lines changed

6 files changed

+50
-23
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
SSHPROXY_VERSION ?= 1.3.7
1+
SSHPROXY_VERSION ?= 1.3.8
22
SSHPROXY_GIT_URL ?= github.com/cea-hpc/sshproxy
33

44
prefix ?= /usr

config/sshproxy.yaml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,15 @@
127127
# default:
128128
# dest: ["host5:4222"]
129129

130-
# Each option can be overridden for a Unix group of users.
130+
# Each option can be overridden for a Unix group of users. Multiple groups can
131+
# be defined on the same line, separated by commas.
131132
# If a user is in multiple groups and these groups are defined in the
132133
# configuration, the configuration of a previous group will be overridden by the
133134
# next ones.
134135
# The parameters defined in a "users" option (see below) will be applied last
135136
# and override groups parameters.
136137
#groups:
137-
# foo:
138+
# foo,bar:
138139
# debug: true
139140
# log: /tmp/sshproxy-foo/{user}.log
140141
# # An associative array is used to specify environment, SSH options or
@@ -149,9 +150,10 @@
149150
# dest: [hostx]
150151

151152
# Each option can also be overridden for a specific user (eg. for debugging
152-
# purpose).
153+
# purpose). Multiple users can be defined on the same line, separated by
154+
# commas.
153155
#users:
154-
# foo:
156+
# foo,bar:
155157
# debug: true
156158
# log: /tmp/sshproxy-{user}.log
157159
# dump: /tmp/sshproxy-{user}-{time}.dump

doc/sshproxy.yaml.txt

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,16 @@ For example if we want to save debug messages for the 'foo' group we define:
193193
foo:
194194
debug: true
195195

196+
It is possible to override the same options for multiple groups in a single
197+
line, with comma-separated groups.
198+
199+
For example, if we want to save debug messages for the 'foo' and 'bar' groups
200+
we define:
201+
202+
groups:
203+
foo,bar:
204+
debug: true
205+
196206
Routes, environment or SSH options can also be defined:
197207

198208
groups:
@@ -204,7 +214,7 @@ Routes, environment or SSH options can also be defined:
204214
ssh:
205215
args: ["-vvv", "-Y"]
206216

207-
The routes are fully overridden and not merged with previous defined ones.
217+
The routes are merged with previous defined ones.
208218

209219
If a user belongs to several groups and these groups are defined in the
210220
configuration file, each setting can be overridden by the next group.
@@ -220,13 +230,14 @@ in '/var/log/sshproxy/admin/\{user}.log' with the following configuration:
220230
log: /var/log/sshproxy/admin/{user}.log
221231

222232
We can also override the parameters for a specific user with the 'users'
223-
associative array.
233+
associative array. We can also override the parameters for multiple users in a
234+
single line, with comma-separated users.
224235

225-
For example if we want to save debug messages for the 'foo' user we
226-
define:
236+
For example if we want to save debug messages for the 'foo' and the 'bar'
237+
users we define:
227238

228239
users:
229-
foo:
240+
foo,bar:
230241
debug: true
231242

232243
As for the groups, we can modify routes, environment or SSH options:

misc/sshproxy.spec

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
%global debug_package %{nil}
44

55
Name: sshproxy
6-
Version: 1.3.7
6+
Version: 1.3.8
77
Release: 1%{?dist}
88
Summary: SSH proxy
99
License: CeCILL-B
@@ -51,7 +51,10 @@ install -p -m 0644 config/sshproxy.yaml %{buildroot}%{_sysconfdir}/sshproxy
5151
%{_mandir}/man8/sshproxy-replay.8*
5252

5353
%changelog
54-
* Fri Apr 09 2021 Cyril Servant <[email protected]> - 1.3.7-1
54+
* Wed Jul 28 2021 Cyril Servant <[email protected]> - 1.3.8-1
55+
- sshproxy 1.3.8
56+
57+
* Tue Jun 29 2021 Cyril Servant <[email protected]> - 1.3.7-1
5558
- sshproxy 1.3.7
5659

5760
* Fri Apr 09 2021 Cyril Servant <[email protected]> - 1.3.6-1

pkg/utils/config.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"fmt"
1515
"io/ioutil"
1616
"regexp"
17+
"strings"
1718
"time"
1819

1920
"gopkg.in/yaml.v2"
@@ -170,9 +171,9 @@ func replace(src string, replacer *patternReplacer) string {
170171
}
171172

172173
// LoadConfig load configuration file and adapt it according to specified user.
173-
func LoadConfig(filename, username, sid string, start time.Time, groups map[string]bool) (*Config, error) {
174+
func LoadConfig(filename, currentUsername, sid string, start time.Time, groups map[string]bool) (*Config, error) {
174175
patterns := map[string]*patternReplacer{
175-
"{user}": {regexp.MustCompile(`{user}`), username},
176+
"{user}": {regexp.MustCompile(`{user}`), currentUsername},
176177
"{sid}": {regexp.MustCompile(`{sid}`), sid},
177178
"{time}": {regexp.MustCompile(`{time}`), start.Format(time.RFC3339Nano)},
178179
}
@@ -198,17 +199,27 @@ func LoadConfig(filename, username, sid string, start time.Time, groups map[stri
198199
config.SSH.Args = defaultSSHArgs
199200
}
200201

201-
for groupname, groupconfig := range config.Groups {
202-
if groups[groupname] {
203-
if err := parseSubConfig(&config, &groupconfig); err != nil {
204-
return nil, err
202+
for groupnames, groupconfig := range config.Groups {
203+
for _, groupname := range strings.Split(groupnames, ",") {
204+
if groups[groupname] {
205+
if err := parseSubConfig(&config, &groupconfig); err != nil {
206+
return nil, err
207+
}
208+
// no need to to parse the same subconfig twice
209+
break
205210
}
206211
}
207212
}
208213

209-
if userconfig, present := config.Users[username]; present {
210-
if err := parseSubConfig(&config, &userconfig); err != nil {
211-
return nil, err
214+
for usernames, userconfig := range config.Users {
215+
for _, username := range strings.Split(usernames, ",") {
216+
if username == currentUsername {
217+
if err := parseSubConfig(&config, &userconfig); err != nil {
218+
return nil, err
219+
}
220+
// no need to to parse the same subconfig twice
221+
break
222+
}
212223
}
213224
}
214225

test/centos-image/gateway.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,14 +56,14 @@ routes:
5656
dest: ["server3"]
5757
5858
groups:
59-
user1:
59+
user1,unknowngroup:
6060
routes:
6161
service2:
6262
source: ["gateway1:2023"]
6363
dest: ["server2"]
6464
6565
users:
66-
user2:
66+
unknownuser,user2:
6767
routes:
6868
service3:
6969
source: ["gateway1:2024"]

0 commit comments

Comments
 (0)