Skip to content

Upload ingress certificates stored in k8s secret.#6

Open
barakgazala wants to merge 1 commit intomasterfrom
upload-certificates
Open

Upload ingress certificates stored in k8s secret.#6
barakgazala wants to merge 1 commit intomasterfrom
upload-certificates

Conversation

@barakgazala
Copy link
Copy Markdown

Currently, when one uses an Ingress resource fronted by Cloudflare CDN, and that Ingress uses a TLS certificate, that certificate has to be uploaded to Cloudflare as well. Otherwise, Cloudflare cannot serve the content under SSL since it does not have the certificate.

This commit enables automatically uploading the Ingress's certificate (found under the Ingress's TLS secret) to Cloudflare, via its APIs. Then, Cloudflare can serve that Ingress under SSL.

Currently, when one uses an Ingress resource fronted by Cloudflare CDN, and that Ingress uses a TLS certificate, that certificate has to be uploaded to Cloudflare as well. Otherwise, Cloudflare cannot serve the content under SSL since it does not have the certificate.

This commit enables automatically uploading the Ingress's certificate (found under the Ingress's TLS secret) to Cloudflare, via its APIs. Then, Cloudflare can serve that Ingress under SSL.
@infolinksbot
Copy link
Copy Markdown
Contributor

Hello, I'm the Infolinks Robot, here to help with development on this issue. Useful commands:

  • use /release [version [merge|squash|rebase]] to release this pull request and optionally merge it back to master.

Note that you first need to authenticate to Infobot on Slack; to do that, just head over to Slack and type @infobot show me on GitHub or simply @infobot help.

@barakgazala barakgazala requested a review from arikkfir December 12, 2017 16:25
Comment thread upload_certificate.py


# build headers
def build_cloudflare_request_headers(auth_email: str, auth_key: str) -> Mapping[str, str]:
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we share "build_cloudflare_request_headers" function with the other Python script? (ie. a shared Python file imported in both Python scripts)

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread upload_certificate.py

# upload certificate to cloudflare
def upload_certificate(zone_id: str, auth_email: str, auth_key: str, key: str, crt: str):
url: str = f"{CF_BASE_URL}/zones/{zone_id}"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CF_BASE_URL should also be imported from a shared Python file.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread upload_certificate.py
argparser.add_argument('auth_key', metavar='KEY', help='authentication key of the Cloudflare account')
args = argparser.parse_args()

zone: dict = requests.get(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets also add a fetch_cloudflare_zone function in the shared Python script.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment thread upload_certificate.py

requests.post(url=certificates_url,
headers=build_cloudflare_request_headers(auth_email=auth_email, auth_key=auth_key),
json=certificate).raise_for_status()
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per your suggestion, lets also check if the certificate exists; if so, compare it and update if necessary. Otherwise, create (as you do now).

@barakgazala barakgazala self-assigned this Dec 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants