Skip to content

Upload ingress certificates stored in k8s secret. #6

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

barakgazala
Copy link

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
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


# build headers
def build_cloudflare_request_headers(auth_email: str, auth_key: str) -> Mapping[str, str]:
Copy link
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
Author

Choose a reason for hiding this comment

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

Done


# 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
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
Author

Choose a reason for hiding this comment

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

Done

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

zone: dict = requests.get(
Copy link
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
Author

Choose a reason for hiding this comment

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

Done


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
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