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

Optimize dynamic loading of IaaS Credentials using credential file timestamps #670

Merged
merged 15 commits into from
Dec 15, 2023

Conversation

renormalize
Copy link
Member

@renormalize renormalize commented Oct 20, 2023

What this PR does / why we need it:
Dynamic loading of IaaS credentials currently involves computing the hash of the secret file and comparing the in-memory hash with the newly computed hash to check for changes in the access credentials.

When there is a change in the hash, the SnapStore object is updated. The computation of this hash happens whenever a delta snapshot is triggered.

This is now optimized by checking the timestamps of the credential files which were used to calculate the hash.

Currently the following providers are supported:

  • AWS S3
  • Azure Blob Storage
  • Google Cloud Storage
  • Alibaba Cloud OSS
  • OpenStack Swift
  • OpenShift Container Storage

Which issue(s) this PR fixes:
Fixes #449 #683

Special notes for your reviewer:

Release note:

Dynamic loading of IaaS credentials is now optimized to make use of file system information instead of calculating a hash of the credentials to detect changes.

@gardener-robot
Copy link

@renormalize Thank you for your contribution.

@gardener-robot gardener-robot added needs/review Needs review size/m Size of pull request is medium (see gardener-robot robot/bots/size.py) labels Oct 20, 2023
@gardener-robot-ci-2
Copy link
Contributor

Thank you @renormalize for your contribution. Before I can start building your PR, a member of the organization must set the required label(s) {'reviewed/ok-to-test'}. Once started, you can check the build status in the PR checks section below.

@gardener-robot gardener-robot added size/l Size of pull request is large (see gardener-robot robot/bots/size.py) needs/second-opinion Needs second review by someone else and removed size/m Size of pull request is medium (see gardener-robot robot/bots/size.py) labels Oct 20, 2023
@renormalize renormalize force-pushed the optimize-dynamic-loading branch from 9822ec3 to 7a5e52b Compare October 20, 2023 11:07
@gardener-robot gardener-robot added size/xl Size of pull request is huge (see gardener-robot robot/bots/size.py) size/l Size of pull request is large (see gardener-robot robot/bots/size.py) and removed size/l Size of pull request is large (see gardener-robot robot/bots/size.py) size/xl Size of pull request is huge (see gardener-robot robot/bots/size.py) labels Oct 23, 2023
@renormalize renormalize marked this pull request as ready for review October 23, 2023 11:22
@renormalize renormalize requested a review from a team as a code owner October 23, 2023 11:22
@shreyas-s-rao shreyas-s-rao added this to the v0.27.0 milestone Nov 9, 2023
@shreyas-s-rao
Copy link
Collaborator

/assign @ishan16696

Copy link
Contributor

@seshachalam-yv seshachalam-yv left a comment

Choose a reason for hiding this comment

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

Thanks @renormalize for PR

Overall looks good to me.
Please address my NIT comments

pkg/snapshot/snapshotter/snapshotter.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshotter/snapshotter.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshotter/snapshotter.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshotter/snapshotter.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshotter/snapshotter.go Outdated Show resolved Hide resolved
pkg/snapstore/s3_snapstore.go Outdated Show resolved Hide resolved
pkg/snapstore/s3_snapstore.go Outdated Show resolved Hide resolved
pkg/snapstore/s3_snapstore.go Outdated Show resolved Hide resolved
pkg/snapstore/s3_snapstore.go Outdated Show resolved Hide resolved
pkg/snapstore/s3_snapstore.go Outdated Show resolved Hide resolved
@gardener-robot gardener-robot added the needs/changes Needs (more) changes label Nov 13, 2023
@seshachalam-yv seshachalam-yv added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 13, 2023
@gardener-robot-ci-1 gardener-robot-ci-1 added needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Nov 13, 2023
@seshachalam-yv seshachalam-yv added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 14, 2023
@gardener-robot-ci-3 gardener-robot-ci-3 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 14, 2023
@seshachalam-yv seshachalam-yv added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 14, 2023
@gardener-robot-ci-1 gardener-robot-ci-1 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Nov 14, 2023
Copy link
Contributor

@seshachalam-yv seshachalam-yv left a comment

Choose a reason for hiding this comment

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

Thanks @renormalize for addressing my comments.
Overall looks good to me.

pkg/snapstore/utils.go Outdated Show resolved Hide resolved
pkg/snapstore/utils.go Outdated Show resolved Hide resolved
pkg/snapshot/snapshotter/snapshotter.go Outdated Show resolved Hide resolved
@renormalize renormalize force-pushed the optimize-dynamic-loading branch from 7d02cd4 to fd46a0c Compare November 14, 2023 14:32
@gardener-robot-ci-2 gardener-robot-ci-2 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Dec 6, 2023
Comment on lines 325 to 328
for providerIndex, provider := range providers {
// value is used in the closure, thus is to be redefined
providerIndex := providerIndex
provider := provider
Copy link
Member

Choose a reason for hiding this comment

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

I didn't get the reasoning, why they require to be redefined ?

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason the loop variables, and many variables in the tests had to be redefined as so was that the closure functions which are used to define the test cases using the Ginkgo framework capture the address of the loop variables when Describe, Context, and It functions run. This is essentially the infamous for loop "bug" when using the address of the loop variable inside the for loop in Go. Redefining ensures the right values are passed to the closures in new variables instead of the actual loop variable which is rewritten every time during the spec tree construction, before the tests are actually run.

pkg/snapstore/snapstore_test.go Outdated Show resolved Hide resolved
pkg/snapstore/snapstore_test.go Outdated Show resolved Hide resolved
pkg/snapstore/snapstore_test.go Outdated Show resolved Hide resolved
…).TempDir()` and structs for cleaner tests.

* Only Ginkgo provided temporary directories are used for the unit tests.
* Structs defined where each instance holds all relevant information for the test.
* Same tests cover both directory flow and JSON flow.
@gardener-robot-ci-1 gardener-robot-ci-1 added the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Dec 12, 2023
@gardener-robot-ci-2 gardener-robot-ci-2 removed the reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) label Dec 12, 2023
pkg/snapstore/snapstore_test.go Outdated Show resolved Hide resolved
pkg/snapstore/snapstore_test.go Outdated Show resolved Hide resolved
pkg/snapstore/snapstore_test.go Outdated Show resolved Hide resolved
pkg/snapstore/snapstore_test.go Outdated Show resolved Hide resolved
pkg/snapstore/snapstore_test.go Outdated Show resolved Hide resolved
* Changed a few function definition comments
* Changed the verb to `%q` in Ginkgo nodes' strings for better string formatting
@gardener-robot-ci-3 gardener-robot-ci-3 added reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) and removed reviewed/ok-to-test Has approval for testing (check PR in detail before setting this label because PR is run on CI/CD) labels Dec 13, 2023
Copy link
Contributor

@seshachalam-yv seshachalam-yv left a comment

Choose a reason for hiding this comment

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

Overall looks good to me
Thanks @renormalize for addressing my review comments

@ishan16696 ishan16696 assigned ishan16696 and unassigned renormalize Dec 14, 2023
Copy link
Member

@ishan16696 ishan16696 left a comment

Choose a reason for hiding this comment

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

LGTM!!

@ishan16696 ishan16696 added reviewed/do-not-merge Has no approval for merging as it may break things, be of poor quality or have (ext.) dependencies and removed reviewed/do-not-merge Has no approval for merging as it may break things, be of poor quality or have (ext.) dependencies labels Dec 15, 2023
@ishan16696 ishan16696 merged commit 6958118 into gardener:master Dec 15, 2023
9 checks passed
@gardener-robot gardener-robot added the status/closed Issue is closed (either delivered or triaged) label Dec 15, 2023
@shreyas-s-rao shreyas-s-rao added this to the v0.28.0 milestone Dec 15, 2023
@shreyas-s-rao
Copy link
Collaborator

@ishan16696 this needs to be cherry-picked to rel-v0.24 branch right?

@ishan16696
Copy link
Member

@ishan16696 this needs to be cherry-picked to rel-v0.24 branch right?

yes .... but we need to revisit all PRs which are merged after v0.27, to check whether it make sense to cherry pick them to branch rel-v0.24 or not.
Anyway for this PR needs/cherry-pick label has been already added.

@shreyas-s-rao
Copy link
Collaborator

Ok. Then @renormalize can you please take care of raising a cherry-pick PR on rel-v0.24 branch then?

renormalize added a commit to renormalize/etcd-backup-restore that referenced this pull request Dec 20, 2023
…mestamps (gardener#670)

* Dynamic access credential rotation unit tests written for all providers

* Unit tests for GetSnapstoreSecretModifiedTime() use idiomatic `time` functions

* Unit tests reworked to fix concourse build

* Changes to test GinkgoT and os temp directories for unit tests for dynamic loading

* Added a direct os.Stat to ensure the correct time is being fetched

* Workaround to change the modification time of a credential file in the unit test
* Writing to the file does not change the modification time on the concourse machine.
  This is worked around by recreating the credential file.
* Better logging during the tests for easier debugging.

* Changed the directory used by the dynamic credential loading unit tests
* The directory is set to /test/credential to store the files.
* Cleaner logging.

* Added test to verify concourse's time modification os call

* Added a time.Sleep() before modifying the file.

* Replaced random file deletion test with file deletion of each possible credential file

* Unit tests now use a sleep to fix issues on concourse, .ci/unit_test restored so all tests run.

* Addressing review comments for units tests of dynamic credential loading 1

* Dynamic credential loading unit tests: removed file creation and updation logs

* `GetSnapstoreSecretModifiedTime` unit tests rewritten using `GinkgoT().TempDir()` and structs for cleaner tests.
* Only Ginkgo provided temporary directories are used for the unit tests.
* Structs defined where each instance holds all relevant information for the test.
* Same tests cover both directory flow and JSON flow.

* Addressing review comments
* Changed a few function definition comments
* Changed the verb to `%q` in Ginkgo nodes' strings for better string formatting
ishan16696 pushed a commit that referenced this pull request Dec 20, 2023
…mestamps (#670) (#695)

* Dynamic access credential rotation unit tests written for all providers

* Unit tests for GetSnapstoreSecretModifiedTime() use idiomatic `time` functions

* Unit tests reworked to fix concourse build

* Changes to test GinkgoT and os temp directories for unit tests for dynamic loading

* Added a direct os.Stat to ensure the correct time is being fetched

* Workaround to change the modification time of a credential file in the unit test
* Writing to the file does not change the modification time on the concourse machine.
  This is worked around by recreating the credential file.
* Better logging during the tests for easier debugging.

* Changed the directory used by the dynamic credential loading unit tests
* The directory is set to /test/credential to store the files.
* Cleaner logging.

* Added test to verify concourse's time modification os call

* Added a time.Sleep() before modifying the file.

* Replaced random file deletion test with file deletion of each possible credential file

* Unit tests now use a sleep to fix issues on concourse, .ci/unit_test restored so all tests run.

* Addressing review comments for units tests of dynamic credential loading 1

* Dynamic credential loading unit tests: removed file creation and updation logs

* `GetSnapstoreSecretModifiedTime` unit tests rewritten using `GinkgoT().TempDir()` and structs for cleaner tests.
* Only Ginkgo provided temporary directories are used for the unit tests.
* Structs defined where each instance holds all relevant information for the test.
* Same tests cover both directory flow and JSON flow.

* Addressing review comments
* Changed a few function definition comments
* Changed the verb to `%q` in Ginkgo nodes' strings for better string formatting
@renormalize renormalize deleted the optimize-dynamic-loading branch April 4, 2024 14:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merge/squash Should be merged via 'Squash and merge' needs/cherry-pick Needs to be cherry-picked to older version needs/ok-to-test Needs approval for testing (check PR in detail before setting this label because PR is run on CI/CD) needs/second-opinion Needs second review by someone else size/xl Size of pull request is huge (see gardener-robot robot/bots/size.py) status/closed Issue is closed (either delivered or triaged)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Feature] Optimize dynamic loading of IaaS credentials
9 participants