| 1 |
[[cert-authentication]] |
| 2 |
= Certificate/smart card authentication |
| 3 |
|
| 4 |
Cockpit can use TLS client certificates for authenticating users. |
| 5 |
Commonly these are provided by a smart card, but it's equally possible |
| 6 |
to import certificates directly into the web browser. |
| 7 |
|
| 8 |
This requires the host to be in an Identity Management domain like |
| 9 |
https://www.freeipa.org[FreeIPA] or |
| 10 |
https://en.wikipedia.org/wiki/Active_Directory[Active Directory], which |
| 11 |
can associate certificates to users. |
| 12 |
|
| 13 |
To authenticate users from a Identity Management domain, the server that |
| 14 |
Cockpit is running on must be joined to that domain. See the |
| 15 |
xref:sso.adoc#sso-server[SSO server requirements] for details. |
| 16 |
|
| 17 |
[[certauth-server-cert-generation]] |
| 18 |
== User certificate generation |
| 19 |
|
| 20 |
Generating the certificates for users is usually done with a certificate |
| 21 |
management system like https://pagure.io/certmonger[certmonger] or |
| 22 |
https://www.freeipa.org/page/PKI[FreeIPA], which are not documented |
| 23 |
here. This command generates a simple key and certificate request for |
| 24 |
the "alice" user: |
| 25 |
|
| 26 |
.... |
| 27 |
openssl req -new -newkey rsa:2048 -days 365 \ |
| 28 |
-keyout alice.key -out alice.csr -subj "/CN=alice" |
| 29 |
.... |
| 30 |
|
| 31 |
Now get this certificate request signed by the Certificate Authority of |
| 32 |
your Identity Management domain, to get a PEM certificate. Browsers and |
| 33 |
smart cart utilities accept PKCS#12 format for importing/transfer, so |
| 34 |
convert the certificate/key pair; it will ask for and protect it with a |
| 35 |
transfer password: |
| 36 |
|
| 37 |
.... |
| 38 |
openssl pkcs12 -export -in alice.pem -inkey alice.key -out alice.p12 |
| 39 |
.... |
| 40 |
|
| 41 |
Don't forget to clean up the key file when you do not need it any more: |
| 42 |
|
| 43 |
.... |
| 44 |
shred -u alice.key |
| 45 |
.... |
| 46 |
|
| 47 |
You can now import `+alice.p12+` directly into your browser, with giving |
| 48 |
the transfer password set above. Or |
| 49 |
https://linux.die.net/man/1/pkcs15-init[put the certificate onto a smart |
| 50 |
card]: |
| 51 |
|
| 52 |
.... |
| 53 |
pkcs15-init --store-private-key alice.p12 --format pkcs12 --auth-id 01 |
| 54 |
.... |
| 55 |
|
| 56 |
[[certauth-server-ipa]] |
| 57 |
== Certificate mapping with FreeIPA |
| 58 |
|
| 59 |
The recommended method to sign a user certificate request and associate |
| 60 |
it to a user is `+ipa cert-request+`: |
| 61 |
|
| 62 |
.... |
| 63 |
ipa cert-request alice.csr --principal=alice --certificate-out=alice.pem |
| 64 |
.... |
| 65 |
|
| 66 |
Alternatively, if you are using a different CA, you can use |
| 67 |
`+ipa user-add-cert+` to associate the signed certificate to the user. |
| 68 |
This expects PEM format, but without the `+-----BEGIN+`/`+-----END+` |
| 69 |
markers: |
| 70 |
|
| 71 |
.... |
| 72 |
ipa user-add-cert alice --certificate="$(grep -v ^---- alice.pem)" |
| 73 |
.... |
| 74 |
|
| 75 |
See the |
| 76 |
https://www.freeipa.org/page/V4/User_Certificates#Feature_Management[FreeIPA |
| 77 |
User Certificates documentation] for details. |
| 78 |
|
| 79 |
[[certauth-server-ms-ad]] |
| 80 |
== Certificate mapping with Microsoft Active Directory |
| 81 |
|
| 82 |
The domain user certificates get imported into the |
| 83 |
`+userCertificate;binary+` LDAP attribute. The following commands |
| 84 |
convert the PEM certificate into binary DER form, create an |
| 85 |
https://ldap.com/ldif-the-ldap-data-interchange-format/[LDIF] file and |
| 86 |
apply it to the LDAP server running on the domain controller |
| 87 |
"dc.example.com": |
| 88 |
|
| 89 |
.... |
| 90 |
openssl x509 -outform der -in alice.pem -out alice.der |
| 91 |
|
| 92 |
cat <<EOF > alice.ldif |
| 93 |
version: 1 |
| 94 |
dn: cn=alice,ou=users,ou=YOUR_NETBIOS_NAME,dc=example,dc=com |
| 95 |
changetype: modify |
| 96 |
add: userCertificate;binary |
| 97 |
userCertificate;binary:< file://$(pwd)/alice.der |
| 98 |
EOF |
| 99 |
|
| 100 |
ldapmodify -H ldap://dc.example.com -f alice.ldif |
| 101 |
.... |
| 102 |
|
| 103 |
[[certauth-server-samba-ad]] |
| 104 |
== Certificate mapping with Samba Active Directory |
| 105 |
|
| 106 |
At least some versions of https://www.samba.org/[Samba] do not support |
| 107 |
the `+userCertificate;binary+` LDAP attribute, so the import has to |
| 108 |
happen in base64 PEM form into the textual `+userCertificate+` attribute |
| 109 |
instead. Also, Samba uses a slightly different user hierarchy: |
| 110 |
|
| 111 |
.... |
| 112 |
cat <<EOF > alice.ldif |
| 113 |
version: 1 |
| 114 |
dn: cn=alice,cn=users,dc=example,dc=com |
| 115 |
changetype: modify |
| 116 |
add: userCertificate |
| 117 |
userCertificate: $(grep -v ^---- alice.pem | tr -d '\n') |
| 118 |
EOF |
| 119 |
|
| 120 |
ldapmodify -H ldap://dc.example.com -f alice.ldif |
| 121 |
.... |
| 122 |
|
| 123 |
As `+userCertificate+` is a text instead of binary field, you need to |
| 124 |
set up a |
| 125 |
https://www.mankier.com/5/sssd.conf#Certificate_Mapping_Section[certificate |
| 126 |
mapping rule] in `+sssd.conf(5)+` in a `+[certmap/domain/rulename]+` |
| 127 |
section, for example: |
| 128 |
|
| 129 |
.... |
| 130 |
[certmap/example.com/adcerts] |
| 131 |
# we match full certificates, so it is not important to check anything here |
| 132 |
matchrule = <KU>digitalSignature |
| 133 |
maprule = LDAP:(userCertificate={cert!base64}) |
| 134 |
.... |
| 135 |
|
| 136 |
[[certauth-server-cockpitconf]] |
| 137 |
== Cockpit web server configuration |
| 138 |
|
| 139 |
Set the trusted Certificate Authority of your user certificates in |
| 140 |
`+sssd+`, either by copying the CA PEM file to |
| 141 |
`+/etc/sssd/pki/sssd_auth_ca_db.pem+` or setting the |
| 142 |
https://www.mankier.com/5/sssd.conf#Services_Sections-PAM_configuration_options[`+pam_cert_db_path+`] |
| 143 |
configuration option to the path of the CA. If you use FreeIPA and its |
| 144 |
CA: |
| 145 |
|
| 146 |
.... |
| 147 |
cp /etc/ipa/ca.crt /etc/sssd/pki/sssd_auth_ca_db.pem |
| 148 |
.... |
| 149 |
|
| 150 |
Certificate authentication needs to be enabled in |
| 151 |
man:cockpit.conf[5] explicitly: |
| 152 |
|
| 153 |
.... |
| 154 |
[WebService] |
| 155 |
ClientCertAuthentication = yes |
| 156 |
.... |
| 157 |
|
| 158 |
When enabling this mode, |
| 159 |
https://github.com/cockpit-project/cockpit/blob/main/doc/authentication.md[other |
| 160 |
authentication types] commonly get disabled, so that _only_ client |
| 161 |
certificate authentication will be accepted. By default, after a failed |
| 162 |
certificate authentication attempt, Cockpit's normal login page will |
| 163 |
appear and permit other login types such as `+basic+` (passwords) or |
| 164 |
`+negotiate+` (Kerberos). For example, password authentication gets |
| 165 |
disabled with: |
| 166 |
|
| 167 |
.... |
| 168 |
[basic] |
| 169 |
action = none |
| 170 |
.... |
| 171 |
|
| 172 |
[[certauth-server-resourcelimits]] |
| 173 |
== Cockpit web server resource limits |
| 174 |
|
| 175 |
When using certificate authentication, all requests with a particular |
| 176 |
certificate will be handled by a separate and isolated instance of the |
| 177 |
man:cockpit-ws[8] web server. This protects against |
| 178 |
possible vulnerabilities in the web server and prevents an attacker from |
| 179 |
impersonating another user. However, this introduces a potential Denial |
| 180 |
of Service: Some remote attacker could create a large number of |
| 181 |
certificates and send a large number of http requests to Cockpit with |
| 182 |
these. |
| 183 |
|
| 184 |
To mitigate that, all `+cockpit-ws+` instances run in a |
| 185 |
`+system-cockpithttps.slice+` |
| 186 |
https://www.freedesktop.org/software/systemd/man/systemd.slice.html[systemd |
| 187 |
slice unit] which |
| 188 |
https://www.freedesktop.org/software/systemd/man/systemd.resource-control.html[limits |
| 189 |
the collective resources] of these web server instances: by default, |
| 190 |
this slice sets a limit of 200 threads (roughly 100 instances of |
| 191 |
`+cockpit-ws+` -- in other words, a maximum of 100 parallel user |
| 192 |
sessions with different certificates) and a 75% (soft)/90% (hard) memory |
| 193 |
limit. |
| 194 |
|
| 195 |
You are welcome to adjust these limits to your need through a |
| 196 |
https://www.freedesktop.org/software/systemd/man/systemd.unit.html[drop-in]. |
| 197 |
For example: |
| 198 |
|
| 199 |
.... |
| 200 |
# systemctl edit system-cockpithttps.slice |
| 201 |
|
| 202 |
[Slice] |
| 203 |
# change existing value |
| 204 |
TasksMax=100 |
| 205 |
# add new restriction |
| 206 |
CPUQuota=30% |
| 207 |
.... |
| 208 |
|
| 209 |
[[certauth-forwarding]] |
| 210 |
== Authentication to other services like sudo and ssh |
| 211 |
|
| 212 |
Once you logged into Cockpit with a certificate, you likely need to |
| 213 |
switch to administrative mode (root privileges through sudo), or connect |
| 214 |
to remote machines through SSH. If your user account has a password, |
| 215 |
that can be used for authenticating to sudo or ssh as usual. |
| 216 |
|
| 217 |
_Supported with FreeIPA only:_ As an alternative to password |
| 218 |
authentication, you can also declare the initial Cockpit certificate |
| 219 |
authentication as trusted for authenticating to SSH, sudo, or other |
| 220 |
services. For that purpose, Cockpit automatically creates an |
| 221 |
https://docs.microsoft.com/en-us/openspecs/windows_protocols/ms-sfu/bde93b0e-f3c9-4ddf-9f44-e1453be7af5a[S4U2Proxy |
| 222 |
Kerberos ticket] in the user session: |
| 223 |
|
| 224 |
.... |
| 225 |
$ klist |
| 226 |
Ticket cache: FILE:/run/user/1894000001/cockpit-session-3692.ccache |
| 227 |
Default principal: [email protected] |
| 228 |
|
| 229 |
Valid starting Expires Service principal |
| 230 |
07/30/21 09:19:06 07/31/21 09:19:06 HTTP/[email protected] |
| 231 |
07/30/21 09:19:06 07/31/21 09:19:06 krbtgt/[email protected] |
| 232 |
for client HTTP/[email protected] |
| 233 |
.... |
| 234 |
|
| 235 |
You can set up |
| 236 |
https://www.freeipa.org/page/V4/Service_Constraint_Delegation[constrained |
| 237 |
delegation rules] to enumerate which hosts (including its own) that |
| 238 |
ticket is trusted to access. For example, if the cockpit session runs on |
| 239 |
host `+myhost.example.com+` and should be trusted to access its own host |
| 240 |
(through sudo) and another host `+remote.example.com+` (through ssh), |
| 241 |
create a delegation like this: |
| 242 |
|
| 243 |
.... |
| 244 |
# a list of target machines which can be accessed by a particular rule |
| 245 |
ipa servicedelegationtarget-add cockpit-target |
| 246 |
ipa servicedelegationtarget-add-member cockpit-target \ |
| 247 |
--principals=host/[email protected] \ |
| 248 |
--principals=host/[email protected] |
| 249 |
|
| 250 |
# allow cockpit sessions (HTTP/ principal) to access that host list |
| 251 |
ipa servicedelegationrule-add cockpit-delegation |
| 252 |
ipa servicedelegationrule-add-member cockpit-delegation \ |
| 253 |
--principals=HTTP/[email protected] |
| 254 |
ipa servicedelegationrule-add-target cockpit-delegation \ |
| 255 |
--servicedelegationtargets=cockpit-target |
| 256 |
.... |
| 257 |
|
| 258 |
In addition, you need to enable GSS (Kerberos) authentication in the |
| 259 |
corresponding services. |
| 260 |
|
| 261 |
* For SSH, enable `+GSSAPIAuthentication yes+` in |
| 262 |
https://linux.die.net/man/5/sshd_config[/etc/ssh/sshd_config]. |
| 263 |
* For sudo, enable `+pam_sss_gss+` as described in the |
| 264 |
https://www.mankier.com/8/pam_sss_gss[manpage]: In |
| 265 |
`+/etc/sssd/sssd.conf+`: Add an entry for your domain: |
| 266 |
+ |
| 267 |
.... |
| 268 |
[domain/example.com] |
| 269 |
pam_gssapi_services = sudo, sudo-i |
| 270 |
.... |
| 271 |
+ |
| 272 |
In `+/etc/pam.d/sudo+`, enable the module in the first line: |
| 273 |
+ |
| 274 |
.... |
| 275 |
auth sufficient pam_sss_gss.so |
| 276 |
.... |
| 277 |
|
| 278 |
_Caveat:_ The delegated S4U ticket is not yet forwarded to remote SSH |
| 279 |
hosts when connecting to them from Cockpit, so authenticating to sudo on |
| 280 |
the remote host with that ticket does not work. This will be provided in |
| 281 |
a future version. |