Skip to content
This repository was archived by the owner on Oct 2, 2022. It is now read-only.

Commit 20f37e6

Browse files
authored
Compatibility fixes with ContainerSSH 0.3 (#2)
1 parent 6bbd16f commit 20f37e6

File tree

10 files changed

+472
-18
lines changed

10 files changed

+472
-18
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Changelog
2+

appconfig.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ import (
1313

1414
// AppConfig is the root configuration object of ContainerSSH.
1515
type AppConfig struct {
16+
// Listen is an alias for ssh.listen. Its usage is deprecated.
17+
Listen string `json:"listen,omitempty" yaml:"listen,omitempty" default:""`
1618
// SSH contains the configuration for the SSH server.
1719
// swagger:ignore
1820
SSH sshserver.Config `json:"ssh" yaml:"ssh" comment:"SSH configuration"`
@@ -42,3 +44,16 @@ type AppConfig struct {
4244
// KubeRun contains the configuration for the kuberun backend.
4345
KubeRun kuberun.Config `json:"kuberun" yaml:"kuberun" comment:"Kubernetes configuration to use when the Kubernetes run backend is used."`
4446
}
47+
48+
func (cfg *AppConfig) FixCompatibility(logger log.Logger) error {
49+
if cfg.Listen != "" {
50+
if cfg.SSH.Listen == "" || cfg.SSH.Listen == "0.0.0.0:2222" {
51+
logger.Warningf("you are using the deprecated 'listen' option for SSH listen socket instead of the new 'ssh -> listen', please change your configuration")
52+
cfg.SSH.Listen = cfg.Listen
53+
cfg.Listen = ""
54+
} else {
55+
logger.Warningf("you are using both the deprecated 'listen' and the new 'ssh -> listen' options, the new option takes precedence")
56+
}
57+
}
58+
return nil
59+
}

compatibility_test.go

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
package configuration_test
2+
3+
import (
4+
"context"
5+
"os"
6+
"testing"
7+
8+
"github.com/containerssh/log"
9+
"github.com/stretchr/testify/assert"
10+
11+
"github.com/containerssh/configuration"
12+
)
13+
14+
// Test03Compatibility tests if a configuration file for ContainerSSH version 0.3 can be read.
15+
func Test03Compatibility(t *testing.T) {
16+
logger, err := log.New(
17+
log.Config{
18+
Level: log.LevelDebug,
19+
Format: "text",
20+
},
21+
"config",
22+
os.Stdout,
23+
)
24+
assert.NoError(t, err)
25+
26+
logger.Infof("FYI: the deprecation notice in this test is intentional")
27+
28+
testFile, err := os.Open("data/0.3.yaml")
29+
assert.NoError(t, err)
30+
reader, err := configuration.NewReaderLoader(
31+
testFile,
32+
logger,
33+
configuration.FormatYAML,
34+
)
35+
assert.NoError(t, err)
36+
37+
config := configuration.AppConfig{}
38+
err = reader.Load(context.Background(), &config)
39+
assert.NoError(t, err)
40+
41+
assert.Equal(t, "0.0.0.0:2222", config.SSH.Listen)
42+
}

data/0.3.yaml

Lines changed: 241 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,241 @@
1+
listen: 0.0.0.0:2222
2+
ssh:
3+
ciphers:
4+
- chacha20-poly1305@openssh.com
5+
- aes256-gcm@openssh.com
6+
- aes128-gcm@openssh.com
7+
- aes256-ctr
8+
- aes192-ctr
9+
- aes128-ctr
10+
kex:
11+
- curve25519-sha256@libssh.org
12+
- ecdh-sha2-nistp521
13+
- ecdh-sha2-nistp384
14+
- ecdh-sha2-nistp256
15+
macs:
16+
- hmac-sha2-256-etm@openssh.com
17+
- hmac-sha2-256
18+
- hmac-sha1
19+
- hmac-sha1-96
20+
hostkeys: []
21+
configserver:
22+
timeout: 2s
23+
url: ""
24+
cacert: ""
25+
cert: ""
26+
key: ""
27+
auth:
28+
url: ""
29+
cacert: ""
30+
timeout: 2s
31+
cert: ""
32+
key: ""
33+
password: true
34+
pubkey: false
35+
backend: dockerrun
36+
dockerrun:
37+
host: unix:///var/run/docker.sock
38+
cacert: ""
39+
cert: ""
40+
key: ""
41+
config:
42+
container:
43+
hostname: ""
44+
domainname: ""
45+
user: ""
46+
attachstdin: false
47+
attachstdout: false
48+
attachstderr: false
49+
exposedports: {}
50+
tty: false
51+
openstdin: false
52+
stdinonce: false
53+
env: []
54+
cmd: []
55+
healthcheck: null
56+
argsescaped: false
57+
image: janoszen/containerssh-image
58+
volumes: {}
59+
workingdir: ""
60+
entrypoint: []
61+
networkdisabled: false
62+
macaddress: ""
63+
onbuild: []
64+
labels: {}
65+
stopsignal: ""
66+
stoptimeout: null
67+
shell: []
68+
host:
69+
binds: []
70+
containeridfile: ""
71+
logconfig:
72+
type: ""
73+
config: {}
74+
networkmode: ""
75+
portbindings: {}
76+
restartpolicy:
77+
name: ""
78+
maximumretrycount: 0
79+
autoremove: false
80+
volumedriver: ""
81+
volumesfrom: []
82+
capadd: []
83+
capdrop: []
84+
dns: []
85+
dnsoptions: []
86+
dnssearch: []
87+
extrahosts: []
88+
groupadd: []
89+
ipcmode: ""
90+
cgroup: ""
91+
links: []
92+
oomscoreadj: 0
93+
pidmode: ""
94+
privileged: false
95+
publishallports: false
96+
readonlyrootfs: false
97+
securityopt: []
98+
storageopt: {}
99+
tmpfs: {}
100+
utsmode: ""
101+
usernsmode: ""
102+
shmsize: 0
103+
sysctls: {}
104+
runtime: ""
105+
consolesize:
106+
- 0
107+
- 0
108+
isolation: ""
109+
resources:
110+
cpushares: 0
111+
memory: 0
112+
nanocpus: 0
113+
cgroupparent: ""
114+
blkioweight: 0
115+
blkioweightdevice: []
116+
blkiodevicereadbps: []
117+
blkiodevicewritebps: []
118+
blkiodevicereadiops: []
119+
blkiodevicewriteiops: []
120+
cpuperiod: 0
121+
cpuquota: 0
122+
cpurealtimeperiod: 0
123+
cpurealtimeruntime: 0
124+
cpusetcpus: ""
125+
cpusetmems: ""
126+
devices: []
127+
diskquota: 0
128+
kernelmemory: 0
129+
memoryreservation: 0
130+
memoryswap: 0
131+
memoryswappiness: null
132+
oomkilldisable: null
133+
pidslimit: 0
134+
ulimits: []
135+
cpucount: 0
136+
cpupercent: 0
137+
iomaximumiops: 0
138+
iomaximumbandwidth: 0
139+
mounts: []
140+
init: null
141+
initpath: ""
142+
network:
143+
endpointsconfig: {}
144+
containername: ""
145+
subsystems:
146+
sftp: /usr/lib/openssh/sftp-server
147+
disableCommand: false
148+
kuberun:
149+
connection:
150+
host: kubernetes.default.svc
151+
path: /api
152+
username: ""
153+
password: ""
154+
insecure: false
155+
serverName: ""
156+
certFile: /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
157+
keyFile: ""
158+
cacertFile: ""
159+
cert: ""
160+
key: ""
161+
cacert: ""
162+
bearerToken: ""
163+
bearerTokenFile: ""
164+
qps: 5
165+
burst: 10
166+
timeout: 0s
167+
pod:
168+
namespace: default
169+
consoleContainerNumber: 0
170+
podSpec:
171+
volumes: []
172+
initcontainers: []
173+
containers:
174+
- name: shell
175+
image: janoszen/containerssh-image
176+
command: []
177+
args: []
178+
workingdir: ""
179+
ports: []
180+
envfrom: []
181+
env: []
182+
resources:
183+
limits: {}
184+
requests: {}
185+
volumemounts: []
186+
volumedevices: []
187+
livenessprobe: null
188+
readinessprobe: null
189+
startupprobe: null
190+
lifecycle: null
191+
terminationmessagepath: ""
192+
terminationmessagepolicy: ""
193+
imagepullpolicy: ""
194+
securitycontext: null
195+
stdin: false
196+
stdinonce: false
197+
tty: false
198+
ephemeralcontainers: []
199+
restartpolicy: ""
200+
terminationgraceperiodseconds: null
201+
activedeadlineseconds: null
202+
dnspolicy: ""
203+
nodeselector: {}
204+
serviceaccountname: ""
205+
deprecatedserviceaccount: ""
206+
automountserviceaccounttoken: null
207+
nodename: ""
208+
hostnetwork: false
209+
hostpid: false
210+
hostipc: false
211+
shareprocessnamespace: null
212+
securitycontext: null
213+
imagepullsecrets: []
214+
hostname: ""
215+
subdomain: ""
216+
affinity: null
217+
schedulername: ""
218+
tolerations: []
219+
hostaliases: []
220+
priorityclassname: ""
221+
priority: null
222+
dnsconfig: null
223+
readinessgates: []
224+
runtimeclassname: null
225+
enableservicelinks: null
226+
preemptionpolicy: null
227+
overhead: {}
228+
topologyspreadconstraints: []
229+
sethostnameasfqdn: null
230+
subsystems:
231+
sftp: /usr/lib/openssh/sftp-server
232+
disableCommand: false
233+
timeout: 1m0s
234+
log:
235+
level: info
236+
metrics:
237+
enable: false
238+
listen: 0.0.0.0:9100
239+
path: /metrics
240+
geoip:
241+
maxmind-geoip2-file: /var/lib/GeoIP/GeoIP2-Country.mmdb

format.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package configuration
2+
3+
import (
4+
"fmt"
5+
)
6+
7+
// Format describes the format of the file being read.
8+
type Format string
9+
10+
const (
11+
// FormatJSON reads/writes in JSON format
12+
FormatJSON Format = "json"
13+
// FormatYAML reads/writes in YAML format
14+
FormatYAML Format = "yaml"
15+
)
16+
17+
// Validate validates the given format.
18+
func (f Format) Validate() error {
19+
switch f {
20+
case FormatJSON:
21+
fallthrough
22+
case FormatYAML:
23+
return nil
24+
default:
25+
return fmt.Errorf("invalid format: %s", f)
26+
}
27+
}

go.mod

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,19 +4,18 @@ go 1.14
44

55
require (
66
github.com/containerssh/auditlog v0.9.3
7-
github.com/containerssh/auth v0.9.1
7+
github.com/containerssh/auth v0.9.2
88
github.com/containerssh/dockerrun v0.9.1
99
github.com/containerssh/geoip v0.9.3
1010
github.com/containerssh/http v0.9.1
1111
github.com/containerssh/kuberun v0.9.1
12-
github.com/containerssh/log v0.9.4
13-
github.com/containerssh/metrics v0.9.1
12+
github.com/containerssh/log v0.9.6
13+
github.com/containerssh/metrics v0.9.2
1414
github.com/containerssh/service v0.9.0
1515
github.com/containerssh/sshserver v0.9.9
1616
github.com/containerssh/structutils v0.9.0
17-
github.com/google/go-cmp v0.5.2
17+
github.com/google/go-cmp v0.5.4
1818
github.com/stretchr/testify v1.6.1
19-
gopkg.in/yaml.v2 v2.4.0 // indirect
2019
gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776
2120
gotest.tools v2.2.0+incompatible
2221
)

0 commit comments

Comments
 (0)