Code Monkey home page Code Monkey logo

trellis-cloudflare-origin-ca's Introduction

Trellis Cloudflare Origin CA

Ansible Role GitHub tag (latest SemVer) Ansible Role Downloads Ansible Quality Score CircleCI License Twitter Follow @TangRufus Hire Typist Tech

Add Cloudflare Origin CA to Trellis as a SSL provider.

Built with ♥ by Typist Tech


Trellis Cloudflare Origin CA is an open source project and completely free to use.

However, the amount of effort needed to maintain and develop new features is not sustainable without proper financial backing. If you have the capability, please consider donating using the links below:

GitHub via Sponsor Sponsor via PayPal More Sponsorship Information


Add Cloudflare Origin CA to Trellis as a SSL provider

Why?

Short answer: To keep connection between Cloudflare and your severs private and secure from tampering.

Long answer:

Cloudflare’s Flexible SSL mode is the default for Cloudflare sites on the Free plan. Flexible SSL mode means that traffic from browsers to Cloudflare will be encrypted, but traffic from Cloudflare to a site's origin server will not be. To take advantage of our Full and Strict SSL mode—which encrypts the connection between Cloudflare and the origin server—it’s necessary to install a certificate on the origin server.

Cloudflare Blog - Origin Server Connection Security with Universal SSL

What are the benefits of Cloudflare Origin CA over Let's Encrypt?

To get certificates from Let's Encrypt, you have to first disable Cloudflare because Cloudflare hides actual server IPs and make Let's Encrypt challenges fail. Using Cloudflare Origin CA simplifies the troubles.

What are the benefits of Cloudflare Origin CA over other public certificates?

See Introducing Cloudflare Origin CA on Cloudflare blog.

Role Variables

# group_vars/<environment>/vault.yml
# This file should be encrypted. See: https://roots.io/trellis/docs/vault/
##########################################################################

# Cloudflare Origin CA Key
# Not to confuse with Cloudflare Global API Key
# See: https://blog.cloudflare.com/cloudflare-ca-encryption-origin/#iiobtainyourcertificateapitoken
vault_cloudflare_origin_ca_key: v1.0-xxxxxxxxxxx

# group_vars/<environment>/main.yml
###################################

# Indicates the desired package state.
# `latest` ensures that the latest version is installed.
# `present` does not update if already installed.
# Choices: present|latest
# Default: latest
cfca_package_state: present

# Whether to hide results of sensitive tasks which
# may include Cloudflare Origin CA Key in plain text.
# Choices: true|false
# Default: false
cloudflare_origin_ca_no_log: true

# group_vars/<environment>/wordpress_sites.yml
##############################################

wordpress_sites:
  example.com:
    # Your Cloudflare account must own all these domains
    site_hosts:
      - canonical: example.com
        redirects:
          - hi.example.com
          - hello.another-example.com
    ssl:
      # SSL must be enabled
      enabled: true
      # OCSP stapling must be disabled
      stapling_enabled: false
      # Use this role to generate Cloudflare Origin CA certificate
      provider: cloudflare-origin-ca
    # The followings are optional
    cloudflare_origin_ca:
      # Number of days for which the issued cert will be valid. Acceptable options are: 7, 30, 90, 365 (1y), 730 (2y), 1095 (3y), 5475 (15y).
      # Default: 5475
      days: 7
      # List of fully-qualified domain names to include on the certificate as Subject Alternative Names.
      # Default: All canonical and redirect domains
      # In the above example: example.com, hi.example.com, hello.another-example.com
      hostnames:
        - example.com
        - '*.example.com'
        - '*.another-example.com'

Typist Tech is ready to build your next awesome WordPress site. Hire us!


Requirements

Installation

Add this role to galaxy.yml:

- src: TypistTech.trellis-cloudflare-origin-ca # Case-sensitive!
  version: 0.8.0 # Check for latest version!

Run $ trellis galaxy install

Hacking Trellis' Playbook

Add this role to server.yml immediately after role: wordpress-setup:

    roles:
      # ...
-     - { role: wordpress-setup, tags: [wordpress, wordpress-setup, letsencrypt] }
+     - { role: wordpress-setup, tags: [wordpress, wordpress-setup, letsencrypt, cloudflare-origin-ca] }
+     - { role: TypistTech.trellis-cloudflare-origin-ca, tags: [cloudflare-origin-ca, wordpress-setup], when: sites_using_cloudflare_origin_ca | count }
      # ...

Note: role: wordpress-setup is tagged with cloudflare-origin-ca.

Nginx Includes

This role templates Nginx SSL directives out to {{ nginx_path }}/includes.d/{{ item.key }}/cloudflare-origin-ca.conf. Trellis includes this file here and here by default, no action needed.

If you using Nginx child templates, add this line into your server blocks:

include includes.d/{{ item.key }}/cloudflare-origin-ca.conf;

Common Errors

No site is using Cloudflare Origin CA

Obviously, you should not run this role when you don't use Cloudflare Origin CA.

vault_cloudflare_origin_ca_key is not defined

Encrypt your Cloudflare Origin CA Key in group_vars/<environment>/vault.yml. See role variables.

example.com is using Cloudflare Origin CA but OCSP stapling is enabled

... you're trying to staple OCSP responses with Origin CA. Right now OCSP is not supported with Origin CA, so you should remove the ssl_staping directive for the host that you're using the Origin CA cert on...

--- Cloudflare Support

Cloudflare Origin CA doesn't support OCSP stapling. Disable OCSP stapling for all sites using Cloudflare Origin CA. See role variables.

key_type is deprecated. Please remove it from example.com

To avoid misconfiguration, the key_type (ECDSA or RSA) and key_size (bits) options are deprecated. Since v0.8, this role generates 521-bit ECDSA keys only.

If you had previsously generated CA certificates with other configurations:

  1. remove the CA certificates from servers
  2. revoke the CA certificates via Cloudflare dashboard
  3. re-provision the servers

key_size is deprecated. Please remove it from example.com

To avoid misconfiguration, the key_type (ECDSA or RSA) and key_size (bits) options are deprecated. Since v0.8, this role generates 521-bit ECDSA keys only.

If you had previsously generated CA certificates with other configurations:

  1. remove the CA certificates from servers
  2. revoke the CA certificates via Cloudflare dashboard
  3. re-provision the servers

Nginx directories not included

Make sure you have roots/trellis@f2b8107 or later.

400 Bad Request - No required SSL certificate was sent

Symptoms:

  • Server returns "400 Bad Request - No required SSL certificate was sent" for all requests
  • Nginx logged "client sent no required SSL certificate while reading client request headers, client: [redacted], server:[redacted], request: "GET / HTTP/1.1", host: "[redacted]""
  • ssl_verify_client on; somewhere in Nginx config files
  • Using client_cert_url in wordpress_sites.yml, i.e: roots/trellis#869

Culprit:

Your Authenticated Origin Pulls configuration is incorrect.

Fact:

This role has nothing to do with Authenticated Origin Pulls or ssl_verify_client.

Solution:

  1. Read Introducing Cloudflare Origin CA
  2. Read Authenticated Origin Pulls
  3. Understand this role is Cloudflare Origin CA
  4. Understand Cloudflare Origin CA and Authenticated Origin Pulls are 2 different things
  5. Read #34
  6. Contact Cloudflare support if you still have questions

FAQ

Why only 521-bit ECDSA keys allowed?

I assume you would like to setup Authenticated Origin Pulls with Cloudflare. I would recommend ECDSA, as elliptic curves provide the same security with less computational overhead.

Find out more about ECDSA: The digital signature algorithm of a better internet The above article also mentioned that: According to the ECRYPT II recommendations on key length, a 256-bit elliptic curve key provides as much protection as a 3,248-bit asymmetric key.Typical RSA keys in website certificates are 2048-bits. So, I think going with 256-bits ECDSA will be a good choice.

--- Cloudflare Support, September 2017

To avoid misconfiguration, the key_type (ECDSA or RSA) and key_size (bits) options are deprecated. Since v0.8, this role generates 521-bit ECDSA keys only.

If you had previsously generated CA certificates with other configurations:

  1. remove the CA certificates from servers
  2. revoke the CA certificates via Cloudflare dashboard
  3. re-provision the servers

Why Cloudflare Origin CA key is logged even cloudflare_origin_ca_no_log is true?

Note that the use of the no_log attribute does not prevent data from being shown when debugging Ansible itself via the ANSIBLE_DEBUG environment variable.

--- Ansible Docs

Does Cloudflare Origin CA perfect?

It looks awesome. Where can I find some more goodies like this

Where can I give 5-star reviews?

Thanks! Glad you like it. It's important to let me knows somebody is using this project. Please consider:

See Also

Running the Tests

Run the tests:

ansible-playbook -vvv -i 'localhost,' --syntax-check tests/test.yml
ansible-lint -vv .

Feedback

Please provide feedback! We want to make this project as useful as possible. Please submit an issue and point out what you do and don't like, or fork the project and send pull requests. No issue is too small.

Security Vulnerabilities

If you discover a security vulnerability within this project, please email us at [email protected]. All security vulnerabilities will be promptly addressed.

Credits

Trellis Cloudflare Origin CA is a Typist Tech project and maintained by Tang Rufus, freelance developer for hire.

Special thanks to the Roots team whose Trellis make this project possible.

Full list of contributors can be found here.

License

Trellis Cloudflare Origin CA is released under the MIT License.

trellis-cloudflare-origin-ca's People

Contributors

partounian avatar tangrufus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

trellis-cloudflare-origin-ca's Issues

Manual + Cloudflare on one server

I have multiple sites on one trellis, and some use different cloudflare accounts. When attempting to use a combination of manual and cloudflare it says that it can't find the domain (predictably) but, it shouldn't be trying to because i have those set to manual SSL.
What I've done for now is set all sites to manual, then it provisions successfully.

Another solution could be using multiple account keys and setting them for each site in wordpress_sites.yml or vault.yml
This could just be some weird edge case that nobody ever does though. :)

400 No required SSL certificate was sent

Submit a feature request or bug report

Replace any X with your information.


What is the current behavior?

400 Bad Request
No required SSL certificate was sent after running ansible-playbook server.yml -e env=staging -t cloudflare-origin-ca


Bug report

(delete this section if not applicable)

Please provide steps to reproduce, including full log output:

X Somehow nothing in nginx logs.

Please describe your local environment:

Ansible version: 2.5

OS: macOS 10.13.3

Vagrant version: n/a

Trellis commit: 9dfddfd

Where did the bug happen? Development or remote servers?

X Remote

Why don't you create a pull request to fix it?

X Not sure what causes the error

Other relevant information:

X Cloudflare has generated the Origin cert, and it seems client cert field has been updated in nginx config.

Fix bare variable deprecation warning

TASK [TypistTech.trellis-cloudflare-origin-ca : fail] **************************
[DEPRECATION WARNING]: evaluating ssl_enabled and item.value.ssl.provider |
default('manual') == 'cloudflare-origin-ca' as a bare variable, this behaviour
will go away and you might need to add |bool to the expression in the future.
Also see CONDITIONAL_BARE_VARS configuration toggle.. This feature will be
removed in version 2.12. Deprecation warnings can be disabled by setting
deprecation_warnings=False in ansible.cfg.

Overwrite SSL certificates if settings are changed

Submit a feature request or bug report


What is the current behavior?

When adding domains or changing the site_hosts the cloudflare_origin_ca doesn't get updated because {site_key}.pem already exists.
[FATAL] Certificate file "{site_key}.pem" already exists, use -overwrite to overwrite
This results in cloudflare not adding the origin ca to additional domains or updating the hostnames.

What is the expected or desired behavior?

I think this behavior should be documented and/or be resolved. A solution would be to allowing to overwrite the certificate file name or passing -overwrite using an argument.

Does this autorenew certificates?

Hi, simple question. You have set the certificate days default value to 7. What happens when the certificate generated by this expires? Does it auto renew or do you have to reprovision the take again to generate a new one?

Many thanks

Failing on Add Cloudflare key - pubkey 404

Hello,

I've used your package several times. Now when trying to reprovision a new server it is failing with the below. Any ideas? All my setup is correct as I have used your package before.

Many thanks,
Aaron

TASK [TypistTech.trellis-cloudflare-origin-ca : Add Cloudflare key] ************
fatal: [***********]: FAILED! => {"changed": false, "msg": "Failed to download key at https://pkg.cloudflare.com/pubkey.gpg: HTTP Error 404: Not Found"}

Can we create one certificate manually on Cloudflare dashboard and this role picks that instead of creating new certificates every time?

Hi,

I have started using Trellis recently and in the last couple of days, I see that my Cloudflare dashboard has about 4 origin certificates with the same domains in it.

Is it not possible that we create one origin certificate defining example.com and *.example.com from the dashboard and this plugin picks that instead of creating a new one every time?

I am not very clear about what exactly triggered the new certificates, it might be the creation of a new machine on Google Cloud. I have provisioned the server multiple times so higher chances are that creation of a new machine and then the first provision on that creates a new origin certificate.

Nonetheless, could you please shed some light on this matter. Does Cloudflare limit the number of origin certificates creation? And if by any chance referencing an old manually created certificate is possible, and if that would help.

All I see is 4 certificates on my dashboard which I will manually delete.

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.