1 package PVE
::API2
::AccessControl
;
7 use PVE
::RPCEnvironment
;
8 use PVE
::Cluster
qw(cfs_read_file);
10 use PVE
::AccessControl
;
11 use PVE
::JSONSchema
qw(get_standard_option);
12 use PVE
::API2
::Domains
;
18 use base
qw(PVE::RESTHandler);
20 __PACKAGE__-
>register_method ({
21 subclass
=> "PVE::API2::User",
25 __PACKAGE__-
>register_method ({
26 subclass
=> "PVE::API2::Group",
30 __PACKAGE__-
>register_method ({
31 subclass
=> "PVE::API2::Role",
35 __PACKAGE__-
>register_method ({
36 subclass
=> "PVE::API2::ACL",
40 __PACKAGE__-
>register_method ({
41 subclass
=> "PVE::API2::Domains",
45 __PACKAGE__-
>register_method ({
49 description
=> "Directory index.",
51 additionalProperties
=> 0,
59 subdir
=> { type
=> 'string' },
62 links
=> [ { rel
=> 'child', href
=> "{subdir}" } ],
69 my $ma = __PACKAGE__-
>method_attributes();
71 foreach my $info (@$ma) {
72 next if !$info->{subclass
};
74 my $subpath = $info->{match_re
}->[0];
76 push @$res, { subdir
=> $subpath };
79 push @$res, { subdir
=> 'ticket' };
84 __PACKAGE__-
>register_method ({
85 name
=> 'create_ticket',
88 permissions
=> { user
=> 'world' },
89 protected
=> 1, # else we can't access shadow files
90 description
=> "Create authentication ticket.",
92 additionalProperties
=> 0,
95 description
=> "User name",
99 realm
=> get_standard_option
('realm', {
100 description
=> "You can optionally pass the realm using this parameter. Normally the realm is simply added to the username <username>\@<relam>.",
103 description
=> "The secret password. This can also be a valid ticket.",
107 description
=> "Only create ticket if user have access 'privs' on 'path'",
114 description
=> "Only create ticket if user have access 'privs' on 'path'",
115 type
=> 'string' , format
=> 'pve-priv-list',
125 ticket
=> { type
=> 'string' },
126 username
=> { type
=> 'string' },
127 CSRFPreventionToken
=> { type
=> 'string' },
133 my $username = $param->{username
};
134 $username .= "\@$param->{realm}" if $param->{realm
};
136 my $rpcenv = PVE
::RPCEnvironment
::get
();
137 my $clientip = $rpcenv->get_client_ip() || '';
143 if ($param->{path
} && $param->{privs
}) {
144 my $privs = [ PVE
::Tools
::split_list
($param->{privs
}) ];
145 my $path = PVE
::AccessControl
::normalize_path
($param->{path
});
146 if (!($path && scalar(@$privs) && $rpcenv->check($username, $path, $privs))) {
147 die "no permission ($param->{path}, $param->{privs})\n";
152 if (($tmp = PVE
::AccessControl
::verify_ticket
($param->{password
}, 1)) &&
153 ($tmp eq 'root@pam' || $tmp eq $username)) {
155 # Note: root@pam can create tickets for other users
157 # test if user exists and is enabled
158 my $usercfg = cfs_read_file
('user.cfg');
159 die "no such user ('$username')\n" if !user_enabled
($usercfg, $username);
161 $username = PVE
::AccessControl
::authenticate_user
($username, $param->{password
});
163 $ticket = PVE
::AccessControl
::assemble_ticket
($username);
164 $token = PVE
::AccessControl
::assemble_csrf_prevention_token
($username);
167 syslog
('err', "authentication failure; rhost=$clientip user=$username msg=$err");
171 PVE
::Cluster
::log_msg
('info', 'root@pam', "successful auth for user '$username'");
175 username
=> $username,
176 CSRFPreventionToken
=> $token,