Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Client certificate authentication #282

Closed
stoofvlees opened this issue Apr 8, 2022 · 5 comments
Closed

Client certificate authentication #282

stoofvlees opened this issue Apr 8, 2022 · 5 comments

Comments

@stoofvlees
Copy link

Request

Beste xirixiz,

Allereerst bedankt voor de handige Docker-container voor DSMR reader. Ik gebruik het met veel plezier. Het enige wat ik nog miste was de mogelijkheid om authenticatie te laten verlopen via een client certificate. Daarom heb ik de volgende functie gemaakt, naar model van de basic http authentication-feature geschreven door @Caroga. Zelf ben ik niet handig genoeg met github om een pull request te doen, vandaar via deze weg. Hoop dat je dat niet erg vindt. In principe zou het toegevoegd kunnen worden aan /rootfs/etc/cont-init.d/20-set-app-defaults zodat anderen er wellicht ook wat aan hebben.

function _generate_clientcert_auth_configuration() {
  _info "Checking for CLIENT CERTIFICATE AUTHENTICATION configuration..."
  if [[ -n "${ENABLE_CLIENTCERT_AUTH}" ]]; then
    if [[ "${ENABLE_CLIENTCERT_AUTH}" = true ]]; then
      _info "ENABLE_CLIENTCERT_AUTH is enabled, let's secure this!"
      canWeContinue=true
      if [[ ! -f /etc/nginx/client_cert/cacert.pem ]]; then
        _warn "Please map a CA.pem file to /etc/nginx/client_cert/cacert.pem"
        canWeContinue=false
      fi
      if [[ "${canWeContinue}" = false ]]; then
        _error "Sorry, something failed. Please check above warnings."
        exit 1
      fi
      _info "Enabling the configuration in NGINX..."
      sed -i '/server_name _;/a\\tssl_client_certificate /etc/nginx/client_cert/cacert.pem;\n\tssl_verify_client on;' /etc/nginx/http.d/dsmr-webinterface.conf
      if [[ -f /etc/nginx/client_cert/ca.crl ]]; then
        _info "Found CRL file, adding to configuration..."
        sed -i '/server_name _;/a\\tssl_crl /etc/nginx/client_cert/ca.crl;' /etc/nginx/http.d/dsmr-webinterface.conf
      fi
      if nginx -c /etc/nginx/nginx.conf -t 2>/dev/null; then
        _info "CLIENT CERT AUTHENTICATION configured and enabled"
        return
      else
        _error "NGINX configuration error"
        exit 1
      fi
    fi
  fi
  _info "ENABLE_CLIENTCERT_AUTH is disabled, nothing to see here. Continuing..."
}

  _generate_clientcert_auth_configuration

Enkele korte instructies om e.e.a. werkend te krijgen:

HTTP client certificate authentication
Can be used with or without ENABLE_HTTP_AUTH.

Instructions:

  1. Build a PKI using OpenSSL
  2. Set environment variable ENABLE_CLIENTCERT_AUTH=true
  3. Map file /etc/nginx/client_cert/cacert.pem to your ca.pem file
  4. (optional) Map file /etc/nginx/client_cert/ca.crl to your CRL file
  5. Import client key/certificate in browser

Hartelijke groet!

Additional information

No response

@xirixiz
Copy link
Owner

xirixiz commented Apr 9, 2022

Goedemorgen, bedankt voor de bijdrage. Ik zal er vandaag eens induiken.

@xirixiz
Copy link
Owner

xirixiz commented Apr 9, 2022

Ik heb het toegevoegd aan de development release. Wellicht kan je verifieren of het naar behoren werkt wanneer de pipeline klaar is met bouwen: https://github.com/xirixiz/dsmr-reader-docker/actions/runs/2139838126

Ik zal het ook nog even testen. Indien alles naar behoren werkt kan ik het mergen naar master en een nieuwe release uitbrengen.

@stoofvlees
Copy link
Author

Goedemorgen, dank voor de snelle actie! Net even getest met https://hub.docker.com/layers/xirixiz/dsmr-reader-docker/amd64-development/images/sha256-cc61c90f719d351e875269e1834dc0d10597aafe66059e23782635fc59c4dd31 en dat werkt uitstekend.
Nogmaals dank!

@xirixiz
Copy link
Owner

xirixiz commented Apr 10, 2022

Mooi! Dan gaat het mee in de volgende release. Ik heb ook geen issues gehad.

@Caroga
Copy link
Contributor

Caroga commented Apr 10, 2022 via email

@xirixiz xirixiz closed this as completed Apr 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants