Lukáš Bařinka
© 2021
REV 2.10
auth_*
Authentication type - HTTP Basic or HTTP Digestauthn_*
Authentication providerauthz_*
Authorization providerauthnz_*
Authentication/Authorization providerauth_*
Typ autentizace - HTTP Basic nebo HTTP Digestauthn_*
Poskytovatel autentizaceauthz_*
Poskytovatel autorizaceauthnz_*
Poskytovatel autentizace i autorizaceAuthType
selects the type - basic / digest
Určuje typ - basic / digest
AuthType Basic|Digest|Form|None
Context: directory, .htaccess
Kontext: directory, .htaccess
AuthName
Sets the name of the authorization realm
Nastavuje realm
AuthName auth-domain
Context: directory, .htaccess
Kontext: directory, .htaccess
GET /private/index.html HTTP/1.0
Host: www.mycorp.net
401 UNAUTHORIZED
message
HTTP/1.0 401 UNAUTHORIZED
Server: Apache
WWW-Authenticate: Basic realm="Secured"
GET /private/index.html HTTP/1.0
Host: www.mycorp.net
401 UNAUTHORIZED
HTTP/1.0 401 UNAUTHORIZED
Server: Apache
WWW-Authenticate: Basic realm="Secured"
GET /private/index.html HTTP/1.0
Host: www.mycorp.net
Authorization: Basic eTM2YXdzOnRham5laGVzbG8=
HTTP 200 OK
or again with
HTTP 401 UNAUTHORIZED
GET /private/index.html HTTP/1.0
Host: www.mycorp.net
Authorization: Basic eTM2YXdzOnRham5laGVzbG8=
HTTP 200 OK
nebo opět
HTTP 401 UNAUTHORIZED
base64
base64
v HTTP hlavičcemod_auth_basic
modulemod_auth_basic
AuthBasicProvider
directive
Sets the authentication provider(s)
AuthBasicProvider file
Context: directory, .htaccess
mod_authn_file
implements file
provider
AuthBasicAuthoritative
directive
Sets whether authorization and authentication are passed to lower level modules
AuthBasicAuthoritative On|Off
Context: directory, .htaccess
AuthBasicProvider
Nastavuje způsob uložení dat pro autentizaci
AuthBasicProvider file
Kontext: directory, .htaccess
Poskytovatel souborového (file
) úložište je implementovavý v mod_authn_file
AuthBasicAuthoritative
Nastavuje, jestli autorizace a autentizace se má postoupit do dalšího modulu nižší úrovně
AuthBasicAuthoritative On|Off
Kontext: directory, .htaccess
AuthBasicFake
Fake basic authentication using the given expressions for username and password which is passed as Authorization header to the service behind the webserver
AuthBasicFake off|username [password]
Context: directory, .htaccess
AuthBasicFake
Slouží k nastavení jména a hesla, které se použijí při dotazech na další server uvnitř Authorization hlavičky
AuthBasicFake off|username [password]
Kontext: directory, .htaccess
nonce
number, generates the webserver
Nonce = number used once
H1 = md5(username:realm:password)
H2 = md5(method:digestURI),
response = md5(H1:nonce:H2)
nonce
, určuje webserver
Nonce = number used once
H1 = md5(username:realm:password)
H2 = md5(method:digestURI),
response = md5(H1:nonce:H2)
GET /private-digest/index.html HTTP/1.0
Host: www.mycorp.net
401 UNAUTHORIZED
message
HTTP 401 UNAUTHORIZED
Server: Apache
WWW-Authenticate: Digest realm="Secured", \
nonce="rCILfGxcBAA=75f715e2f17a607a2d5760692c755c1d142a06a7", \
algorithm=MD5, domain="/private"
…
GET /private-digest/index.html HTTP/1.0
Host: www.mycorp.net
HTTP 401 UNAUTHORIZED
Server: Apache
WWW-Authenticate: Digest realm="Secured", \
nonce="rCILfGxcBAA=75f715e2f17a607a2d5760692c755c1d142a06a7", \
algorithm=MD5, domain="/private"
…
GET /private-digest/index.html HTTP/1.0
Host: www.mycorp.net
Authorization: Digest username="alice", realm="Secured", \
nonce="rCILfGxcBAA=75f715e2f17a607a2d5760692c755c1d142a06a7", \
uri="/private-digest/index.html", algorithm=MD5, \
response="cbcb5ab6b72ff3f8a9cff3073fccafd3", \
qop=auth, nc=00000001, cnonce="4c45d62bd34bb841"
HTTP 200 OK
or again with
HTTP 401 UNAUTHORIZED
GET /private-digest/index.html HTTP/1.0
Host: www.mycorp.net
Authorization: Digest username="alice", realm="Secured", \
nonce="rCILfGxcBAA=75f715e2f17a607a2d5760692c755c1d142a06a7", \
uri="/private-digest/index.html", algorithm=MD5, \
response="cbcb5ab6b72ff3f8a9cff3073fccafd3", \
qop=auth, nc=00000001, cnonce="4c45d62bd34bb841"
HTTP 200 OK
nebo opět
HTTP 401 UNAUTHORIZED
AuthUserFile
Sets pathname to user password file
AuthUserFile /pathname/to/.htpasswd
Context: directory, .htaccess
AuthGroupFile
Sets pathname to group file
AuthGroupFile /pathname/to/.htgroup
Context: directory, .htaccess
GroupName: user1 user2 …
AuthUserFile
Nastavuje cestu k souboru s uživateli
AuthUserFile /cesta/k/.htpasswd
Kontext: directory, .htaccess
AuthGroupFile
Nastavuje cestu k souboru se skupinami
AuthGroupFile /cesta/k/.htgroup
Kontext: directory, .htaccess
GroupName: user1 user2 …
htpasswd
command
-c | Create a new file |
-b | Use the password from the command line rather than prompting for it |
-D | Delete the specified user |
-n | Don't update file; display results on stdout |
htpasswd
-c | Vytvoří nový soubor |
-b | Použije argument z příkazové řádky jako heslo |
-D | Smaže zadaného uživatele |
-n | Nezmění soubor, jenom zobrazí výsledek na výstup |
htpasswd passwordfile username
htpasswd -b passwordfile username password
htpasswd -n username
htpasswd -nb username password
Require
(core)
Allows request based on condition - user, valid-user, group, …
Require [not] entity-name
Context: directory, .htaccess
Satisfy
(core) legacy
Access policy if both Allow and Require usedRequireAny
/ RequireAll
containers
Satisfy Any|All
Default: Satisfy All
, context: directory, .htaccess
Require
(core)
Vyžaduje splnění kritéria - user, valid-user, group, …
Require [not] entity-name
Kontext: directory, .htaccess
Satisfy
(core) legacy
Vyžaduje splnění alespoň nějakého/všech kritériíRequire
nebo Allow from
) RequireAny
/ RequireAll
Satisfy Any|All
Výchozí: Satisfy All
, kontext: directory, .htaccess
Require
Allows or denies access to requested resource based on many conditions
Řídí přístup ke zdroji na základě různých kritérií
Require all denied|granted
Require host address
Require ip ip.address
Require forward-dns hostname
Require local
Require env variable
Require method http-method
Require expr expression
Require user username
Require group groupname
Require valid-user
Require not …
mod_authz_owner
moduleRequire
entities
file-owner
file-group
AuthzOwnerAuthoritative
Sets whether authorization will be passed on to lower level modules deprecated
AuthzOwnerAuthoritative On|Off
mod_authz_owner
Require
)
file-owner
file-group
AuthzOwnerAuthoritative
Povoluje/zakazuje postoupení kontroly dalším modulům deprecated
AuthzOwnerAuthoritative On|Off
<Directory /var/www/main/private>
AuthType basic
AuthName "Secured"
AuthBasicProvider file
AuthBasicAuthoritative On
AuthUserFile /var/www/.htpasswd
Require valid-user
</Directory>
AuthMerging
Controls the manner of configuration sections combination
AuthMerging Off | And | Or
Default: AuthMerging Off
, context: directory, .htaccess
<Directory "/www/docs"> # alpha only
AuthType Basic
AuthName Documents
AuthBasicProvider file
AuthUserFile "/usr/local/apache/passwd/passwords"
AuthGroupFile "/usr/local/apache/passwd/groups"
Require group alpha
</Directory>
<Directory "/www/docs/ab"> # alpha or beta
AuthMerging Or
Require group beta
</Directory>
<Directory "/www/docs/ab/gamma"> # gama only – the default manner
Require group gamma
</Directory>
AuthMerging
Ovládá způsob kombinace konfiguračních sekcí (kontejnerů)
AuthMerging Off | And | Or
Výchozí: AuthMerging Off
, kontext: directory, .htaccess
<Directory "/www/docs"> # jenoma alpha
AuthType Basic
AuthName Documents
AuthBasicProvider file
AuthUserFile "/usr/local/apache/passwd/passwords"
AuthGroupFile "/usr/local/apache/passwd/groups"
Require group alpha
</Directory>
<Directory "/www/docs/ab"> # alpha nebo beta
AuthMerging Or
Require group beta
</Directory>
<Directory "/www/docs/ab/gamma"> # jenom gama – výchozí způsob kombinace
Require group gamma
</Directory>
The goal is to configure authentication required to access resources. Usernames and passwords have to be created for that purpose inside webserver (they do not need to match operating system users). In another case, those users need to correspond to system users to use ownership condition.
Cílem je nakonfigurovat použití autentizace pro umožnění přístupu ke zdrojům. K tomu je potřeba definovat uživatele (a jejich hesla) v rámci webového serveru. Aby bylo možné vyzkoušet navázat autorizaci na vlastnictví souborů, je potřeba také vytvořit odpovídající uživatele v operačním systému.
If authenticated user is required but there is no authentication configured, server status is 500
.
Pokud je požadován přihlášený uživatel, ale autentizace není nakonfigurovaná, server vrací stavový kód 500
.
useradd alice # already present
useradd bob # already present
useradd cecil # new system user
echo -n user:pass | base64 # ↓
curl -H 'Authorization: Basic …' URL
/var/www/main/private
directory and its files alice.txt
and bob.txt
with corresponding ownerslocalhost
onlyalice
, bob
, and cecil
to access to that directoryalice
only to that directory/var/www/main/private
a v něm soubory alice.txt
a bob.txt
, které budou vlastnit příslušní uživatelélocalhost
ualice
, bob
a cecil
alice
localhost
, orlocalhost
u neboauthz_owner
modulececil
cecil
but from localhost
onlyauthz_owner
cecil
cecil
a to pouze z localhost
u
LoadModule authz_owner_module \
modules/mod_authz_owner.so
<Directory /var/www/main/private>
AuthType basic
AuthName "Secured"
AuthBasicProvider file
AuthBasicAuthoritative On
AuthUserFile /var/www/.htpasswd
<RequireAll>
<RequireAny>
Require file-owner
Require user cecil
</RequireAny>
Require local
</RequireAll>
</Directory>
DN fieldExample | Abbrev. | Description |
---|---|---|
Common NameCN=fit.cvut.cz | CN | Name being certified |
OrganizationO=CTU in Prague | O | Name is associated with this organization |
Organizational UnitOU=ICT | OU | Name is associated with this organization unit (department) |
City/LocalityL=Prague 6 - Dejvice | L | Name is located in this City |
State/ProvinceST=Prague | ST | Name is located in this State/Province |
CountryC=CZ | C | Name is located in this Country (ISO code) |
DN polePříklad | Zkratka | Popis |
---|---|---|
Common NameCN=fit.cvut.cz | CN | certifikované jméno |
OrganizationO=ČVUT v Praze | O | jméno organizace |
Organizational UnitOU=ICT | OU | jméno organizační jednotky |
City/LocalityL=Praha 6 - Dejvice | L | jméno města |
State/ProvinceST=Hlavní město Praha | ST | jméno kraje |
CountryC=CZ | C | jméno země (ISO code) |
Binary format of a certificate – variants:
Binární formát certifikátu – způsoby uložení:
DER
– Raw binary data Distinguished Encoding Rules
PEM
– Base64 encoded (ASCII) Privacy Enhanced Mail
DER
– přímo binární data Distinguished Encoding Rules
PEM
– Base64 encoded (ASCII) Privacy Enhanced Mail
openssl x509 -in cert.pem -out cert.der -outform DER
openssl req -new -x509 -nodes -out server.crt -keyout server.key -days 365
Generating a 1024 bit RSA private key
…
Country Name (2 letter code) [AU]:CZ
State or Province Name (full name) [Some-State]:Prague
Locality Name (eg, city) []:Prague
Organization Name (eg, company) [Internet Widgits Pty Ltd]:MyCorporation
Organizational Unit Name (eg, section) []:Web
Common Name (eg, YOUR name) []:www.mycorp.net
Email Address []:admin@mycorp.net
openssl req -new -x509 -nodes -out server.crt -keyout server.key -days 365 \
-subj "/C=CZ/ST=Prague/L=Prague/O=MyCorporation/OU=Web/"\
"CN=www.mycorp.net/emailAddress=admin@mycorp.net/"
openssl x509 -noout -text -in server.crt
Finished
) contains hash of all transferred messages during initializationFinished
) obsahuje hash všech zpráv vyměněných v rámci inicializace oběma stranamiSecurity is dependent on cryptographic algorithms supported by web server and web browser Bezpečnost je značně závislá na kryptografických algoritmech podporovaných web serverem a prohlížečem https://httpd.apache.org/docs/2.4/mod/mod_ssl.html#sslciphersuite
Host:
Host:
!
<IfDefine SSL>
LoadModule ssl_module modules/mod_ssl.so
</IfDefine>
openssl version
OpenSSL 1.1.1k 25 Mar 2021
SSLEngine
directive
Enable/disable SSL, usually per virtualhost
SSLEngine On|Off|optional
Context: server, virtualhost
SSLOptions
directive
Configure various SSL engine run-time options
SSLOptions [+|-] option …
Context: server, virtualhost, directory, .htaccess
StdEnvVars
SSL related CGI/SSI environment variables are createdExportCertData
additional CGI/SSI environment variables are createdSSLEngine
Zapne/vypne SSL, typicky virtualhost
SSLEngine On|Off|optional
Kontext: server, virtualhost
SSLOptions
Nastavuje různé možnosti SSL
SSLOptions [+|-] option …
Kontext: server, virtualhost, directory, .htaccess
StdEnvVars
exportuje standardní proměnné prostředí spojené se SSLExportCertData
do proměnných prostředí uloží certifikáty klienta a serveruSSLProtocol
directive
Configure usable SSL/TLS protocol versions SSLv3, TLSv1, TLSv1.1, TLSv1.2, TLSv1.3, All
SSLProtocol [+|-]protocol
Default: SSLProtocol All
, context: server, virtualhost
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
SSLProtocol
Určuje verzi protokolu SSLv3, TLSv1, TLSv1.1, TLSv1.2, TLSv1.3, All
SSLProtocol [+|-]protocol
Výchozí: SSLProtocol All
, kontext: server, virtualhost
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
SSLCipherSuite
directive
Cipher Suite available for negotiation in SSL handshake
Určuje šifry, které se mohou použít při dojednání s klientem
SSLCipherSuite cipher-spec
Default: SSLCipherSuite DEFAULT
(depends on OpenSSL version), context: server, virtualhost, directory, .htaccess
Výchozí: SSLCipherSuite DEFAULT
(závisí na verzi OpenSSL), kontext: server, virtualhost, directory, .htaccess
Since TLSv1.3 does not offer renegotiations, specifying ciphers for it in a directory context is not allowed.
Od TLSv1.3 není podporováno nové vyjednávání (renegotiations), proto není možná konfigurace per adresář.
# Be liberal in general
SSLCipherSuite ALL:!aNULL:RC4+RSA:+HIGH:+MEDIUM:+LOW:+EXP:+eNULL
<Location "/strong/area">
# But here and below requires strong ciphers
SSLCipherSuite HIGH:!aNULL:!MD5
</Location>
none | Add cipher to list |
+ | Move matching ciphers to the current location in list |
- | Remove cipher from list (can be added later again) |
! | Kill cipher from list completely (can not be added later again) |
none | Přidá šifru do seznamu |
+ | Přesune šifru na aktuální pozici v seznamu |
- | Odebere šifru ze seznamu (lze přidat později) |
! | Odebere úplně šifru ze seznamu (nelze přidat později) |
SSLCertificateFile
directive
Server PEM-encoded X.509 certificate data file/token identifier
SSLCertificateFile /pathname/to/certificate.crt
Context: server, virtualhost
SSLCertificateKeyFile
directive
Server PEM-encoded private key file
SSLCertificateKeyFile /pathname/to/certificate.key
Context: server, virtualhost
SSLCertificateChainFile
directive
File of PEM-encoded Server CA Certificates
SSLCertificateChainFile /pathname/to/ca.crt
Context: server, virtualhost
SSLCertificateFile
Souboru s certifikátem serveru v PEM formátu
SSLCertificateFile /cesta/k/certifikatu.crt
Kontext: server, virtualhost
SSLCertificateKeyFile
Souboru s privátním klíčem serveru v PEM formátu
SSLCertificateKeyFile /cesta/k/certifikatu.key
Kontext: server, virtualhost
SSLCertificateChainFile
Souboru s řetězcem certifikátů CA – vydaly certifikát serveru
SSLCertificateChainFile /cesta/k/ca.crt
Kontext: server, virtualhost
SSLRequireSSL
directive
Deny access when SSL is not used for the HTTP request
SSLRequireSSL
Context: directory, .htaccess
SSLRequire
directive - deprecated ⇒ Use Require expr
instead
Allow access only when an arbitrarily complex boolean expression is true, it's possible to use environment variables
SSLRequire true | false | expr && expr ...
Context: directory, .htaccess
SSLRequire %{SSL_CIPHER_USEKEYSIZE} >= 128
SSLRequireSSL
Direktiva vynucuje SSL pro přístup ke zdroji
SSLRequireSSL
Kontext: directory, .htaccess
SSLRequire
- deprecated ⇒ Místo ní použijte Require expr
Udává požadavky, které musí být splněny při komunikaci - boolovská podmínka - lze používat proměnné prostředí
SSLRequire true | false | expr && expr ...
Kontext: directory, .htaccess
SSLRequire %{SSL_CIPHER_USEKEYSIZE} >= 128
Listen …:443
LoadModule ssl_module modules/mod_ssl.so
<VirtualHost …:443>
ServerName www.mycorp.net
# enable SSL
SSLEngine on
# TLSv1.2, TLSv1.3
SSLProtocol all -SSLv3 -TLSv1 -TLSv1.1
# SSL Cipher Suite:
SSLCipherSuite ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:…
# Server Certificate (RSA)
SSLCertificateFile conf/ssl/mycorp.crt
# Server Private Key (RSA)
SSLCertificateKeyFile conf/ssl/mycorp.key
CustomLog /var/log/apache2/ssl.log "%h %t \"%r\" %{SSL_PROTO}x %{SSL_CIPHER}x"
</VirtualHost>
https://ssl-config.mozilla.org/#server=apache
telnet localhost 80
GET / HTTP/1.0
openssl s_client -connect localhost:443 -state -debug
GET / HTTP/1.0^V↵↵^V↵↵
Lines end with CR+LF (\r\n
): Use ^V↵↵
to insert CR+LF
telnet localhost 80
GET / HTTP/1.0
openssl s_client -connect localhost:443 -state -debug
GET / HTTP/1.0^V↵↵^V↵↵
Jako konec řádku je potřeba odeslat \r\n
: ^V↵↵
The goal is to configure secure connection. A pair of keys (private and public) and a certificate are needed for that. It is possible to have different certificates for different virtualhosts.
Cílem je nakonfigurovat použití šifrovaného spojení se serverem. K tomu je zapotřebí vytvořit dvojici klíčů (veřejný a soukromý) a certifikáty. Pro různé virtualhosty je možné použít různé certifikáty.
mod_ssl
module
E.g. They are part of libssl-dev
package in Debian
apt install -y libssl-dev
mod_ssl
jsou zapotřebí hlavičkové soubory knihovny SSL
Např. v Debianu jsou součástí balíku libssl-dev
apt install -y libssl-dev
www.mycorp.net
domainwww.othercorp1.net
and www.othercorp2.net
domainswww.mycorp.net
www.othercorp1.net
a www.othercorp2.net
openssl genrsa -out CA.key 2048
openssl req -x509 -new -nodes -days 7300 -key CA.key -days 7300 -out CA.pem
openssl genrsa -out alice.key 2048
openssl req -new -key alice.key -out alice.csr
openssl x509 -sha256 -req -in alice.csr -out alice.crt \
-CA CA.pem -CAkey CA.key -CAcreateserial -days 1095
.csr
= Certificate Signing Request
<VirtualHost ....:443>
ServerName www.mycorp.net
ServerAlias www.aliascorp.net
DocumentRoot /var/www/vhosts/mycorp
SSLEngine on
SSLCertificateFile server.crt
SSLCertificateKeyFile server.key
SSLCACertificateFile CA.pem
<Location />
SSLOptions +StdEnvVars
SSLVerifyClient require
SSLRequire ( %{SSL_CLIENT_S_DN_CN} == 'Alice' )
</Location>
</VirtualHost>
curl -i -k -E alice.crt --key alice.key https://www.mycorp.net/
SSLVerifyClient
directive
Type of client certificate verification
SSLVerifyClient none
Context: server, virtualhost, directory, .htaccess
none | no client certificate is required at all |
optional | the client may present a valid certificate |
require | the client has to present a valid certificate |
optional_no_ca | the client may present a valid certificate but it need not to be verifiable Not for authentication |
SSLVerifyClient
Určuje způsob ověření klientského certifikátu
SSLVerifyClient none
Kontext: server, virtualhost, directory, .htaccess
none | není vyžadován/zpracováván certifikát |
optional | klient může poskytnou certifikát |
require | je vyžadován certifikát |
optional_no_ca | klient může poskytnout certifikát, který není ověřitelný Not for authentication |
SSLUserName
directive
Variable name to determine user name
SSLUserName varname
Context: server, directory, .htaccess
Kontext: server, directory, .htaccess
SSLUserName SSL_CLIENT_S_DN_CN
<Location />
SSLOptions +StdEnvVars
SSLVerifyClient optional
</Location>
<Directory /var/www/main/private>
Require user Alice
</Directory>