-
Notifications
You must be signed in to change notification settings - Fork 753
TACACSPLUS_PASSKEY_ENCRYPTION support Part - I #3027
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
2a61142
3e9ff3d
4685761
a59ac2e
8681114
2fbb377
877a337
0e954fb
d4f11da
476df50
243aea5
6d44a02
1b5812e
cbdcade
b2a4571
eab3806
43f523f
7916ae0
519ab30
b0166c0
f4636f8
39dc324
ecc6b63
2d002d8
c54d597
ab6f427
cb9829e
4edc678
8b99b92
c72e7d4
41ed473
73fbfcf
dfc4aec
85e9041
a062307
b5f0994
d18f30f
af22cf3
2ef202f
76a4a93
8251fcb
beee7ee
5602145
d1f70c6
1b33818
0e65caf
9fbee7e
4a02f3c
b4367ef
a3fe107
2e6fb56
754fa7d
43d41f1
710ad66
bad694d
ef6ef7b
f1d9eda
e35a14a
38acd5c
39dfc85
5ceda92
c55ad97
70a9fb2
4c4797b
ae6c021
0bfb9d7
6fc974c
70ea9ad
439d5da
c4ac296
8f704c2
e424eb9
770d1a0
586cd98
b24d3a9
27591fa
57f90ab
57af667
d8a9dde
8f9ed9e
4de20b3
619f78b
13af66e
68e0217
88bfeb2
e366e5c
8a589e9
7c778dd
53b684e
d1460d2
ef86569
de02a35
210a468
f44b740
434e2e4
8a8d5f0
e0d060c
3d76f6b
c02e0f1
c495721
31663e9
3c6edf6
d2f8e14
603fd11
cce4bb8
f7de2a5
f37afcf
9b5b6e9
6496305
b7e3625
d8e58d1
4c9dfd0
bc61f78
c8a0dee
a83517f
657241e
1d70e7f
a57cd50
e4f1d3f
157cf3a
e3c0b1d
d8c4327
5bf0d2f
7ffde34
6a2c26e
27649ef
d6fb602
2b76671
45e910e
ae354f5
7845b5e
cac3dd4
1294488
2fb69a6
0a225b7
c50dd46
1ae5f24
27e06a5
055a761
79e0bb2
8778e68
f87274f
3a58e7c
5f24c66
6960cdb
26b40a6
aac73f7
4cdc148
78454de
7cb1b32
33e0373
5a3f2b4
4bc1969
8d7dfc5
6817b21
00ef4a4
a97e40b
9b50790
95372fc
1a1695d
aca8b17
5425e0b
001cab4
e9d3075
aca3aba
9eca6de
62138d7
230f8e9
76c99c0
74593f4
5ae1360
7c11649
c374dc6
d47ddd0
1cd8914
34fe1bc
30b6b3b
deda670
b15f73a
53a0ec8
3baf552
56d309b
25443e2
b6ef169
a37733a
205011e
2e6888b
807d687
965b72f
fdb404e
b0166c4
b91143b
cbf2c7b
d2dbbec
35716ef
8d60c11
00d5294
910dd2f
aadc485
450bb30
f204f99
31e96f4
786aaed
a7e5fab
f302486
1d47906
c54b6dd
ba21682
43f0b75
5f5fe24
6b97567
567ca49
b7cb82f
8bdde3c
8aa893e
6c8ccab
7b5ba13
5f2fcfe
9c970ed
ed86150
8631235
8c3deeb
984f1c6
931077d
0e8aa16
291938d
98a15e2
894db81
0beb33c
7aff27e
7b19ce5
c295f20
b0f6f90
f248b92
d05a119
1d612ef
6a94350
4bcb8e4
64b77d1
d8b3bcb
764a74b
9ae6ad4
4e892ed
4753d3c
d533482
84fd523
bd0111d
67a3fd0
b1f8869
f4d7031
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,16 +1,21 @@ | ||
| import click | ||
| import ipaddress | ||
| import re | ||
| import subprocess | ||
| from swsscommon.swsscommon import ConfigDBConnector | ||
| from .validated_config_db_connector import ValidatedConfigDBConnector | ||
| from jsonpatch import JsonPatchConflict | ||
| from jsonpointer import JsonPointerException | ||
| import utilities_common.cli as clicommon | ||
| from sonic_py_common.security_cipher import master_key_mgr | ||
|
|
||
| ADHOC_VALIDATION = True | ||
| RADIUS_MAXSERVERS = 8 | ||
| RADIUS_PASSKEY_MAX_LEN = 65 | ||
| VALID_CHARS_MSG = "Valid chars are ASCII printable except SPACE, '#', and ','" | ||
| TACACS_PASSKEY_MAX_LEN = 65 | ||
|
|
||
| secure_cipher = master_key_mgr() | ||
|
|
||
| def is_secret(secret): | ||
| return bool(re.match('^' + '[^ #,]*' + '$', secret)) | ||
|
|
@@ -234,13 +239,37 @@ def authtype(ctx, type): | |
|
|
||
| @click.command() | ||
| @click.argument('secret', metavar='<secret_string>', required=False) | ||
| @click.option('-e', '--encrypt', help='Enable passkey encryption feature', is_flag=True) | ||
| @click.pass_context | ||
| def passkey(ctx, secret): | ||
| def passkey(ctx, secret, encrypt): | ||
| """Specify TACACS+ server global passkey <STRING>""" | ||
| if ctx.obj == 'default': | ||
| del_table_key('TACPLUS', 'global', 'passkey') | ||
|
||
| elif secret: | ||
| add_table_kv('TACPLUS', 'global', 'passkey', secret) | ||
| if len(secret) > TACACS_PASSKEY_MAX_LEN: | ||
| click.echo('Maximum of %d chars can be configured' % TACACS_PASSKEY_MAX_LEN) | ||
| return | ||
| elif not is_secret(secret): | ||
| click.echo(VALID_CHARS_MSG) | ||
| return | ||
|
|
||
| if encrypt: | ||
| try: | ||
| passwd = getpass.getpass() | ||
nmoray marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| except Exception as e: | ||
|
||
| click.echo('getpass aborted' % e) | ||
nmoray marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| return | ||
| add_table_kv('TACPLUS', 'global', 'key_encrypt', True) | ||
|
||
| outsecret, errs = secure_cipher.encrypt_passkey('TACPLUS', secret, passwd) | ||
| if not errs: | ||
| add_table_kv('TACPLUS', 'global', 'passkey', outsecret) | ||
| else: | ||
| click.echo('Passkey configuration failed' % errs) | ||
|
||
| return | ||
| else: | ||
| add_table_kv('TACPLUS', 'global', 'key_encrypt', False) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same as above, the value must be "false" and not a literal False. "False" will work but not as intended, should stick with lowercase "false" |
||
| add_table_kv('TACPLUS', 'global', 'passkey', secret) | ||
| secure_cipher.del_cipher_pass() | ||
|
||
| else: | ||
| click.echo('Argument "secret" is required') | ||
| tacacs.add_command(passkey) | ||
|
|
@@ -256,7 +285,8 @@ def passkey(ctx, secret): | |
| @click.option('-o', '--port', help='TCP port range is 1 to 65535, default 49', type=click.IntRange(1, 65535), default=49) | ||
| @click.option('-p', '--pri', help="Priority, default 1", type=click.IntRange(1, 64), default=1) | ||
| @click.option('-m', '--use-mgmt-vrf', help="Management vrf, default is no vrf", is_flag=True) | ||
| def add(address, timeout, key, auth_type, port, pri, use_mgmt_vrf): | ||
| @click.option('-e', '--encrypt', help='Enable passkey encryption feature', is_flag=True) | ||
|
||
| def add(address, timeout, key, auth_type, port, pri, use_mgmt_vrf, encrypt): | ||
| """Specify a TACACS+ server""" | ||
| if ADHOC_VALIDATION: | ||
| if not clicommon.is_ipaddress(address): | ||
|
|
@@ -278,7 +308,23 @@ def add(address, timeout, key, auth_type, port, pri, use_mgmt_vrf): | |
| if timeout is not None: | ||
| data['timeout'] = str(timeout) | ||
| if key is not None: | ||
| data['passkey'] = key | ||
| if encrypt: | ||
| try: | ||
| passwd = getpass.getpass() | ||
| except Exception as e: | ||
| click.echo('getpass aborted' % e) | ||
| return | ||
| add_table_kv('TACPLUS', 'global', 'key_encrypt', True) | ||
| outsecret, errs = secure_cipher.encrypt_passkey('TACPLUS', key, passwd) | ||
|
||
| if not errs: | ||
| data['passkey'] = outsecret | ||
| else: | ||
| click.echo('Passkey configuration failed' % errs) | ||
| return | ||
| else: | ||
| add_table_kv('TACPLUS', 'global', 'key_encrypt', False) | ||
| data['passkey'] = key | ||
| secure_cipher.del_cipher_pass() | ||
nmoray marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| if use_mgmt_vrf : | ||
| data['vrf'] = "mgmt" | ||
| try: | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sonic-net/sonic-buildimage#17201 changes this limit to 256, do you want to change it here as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the length set for actual secret which is in plaintext. IMO, 65 chars are good enough.