Skip to content

Commit 31185c4

Browse files
committed
config: add security section to schema
The following box.cfg options were described in instance_config with defaults similar to ones in box.cfg: * auth_type * auth_delay * disable_guest * password_lifetime_days * password_min_length * password_enforce_uppercase * password_enforce_lowercase * password_enforce_digits * password_enforce_specialchars * password_history_length Part of tarantool#8861 NO_DOC=tarantool/doc#3544 links the most actual schema, no need to update the issue.
1 parent 03db58f commit 31185c4

File tree

5 files changed

+187
-12
lines changed

5 files changed

+187
-12
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
## feature/config
2+
3+
* All security hardening box.cfg options are now supported by config (gh-8861).

src/box/lua/config/instance_config.lua

+62
Original file line numberDiff line numberDiff line change
@@ -1241,6 +1241,68 @@ return schema.new('instance_config', schema.record({
12411241
validate = feedback_validate,
12421242
}),
12431243
}),
1244+
security = schema.record({
1245+
auth_type = schema.enum({
1246+
'chap-sha1',
1247+
'pap-sha256',
1248+
}, {
1249+
box_cfg = 'auth_type',
1250+
default = 'chap-sha1',
1251+
validate = function(auth_type, w)
1252+
if auth_type ~= 'chap-sha1' and
1253+
tarantool.package ~= 'Tarantool Enterprise' then
1254+
w.error('"chap-sha1" is the only auth_type available in' ..
1255+
' Tarantool Community Edition (%q requested)',
1256+
auth_type)
1257+
end
1258+
end,
1259+
}),
1260+
auth_delay = enterprise_edition(schema.scalar({
1261+
type = 'number',
1262+
default = 0,
1263+
box_cfg = 'auth_delay',
1264+
})),
1265+
disable_guest = enterprise_edition(schema.scalar({
1266+
type = 'boolean',
1267+
default = false,
1268+
box_cfg = 'disable_guest',
1269+
})),
1270+
password_lifetime_days = enterprise_edition(schema.scalar({
1271+
type = 'integer',
1272+
default = 0,
1273+
box_cfg = 'password_lifetime_days',
1274+
})),
1275+
password_min_length = enterprise_edition(schema.scalar({
1276+
type = 'integer',
1277+
default = 0,
1278+
box_cfg = 'password_min_length',
1279+
})),
1280+
password_enforce_uppercase = enterprise_edition(schema.scalar({
1281+
type = 'boolean',
1282+
default = false,
1283+
box_cfg = 'password_enforce_uppercase',
1284+
})),
1285+
password_enforce_lowercase = enterprise_edition(schema.scalar({
1286+
type = 'boolean',
1287+
default = false,
1288+
box_cfg = 'password_enforce_lowercase',
1289+
})),
1290+
password_enforce_digits = enterprise_edition(schema.scalar({
1291+
type = 'boolean',
1292+
default = false,
1293+
box_cfg = 'password_enforce_digits',
1294+
})),
1295+
password_enforce_specialchars = enterprise_edition(schema.scalar({
1296+
type = 'boolean',
1297+
default = false,
1298+
box_cfg = 'password_enforce_specialchars',
1299+
})),
1300+
password_history_length = enterprise_edition(schema.scalar({
1301+
type = 'integer',
1302+
default = 0,
1303+
box_cfg = 'password_history_length',
1304+
})),
1305+
}),
12441306
}, {
12451307
-- This kind of validation cannot be implemented as the
12461308
-- 'validate' annotation of a particular schema node. There

test/config-luatest/cluster_config_schema_test.lua

+16
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ local cluster_config = require('internal.config.cluster_config')
55

66
local g = t.group()
77

8+
local is_enterprise = require('tarantool').package == 'Tarantool Enterprise'
9+
810
g.test_cluster_config = function()
911
local config = {
1012
credentials = {
@@ -231,6 +233,20 @@ g.test_defaults = function()
231233
interval = 3600,
232234
metrics_limit = 1024*1024,
233235
} or nil,
236+
security = is_enterprise and {
237+
auth_delay = 0,
238+
auth_type = "chap-sha1",
239+
disable_guest = false,
240+
password_enforce_digits = false,
241+
password_enforce_lowercase = false,
242+
password_enforce_specialchars = false,
243+
password_enforce_uppercase = false,
244+
password_history_length = 0,
245+
password_lifetime_days = 0,
246+
password_min_length = 0,
247+
} or {
248+
auth_type = "chap-sha1"
249+
},
234250
}
235251
local res = cluster_config:apply_default({})
236252
t.assert_equals(res, exp)

test/config-luatest/config_test.lua

+56
Original file line numberDiff line numberDiff line change
@@ -391,3 +391,59 @@ g.test_feedback_options = function()
391391
t.assert_equals(box.cfg.feedback_metrics_limit, 1000000)
392392
end)
393393
end
394+
395+
g.test_security_options = function()
396+
t.tarantool.skip_if_not_enterprise()
397+
local dir = treegen.prepare_directory(g, {}, {})
398+
-- guest user is required for luatest.server helper to function properly,
399+
-- so it is enabled (`disable_guest: false`) unlike other options.
400+
local config = [[
401+
credentials:
402+
users:
403+
guest:
404+
roles:
405+
- super
406+
407+
iproto:
408+
listen: unix/:./{{ instance_name }}.iproto
409+
410+
security:
411+
auth_type: pap-sha256
412+
auth_delay: 5
413+
disable_guest: false
414+
password_lifetime_days: 90
415+
password_min_length: 14
416+
password_enforce_uppercase: true
417+
password_enforce_lowercase: true
418+
password_enforce_digits: true
419+
password_enforce_specialchars: true
420+
password_history_length: 3
421+
422+
groups:
423+
group-001:
424+
replicasets:
425+
replicaset-001:
426+
instances:
427+
instance-001: {}
428+
]]
429+
local config_file = treegen.write_script(dir, 'config.yaml', config)
430+
local opts = {
431+
config_file = config_file,
432+
alias = 'instance-001',
433+
chdir = dir,
434+
}
435+
g.server = server:new(opts)
436+
g.server:start()
437+
g.server:exec(function()
438+
t.assert_equals(box.cfg.auth_type, 'pap-sha256')
439+
t.assert_equals(box.cfg.auth_delay, 5)
440+
t.assert_equals(box.cfg.disable_guest, false)
441+
t.assert_equals(box.cfg.password_lifetime_days, 90)
442+
t.assert_equals(box.cfg.password_min_length, 14)
443+
t.assert_equals(box.cfg.password_enforce_uppercase, true)
444+
t.assert_equals(box.cfg.password_enforce_lowercase, true)
445+
t.assert_equals(box.cfg.password_enforce_digits, true)
446+
t.assert_equals(box.cfg.password_enforce_specialchars, true)
447+
t.assert_equals(box.cfg.password_history_length, 3)
448+
end)
449+
end

test/config-luatest/instance_config_schema_test.lua

+50-12
Original file line numberDiff line numberDiff line change
@@ -1032,18 +1032,6 @@ g.test_box_cfg_coverage = function()
10321032
audit_format = true,
10331033
audit_filter = true,
10341034

1035-
-- TODO: Will be added in the scope of gh-8861.
1036-
auth_type = true,
1037-
auth_delay = true,
1038-
disable_guest = true,
1039-
password_lifetime_days = true,
1040-
password_min_length = true,
1041-
password_enforce_uppercase = true,
1042-
password_enforce_lowercase = true,
1043-
password_enforce_digits = true,
1044-
password_enforce_specialchars = true,
1045-
password_history_length = true,
1046-
10471035
-- TODO: Will be added in the scope of gh-8861.
10481036
flightrec_enabled = true,
10491037
flightrec_logs_size = true,
@@ -1210,3 +1198,53 @@ g.test_feedback_disabled = function()
12101198
'without feedback reports sending support'
12111199
t.assert_equals(err, exp)
12121200
end
1201+
1202+
g.test_security_enterprise = function()
1203+
t.tarantool.skip_if_not_enterprise()
1204+
1205+
local iconfig = {
1206+
security = {
1207+
auth_type = 'pap-sha256',
1208+
auth_delay = 5,
1209+
disable_guest = true,
1210+
password_lifetime_days = 90,
1211+
password_min_length = 10,
1212+
password_enforce_uppercase = true,
1213+
password_enforce_lowercase = true,
1214+
password_enforce_digits = true,
1215+
password_enforce_specialchars = true,
1216+
password_history_length = 3,
1217+
}
1218+
}
1219+
1220+
instance_config:validate(iconfig)
1221+
validate_fields(iconfig.security, instance_config.schema.fields.security)
1222+
end
1223+
1224+
g.test_security_community = function()
1225+
t.tarantool.skip_if_enterprise()
1226+
local iconfig = {
1227+
security = {
1228+
auth_type = 'pap-sha256',
1229+
}
1230+
}
1231+
1232+
local ok, err = pcall(instance_config.validate, instance_config, iconfig)
1233+
t.assert_not(ok)
1234+
local exp = '[instance_config] security.auth_type: "chap-sha1" is the ' ..
1235+
'only auth_type available in Tarantool Community Edition ' ..
1236+
'(\"pap-sha256\" requested)'
1237+
t.assert_equals(err, exp)
1238+
1239+
iconfig = {
1240+
security = {
1241+
auth_type = 'chap-sha1',
1242+
auth_delay = 5,
1243+
}
1244+
}
1245+
1246+
ok, err = pcall(instance_config.validate, instance_config, iconfig)
1247+
t.assert_not(ok)
1248+
exp = '[instance_config] security.auth_delay: This configuration parameter is available only in Tarantool Enterprise Edition'
1249+
t.assert_equals(err, exp)
1250+
end

0 commit comments

Comments
 (0)