Skip to content

Commit 9278896

Browse files
committed
Bugfix: ordering maps of groups and users. Warning: there is a
configuration change! Users and groups ar now in a table, so must be prefixed with a "-"
1 parent ff7b426 commit 9278896

File tree

6 files changed

+40
-33
lines changed

6 files changed

+40
-33
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.8
1+
SSHPROXY_VERSION ?= 1.4.0
22
SSHPROXY_GIT_URL ?= github.com/cea-hpc/sshproxy
33

44
prefix ?= /usr

config/sshproxy.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@
135135
# The parameters defined in a "users" option (see below) will be applied last
136136
# and override groups parameters.
137137
#groups:
138-
# foo,bar:
138+
# - foo,bar:
139139
# debug: true
140140
# log: /tmp/sshproxy-foo/{user}.log
141141
# # An associative array is used to specify environment, SSH options or
@@ -153,7 +153,7 @@
153153
# purpose). Multiple users can be defined on the same line, separated by
154154
# commas.
155155
#users:
156-
# foo,bar:
156+
# - foo,bar:
157157
# debug: true
158158
# log: /tmp/sshproxy-{user}.log
159159
# dump: /tmp/sshproxy-{user}-{time}.dump

doc/sshproxy.yaml.txt

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ Each of the previous parameters can be overridden for a group thanks to the
190190
For example if we want to save debug messages for the 'foo' group we define:
191191

192192
groups:
193-
foo:
193+
- foo:
194194
debug: true
195195

196196
It is possible to override the same options for multiple groups in a single
@@ -200,17 +200,16 @@ For example, if we want to save debug messages for the 'foo' and 'bar' groups
200200
we define:
201201

202202
groups:
203-
foo,bar:
203+
- foo,bar:
204204
debug: true
205205

206206
Routes, environment or SSH options can also be defined:
207207

208208
groups:
209-
foo:
209+
- foo:
210210
routes:
211211
default:
212212
dest: [hostx]
213-
214213
ssh:
215214
args: ["-vvv", "-Y"]
216215

@@ -223,10 +222,9 @@ For example, if a user is in the 'admin' and 'users' groups the logs will be
223222
in '/var/log/sshproxy/admin/\{user}.log' with the following configuration:
224223

225224
groups:
226-
users:
225+
- users:
227226
log: /var/log/sshproxy/users/{user}.log
228-
229-
admin:
227+
- admin:
230228
log: /var/log/sshproxy/admin/{user}.log
231229

232230
We can also override the parameters for a specific user with the 'users'
@@ -237,13 +235,13 @@ For example if we want to save debug messages for the 'foo' and the 'bar'
237235
users we define:
238236

239237
users:
240-
foo,bar:
238+
- foo,bar:
241239
debug: true
242240

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

245243
users:
246-
foo:
244+
- foo:
247245
ssh:
248246
args: ["-vvv", "-Y"]
249247

@@ -275,13 +273,13 @@ routes:
275273
route_select: random
276274

277275
groups:
278-
admin:
276+
- admin:
279277
routes:
280278
default:
281279
dest: [login0]
282280

283281
users:
284-
user1234:
282+
- user1234:
285283
debug: true
286284
dump: /var/spool/sshproxy/{user}-{time}-{sid}.dump
287285
------------------------------------------------------------------------------

misc/sshproxy.spec

Lines changed: 4 additions & 1 deletion
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.8
6+
Version: 1.4.0
77
Release: 1%{?dist}
88
Summary: SSH proxy
99
License: CeCILL-B
@@ -51,6 +51,9 @@ install -p -m 0644 config/sshproxy.yaml %{buildroot}%{_sysconfdir}/sshproxy
5151
%{_mandir}/man8/sshproxy-replay.8*
5252

5353
%changelog
54+
* Mon Aug 16 2021 Cyril Servant <cyril.servant@cea.fr> - 1.4.0-1
55+
- sshproxy 1.4.0
56+
5457
* Wed Jul 28 2021 Cyril Servant <cyril.servant@cea.fr> - 1.3.8-1
5558
- sshproxy 1.3.8
5659

pkg/utils/config.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@ type Config struct {
4141
SSH sshConfig
4242
Environment map[string]string
4343
Routes map[string]*RouteConfig
44-
Users map[string]subConfig
45-
Groups map[string]subConfig
44+
Users []map[string]subConfig
45+
Groups []map[string]subConfig
4646
}
4747

4848
// RouteConfig represents the configuration of a route. Dest is mandatory,
@@ -199,26 +199,32 @@ func LoadConfig(filename, currentUsername, sid string, start time.Time, groups m
199199
config.SSH.Args = defaultSSHArgs
200200
}
201201

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
202+
// we have to use a slice of maps in order to have ordered maps
203+
for _, groupconfigs := range config.Groups {
204+
for groupnames, groupconfig := range groupconfigs {
205+
for _, groupname := range strings.Split(groupnames, ",") {
206+
if groups[groupname] {
207+
if err := parseSubConfig(&config, &groupconfig); err != nil {
208+
return nil, err
209+
}
210+
// no need to to parse the same subconfig twice
211+
break
207212
}
208-
// no need to to parse the same subconfig twice
209-
break
210213
}
211214
}
212215
}
213216

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
217+
// we have to use a slice of maps in order to have ordered maps
218+
for _, userconfigs := range config.Users {
219+
for usernames, userconfig := range userconfigs {
220+
for _, username := range strings.Split(usernames, ",") {
221+
if username == currentUsername {
222+
if err := parseSubConfig(&config, &userconfig); err != nil {
223+
return nil, err
224+
}
225+
// no need to to parse the same subconfig twice
226+
break
219227
}
220-
// no need to to parse the same subconfig twice
221-
break
222228
}
223229
}
224230
}

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,unknowngroup:
59+
- user1,unknowngroup:
6060
routes:
6161
service2:
6262
source: ["gateway1:2023"]
6363
dest: ["server2"]
6464
6565
users:
66-
unknownuser,user2:
66+
- unknownuser,user2:
6767
routes:
6868
service3:
6969
source: ["gateway1:2024"]

0 commit comments

Comments
 (0)