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

COSI-40, COSI-52: Revoke Bucket Access API Implementation and Tests #57

Merged
merged 7 commits into from
Dec 13, 2024

Conversation

anurag4DSB
Copy link
Collaborator

@anurag4DSB anurag4DSB commented Dec 10, 2024

Summary

This PR implements the DriverRevokeBucketAccess API, enhances the IAM client, and adds comprehensive tests, including unit and end-to-end coverage.

Key Changes

  1. COSI-40: Remove Prefix from Inline Policies
  • Inline policy names now match bucket names, simplifying access control.
  1. COSI-40: API Implementation
  • Fetches bucket parameters for IAM client configuration.
  • Adds IAM methods to delete users, inline policies, and keys.
  1. COSI-40: Add Unit Tests
  • Updated IAM mock and added unit tests for IAM client new methods and RevokeBucketAccess.
  1. COSI-52: Add E2E Test
  • Validates end-to-end flow for revoking bucket access by checking if the IAM user was deleted.

@anurag4DSB anurag4DSB changed the title COSI-40: remove-prefix-from-IAM-user-inline-policy COSI-40: Revoke Bucket Access API (delete IAM user, inline policy and keys) Dec 10, 2024
Copy link

codecov bot commented Dec 10, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 93.12%. Comparing base (7bc2de2) to head (07a2202).
Report is 8 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

Files with missing lines Coverage Δ
pkg/clients/iam/iam_client.go 100.00% <100.00%> (+3.15%) ⬆️
pkg/driver/provisioner_server_impl.go 97.36% <100.00%> (+0.35%) ⬆️

... and 1 file with indirect coverage changes

Components Coverage Δ
🏠 Main Package ∅ <ø> (∅)
🚗 Driver Package 91.40% <100.00%> (+1.01%) ⬆️
📡 gRPC Factory Package 81.65% <ø> (ø)
🔐 IAM Client Package 100.00% <100.00%> (+3.15%) ⬆️
🌐 S3 Client Package 100.00% <ø> (+6.12%) ⬆️
🔧 Util Package 100.00% <ø> (ø)
@@            Coverage Diff             @@
##             main      #57      +/-   ##
==========================================
+ Coverage   90.69%   93.12%   +2.42%     
==========================================
  Files           9        9              
  Lines         516      611      +95     
==========================================
+ Hits          468      569     +101     
+ Misses         38       36       -2     
+ Partials       10        6       -4     

@anurag4DSB anurag4DSB changed the title COSI-40: Revoke Bucket Access API (delete IAM user, inline policy and keys) COSI-40: Revoke Bucket Access API Implementation and Tests Dec 10, 2024
@anurag4DSB anurag4DSB force-pushed the feature/COSI-40-DriverRevokeBucketAccess-api branch 6 times, most recently from ba8f6a1 to e1e12fc Compare December 11, 2024 11:36
@anurag4DSB anurag4DSB marked this pull request as ready for review December 11, 2024 11:41
Base automatically changed from improvement/COSI-72-unit-tests-improvements to main December 11, 2024 13:19
@anurag4DSB anurag4DSB force-pushed the feature/COSI-40-DriverRevokeBucketAccess-api branch from e1e12fc to cac48a6 Compare December 11, 2024 19:57
@anurag4DSB anurag4DSB changed the title COSI-40: Revoke Bucket Access API Implementation and Tests COSI-40, COSI-52: Revoke Bucket Access API Implementation and Tests Dec 12, 2024
@@ -145,3 +152,88 @@ func (client *IAMClient) CreateBucketAccess(ctx context.Context, userName, bucke

return accessKeyOutput, nil
}

// RevokeBucketAccess is a helper that revokes bucket access by orchestrating individual steps to delete the user, inline policy, and access keys.
func (client *IAMClient) RevokeBucketAccess(ctx context.Context, userName, bucketName string) error {

Choose a reason for hiding this comment

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

So I assume there is a 1-1 mapping between users and buckets, in which case it looks correct to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

There is a 1 to many mapping for buckets and users.
1 bucket can have multiple IAM users accessing it.

But for each access indeed we have 1 IAM user

pkg/driver/provisioner_server_impl.go Outdated Show resolved Hide resolved
mockIAM = &mock.MockIAMClient{}
})

It("should fail on non-existent user gracefully", func(ctx SpecContext) {

Choose a reason for hiding this comment

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

The test says that it should fail "gracefully" but doesn't seem to check the gracefulness of the error (i.e. it tests the same way than the next test).

Copy link
Collaborator Author

@anurag4DSB anurag4DSB Dec 13, 2024

Choose a reason for hiding this comment

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

Thank you for your feedback — it helped me catch a bug. I’ve added the change along with tests: if an access key is deleted between listing and deletion, we now handle it by returning a “not found” error and continuing with the list.

Additionally, I’ve created a ticket for next week to review the graceful handling of all errors, and I’ve added it to the next sprint: S3C-9439. I have more instances like this.

client.IAMService = mockIAM

err := client.RevokeBucketAccess(ctx, "test-user", "test-bucket")
Expect(err).To(BeNil())

Choose a reason for hiding this comment

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

It would be good to check the side-effects of the function i.e. that it actually deleted stuff, although I don't know if this test suite is the good place where it can be done. It also applies to other tests around for function calls that have (or shouldn't have) side-effects.

One way I'm thinking about is attempting to use an access key that was revoked should not be possible, and conversely, using the access key that shouldn't have been revoked should still work. But that may be best done in E2E tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

We rely on Vault to handle the revocation of access keys, ensuring that deleted keys cannot be used. As such, this should not be tested in this particular test suite. Instead, the E2E tests verify the deletion of the IAM user, which falls under the scope of the COSI driver’s responsibility.

While I considered testing the deletion of the Kubernetes secret containing access, the responsibility for managing that lies with the COSI controller, not the COSI driver.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Relying on contracts/promises from other services.

@anurag4DSB anurag4DSB force-pushed the feature/COSI-40-DriverRevokeBucketAccess-api branch from 8b65b98 to 6e9393f Compare December 13, 2024 11:14
@anurag4DSB
Copy link
Collaborator Author

Addressed review comments, and added more tests for noSuchEntity scenarios.

We do not need a prefix for inline policy, as bucket object is linked to
access at kubernetes level, we keep inline policy name as bucket name
@anurag4DSB anurag4DSB force-pushed the feature/COSI-40-DriverRevokeBucketAccess-api branch from 6e9393f to e27a1d2 Compare December 13, 2024 11:19
- Gets parameters from the bucket object to get config for IAM client
- Adds methods to IAM client to delete user, inline policy and keys
- If inline policy doesn't exist, logs a warning and continues
- updated IAM mock with new IAM API methods
- added unit tests for RevokeBucketAccess IAM API methods
- removed the unimplemented test for RevokeBucketAccess
@anurag4DSB anurag4DSB force-pushed the feature/COSI-40-DriverRevokeBucketAccess-api branch from e27a1d2 to 07a2202 Compare December 13, 2024 11:22
@anurag4DSB anurag4DSB merged commit daa6db6 into main Dec 13, 2024
8 checks passed
@anurag4DSB anurag4DSB deleted the feature/COSI-40-DriverRevokeBucketAccess-api branch December 13, 2024 11:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants