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

Add periodic updates of maxmind databases #10983

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

moleus
Copy link

@moleus moleus commented Feb 14, 2024

Periodically download new versions of maxmind databases to keep up to date during pod lifetime

What this PR does / why we need it:

Maxmind releases new versions of their databases a few time a week. Currently there is no way to update GeoIp databases after ingress-nginx pod is started. So, after some time GeoIp informationon starts being outdated and even start conflicting with other instances of ingress-nginx, which started later and have newer version of databases.

This PR adds functionality for periodic database updates. This feature is disabled by default.

Any suggestions or improvements are welcome!

Notes

  • URL is changed from download.maxmind.com to updates.maxmind.com. Like in geoipupdate we use md5 hash to check for new version and skip the download if there are no updates.
  • Download from mirror logic is kept untouched, so it won't check any md5 or auth to keep backwards compatibility.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • CVE Report (Scanner found CVE and adding report)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation only

How Has This Been Tested?

I've mocked maxmind API in maxmind_test.go, test cases are taken from geoipupdate source code. This change only affects how maxmind database is fetched.

Checklist:

  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I've read the CONTRIBUTION guide
  • I have added unit and/or e2e tests to cover my changes.
  • All new and existing tests passed.

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 14, 2024
Copy link

linux-foundation-easycla bot commented Feb 14, 2024

CLA Signed

The committers listed above are authorized under a signed CLA.

Copy link

netlify bot commented Feb 14, 2024

Deploy Preview for kubernetes-ingress-nginx canceled.

Name Link
🔨 Latest commit 52a47af
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-ingress-nginx/deploys/65d614a5ec2ad000088b075a

@k8s-ci-robot k8s-ci-robot added cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Feb 14, 2024
@k8s-ci-robot
Copy link
Contributor

This issue is currently awaiting triage.

If Ingress contributors determines this is a relevant issue, they will accept it by applying the triage/accepted label and provide further guidance.

The triage/accepted label can be added by org members by writing /triage accepted in a comment.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 14, 2024
@k8s-ci-robot
Copy link
Contributor

Welcome @moleus!

It looks like this is your first PR to kubernetes/ingress-nginx 🎉. Please refer to our pull request process documentation to help your PR have a smooth ride to approval.

You will be prompted by a bot to use commands during the review process. Do not be afraid to follow the prompts! It is okay to experiment. Here is the bot commands documentation.

You can also check if kubernetes/ingress-nginx has its own contribution guidelines.

You may want to refer to our testing guide if you run into trouble with your tests not passing.

If you are having difficulty getting your pull request seen, please follow the recommended escalation practices. Also, for tips and tricks in the contribution process you may want to read the Kubernetes contributor cheat sheet. We want to make sure your contribution gets all the attention it needs!

Thank you, and welcome to Kubernetes. 😃

@k8s-ci-robot
Copy link
Contributor

Hi @moleus. Thanks for your PR.

I'm waiting for a kubernetes member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added needs-priority size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Feb 14, 2024
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: Moleus
Once this PR has been reviewed and has the lgtm label, please assign rikatz for approval. For more information see the Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found here.

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. and removed cncf-cla: no Indicates the PR's author has not signed the CNCF CLA. labels Feb 14, 2024
@moleus moleus marked this pull request as ready for review February 21, 2024 10:11
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 21, 2024
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 21, 2024
@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 28, 2024
@k8s-ci-robot
Copy link
Contributor

PR needs rebase.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@@ -81,6 +103,17 @@ func GeoLite2DBExists() bool {
return true
}

// DownloadGeoLite2DBPeriodically starts a goroutine to periodically sync the GeoIP databases
func DownloadGeoLite2DBPeriodically(syncPeriod time.Duration) {
Copy link
Member

Choose a reason for hiding this comment

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

I thought Maxmind did this itself, which is why it needed curl; we discovered this when we tried to remove Curl and found it was dependent on Maxmind; it setups a cronjob to download.

Copy link
Author

Choose a reason for hiding this comment

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

Apologies for the delayed response, I was on holiday. I've tried to look for cronjobs or any other Maxmind related references in this repository, but couldn't find any curl/cronjob used by Maxmind. As far as I understand the only file which downloads db is internal/nginx/maxmind.go. Could you send me the link where Maxmind setups a cronjob to download a db?

Copy link
Author

Choose a reason for hiding this comment

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

@strongjz Hey! Are there any actions I can do to help with review of this PR?

Copy link
Member

Choose a reason for hiding this comment

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

@rpkatz found it when we were trying to remove curl from the container image.
https://alpine.pkgs.org/3.17/alpine-main-aarch64/libmaxminddb-1.7.1-r0.apk.html

One of the deps is curl.

@moleus moleus marked this pull request as draft March 26, 2024 13:33
@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 26, 2024
@@ -43,6 +43,9 @@ They are set in the container spec of the `ingress-nginx-controller` Deployment
| `--maxmind-retries-count` | Number of attempts to download the GeoIP DB. (default 1) |
| `--maxmind-license-key` | Maxmind license key to download GeoLite2 Databases. https://blog.maxmind.com/2019/12/18/significant-changes-to-accessing-and-using-geolite2-databases . |
| `--maxmind-mirror` | Maxmind mirror url (example: http://geoip.local/databases. |
| `--maxmind-enable-sync` | Enable the synchronization of the GeoIP databases. (default false) |
| `--maxmind-sync-period` | Period at which the controller fetches updates for GeoIp Databases (default 24h) |
| `--maxmind-url` | Maxmind url to download GeoLite2 Databases. (default "https://updates.maxmind.com") |
Copy link

@pinkavaj pinkavaj Apr 2, 2024

Choose a reason for hiding this comment

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

There is already --maxmind-mirror parameter, --maxmind-url looks like kind of partial duplication. Would it be possible to use only --maxmind-mirror ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/docs cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. needs-kind Indicates a PR lacks a `kind/foo` label and requires one. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. needs-priority needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants