File: configurations.md

package info (click to toggle)
erlang 1%3A27.3.4.1%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 225,000 kB
  • sloc: erlang: 1,658,966; ansic: 405,769; cpp: 177,850; xml: 82,435; makefile: 15,031; sh: 14,401; lisp: 9,812; java: 8,603; asm: 6,541; perl: 5,836; python: 5,484; sed: 72
file content (334 lines) | stat: -rw-r--r-- 11,528 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
<!--
%CopyrightBegin%

Copyright Ericsson AB 2023-2024. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

%CopyrightEnd%
-->
# Configuration in SSH

## Introduction

The OTP SSH app can be configurated by a large amount of _Options_. This chapter
will not go into details of what each of the options does. It will however
describe and define different ways by which they could be entered.

Options for hardening are described in the [Hardening SSH](hardening.md)
chapter. How the options for algorithm configuration interact are described in
the [Configuring algorithms in SSH](configure_algos.md) chapter.

## Options configuration

There are from OTP-23.0 two main ways to set an option:

- Like before, in the `Options` parameter in the Erlang code in a call to for
  example `ssh:daemon/3` or `ssh:connect/3` or any of their variants. Example:

  ```erlang
  ssh:connect(22, [{user,"foo"}])
  ```

- In [OTP Configuration Parameters](`e:kernel:config.md`):

  - In the erl command line:

    ```text
    erl -ssh user \"foo\"
    ```

  - In the `ssh.app` file, in the `env` part

    ```erlang
    {application, ssh,
     [{description, "SSH-2 for Erlang/OTP"},
      {vsn, "4.9"},
      {modules, [ssh,
            ...
    	     ssh_xfer]},
      {registered, []},
      {applications, [kernel, stdlib, crypto, public_key]},
      {env, [{user, "bar"]}, % <<<<<<<<<<<<<<<<<<<<<<<<<<<<<< HERE
      {mod, {ssh_app, []}},
           ...
    ```

  - In a .config file:

    ```text
    erl -config ex1
    ```

    where `ex1.config` contains:

    ```erlang
    [
    {ssh, [{user, "foo"}]}
    ].
    ```

  If the option is intended only for a server or for a client, it may be set in
  this way:

  ```erlang
  [
  {ssh, [{server_options,[{user, "foo"}]},
         {client_options,[{user, "bar"}]}
  ].
  ```

  A server (daemon) will use the user name `foo`, and a client will use the name
  `bar`.

## Precedence

If an option is set in more than one way, what happens?

There is an ordering, which is:

- Level 0: Hard-coded default values in the OTP SSH source code
- Level 1: [OTP Configuration Parameters](`e:kernel:config.md`)
- Level 2: Options in the [OTP Configuration Parameters](`e:kernel:config.md`)
  `server_options` or `client_options`
- Level 3: Options in argument list to a function

If the same option is set at two different levels, the one at the highest level
is used.

The only exception is the
[modify_algorithms](`t:ssh:modify_algorithms_common_option/0`) common option.
They are all applied in ascending level order on the set of algorithms. So a
`modify_algorithms` on level one is applied before one of level two and so on.

If there is an
[preferred_algorithms](`t:ssh:preferred_algorithms_common_option/0`) option on
some level the whole set is replaced by that in that option and _all
modify_algorithms are applied_ in level ordering.

The reason for applying all
[modify_algorithms](`t:ssh:modify_algorithms_common_option/0`) in level order,
is to enable the user to add an algorithm that has been removed from the default
set without code changes, only by adding an option in a config file. This can be
used to interoperate with legacy systems that still uses algorithms no longer
considered secure enough to be supported by default.

### Algorithm configuration

There is a [separate chapter](configure_algos.md#introduction) about how
[preferred_algorithms](`t:ssh:preferred_algorithms_common_option/0`) and
[modify_algorithms](`t:ssh:modify_algorithms_common_option/0`) co-operate. How
the different configuration levels affect them, is described here in this
section.

#### The ssh:start/0 function

If the application SSH is _not_ [started](`ssh:start/0`), the command
`ssh:default_algorithms/0` delivers the list of default (hardcoded) algorithms
with respect to the support in the current cryptolib.

If the application SSH _is_ [started](`ssh:start/0`), the command
`ssh:default_algorithms/0` delvers the list of algorithms after application of
level 0 and level 1 configurations.

Here is an example. The config-file has the following contents:

```text
$ cat ex2.config
[
 {ssh, [{preferred_algorithms, [{cipher, ['aes192-ctr']},
       			        {public_key, ['ssh-rsa']},
                                {kex, ['ecdh-sha2-nistp384']},
                                {mac, ['hmac-sha1']}]}]}
].
```

Erlang is started with `ex2.config` as configuration and we check the default
set of algorithms before starting ssh:

```text
$ erl -config ex2
Erlang/OTP 23 [RELEASE CANDIDATE 1] [erts-10.6.4] [source-96a0823109] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1] [hipe]

Eshell V10.6.4  (abort with ^G)
1> ssh:default_algorithms().
[{kex,['ecdh-sha2-nistp384','ecdh-sha2-nistp521',
       'ecdh-sha2-nistp256','diffie-hellman-group-exchange-sha256',
       'diffie-hellman-group16-sha512',
       'diffie-hellman-group18-sha512',
       'diffie-hellman-group14-sha256','curve25519-sha256',
       'curve25519-sha256@libssh.org','curve448-sha512',
       'diffie-hellman-group14-sha1',
       'diffie-hellman-group-exchange-sha1']},
 {public_key,['ecdsa-sha2-nistp384','ecdsa-sha2-nistp521',
              'ecdsa-sha2-nistp256','ssh-ed25519','ssh-ed448','ssh-rsa',
              'rsa-sha2-256','rsa-sha2-512','ssh-dss']},
 {cipher,[{client2server,['chacha20-poly1305@openssh.com',
                          'aes256-gcm@openssh.com','aes256-ctr','aes192-ctr',
                          'aes128-gcm@openssh.com','aes128-ctr','aes256-cbc',
                          'aes192-cbc','aes128-cbc','3des-cbc']},
          {server2client,['chacha20-poly1305@openssh.com',
                          'aes256-gcm@openssh.com','aes256-ctr','aes192-ctr',
                          'aes128-gcm@openssh.com','aes128-ctr','aes256-cbc',
                          'aes192-cbc','aes128-cbc','3des-cbc']}]},
 {mac,[{client2server,['hmac-sha2-256','hmac-sha2-512',
                       'hmac-sha1']},
       {server2client,['hmac-sha2-256','hmac-sha2-512',
                       'hmac-sha1']}]},
 {compression,[{client2server,[none,'zlib@openssh.com',zlib]},
               {server2client,[none,'zlib@openssh.com',zlib]}]}]
```

Note that the algorithms in the file `ex2.config` is not yet applied. They will
be when we start ssh:

```erlang
2> ssh:start().
ok
3> ssh:default_algorithms().
[{kex,['ecdh-sha2-nistp384']},
 {public_key,['ssh-rsa']},
 {cipher,[{client2server,['aes192-ctr']},
          {server2client,['aes192-ctr']}]},
 {mac,[{client2server,['hmac-sha1']},
       {server2client,['hmac-sha1']}]},
 {compression,[{client2server,[none,'zlib@openssh.com',zlib]},
               {server2client,[none,'zlib@openssh.com',zlib]}]}]
4>
```

We see that the algorithm set is changed to the one in the `ex2.config`. Since
`compression` is not specified in the file, the hard-coded default is still used
for that entry.

#### Establishing a connection (ssh:connect et al) or starting a daemon (ssh:daemon)

Both when the client establishes a connection with ssh:connect or other
functions, or a daemon is started with ssh:daemon, the option lists in the
function calls are also used.

If a client is started (ssh:connect et al), the environment variable
`client_options` is used. Similarly for a daemon the `server_options` variable
is handled.

If any [preferred_algorithms](`t:ssh:preferred_algorithms_common_option/0`) is
present, the one with the highest level is used, that is, the `Option` list
parameter has the highest priority. Then the
[modify_algorithms](`t:ssh:modify_algorithms_common_option/0`) on all levels in
order starting with level 0 are applied.

We continue the example above by connecting to a server and modifying the `kex`
algorithm set. We remove the only one (`'ecdh-sha2-nistp384'`) and add
`'curve25519-sha256@libssh.org'` by appending it to the now empty list:

```erlang
4> {ok,C} = ssh:connect(loopback, 22,
                        [{modify_algorithms,
                                 [{rm,
                                     [ {kex,['ecdh-sha2-nistp384']} ]
				  },
                                  {append,
			             [ {kex,['curve25519-sha256@libssh.org']} ]
				  }
				 ]
	                 }
                        ]).
{ok,>0.118.0>}
```

We check which algorithms are negotiated by the client and the server, and note
that the (only) `kex` algorithm `'curve25519-sha256@libssh.org'` was selected:

```erlang
5> ssh:connection_info(C, algorithms).
{algorithms,[{kex,'curve25519-sha256@libssh.org'},
             {hkey,'ssh-rsa'},
             {send_mac,'hmac-sha1'},
             {recv_mac,'hmac-sha1'},
             {encrypt,'aes192-ctr'},
             {decrypt,'aes192-ctr'},
             {compress,none},
             {decompress,none},
             {send_ext_info,false},
             {recv_ext_info,true}]}
```

#### Example of modify_algorithms handling

We will now check if the
[modify_algorithms](`t:ssh:modify_algorithms_common_option/0`) on a lower level
is applied to a
[preferred_algorithms](`t:ssh:preferred_algorithms_common_option/0`) on a higher
level. We will do that by enabling the `ssh-dss` algorithm that is supported,
but not in the default set.

The config file `ex3.config` has the contents:

```erlang
[
 {ssh, [{modify_algorithms,
         [ {prepend, [{public_key, ['ssh-dss']}]} ]
        }]}
].
```

A newly started erlang shell shows that no `'ssh-dss'` is present in the
`public_key` entry:

```erlang
1> proplists:get_value(public_key, ssh:default_algorithms()).
['ecdsa-sha2-nistp384','ecdsa-sha2-nistp521',
 'ecdsa-sha2-nistp256','ssh-ed25519','ssh-ed448',
 'rsa-sha2-256','rsa-sha2-512','ssh-rsa']
2>
```

A call to `ssh:connect/3` removes all algorithms but one of each type:

```erlang
2> ssh:start().
ok
3> {ok,C} = ssh:connect(loopback, 22,
                        [{preferred_algorithms,
                         [{public_key, ['ecdsa-sha2-nistp256']},
			  {kex, ['ecdh-sha2-nistp256']},
		          {cipher, ['chacha20-poly1305@openssh.com']},
			  {mac, ['hmac-sha2-256']},
			  {compression, [none]}
			  ]}
			 ]).
{ok,<0.101.0>}
4> ssh:connection_info(C,algorithms).
{algorithms,[{kex,'ecdh-sha2-nistp256'},
             {hkey,'ssh-dss'},
             {send_mac,'chacha20-poly1305@openssh.com'},
             {recv_mac,'chacha20-poly1305@openssh.com'},
             {encrypt,'chacha20-poly1305@openssh.com'},
             {decrypt,'chacha20-poly1305@openssh.com'},
             {compress,none},
             {decompress,none},
             {send_ext_info,false},
             {recv_ext_info,true}]}
5>
```

But `'ssh-dss'` is selected although the call inserted _only_
`'ecdsa-sha2-nistp256'` as acceptable.

This example showed that we could augment the set of algorithms with a
config-file without the need to change the actual call.

For demonstration purposes we used `prepend` instead of `append`. This forces
the negotiation to select `ssh-dss` since the the full list of public key
algorithms was `['ssh-dss','ecdsa-sha2-nistp256']`. Normally it is safer to
append a non-default algorithm.