-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathschema.mjs
More file actions
128 lines (122 loc) · 4.6 KB
/
schema.mjs
File metadata and controls
128 lines (122 loc) · 4.6 KB
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
import Ajv from 'ajv';
const quotaSpec = {
type: "object",
properties: {
path: {
description: "Path to apply quota to. Must be a valid mountpoint.",
type: "string",
},
bytes_soft_limit: {
description:
"Soft limit in bytes. Set to `0` to disable this limit. Supports the following suffixes for readability: `Ki` (multiples of 2^10), `Mi` (multiples of 2^20), `Gi` (multiples of 2^30).",
type: "string",
pattern: "^[0-9]+(Ki|Mi|Gi)?$",
default: "0",
},
bytes_hard_limit: {
description:
"Hard limit in bytes. Set to `0` to disable this limit. Supports the following suffixes for readability: `Ki` (multiples of 2^10), `Mi` (multiples of 2^20), `Gi` (multiples of 2^30).",
type: "string",
pattern: "^[0-9]+(Ki|Mi|Gi)?$",
default: "0",
},
inodes_soft_limit: {
type: "string",
description:
"Soft limit in inodes. Set to `0` to disable this limit. Supports the following suffixes for readability: `k` (multiples of 10^3), `m` (multiples of 10^6), `g` (multiples of 10^9), `t` (multiples of 10^12).",
pattern: "^[0-9]+(k|m|g|t)?$",
default: "0",
},
inodes_hard_limit: {
type: "string",
description:
"Hard limit in inodes. Set to `0` to disable this limit. Supports the following suffixes for readability: `k` (multiples of 10^3), `m` (multiples of 10^6), `g` (multiples of 10^9), `t` (multiples of 10^12).",
pattern: "^[0-9]+(k|m|g|t)?$",
default: "0",
},
},
additionalProperties: false,
};
const userSchema = {
type: "object",
properties: {
username: { type: "string" },
password: { type: "string" },
update_password: { enum: ["always", "on_create"] },
uid: { type: "number" },
primary_group: { type: "string" },
additional_groups: {
type: "array",
items: { type: "string" },
uniqueItems: true,
default: [],
},
shell: { type: "string", default: "/bin/bash" },
ssh_authorized_keys: { type: "array", items: { type: "string" }, default: [] },
linger: { type: "boolean", default: false },
disk_quota: {
type: "array",
items: quotaSpec,
default: [],
},
},
required: ["username", "password", "update_password", "uid", "primary_group"],
additionalProperties: false,
};
const groupSchema = {
type: "object",
properties: {
groupname: { type: "string" },
gid: { type: "number" },
},
required: ["groupname", "gid"],
additionalProperties: false,
};
export const configSchema = {
type: "object",
properties: {
users: { type: "array", items: userSchema },
groups: { type: "array", items: groupSchema },
managed_uid_range: {
type: "array",
description:
"Range of UIDs that are managed by this script. Users with UIDs in this range will be deleted if they are not in the config.",
items: { type: "number" },
minItems: 2,
maxItems: 2,
},
managed_gid_range: {
type: "array",
description:
"Range of GIDs that are managed by this script. Groups with GIDs in this range will be deleted if they are not in the config.",
items: { type: "number" },
minItems: 2,
maxItems: 2,
},
managed_user_directories: {
type: "array",
description: "List of directories to create and delete automatically for each user. Supports templating with %u (username) and %U (uid). The script will create the directory with permissions 700 and ownership of the user. If not already existing, directories leading up to the directory will be created with permissions 755 and ownership of the provisioner user.",
items: { type: "string" },
default: [],
},
home_dir: {
type: "string",
default: "/home/%u",
description: "Home directory for users. Supports templating with %u (username) and %U (uid). Defaults to `/home/%u`."
},
ssh_authorized_keys_path: {
type: "string",
description: "Path to the SSH authorized keys file. Supports templating with %u (username) and %U (uid). Defaults to `<home_dir>/.ssh/authorized_keys` where `<home_dir>` is the value of the `home_dir` property."
},
// XFS default quota can be set using `sudo xfs_quota <path> -x -c "limit -d bsoft=<bsoft> bhard=<bhard> isoft=<isoft> ihard=<ihard>"`
xfs_default_user_quota: {
type: "array",
items: quotaSpec,
default: [],
},
},
required: ["users", "groups", "managed_uid_range", "managed_gid_range"],
additionalProperties: false,
};
const ajv = new Ajv({ allErrors: true, strict: true, useDefaults: true });
export const validateConfig = ajv.compile(configSchema);