1 package PVE
::AccessControl
;
6 use Crypt
::OpenSSL
::Random
;
7 use Crypt
::OpenSSL
::RSA
;
18 use PVE
::Tools
qw(run_command lock_file file_get_contents split_list safe_print);
19 use PVE
::Cluster
qw(cfs_register_file cfs_read_file cfs_write_file cfs_lock_file);
20 use PVE
::JSONSchema
qw(register_standard_option get_standard_option);
24 use PVE
::Auth
::Plugin
;
29 use PVE
::Auth
::OpenId
;
31 # load and initialize all plugins
33 PVE
::Auth
::AD-
>register();
34 PVE
::Auth
::LDAP-
>register();
35 PVE
::Auth
::PVE-
>register();
36 PVE
::Auth
::PAM-
>register();
37 PVE
::Auth
::OpenId-
>register();
38 PVE
::Auth
::Plugin-
>init();
40 # $authdir must be writable by root only!
41 my $confdir = "/etc/pve";
42 my $authdir = "$confdir/priv";
44 my $pve_www_key_fn = "$confdir/pve-www.key";
46 my $pve_auth_key_files = {
47 priv
=> "$authdir/authkey.key",
48 pub
=> "$confdir/authkey.pub",
49 pubold
=> "$confdir/authkey.pub.old",
52 my $pve_auth_key_cache = {};
54 my $ticket_lifetime = 3600 * 2; # 2 hours
55 my $auth_graceperiod = 60 * 5; # 5 minutes
56 my $authkey_lifetime = 3600 * 24; # rotate every 24 hours
58 Crypt
::OpenSSL
::RSA-
>import_random_seed();
60 cfs_register_file
('user.cfg', \
&parse_user_config
, \
&write_user_config
);
61 cfs_register_file
('priv/tfa.cfg', \
&parse_priv_tfa_config
, \
&write_priv_tfa_config
);
64 PVE
::Auth
::Plugin
::verify_username
(@_);
67 sub pve_verify_realm
{
68 PVE
::Auth
::Plugin
::pve_verify_realm
(@_);
71 sub lock_user_config
{
72 my ($code, $errmsg) = @_;
74 cfs_lock_file
("user.cfg", undef, $code);
76 $errmsg ?
die "$errmsg: $err" : die $err;
80 my $cache_read_key = sub {
83 my $path = $pve_auth_key_files->{$type};
85 my $read_key_and_mtime = sub {
86 my $fh = IO
::File-
>new($path, "r");
88 return undef if !defined($fh);
91 my $pem = PVE
::Tools
::safe_read_from
($fh, 0, 0, $path);
96 if ($type eq 'pub' || $type eq 'pubold') {
97 $key = eval { Crypt
::OpenSSL
::RSA-
>new_public_key($pem); };
98 } elsif ($type eq 'priv') {
99 $key = eval { Crypt
::OpenSSL
::RSA-
>new_private_key($pem); };
101 die "Invalid authkey type '$type'\n";
104 return { key
=> $key, mtime
=> $st->mtime };
107 if (!defined($pve_auth_key_cache->{$type})) {
108 $pve_auth_key_cache->{$type} = $read_key_and_mtime->();
110 my $st = stat($path);
111 if (!$st || $st->mtime != $pve_auth_key_cache->{$type}->{mtime
}) {
112 $pve_auth_key_cache->{$type} = $read_key_and_mtime->();
116 return $pve_auth_key_cache->{$type};
122 my $type = $old ?
'pubold' : 'pub';
124 my $res = $cache_read_key->($type);
125 return undef if !defined($res);
127 return wantarray ?
($res->{key
}, $res->{mtime
}) : $res->{key
};
131 my $res = $cache_read_key->('priv');
133 if (!defined($res) || !check_authkey
(1)) {
135 $res = $cache_read_key->('priv');
138 return wantarray ?
($res->{key
}, $res->{mtime
}) : $res->{key
};
144 # skip check if non-quorate, as rotation is not possible anyway
145 return 1 if !PVE
::Cluster
::check_cfs_quorum
(1);
147 my ($pub_key, $mtime) = get_pubkey
();
149 warn "auth key pair missing, generating new one..\n" if !$quiet;
153 if ($now - $mtime >= $authkey_lifetime) {
154 warn "auth key pair too old, rotating..\n" if !$quiet;;
156 } elsif ($mtime > $now + $auth_graceperiod) {
157 # a nodes RTC had a time set in the future during key generation -> ticket
158 # validity is clamped to 0+5 min grace period until now >= mtime again
159 my (undef, $old_mtime) = get_pubkey
(1);
160 if ($old_mtime && $mtime >= $old_mtime && $mtime - $old_mtime < $ticket_lifetime) {
161 warn "auth key pair generated in the future (key $mtime > host $now),"
162 ." but old key still exists and in valid grace period so avoid automatic"
163 ." fixup. Cluster time not in sync?\n" if !$quiet;
166 warn "auth key pair generated in the future (key $mtime > host $now), rotating..\n" if !$quiet;
169 warn "auth key new enough, skipping rotation\n" if !$quiet;;
176 return if $authkey_lifetime == 0;
178 PVE
::Cluster
::cfs_lock_authkey
(undef, sub {
179 # re-check with lock to avoid double rotation in clusters
180 return if check_authkey
();
182 my $old = get_pubkey
();
183 my $new = Crypt
::OpenSSL
::RSA-
>generate_key(2048);
187 my $pem = $old->get_public_key_x509_string();
188 # mtime is used for caching and ticket age range calculation
189 PVE
::Tools
::file_set_contents
($pve_auth_key_files->{pubold
}, $pem);
191 die "Failed to store old auth key: $@\n" if $@;
195 my $pem = $new->get_public_key_x509_string();
196 # mtime is used for caching and ticket age range calculation,
197 # should be close to that of pubold above
198 PVE
::Tools
::file_set_contents
($pve_auth_key_files->{pub
}, $pem);
202 warn "Failed to store new auth key - $@\n";
203 warn "Reverting to previous auth key\n";
205 my $pem = $old->get_public_key_x509_string();
206 PVE
::Tools
::file_set_contents
($pve_auth_key_files->{pub
}, $pem);
208 die "Failed to restore old auth key: $@\n" if $@;
210 die "Failed to store new auth key - $@\n";
215 my $pem = $new->get_private_key_string();
216 PVE
::Tools
::file_set_contents
($pve_auth_key_files->{priv
}, $pem);
219 warn "Failed to store new auth key - $@\n";
220 warn "Deleting auth key to force regeneration\n";
221 unlink $pve_auth_key_files->{pub
};
222 unlink $pve_auth_key_files->{priv
};
228 PVE
::JSONSchema
::register_standard_option
('tokenid', {
229 description
=> "API token identifier.",
231 format
=> "pve-tokenid",
234 our $token_subid_regex = $PVE::Auth
::Plugin
::realm_regex
;
236 # username@realm username realm tokenid
237 our $token_full_regex = qr/((${PVE::Auth::Plugin::user_regex})\@(${PVE::Auth::Plugin::realm_regex}))!(${token_subid_regex})/;
239 our $userid_or_token_regex = qr/^$PVE::Auth::Plugin::user_regex\@$PVE::Auth::Plugin::realm_regex(?:!$token_subid_regex)?$/;
242 my ($tokenid, $noerr) = @_;
244 if ($tokenid =~ /^${token_full_regex}$/) {
248 die "'$tokenid' is not a valid token ID - not able to split into user and token parts\n" if !$noerr;
254 my ($username, $tokensubid) = @_;
256 my $joined = "${username}!${tokensubid}";
258 return pve_verify_tokenid
($joined);
261 PVE
::JSONSchema
::register_format
('pve-tokenid', \
&pve_verify_tokenid
);
262 sub pve_verify_tokenid
{
263 my ($tokenid, $noerr) = @_;
265 if ($tokenid =~ /^${token_full_regex}$/) {
266 return wantarray ?
($tokenid, $2, $3, $4) : $tokenid;
269 die "value '$tokenid' does not look like a valid token ID\n" if !$noerr;
275 my $csrf_prevention_secret;
276 my $csrf_prevention_secret_legacy;
277 my $get_csrfr_secret = sub {
278 if (!$csrf_prevention_secret) {
279 my $input = PVE
::Tools
::file_get_contents
($pve_www_key_fn);
280 $csrf_prevention_secret = Digest
::SHA
::hmac_sha256_base64
($input);
281 $csrf_prevention_secret_legacy = Digest
::SHA
::sha1_base64
($input);
283 return $csrf_prevention_secret;
286 sub assemble_csrf_prevention_token
{
289 my $secret = &$get_csrfr_secret();
291 return PVE
::Ticket
::assemble_csrf_prevention_token
($secret, $username);
294 sub verify_csrf_prevention_token
{
295 my ($username, $token, $noerr) = @_;
297 my $secret = $get_csrfr_secret->();
299 # FIXME: remove with PVE 7 and/or refactor all into PVE::Ticket ?
300 if ($token =~ m/^([A-Z0-9]{8}):(\S+)$/) {
302 if (length($sig) == 27) {
303 # the legacy secret got populated by above get_csrfr_secret call
304 $secret = $csrf_prevention_secret_legacy;
308 return PVE
::Ticket
::verify_csrf_prevention_token
(
309 $secret, $username, $token, -$auth_graceperiod, $ticket_lifetime, $noerr);
312 my $get_ticket_age_range = sub {
313 my ($now, $mtime, $rotated) = @_;
315 my $key_age = $now - $mtime;
316 $key_age = 0 if $key_age < 0;
318 my $min = -$auth_graceperiod;
319 my $max = $ticket_lifetime;
322 # ticket creation after rotation is not allowed
323 $min = $key_age - $auth_graceperiod;
325 if ($key_age > $authkey_lifetime && $authkey_lifetime > 0) {
326 if (PVE
::Cluster
::check_cfs_quorum
(1)) {
327 # key should have been rotated, clamp range accordingly
328 $min = $key_age - $authkey_lifetime;
330 warn "Cluster not quorate - extending auth key lifetime!\n";
334 $max = $key_age + $auth_graceperiod if $key_age < $ticket_lifetime;
337 return undef if $min > $ticket_lifetime;
341 sub assemble_ticket
{
344 my $rsa_priv = get_privkey
();
346 return PVE
::Ticket
::assemble_rsa_ticket
($rsa_priv, 'PVE', $data);
350 my ($ticket, $noerr) = @_;
357 my ($rsa_pub, $rsa_mtime) = get_pubkey
($old);
358 return undef if !$rsa_pub;
360 my ($min, $max) = $get_ticket_age_range->($now, $rsa_mtime, $old);
361 return undef if !defined($min);
363 return PVE
::Ticket
::verify_rsa_ticket
(
364 $rsa_pub, 'PVE', $ticket, undef, $min, $max, 1);
367 my ($data, $age) = $check->();
369 # check with old, rotated key if current key failed
370 ($data, $age) = $check->(1) if !defined($data);
372 my $auth_failure = sub {
376 # raise error via undef ticket
377 PVE
::Ticket
::verify_rsa_ticket
(undef, 'PVE');
381 if (!defined($data)) {
382 return $auth_failure->();
385 my ($username, $tfa_info);
386 if ($data =~ m{^u2f!([^!]+)!([0-9a-zA-Z/.=_\-+]+)$}) {
387 # Ticket for u2f-users:
388 ($username, my $challenge) = ($1, $2);
389 if ($challenge eq 'verified') {
390 # u2f challenge was completed
392 } elsif (!wantarray) {
393 # The caller is not aware there could be an ongoing challenge,
394 # so we treat this ticket as invalid:
395 return $auth_failure->();
399 challenge
=> $challenge,
401 } elsif ($data =~ /^tfa!(.*)$/) {
402 # TOTP and Yubico don't require a challenge so this is the generic
403 # 'missing 2nd factor ticket'
405 $tfa_info = { type
=> 'tfa' };
407 # Regular ticket (full access)
411 return undef if !PVE
::Auth
::Plugin
::verify_username
($username, $noerr);
413 return wantarray ?
($username, $age, $tfa_info) : $username;
417 my ($api_token) = @_;
419 die "no API token specified\n" if !$api_token;
421 my ($tokenid, $value);
422 if ($api_token =~ /^(.*)=(.*)$/) {
426 die "no tokenid specified\n";
429 my ($username, $token) = split_tokenid
($tokenid);
431 my $usercfg = cfs_read_file
('user.cfg');
432 check_user_enabled
($usercfg, $username);
433 check_token_exist
($usercfg, $username, $token);
435 my $user = $usercfg->{users
}->{$username};
436 my $token_info = $user->{tokens
}->{$token};
439 die "token expired\n" if $token_info->{expire
} && ($token_info->{expire
} < $ctime);
441 die "invalid token value!\n" if !PVE
::Cluster
::verify_token
($tokenid, $value);
443 return wantarray ?
($tokenid) : $tokenid;
448 # - they do not contain the username in plain text
449 # - they are restricted to a specific resource path (example: '/vms/100')
450 sub assemble_vnc_ticket
{
451 my ($username, $path) = @_;
453 my $rsa_priv = get_privkey
();
455 $path = normalize_path
($path);
457 my $secret_data = "$username:$path";
459 return PVE
::Ticket
::assemble_rsa_ticket
(
460 $rsa_priv, 'PVEVNC', undef, $secret_data);
463 sub verify_vnc_ticket
{
464 my ($ticket, $username, $path, $noerr) = @_;
466 my $secret_data = "$username:$path";
468 my ($rsa_pub, $rsa_mtime) = get_pubkey
();
469 if (!$rsa_pub || (time() - $rsa_mtime > $authkey_lifetime && $authkey_lifetime > 0)) {
473 # raise error via undef ticket
474 PVE
::Ticket
::verify_rsa_ticket
($rsa_pub, 'PVEVNC');
478 return PVE
::Ticket
::verify_rsa_ticket
(
479 $rsa_pub, 'PVEVNC', $ticket, $secret_data, -20, 40, $noerr);
482 sub assemble_spice_ticket
{
483 my ($username, $vmid, $node) = @_;
485 my $secret = &$get_csrfr_secret();
487 return PVE
::Ticket
::assemble_spice_ticket
(
488 $secret, $username, $vmid, $node);
491 sub verify_spice_connect_url
{
492 my ($connect_str) = @_;
494 my $secret = &$get_csrfr_secret();
496 return PVE
::Ticket
::verify_spice_connect_url
($secret, $connect_str);
499 sub read_x509_subject_spice
{
503 my $bio = Net
::SSLeay
::BIO_new_file
($filename, 'r');
504 die "Could not open $filename using OpenSSL\n"
507 my $x509 = Net
::SSLeay
::PEM_read_bio_X509
($bio);
508 Net
::SSLeay
::BIO_free
($bio);
510 die "Could not parse X509 certificate in $filename\n"
513 my $nameobj = Net
::SSLeay
::X509_get_subject_name
($x509);
514 my $subject = Net
::SSLeay
::X509_NAME_oneline
($nameobj);
515 Net
::SSLeay
::X509_free
($x509);
517 # remote-viewer wants comma as seperator (not '/')
519 $subject =~ s!/(\w+=)!,$1!g;
524 # helper to generate SPICE remote-viewer configuration
525 sub remote_viewer_config
{
526 my ($authuser, $vmid, $node, $proxy, $title, $port) = @_;
529 my $host = `hostname -f` || PVE
::INotify
::nodename
();
534 my ($ticket, $proxyticket) = assemble_spice_ticket
($authuser, $vmid, $node);
536 my $filename = "/etc/pve/local/pve-ssl.pem";
537 my $subject = read_x509_subject_spice
($filename);
539 my $cacert = PVE
::Tools
::file_get_contents
("/etc/pve/pve-root-ca.pem", 8192);
540 $cacert =~ s/\n/\\n/g;
542 $proxy = "[$proxy]" if Net
::IP
::ip_is_ipv6
($proxy);
544 'secure-attention' => "Ctrl+Alt+Ins",
545 'toggle-fullscreen' => "Shift+F11",
546 'release-cursor' => "Ctrl+Alt+R",
549 host
=> $proxyticket, # this breaks tls hostname verification, so we need to use 'host-subject'
550 proxy
=> "http://$proxy:3128",
552 'host-subject' => $subject,
555 'delete-this-file' => 1,
558 return ($ticket, $proxyticket, $config);
561 sub check_user_exist
{
562 my ($usercfg, $username, $noerr) = @_;
564 $username = PVE
::Auth
::Plugin
::verify_username
($username, $noerr);
565 return undef if !$username;
567 return $usercfg->{users
}->{$username} if $usercfg && $usercfg->{users
}->{$username};
569 die "no such user ('$username')\n" if !$noerr;
574 sub check_user_enabled
{
575 my ($usercfg, $username, $noerr) = @_;
577 my $data = check_user_exist
($usercfg, $username, $noerr);
578 return undef if !$data;
580 return 1 if $data->{enable
};
582 die "user '$username' is disabled\n" if !$noerr;
585 my $expire = $usercfg->{users
}->{$username}->{expire
};
587 die "account expired\n" if $expire && ($expire < $ctime);
592 sub check_token_exist
{
593 my ($usercfg, $username, $tokenid, $noerr) = @_;
595 my $user = check_user_exist
($usercfg, $username, $noerr);
596 return undef if !$user;
598 return $user->{tokens
}->{$tokenid}
599 if defined($user->{tokens
}) && $user->{tokens
}->{$tokenid};
601 die "no such token '$tokenid' for user '$username'\n" if !$noerr;
606 sub verify_one_time_pw
{
607 my ($type, $username, $keys, $tfa_cfg, $otp) = @_;
609 die "missing one time password for two-factor authentication '$type'\n" if !$otp;
611 # fixme: proxy support?
614 if ($type eq 'yubico') {
615 PVE
::OTP
::yubico_verify_otp
($otp, $keys, $tfa_cfg->{url
},
616 $tfa_cfg->{id
}, $tfa_cfg->{key
}, $proxy);
617 } elsif ($type eq 'oath') {
618 PVE
::OTP
::oath_verify_otp
($otp, $keys, $tfa_cfg->{step
}, $tfa_cfg->{digits
});
620 die "unknown tfa type '$type'\n";
624 # password should be utf8 encoded
625 # Note: some plugins delay/sleep if auth fails
626 sub authenticate_user
{
627 my ($username, $password, $otp) = @_;
629 die "no username specified\n" if !$username;
633 ($username, $ruid, $realm) = PVE
::Auth
::Plugin
::verify_username
($username);
635 my $usercfg = cfs_read_file
('user.cfg');
637 check_user_enabled
($usercfg, $username);
639 my $domain_cfg = cfs_read_file
('domains.cfg');
641 my $cfg = $domain_cfg->{ids
}->{$realm};
642 die "auth domain '$realm' does not exist\n" if !$cfg;
643 my $plugin = PVE
::Auth
::Plugin-
>lookup($cfg->{type
});
644 $plugin->authenticate_user($cfg, $realm, $ruid, $password);
646 my ($type, $tfa_data) = user_get_tfa
($username, $realm);
648 if ($type eq 'u2f') {
649 # Note that if the user did not manage to complete the initial u2f registration
650 # challenge we have a hash containing a 'challenge' entry in the user's tfa.cfg entry:
651 $tfa_data = undef if exists $tfa_data->{challenge
};
652 } elsif (!defined($otp)) {
653 # The user requires a 2nd factor but has not provided one. Return success but
654 # don't clear $tfa_data.
656 my $keys = $tfa_data->{keys};
657 my $tfa_cfg = $tfa_data->{config
};
658 verify_one_time_pw
($type, $username, $keys, $tfa_cfg, $otp);
662 # Return the type along with the rest:
671 return wantarray ?
($username, $tfa_data) : $username;
674 sub domain_set_password
{
675 my ($realm, $username, $password) = @_;
677 die "no auth domain specified" if !$realm;
679 my $domain_cfg = cfs_read_file
('domains.cfg');
681 my $cfg = $domain_cfg->{ids
}->{$realm};
682 die "auth domain '$realm' does not exist\n" if !$cfg;
683 my $plugin = PVE
::Auth
::Plugin-
>lookup($cfg->{type
});
684 $plugin->store_password($cfg, $realm, $username, $password);
688 my ($username, $usercfg, $group) = @_;
690 $usercfg->{users
}->{$username}->{groups
}->{$group} = 1;
691 $usercfg->{groups
}->{$group}->{users
}->{$username} = 1;
694 sub delete_user_group
{
695 my ($username, $usercfg) = @_;
697 foreach my $group (keys %{$usercfg->{groups
}}) {
699 delete ($usercfg->{groups
}->{$group}->{users
}->{$username})
700 if $usercfg->{groups
}->{$group}->{users
}->{$username};
704 sub delete_user_acl
{
705 my ($username, $usercfg) = @_;
707 foreach my $acl (keys %{$usercfg->{acl
}}) {
709 delete ($usercfg->{acl
}->{$acl}->{users
}->{$username})
710 if $usercfg->{acl
}->{$acl}->{users
}->{$username};
714 sub delete_group_acl
{
715 my ($group, $usercfg) = @_;
717 foreach my $acl (keys %{$usercfg->{acl
}}) {
719 delete ($usercfg->{acl
}->{$acl}->{groups
}->{$group})
720 if $usercfg->{acl
}->{$acl}->{groups
}->{$group};
724 sub delete_pool_acl
{
725 my ($pool, $usercfg) = @_;
727 my $path = "/pool/$pool";
729 delete ($usercfg->{acl
}->{$path})
732 # we automatically create some predefined roles by splitting privs
733 # into 3 groups (per category)
734 # root: only root is allowed to do that
735 # admin: an administrator can to that
736 # user: a normal user/customer can to that
746 'VM.Config.Options', # covers all other things
752 'VM.Snapshot.Rollback',
755 'VM.Config.CDROM', # change CDROM media
756 'VM.Config.Cloudinit',
768 'Sys.Modify', # edit/change node settings
771 'Permissions.Modify',
783 'Datastore.Allocate',
784 'Datastore.AllocateTemplate',
787 'Datastore.AllocateSpace',
809 'Group.Allocate', # edit/change group settings
810 'Realm.AllocateUser',
818 'Pool.Allocate', # create/delete pools
829 my $valid_privs = {};
831 my $special_roles = {
832 'NoAccess' => {}, # no privileges
833 'Administrator' => $valid_privs, # all privileges
838 foreach my $cat (keys %$privgroups) {
839 my $cd = $privgroups->{$cat};
840 foreach my $p (@{$cd->{root
}}, @{$cd->{admin
}},
841 @{$cd->{user
}}, @{$cd->{audit
}}) {
842 $valid_privs->{$p} = 1;
844 foreach my $p (@{$cd->{admin
}}, @{$cd->{user
}}, @{$cd->{audit
}}) {
846 $special_roles->{"PVE${cat}Admin"}->{$p} = 1;
847 $special_roles->{"PVEAdmin"}->{$p} = 1;
849 if (scalar(@{$cd->{user
}})) {
850 foreach my $p (@{$cd->{user
}}, @{$cd->{audit
}}) {
851 $special_roles->{"PVE${cat}User"}->{$p} = 1;
854 foreach my $p (@{$cd->{audit
}}) {
855 $special_roles->{"PVEAuditor"}->{$p} = 1;
859 $special_roles->{"PVETemplateUser"} = { 'VM.Clone' => 1, 'VM.Audit' => 1 };
864 sub create_priv_properties
{
866 foreach my $priv (keys %$valid_privs) {
867 $properties->{$priv} = {
875 sub role_is_special
{
877 return (exists $special_roles->{$role}) ?
1 : 0;
881 my ($role, $usercfg, $privs) = @_;
885 die "role '$role' does not exist\n" if !$usercfg->{roles
}->{$role};
887 foreach my $priv (split_list
($privs)) {
888 if (defined ($valid_privs->{$priv})) {
889 $usercfg->{roles
}->{$role}->{$priv} = 1;
891 die "invalid privilege '$priv'\n";
896 sub lookup_username
{
897 my ($username, $noerr) = @_;
899 $username =~ m!^(${PVE::Auth::Plugin::user_regex})\@(${PVE::Auth::Plugin::realm_regex})$!;
902 my $domain_cfg = cfs_read_file
("domains.cfg");
903 my $casesensitive = $domain_cfg->{ids
}->{$realm}->{'case-sensitive'} // 1;
904 my $usercfg = cfs_read_file
('user.cfg');
906 if (!$casesensitive) {
907 my @matches = grep { lc $username eq lc $_ } (keys %{$usercfg->{users
}});
909 die "ambiguous case insensitive match of username '$username', cannot safely grant access!\n"
910 if scalar @matches > 1 && !$noerr;
925 $path = '/' if !$path;
927 $path = "/$path" if $path !~ m
|^/|;
929 return undef if $path !~ m
|^[[:alnum
:]\
.\
-\_\
/]+$|;
940 |/access/groups
/[[:alnum
:]\
.\
-\_
]+
942 |/access/realm
/[[:alnum
:]\
.\
-\_
]+
944 |/nodes/[[:alnum
:]\
.\
-\_
]+
946 |/pool/[[:alnum
:]\
.\
-\_
]+
948 |/sdn/zones
/[[:alnum
:]\
.\
-\_
]+
949 |/sdn/vnets
/[[:alnum
:]\
.\
-\_
]+
951 |/storage/[[:alnum
:]\
.\
-\_
]+
957 PVE
::JSONSchema
::register_format
('pve-groupid', \
&verify_groupname
);
958 sub verify_groupname
{
959 my ($groupname, $noerr) = @_;
961 if ($groupname !~ m/^[A-Za-z0-9\.\-_]+$/) {
963 die "group name '$groupname' contains invalid characters\n" if !$noerr;
971 PVE
::JSONSchema
::register_format
('pve-roleid', \
&verify_rolename
);
972 sub verify_rolename
{
973 my ($rolename, $noerr) = @_;
975 if ($rolename !~ m/^[A-Za-z0-9\.\-_]+$/) {
977 die "role name '$rolename' contains invalid characters\n" if !$noerr;
985 PVE
::JSONSchema
::register_format
('pve-poolid', \
&verify_poolname
);
986 sub verify_poolname
{
987 my ($poolname, $noerr) = @_;
989 if ($poolname !~ m/^[A-Za-z0-9\.\-_]+$/) {
991 die "pool name '$poolname' contains invalid characters\n" if !$noerr;
999 PVE
::JSONSchema
::register_format
('pve-priv', \
&verify_privname
);
1000 sub verify_privname
{
1001 my ($priv, $noerr) = @_;
1003 if (!$valid_privs->{$priv}) {
1004 die "invalid privilege '$priv'\n" if !$noerr;
1012 sub userconfig_force_defaults
{
1015 foreach my $r (keys %$special_roles) {
1016 $cfg->{roles
}->{$r} = $special_roles->{$r};
1019 # add root user if not exists
1020 if (!$cfg->{users
}->{'root@pam'}) {
1021 $cfg->{users
}->{'root@pam'}->{enable
} = 1;
1025 sub parse_user_config
{
1026 my ($filename, $raw) = @_;
1030 userconfig_force_defaults
($cfg);
1032 $raw = '' if !defined($raw);
1033 while ($raw =~ /^\s*(.+?)\s*$/gm) {
1037 foreach my $d (split (/:/, $line)) {
1043 my $et = shift @data;
1045 if ($et eq 'user') {
1046 my ($user, $enable, $expire, $firstname, $lastname, $email, $comment, $keys) = @data;
1048 my (undef, undef, $realm) = PVE
::Auth
::Plugin
::verify_username
($user, 1);
1050 warn "user config - ignore user '$user' - invalid user name\n";
1054 $enable = $enable ?
1 : 0;
1056 $expire = 0 if !$expire;
1058 if ($expire !~ m/^\d+$/) {
1059 warn "user config - ignore user '$user' - (illegal characters in expire '$expire')\n";
1062 $expire = int($expire);
1064 #if (!verify_groupname ($group, 1)) {
1065 # warn "user config - ignore user '$user' - invalid characters in group name\n";
1069 $cfg->{users
}->{$user} = {
1073 $cfg->{users
}->{$user}->{firstname
} = PVE
::Tools
::decode_text
($firstname) if $firstname;
1074 $cfg->{users
}->{$user}->{lastname
} = PVE
::Tools
::decode_text
($lastname) if $lastname;
1075 $cfg->{users
}->{$user}->{email
} = $email;
1076 $cfg->{users
}->{$user}->{comment
} = PVE
::Tools
::decode_text
($comment) if $comment;
1077 $cfg->{users
}->{$user}->{expire
} = $expire;
1078 # keys: allowed yubico key ids or oath secrets (base32 encoded)
1079 $cfg->{users
}->{$user}->{keys} = $keys if $keys;
1081 #$cfg->{users}->{$user}->{groups}->{$group} = 1;
1082 #$cfg->{groups}->{$group}->{$user} = 1;
1084 } elsif ($et eq 'group') {
1085 my ($group, $userlist, $comment) = @data;
1087 if (!verify_groupname
($group, 1)) {
1088 warn "user config - ignore group '$group' - invalid characters in group name\n";
1092 # make sure to add the group (even if there are no members)
1093 $cfg->{groups
}->{$group} = { users
=> {} } if !$cfg->{groups
}->{$group};
1095 $cfg->{groups
}->{$group}->{comment
} = PVE
::Tools
::decode_text
($comment) if $comment;
1097 foreach my $user (split_list
($userlist)) {
1099 if (!PVE
::Auth
::Plugin
::verify_username
($user, 1)) {
1100 warn "user config - ignore invalid group member '$user'\n";
1104 if ($cfg->{users
}->{$user}) { # user exists
1105 $cfg->{users
}->{$user}->{groups
}->{$group} = 1;
1107 warn "user config - ignore invalid group member '$user'\n";
1109 $cfg->{groups
}->{$group}->{users
}->{$user} = 1;
1112 } elsif ($et eq 'role') {
1113 my ($role, $privlist) = @data;
1115 if (!verify_rolename
($role, 1)) {
1116 warn "user config - ignore role '$role' - invalid characters in role name\n";
1120 # make sure to add the role (even if there are no privileges)
1121 $cfg->{roles
}->{$role} = {} if !$cfg->{roles
}->{$role};
1123 foreach my $priv (split_list
($privlist)) {
1124 if (defined ($valid_privs->{$priv})) {
1125 $cfg->{roles
}->{$role}->{$priv} = 1;
1127 warn "user config - ignore invalid privilege '$priv'\n";
1131 } elsif ($et eq 'acl') {
1132 my ($propagate, $pathtxt, $uglist, $rolelist) = @data;
1134 $propagate = $propagate ?
1 : 0;
1136 if (my $path = normalize_path
($pathtxt)) {
1137 foreach my $role (split_list
($rolelist)) {
1139 if (!verify_rolename
($role, 1)) {
1140 warn "user config - ignore invalid role name '$role' in acl\n";
1144 if (!$cfg->{roles
}->{$role}) {
1145 warn "user config - ignore invalid acl role '$role'\n";
1149 foreach my $ug (split_list
($uglist)) {
1150 my ($group) = $ug =~ m/^@(\S+)$/;
1152 if ($group && verify_groupname
($group, 1)) {
1153 if (!$cfg->{groups
}->{$group}) { # group does not exist
1154 warn "user config - ignore invalid acl group '$group'\n";
1156 $cfg->{acl
}->{$path}->{groups
}->{$group}->{$role} = $propagate;
1157 } elsif (PVE
::Auth
::Plugin
::verify_username
($ug, 1)) {
1158 if (!$cfg->{users
}->{$ug}) { # user does not exist
1159 warn "user config - ignore invalid acl member '$ug'\n";
1161 $cfg->{acl
}->{$path}->{users
}->{$ug}->{$role} = $propagate;
1162 } elsif (my ($user, $token) = split_tokenid
($ug, 1)) {
1163 if (check_token_exist
($cfg, $user, $token, 1)) {
1164 $cfg->{acl
}->{$path}->{tokens
}->{$ug}->{$role} = $propagate;
1166 warn "user config - ignore invalid acl token '$ug'\n";
1169 warn "user config - invalid user/group '$ug' in acl\n";
1174 warn "user config - ignore invalid path in acl '$pathtxt'\n";
1176 } elsif ($et eq 'pool') {
1177 my ($pool, $comment, $vmlist, $storelist) = @data;
1179 if (!verify_poolname
($pool, 1)) {
1180 warn "user config - ignore pool '$pool' - invalid characters in pool name\n";
1184 # make sure to add the pool (even if there are no members)
1185 $cfg->{pools
}->{$pool} = { vms
=> {}, storage
=> {} } if !$cfg->{pools
}->{$pool};
1187 $cfg->{pools
}->{$pool}->{comment
} = PVE
::Tools
::decode_text
($comment) if $comment;
1189 foreach my $vmid (split_list
($vmlist)) {
1190 if ($vmid !~ m/^\d+$/) {
1191 warn "user config - ignore invalid vmid '$vmid' in pool '$pool'\n";
1196 if ($cfg->{vms
}->{$vmid}) {
1197 warn "user config - ignore duplicate vmid '$vmid' in pool '$pool'\n";
1201 $cfg->{pools
}->{$pool}->{vms
}->{$vmid} = 1;
1203 # record vmid ==> pool relation
1204 $cfg->{vms
}->{$vmid} = $pool;
1207 foreach my $storeid (split_list
($storelist)) {
1208 if ($storeid !~ m/^[a-z][a-z0-9\-\_\.]*[a-z0-9]$/i) {
1209 warn "user config - ignore invalid storage '$storeid' in pool '$pool'\n";
1212 $cfg->{pools
}->{$pool}->{storage
}->{$storeid} = 1;
1214 } elsif ($et eq 'token') {
1215 my ($tokenid, $expire, $privsep, $comment) = @data;
1217 my ($user, $token) = split_tokenid
($tokenid, 1);
1218 if (!($user && $token)) {
1219 warn "user config - ignore invalid tokenid '$tokenid'\n";
1223 $privsep = $privsep ?
1 : 0;
1225 $expire = 0 if !$expire;
1227 if ($expire !~ m/^\d+$/) {
1228 warn "user config - ignore token '$tokenid' - (illegal characters in expire '$expire')\n";
1231 $expire = int($expire);
1233 if (my $user_cfg = $cfg->{users
}->{$user}) { # user exists
1234 $user_cfg->{tokens
}->{$token} = {} if !$user_cfg->{tokens
}->{$token};
1235 my $token_cfg = $user_cfg->{tokens
}->{$token};
1236 $token_cfg->{privsep
} = $privsep;
1237 $token_cfg->{expire
} = $expire;
1238 $token_cfg->{comment
} = PVE
::Tools
::decode_text
($comment) if $comment;
1240 warn "user config - ignore token '$tokenid' - user does not exist\n";
1243 warn "user config - ignore config line: $line\n";
1247 userconfig_force_defaults
($cfg);
1252 sub write_user_config
{
1253 my ($filename, $cfg) = @_;
1257 foreach my $user (sort keys %{$cfg->{users
}}) {
1258 my $d = $cfg->{users
}->{$user};
1259 my $firstname = $d->{firstname
} ? PVE
::Tools
::encode_text
($d->{firstname
}) : '';
1260 my $lastname = $d->{lastname
} ? PVE
::Tools
::encode_text
($d->{lastname
}) : '';
1261 my $email = $d->{email
} || '';
1262 my $comment = $d->{comment
} ? PVE
::Tools
::encode_text
($d->{comment
}) : '';
1263 my $expire = int($d->{expire
} || 0);
1264 my $enable = $d->{enable
} ?
1 : 0;
1265 my $keys = $d->{keys} ?
$d->{keys} : '';
1266 $data .= "user:$user:$enable:$expire:$firstname:$lastname:$email:$comment:$keys:\n";
1268 my $user_tokens = $d->{tokens
};
1269 foreach my $token (sort keys %$user_tokens) {
1270 my $td = $user_tokens->{$token};
1271 my $full_tokenid = join_tokenid
($user, $token);
1272 my $comment = $td->{comment
} ? PVE
::Tools
::encode_text
($td->{comment
}) : '';
1273 my $expire = int($td->{expire
} || 0);
1274 my $privsep = $td->{privsep
} ?
1 : 0;
1275 $data .= "token:$full_tokenid:$expire:$privsep:$comment:\n";
1281 foreach my $group (sort keys %{$cfg->{groups
}}) {
1282 my $d = $cfg->{groups
}->{$group};
1283 my $list = join (',', sort keys %{$d->{users
}});
1284 my $comment = $d->{comment
} ? PVE
::Tools
::encode_text
($d->{comment
}) : '';
1285 $data .= "group:$group:$list:$comment:\n";
1290 foreach my $pool (sort keys %{$cfg->{pools
}}) {
1291 my $d = $cfg->{pools
}->{$pool};
1292 my $vmlist = join (',', sort keys %{$d->{vms
}});
1293 my $storelist = join (',', sort keys %{$d->{storage
}});
1294 my $comment = $d->{comment
} ? PVE
::Tools
::encode_text
($d->{comment
}) : '';
1295 $data .= "pool:$pool:$comment:$vmlist:$storelist:\n";
1300 foreach my $role (sort keys %{$cfg->{roles
}}) {
1301 next if $special_roles->{$role};
1303 my $d = $cfg->{roles
}->{$role};
1304 my $list = join (',', sort keys %$d);
1305 $data .= "role:$role:$list:\n";
1310 my $collect_rolelist_members = sub {
1311 my ($acl_members, $result, $prefix, $exclude) = @_;
1313 foreach my $member (keys %$acl_members) {
1314 next if $exclude && $member eq $exclude;
1318 foreach my $role (sort keys %{$acl_members->{$member}}) {
1319 my $propagate = $acl_members->{$member}->{$role};
1328 $result->{0}->{$l0}->{"${prefix}${member}"} = 1 if $l0;
1329 $result->{1}->{$l1}->{"${prefix}${member}"} = 1 if $l1;
1333 foreach my $path (sort keys %{$cfg->{acl
}}) {
1334 my $d = $cfg->{acl
}->{$path};
1336 my $rolelist_members = {};
1338 $collect_rolelist_members->($d->{'groups'}, $rolelist_members, '@');
1340 # no need to save 'root@pam', it is always 'Administrator'
1341 $collect_rolelist_members->($d->{'users'}, $rolelist_members, '', 'root@pam');
1343 $collect_rolelist_members->($d->{'tokens'}, $rolelist_members, '');
1345 foreach my $propagate (0,1) {
1346 my $filtered = $rolelist_members->{$propagate};
1347 foreach my $rolelist (sort keys %$filtered) {
1348 my $uglist = join (',', sort keys %{$filtered->{$rolelist}});
1349 $data .= "acl:$propagate:$path:$uglist:$rolelist:\n";
1358 # Creates a `PVE::RS::TFA` instance from the raw config data.
1359 # Its contained hash will also support the legacy functionality.
1360 sub parse_priv_tfa_config
{
1361 my ($filename, $raw) = @_;
1363 $raw = '' if !defined($raw);
1364 my $cfg = PVE
::RS
::TFA-
>new($raw);
1366 # Purge invalid users:
1367 foreach my $user ($cfg->users()->@*) {
1368 my (undef, undef, $realm) = PVE
::Auth
::Plugin
::verify_username
($user, 1);
1370 warn "user tfa config - ignore user '$user' - invalid user name\n";
1371 $cfg->remove_user($user);
1378 sub write_priv_tfa_config
{
1379 my ($filename, $cfg) = @_;
1381 # FIXME: Only allow this if the complete cluster has been upgraded to understand the json
1383 return $cfg->write();
1387 my ($cfg, $user, $path) = @_;
1389 # NOTE: we do not consider pools here.
1390 # NOTE: for privsep tokens, this does not filter roles by those that the
1391 # corresponding user has.
1392 # Use $rpcenv->permission() for any actual permission checks!
1394 return 'Administrator' if $user eq 'root@pam'; # root can do anything
1396 if (pve_verify_tokenid
($user, 1)) {
1397 my $tokenid = $user;
1398 my ($username, $token) = split_tokenid
($tokenid);
1400 my $token_info = $cfg->{users
}->{$username}->{tokens
}->{$token};
1401 return () if !$token_info;
1403 my $user_roles = roles
($cfg, $username, $path);
1405 # return full user privileges
1406 return $user_roles if !$token_info->{privsep
};
1411 foreach my $p (sort keys %{$cfg->{acl
}}) {
1412 my $final = ($path eq $p);
1414 next if !(($p eq '/') || $final || ($path =~ m
|^$p/|));
1416 my $acl = $cfg->{acl
}->{$p};
1418 #print "CHECKACL $path $p\n";
1419 #print "ACL $path = " . Dumper ($acl);
1420 if (my $ri = $acl->{tokens
}->{$user}) {
1422 foreach my $role (keys %$ri) {
1423 my $propagate = $ri->{$role};
1424 if ($final || $propagate) {
1425 #print "APPLY ROLE $p $user $role\n";
1427 $new->{$role} = $propagate;
1431 $roles = $new; # overwrite previous settings
1436 if (my $ri = $acl->{users
}->{$user}) {
1438 foreach my $role (keys %$ri) {
1439 my $propagate = $ri->{$role};
1440 if ($final || $propagate) {
1441 #print "APPLY ROLE $p $user $role\n";
1443 $new->{$role} = $propagate;
1447 $roles = $new; # overwrite previous settings
1448 next; # user privs always override group privs
1453 foreach my $g (keys %{$acl->{groups
}}) {
1454 next if !$cfg->{groups
}->{$g}->{users
}->{$user};
1455 if (my $ri = $acl->{groups
}->{$g}) {
1456 foreach my $role (keys %$ri) {
1457 my $propagate = $ri->{$role};
1458 if ($final || $propagate) {
1459 #print "APPLY ROLE $p \@$g $role\n";
1461 $new->{$role} = $propagate;
1467 $roles = $new; # overwrite previous settings
1472 return { 'NoAccess' => $roles->{NoAccess
} } if defined ($roles->{NoAccess
});
1473 #return () if defined ($roles->{NoAccess});
1475 #print "permission $user $path = " . Dumper ($roles);
1477 #print "roles $user $path = " . join (',', @ra) . "\n";
1482 sub remove_vm_access
{
1484 my $delVMaccessFn = sub {
1485 my $usercfg = cfs_read_file
("user.cfg");
1488 if (my $acl = $usercfg->{acl
}->{"/vms/$vmid"}) {
1489 delete $usercfg->{acl
}->{"/vms/$vmid"};
1492 if (my $pool = $usercfg->{vms
}->{$vmid}) {
1493 if (my $data = $usercfg->{pools
}->{$pool}) {
1494 delete $data->{vms
}->{$vmid};
1495 delete $usercfg->{vms
}->{$vmid};
1499 cfs_write_file
("user.cfg", $usercfg) if $modified;
1502 lock_user_config
($delVMaccessFn, "access permissions cleanup for VM $vmid failed");
1505 sub remove_storage_access
{
1508 my $deleteStorageAccessFn = sub {
1509 my $usercfg = cfs_read_file
("user.cfg");
1512 if (my $storage = $usercfg->{acl
}->{"/storage/$storeid"}) {
1513 delete $usercfg->{acl
}->{"/storage/$storeid"};
1516 foreach my $pool (keys %{$usercfg->{pools
}}) {
1517 delete $usercfg->{pools
}->{$pool}->{storage
}->{$storeid};
1520 cfs_write_file
("user.cfg", $usercfg) if $modified;
1523 lock_user_config
($deleteStorageAccessFn,
1524 "access permissions cleanup for storage $storeid failed");
1527 sub add_vm_to_pool
{
1528 my ($vmid, $pool) = @_;
1530 my $addVMtoPoolFn = sub {
1531 my $usercfg = cfs_read_file
("user.cfg");
1532 if (my $data = $usercfg->{pools
}->{$pool}) {
1533 $data->{vms
}->{$vmid} = 1;
1534 $usercfg->{vms
}->{$vmid} = $pool;
1535 cfs_write_file
("user.cfg", $usercfg);
1539 lock_user_config
($addVMtoPoolFn, "can't add VM $vmid to pool '$pool'");
1542 sub remove_vm_from_pool
{
1545 my $delVMfromPoolFn = sub {
1546 my $usercfg = cfs_read_file
("user.cfg");
1547 if (my $pool = $usercfg->{vms
}->{$vmid}) {
1548 if (my $data = $usercfg->{pools
}->{$pool}) {
1549 delete $data->{vms
}->{$vmid};
1550 delete $usercfg->{vms
}->{$vmid};
1551 cfs_write_file
("user.cfg", $usercfg);
1556 lock_user_config
($delVMfromPoolFn, "pool cleanup for VM $vmid failed");
1559 my $USER_CONTROLLED_TFA_TYPES = {
1564 # Delete an entry by setting $data=undef in which case $type is ignored.
1565 # Otherwise both must be valid.
1567 my ($userid, $realm, $type, $data, $cached_usercfg, $cached_domaincfg) = @_;
1569 if (defined($data) && !defined($type)) {
1570 # This is an internal usage error and should not happen
1571 die "cannot set tfa data without a type\n";
1574 my $user_cfg = $cached_usercfg || cfs_read_file
('user.cfg');
1575 my $user = $user_cfg->{users
}->{$userid};
1577 my $domain_cfg = $cached_domaincfg || cfs_read_file
('domains.cfg');
1578 my $realm_cfg = $domain_cfg->{ids
}->{$realm};
1579 die "auth domain '$realm' does not exist\n" if !$realm_cfg;
1581 my $realm_tfa = $realm_cfg->{tfa
};
1582 if (defined($realm_tfa)) {
1583 $realm_tfa = PVE
::Auth
::Plugin
::parse_tfa_config
($realm_tfa);
1584 # If the realm has a TFA setting, we're only allowed to use that.
1585 if (defined($data)) {
1586 die "user '$userid' not found\n" if !defined($user);
1587 my $required_type = $realm_tfa->{type
};
1588 if ($required_type ne $type) {
1589 die "realm '$realm' only allows TFA of type '$required_type\n";
1592 if (defined($data->{config
})) {
1593 # XXX: Is it enough if the type matches? Or should the configuration also match?
1596 # realm-configured tfa always uses a simple key list, so use the user.cfg
1597 $user->{keys} = $data->{keys};
1599 # TFA is enforce by realm, only allow deletion if the whole user gets delete
1600 die "realm '$realm' does not allow removing the 2nd factor\n" if defined($user);
1603 die "user '$userid' not found\n" if !defined($user) && defined($data);
1604 # Without a realm-enforced TFA setting the user can add a u2f or totp entry by themselves.
1605 # The 'yubico' type requires yubico server settings, which have to be configured on the
1606 # realm, so this is not supported here:
1607 die "domain '$realm' does not support TFA type '$type'\n"
1608 if defined($data) && !$USER_CONTROLLED_TFA_TYPES->{$type};
1611 # Custom TFA entries are stored in priv/tfa.cfg as they can be more complet: u2f uses a
1612 # public key and a key handle, TOTP requires the usual totp settings...
1614 my $tfa_cfg = cfs_read_file
('priv/tfa.cfg');
1615 my $tfa = ($tfa_cfg->{users
}->{$userid} //= {});
1617 if (defined($data)) {
1618 $tfa->{type
} = $type;
1619 $tfa->{data
} = $data;
1620 cfs_write_file
('priv/tfa.cfg', $tfa_cfg);
1622 $user->{keys} = "x!$type";
1624 delete $tfa_cfg->{users
}->{$userid};
1625 cfs_write_file
('priv/tfa.cfg', $tfa_cfg);
1627 delete $user->{keys} if defined($user);
1630 cfs_write_file
('user.cfg', $user_cfg) if defined($user);
1634 my ($username, $realm) = @_;
1636 my $user_cfg = cfs_read_file
('user.cfg');
1637 my $user = $user_cfg->{users
}->{$username}
1638 or die "user '$username' not found\n";
1640 my $keys = $user->{keys};
1642 my $domain_cfg = cfs_read_file
('domains.cfg');
1643 my $realm_cfg = $domain_cfg->{ids
}->{$realm};
1644 die "auth domain '$realm' does not exist\n" if !$realm_cfg;
1646 my $realm_tfa = $realm_cfg->{tfa
};
1647 $realm_tfa = PVE
::Auth
::Plugin
::parse_tfa_config
($realm_tfa)
1651 return if !$realm_tfa;
1652 die "missing required 2nd keys\n";
1655 # new style config starts with an 'x' and optionally contains a !<type> suffix
1656 if ($keys !~ /^x(?:!.*)?$/) {
1657 # old style config, find the type via the realm
1658 return if !$realm_tfa;
1659 return ($realm_tfa->{type
}, {
1661 config
=> $realm_tfa,
1664 my $tfa_cfg = cfs_read_file
('priv/tfa.cfg');
1665 my $tfa = $tfa_cfg->{users
}->{$username};
1666 return if !$tfa; # should not happen (user.cfg wasn't cleaned up?)
1669 # if the realm has a tfa setting we need to verify the type:
1670 die "auth domain '$realm' and user have mismatching TFA settings\n"
1671 if $realm_tfa && $realm_tfa->{type
} ne $tfa->{type
};
1674 return ($tfa->{type
}, $tfa->{data
});
1678 # bash completion helpers
1680 register_standard_option
('userid-completed',
1681 get_standard_option
('userid', { completion
=> \
&complete_username
}),
1684 sub complete_username
{
1686 my $user_cfg = cfs_read_file
('user.cfg');
1688 return [ keys %{$user_cfg->{users
}} ];
1691 sub complete_group
{
1693 my $user_cfg = cfs_read_file
('user.cfg');
1695 return [ keys %{$user_cfg->{groups
}} ];
1698 sub complete_realm
{
1700 my $domain_cfg = cfs_read_file
('domains.cfg');
1702 return [ keys %{$domain_cfg->{ids
}} ];