Giter VIP home page Giter VIP logo

spid-wordpress's Introduction

SPID

Join the #spid-wordpress channel Get invited SPID on forum.italia.it Build Status

⚠️ WORK IN PROGRESS ⚠️

spid-wordpress

Plugin WordPress per l'autenticazione attraverso un Identity Provider SPID (Sistema Pubblico di Identità Digitale) basato sulla libreria SPID PHP italia/spid-php-lib.

SPID, il Sistema Pubblico di Identità Digitale, è la soluzione che permette ai cittadini di accedere a tutti i servizi online della Pubblica Amministrazione con un'unica Identità Digitale (username e password) utilizzabile da computer, tablet e smartphone.

Questo plugin integra il login SPID in WordPress, offrendo le seguenti funzionalità:

  • completamente configurabile
  • generazione del metadata del Service Provider (SP)
  • creazione automatica un utente WordPress distinto per ogni utente SPID che accede, e acquisizione dell'indirizzo email dell'utente da SPID
  • possibilità di acquisire altri attributi (codice fiscale, data di nascita ...) se richiesto
  • predisposizione per il testing con l'Identity Provider di test spid-testenv2.

Compatibile con:

  • WordPress 4.9.8
  • PHP 7.2, 7.3 e 7.4
  • Solo WP single-site (no multi-site).

Attenzione alla GDPR!

Quando il plugin è attivo, in base alle impostazioni, esso può salvare certi dati personali degli utenti SPID nel database WordPress.

Si tratta degli attributi utente da richiedere a SPID: due sono indispensabili al funzionamento del plugin (codice identificativo SPID e indirizzo di posta elettronica), gli altri (es. il codice fiscale, la data di nascita, il sesso etc.) possono essere impostati nella sezione "Metadata" di SPID Opzioni.

Più attributi SPID si richiedono più aumentano i rischi e la complessità della gestione di questi dati personali dal punto di vista della GDPR (Regolamento generale sulla protezione dei dati, in inglese General Data Protection Regulation).

Il plugin acquisisce il valido consenso ai sensi della GDPR, tuttavia restano in carico al Service Provider:

  • la sicurezza dell'installazione WordPress
  • la gestione delle richieste da parte degli utenti di accesso e cancellazione dei dati
  • la notifica delle violazioni dei dati
  • e la pubblicazione dell'informativa per gli utenti su fini e modalità del trattamento dei dati personali.

Per iniziare

Testato su: amd64 Debian 10 (buster, current stable) con PHP 7.3.

Installazione e configurazione

Per usare questo plugin, occorre:

  1. Un'installazione WordPress funzionante

  2. Installarlo, attivarlo, e configurarlo completamente usando la pagina di impostazioni.

  3. (OPZIONALE) Generare chiave (wp.key) e certificato (wp.crt) del Service Provider (SP) nella directory {WordPress root}/spid-conf/, ad esempio:

    cd /var/www/html/wp-content/plugins/spid-wordpress
    mkdir -p spid-conf
    cd spid-conf
    openssl req -x509 -nodes -sha256 -days 365 -newkey rsa:2048 -subj "/C=IT/ST=Italy/L=Milan/O=myservice/CN=localhost" -keyout wp.key -out wp.crt
    chown www-data:www-data wp.key wp.crt

    Questo passo può essere saltato (il plugin è in grado di generarli in automatico) tuttavia in questo caso la directory {WordPress root}/spid-conf/ deve essere presente e accessibile in lettura/scrittura all'utente impersonato dal server web (es. www-data).

  4. Scaricare e verificare i metadata degli Identity Provider (IdP) nella directory {WordPress root}/spid-conf/idp_metadata/; un tool per automatizzare questa operazione per gli IdP in produzione è incluso in spid-php-lib, esempio di utilizzo:

    cd /var/www/html/wp-content/plugins/spid-wordpress
    mkdir -p spid-conf/idp_metadata
    ./spid-php-lib/bin/download_idp_metadata.php spid-conf/idp_metadata
  5. Scaricare il metadata del SP (Service Provider) da https://wp.example.com/wp-login.php?sso=spid&metadata e registrarlo coll'IdP.

NOTA: durante il test, si raccomanda l'uso dell'Identity Provider di test spid-testenv2.

Uso

Visitare: https://wp.example.com/wp-login.php e cliccare sul bottone SPID.

Questo screencast mostra cosa dovrebbe succedere se tutto funziona:

img

Demo

Un'installazione WordPress preconfigurata usando docker-compose con questo plugin e l'IdP di test è diponibile qui: https://github.com/simevo/spid-wordpress-example.

Altri esempi applicativi:

Troubleshooting

Per automatizzare la configurazione WordPress di consiglia l'uso della wp-cli (Command-Line Interface for WordPress).

Per analizzare e debuggare i messaggi SPID si rimanda alla sezione Troubleshooting del README della libreria spid-php-lib.

Sviluppo

Per maggiori informazioni su come contribuire allo sviluppo di questo plugin, vedi il file README-DEV.md (en).

Authors

Giulio Gatto, Paolo Greppi, Riccardo Mariani e Michael Tieso

Licenza

Copyright (c) 2018-2020 simevo s.r.l. Licenza: AGPL 3, vedi LICENSE.

spid-wordpress's People

Contributors

giuliogatto avatar michaeltieso avatar simevo avatar valamiro avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

em-

spid-wordpress's Issues

SPID user default role override

in WP è possibile definire il ruolo di difetto per tutti i nuovi utenti; in #1 si propone di permettere l'override di questa impostazione per gli utenti creati dal plugin SPID; questo settaggio però dovrebbe essere opzionale in modo che se non viene impostato li crea con il ruolo default globale ...

save SPID attributes in wp_usermeta

let's use the spid_ prefix; examples of SPID attributes:

  • spid_placeOfBirth
  • spid_countryOfBirth
  • spid_dateOfBirth
  • spid_gender
  • spid_fiscalNumber
  • spid_idCard
  • spid_mobilePhone
  • spid_address
  • spid_expirationDate
  • spid_digitalAddress

SPID users should only be allowed to login with SPID

A user may gain access to a WP install once with her SPID login, then loose access / change her SPID login.
After a year, by resetting her WP password she could login with a regular WordPress user/pass, bypassing SPID, and her SPID attributes would not be refreshed (see #57).

To avoid these situations, on login with regular WP user/pass, if the user is detected as a SPID user (has a spidCode in metadata), we need to force SPID login !

refresh SPID attributes with each login

once #13 and #31 are solved, we need to refresh the SPID attributes with each login

SPID credentials can be modified, as this SPID profile management screenshot for one of the production IdPs shows:

image

Moving external files to the plugin

public function spid_enqueue_scripts() {
function enqueue_login_script() {
wp_enqueue_script( 'spid-smart-button-script', 'https://italia.github.io/spid-smart-button/spid-button.min.js', false );
}
function enqueue_login_css() {
wp_enqueue_style( 'spid-smart-button-css', 'https://italia.github.io/spid-smart-button/spid-button.min.css', false );
wp_enqueue_style( 'general-css', plugin_dir_url( __FILE__ ) . '/css/style.css', false );
}
// enqueue scripts and css only for the login page
add_action( 'login_enqueue_scripts', 'enqueue_login_css', 1 );
add_action( 'login_enqueue_scripts', 'enqueue_login_script', 10 );
}

Should these external scripts be loaded internally? I worry that changes to spid-button.min.js may break functionality in the future for the plugin or if the location of the file moves. We can push an update to the plugin but we all know people may take awhile to update. spid-smart-button looks like it's still in early development and doesn't appear to be versioned yet too. Thoughts?

disable login with user/password

dopo il 1 login SPID viene creato l'utente WP; dopodichè l'utente potrà bypassare il login SPID creandosi una password e accedendo col login WP normale ? ma in tal caso ai login successivi non avremmo più la garanzia SPID e gli eventuali attributi non verebbero aggiornati ! sarebbe una cosa da disabilitare ?

GDPR warnings

write in clear letters that if the plugin user chooses to store user data in WP, she is bound by the GDPR to take care of these data, respond to user requests for access and deletion, and reporting breeches

error when user starts SPID login process then clicks "Cancel"

gifrecord_2018-10-12_143818

the reported error is:

  | <b>Fatal error</b>:  Uncaught Exception: Invalid Response. Response must contain at least one signature in /var/www/html/wp-content/plugins/spid-wordpress/vendor/italia/spid-php-lib/src/Spid/Saml/In/BaseResponse.php:62
  | Stack trace:
  | #0 /var/www/html/wp-content/plugins/spid-wordpress/vendor/italia/spid-php-lib/src/Spid/Saml.php(152): Italia\Spid\Spid\Saml\In\BaseResponse-&gt;validate('-----BEGIN CERT...')
  | #1 [internal function]: Italia\Spid\Spid\Saml-&gt;isAuthenticated()
  | #2 /var/www/html/wp-content/plugins/spid-wordpress/vendor/italia/spid-php-lib/src/Sp.php(36): call_user_func_array(Array, Array)
  | #3 /var/www/html/wp-content/plugins/spid-wordpress/src/SpidWordPress.php(110): Italia\Spid\Sp-&gt;__call('isAuthenticated', Array)
  | #4 /var/www/html/wp-includes/class-wp-hook.php(286): SpidWordPress-&gt;filterAuthenticate(Object(WP_Error), '', '')
  | #5 /var/www/html/wp-includes/plugin.php(203): WP_Hook-&gt;apply_filters(Object(WP_Error), Array)
  | #6 /var/www/html/wp-includes/pluggable.php(532): apply_filters('authenticate', NULL, '', '')
  | #7 /var/www/html/wp in <b>/var/www/html/wp-content/plugins/spid-wordpress/vendor/italia/spid-php-lib/src/Spid/Saml/In/BaseResponse.php</b> on line <b>62</b><br />

what happens is that the IdP login page performs a POST http://localhost:8088/login (IdP) even if the user cancels, and that bounces back to POST http://localhost:8099/wp-login.php?sso=spid (SP) with a SAMLResponse that can be decoded to:

<?xml version="1.0"?>
<samlp:Response xmlns:samlp="urn:oasis:names:tc:SAML:2.0:protocol" InResponseTo="_9b1221a863b662e9afb69278d1521a2b" ID="id_fd3480cd927ab80f40df1ea3d30803743b0db22b" Version="2.0" Destination="http://localhost:8099/wp-login.php?sso=spid" IssueInstant="2018-10-12T12:44:01Z">
  <samlp:Status>
    <samlp:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:AuthnFailed"/>
    <samlp:StatusMessage>ErrorCode nr22</samlp:StatusMessage>
  </samlp:Status>
  <saml:Issuer xmlns:saml="urn:oasis:names:tc:SAML:2.0:assertion" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" NameQualifier="http://localhost:8088" Format="urn:oasis:names:tc:SAML:2.0:nameid-format:entity">http://localhost:8088</saml:Issuer>
</samlp:Response>

not sure if this should be forwarded to spid-php-lib or testenv2 ....

implement logout

if you log onto WP with this plugin then logout, the SPID session will stay open

trying to login again breaks it !

we should call $this->auth->logout()

exclude certain files from the distributables

when we will tag a release, github will make zip and tar.gz downloads available under releases

we do not want ship certain files with those distributables, for example composer.json and composer.lock which are meaningless to people not involved in the plugin development

within spid-php-lib we have successfully used the .gitattributes file to achieve that effect

composer install fails on PHP 7.0

while setting up travis (#39) I stumbled upon this https://travis-ci.com/simevo/spid-wordpress/jobs/153619905

$ composer install --no-interaction
Loading composer repositories with package information
Installing dependencies (including require-dev) from lock file
Your requirements could not be resolved to an installable set of packages.
  Problem 1
    - Installation request for doctrine/instantiator 1.1.0 -> satisfiable by doctrine/instantiator[1.1.0].
    - doctrine/instantiator 1.1.0 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
  Problem 2
    - Installation request for myclabs/deep-copy 1.8.1 -> satisfiable by myclabs/deep-copy[1.8.1].
    - myclabs/deep-copy 1.8.1 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
  Problem 3
    - doctrine/instantiator 1.1.0 requires php ^7.1 -> your PHP version (7.0.25) does not satisfy that requirement.
    - phpunit/phpunit-mock-objects 5.0.10 requires doctrine/instantiator ^1.0.5 -> satisfiable by doctrine/instantiator[1.1.0].
    - Installation request for phpunit/phpunit-mock-objects 5.0.10 -> satisfiable by phpunit/phpunit-mock-objects[5.0.10].

returning SPID user cannot log in

when a SPID used logs to WP for the 1st time, a WP user is created; if this user logs out (beware #12 !) then tries to login again she gets "Questo nome utente esiste già!" (this username already exists):

image

obscure error while displaying metadata when sp.key can not be read

at the end pf the docker-compose procedure when I visit the SP metadata endpoint http://localhost:8099/wp-login.php?sso=spid&metadata instead of the XML I get to see this:

This page contains the following errors:
error on line 2 at column 1: Extra content at the end of the document
Below is a rendering of the page up to the first error.

to reproduce, just make wp.key unaccessible to the docker_wp container with:

chmod 600 wp.key

to fix it, revert that:

chmod 644 wp.key

this is known to spid-php.lib as: italia/spid-php-lib#27

Metadata publishing: url location

I am reading from the official docs, https://spid-regole-tecniche.readthedocs.io/en/latest/metadata.html:
I metadata dei Service Provider saranno disponibili per tutte le entità SPID federate attraverso la URL https:///metadata
(Service Provider metadata will be available for all SPID entities through the URL https:///metadata)
Problem: a WP plugin (or a Drupal module, etc) cannot write in the root folder.
Can we assume this rule is NOT strict and we can provide our own metadata url?

install procedure fails on macOS

make step fails:

# Configure SP
openssl req -x509 -nodes -sha256 -days 365 -newkey rsa:2048 -subj "/C=IT/ST=Italy/L=Rome/O=myservice/CN=localhost" -keyout wp.key -out wp.crt
...
chmod u+r wp.key
envsubst < config.php.tpl > config.php
/bin/sh: envsubst: command not found
make: *** [all] Error 127

see: https://stackoverflow.com/questions/23620827/envsubst-command-not-found-on-mac-os-x-10-8

questo dovrebbe essere aggiunto al README per macOS:

brew install gettext
brew link --force gettext

config page

Formatting:

  • spid logo

Metadata-impacting settings:

  • OrganizationName, OrganizationDisplayName, OrganizationURL
  • gli attributi che ci vogliamo far dare: elenco degli attributi standard SPID con checkbox attiva / disattiva
  • bottone "Configura plugin", vedi #22

spiegare all'utente che se cambia uno di questi 2 settaggi deve ridistribuire il metadata del SP a tutti gli IdP, dal metadata link (attualmente http://localhost:8099/wp-login.php?sso=spid&metadata che tra l'altro è bruttino)

WP Plugin config:

  • SPID level (1 or 2)
  • IdP selection: checkbox to activate / deactivate available IdPs (dai files presenti in idp_metadata)
  • what WP role the new user should be assigned to (i.e. Subscriber)

autoconfigurable plugin

the current install procedure of the spid-php-lib and consequently of this plugin requires generating the SP certificates in a preconfiguration step which can be automated but requires CLI access anyway

in the spirit of keeping WP webmasters free from any kind of coding/CLI duties, we should make it possible to complete this step with a simple button click from the configuration page

detailed requirements

When the plugin is first activated from WP plugin management, but no SP certificates are found, it should be in the "unconfigured" state, i.e show the SPID button disabled (grayed out and doesn't react on click) and in the config page it should say "Il plugin deve ancora essere configurato"

To do that a botton is available: <button>Configura plugin</button>; this is a metadata-impacting change and should be shown in the separate area of the config page where the other metadata-impacting settings are.

When the SP certificates are found, on clicking on the "Configura plugin" button it should additionally present a modal pop-up saying "Attenzione stai per sovrascrivere i certificati ! Questo invaliderà il metadata corrente"

Implementation

we need support from spid-smart-button and from spid-php-lib

  • in spid-smart-button we need an API to disable the button
  • in spid-php-lib we need two new functions in the Italia\Spid\Sp class:
    • isConfigured() returns true if the SP certificates are found where the $settings says they are, and they are valid (i.e. the plugin has been configured correctly)
    • generateCerts($ountryName, stateName, localityName, commonName, emailAddress): generates with openssl the certificates where the $settings says they should be

missing class 'RobRichards\XMLSecLibs\Utils\XPath'

on trying to complete round trip I get:

  | <br />
-- | --
  | <b>Fatal error</b>:  Uncaught Error: Class 'RobRichards\XMLSecLibs\Utils\XPath' not found in /var/www/html/wp-content/plugins/spid-wordpress/spid-php-lib/vendor/robrichards/xmlseclibs/src/XMLSecurityDSig.php:493
  | Stack trace:
  | #0 /var/www/html/wp-content/plugins/spid-wordpress/spid-php-lib/vendor/robrichards/xmlseclibs/src/XMLSecurityDSig.php(591): RobRichards\XMLSecLibs\XMLSecurityDSig-&gt;processRefNode(Object(DOMElement))
  | #1 /var/www/html/wp-content/plugins/spid-wordpress/spid-php-lib/src/Spid/Saml/SignatureUtils.php(96): RobRichards\XMLSecLibs\XMLSecurityDSig-&gt;validateReference()
  | #2 /var/www/html/wp-content/plugins/spid-wordpress/spid-php-lib/src/Spid/Saml/In/BaseResponse.php(95): Italia\Spid\Spid\Saml\SignatureUtils::validateXmlSignature(Object(DOMElement), '-----BEGIN CERT...')
  | #3 /var/www/html/wp-content/plugins/spid-wordpress/spid-php-lib/src/Spid/Saml.php(191): Italia\Spid\Spid\Saml\In\BaseResponse-&gt;validate('-----BEGIN CERT...')
  | #4 [internal function]: Italia\Spid\Spid\Saml-&gt;isAuthenticated()
  | #5 /var/www/html/wp-content/plug in <b>/var/www/html/wp-content/plugins/spid-wordpress/spid-php-lib/vendor/robrichards/xmlseclibs/src/XMLSecurityDSig.php</b> on line <b>493</b><br />

Options in admin

Let's talk about what will go in the admin settings page. I made this https://balsamiq.cloud/syds1m/p1djrkb to help get a feel of the options. It doesn't need to be 100% finalized but it'd help to get a good start before I start coding in the fields.

guest access (optional)

to be evaluated: should we allow a user to access "anonymously" WP without any SPID user attributes ?

this could be used to allow controlled access to read-only, non user-specific data

a generic WP user "guest" could be used for all logins

totally autoconfigurable plugin (optional)

integrate the download of IdP metadata in the plugin setup process so that the plugin can be installed without shell access

on hold, to be evaluated: this needs to be integrated with an automated process for updating SP metadata !

Removing Docker

I don't think Docker is needed here. Testing can and should be done in any environment that the plugin supports. Any test scripts can be made separately and used on any WP install. For anyone that would like to continue to use Docker, install the basic WordPress Docker then install the plugin manually. No need to complicate this with our own Dockerfile. Thoughts?

configurable sso parameter (for scenarios with multiple sso mechanisms)

se qualcuno ha più plugin per il single-sign-on attivi, ad esempio CNS, SAML aziendale interno e SPID, l'url per fare il sso con uno dei SP SPID è: https://example.com/wp-login.php?sso=spid
invece se voglio la CNS https://example.com/wp-login.php?sso=cns e se voglio SAML https://example.com/wp-login.php?sso=cns

con l'opzione sp_sso possiamo fare la possibilità di personalizzare l'url sso:
https://github.com/simevo/spid-wordpress/blob/master/includes/class-spid-core.php#L78-L83

questa url dovrebbe essere usata anche qui:
https://github.com/simevo/spid-wordpress/blob/master/includes/class-spid-core.php#L90
per rilevare quando deve iniziare il processo di login SPID

e qui:
https://github.com/simevo/spid-wordpress/blob/master/templates/spid-button.php#L24
per configurare lo SPID button

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.