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

Support team-id annotation #139

Closed
wants to merge 2 commits into from
Closed

Conversation

zicongmei
Copy link
Contributor

@zicongmei zicongmei commented Feb 22, 2024

Issue #, if available: aws-controllers-k8s/community#2031

Description of changes:

Add support of team-id annotation in the namespace. Each team-id can associate with a different AWS Role ARN. So that the controller can have different roles for different namespaces. It can help fine grained permission when different teams and users are using the same controller.

Changes:

Sample usage:

apiVersion: v1
kind: ConfigMap
metadata:
  name: ack-carm-map
  namespace: ack-system
data:
  owner-account-id/111111111111: arn:aws:iam::111111111111:role/s3FullAccess
  team-id/team-a:  'arn:aws:arn:aws:iam::123456789012:role/read-only'
---
apiVersion: v1
kind: Namespace
metadata:
  name: team
  annotations:
    services.k8s.aws/team-id: "team-a"
---
apiVersion: v1
kind: Namespace
metadata:
  name: account
  annotations:
    services.k8s.aws/owner-account-id: "111111111111"
---

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ack-prow ack-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 22, 2024
@ack-prow ack-prow bot requested review from jlbutler and jljaco February 22, 2024 18:32
Copy link

ack-prow bot commented Feb 22, 2024

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: zicongmei
Once this PR has been reviewed and has the lgtm label, please assign jljaco for approval by writing /assign @jljaco in a comment. 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

@ack-prow ack-prow bot added the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Feb 22, 2024
Copy link

ack-prow bot commented Feb 22, 2024

Hi @zicongmei. Thanks for your PR.

I'm waiting for a aws-controllers-k8s 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.

@zicongmei zicongmei marked this pull request as ready for review February 22, 2024 18:35
@ack-prow ack-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 22, 2024
@zicongmei
Copy link
Contributor Author

/ok-to-test

Copy link

ack-prow bot commented Feb 22, 2024

@zicongmei: Cannot trigger testing until a trusted user reviews the PR and leaves an /ok-to-test message.

In response to this:

/ok-to-test

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.

@a-hilaly
Copy link
Member

/ok-to-test

@ack-prow ack-prow bot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Feb 29, 2024
@a-hilaly
Copy link
Member

/retest

1 similar comment
@a-hilaly
Copy link
Member

a-hilaly commented Mar 1, 2024

/retest

@zicongmei zicongmei marked this pull request as draft March 5, 2024 21:44
@ack-prow ack-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 5, 2024
@zicongmei
Copy link
Contributor Author

/retest

@zicongmei
Copy link
Contributor Author

/retest

@zicongmei zicongmei changed the title Support role annotation Support team-id annotation Mar 12, 2024
@zicongmei
Copy link
Contributor Author

/retest

@zicongmei
Copy link
Contributor Author

/retest

@zicongmei zicongmei marked this pull request as ready for review March 12, 2024 21:07
@ack-prow ack-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 12, 2024
@zicongmei zicongmei marked this pull request as draft March 12, 2024 21:56
@ack-prow ack-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 12, 2024
@zicongmei
Copy link
Contributor Author

/ok-to-test

@zicongmei zicongmei marked this pull request as ready for review March 12, 2024 23:00
@ack-prow ack-prow bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 12, 2024
Copy link
Member

@a-hilaly a-hilaly left a comment

Choose a reason for hiding this comment

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

This is great, thank you so much @zicongmei ! I left few comments and thoughts below

Comment on lines +248 to +251
TeamID, ok := nsa[ackv1alpha1.AnnotationTeamID]
if ok {
nsInfo.teamID = TeamID
}
Copy link
Member

Choose a reason for hiding this comment

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

Just taking notes.. during the refactor we will need to use lowerCamelCase variable names

Comment on lines 76 to 79
Accounts *CARMCache

// Team-ID cache
Teams *CARMCache
Copy link
Member

Choose a reason for hiding this comment

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

The separation of concerns implemented here is a good approach. However, I have a minor concern about spinning up two shared informers, watching the same exact kind (ConfigMap).. This could result in redundant watch operations essentially retrieving the same information (data).

Additionally, I think that using two separate informers can potentially result in delays when updating the caches for teamID and an ownerAccountID. If one cache gets updated before the other, there's a risk that the logic for picking up either the teamID or ownerAccountID may get impacted until both caches are fully synced

Copy link
Member

Choose a reason for hiding this comment

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

What are your thoughts on using a single "cache" object (`CARMCache) to store both the teamIDs and accountIDs?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I like the idea of a single map. We can separate that from this PR.

Comment on lines 152 to 136
parsedARN, err := arn.Parse(string(roleARN))
if err != nil {
return fmt.Errorf("failed to parsed role ARN %q from namespace annotation: %v", teamID, err)
}
Copy link
Member

Choose a reason for hiding this comment

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

Should we move the AWS AccountID and ARN parsing logic to level closer to the CARMCache layer? the issue with handling errors here is that it's tricky properly patch the CRs conditions and trigger a proper requeue.
Second thoughts, i think this needs to be part of the refactor PR.

Comment on lines 47 to 49
// ACKRoleTeamMap is the name of the configmap map object storing
// all the AWS Team IDs associated with their AWS Role ARNs.
ACKRoleTeamMap CARMName = "ack-role-team-map"
Copy link
Member

Choose a reason for hiding this comment

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

I just realized that we're adding a new map to watch here. It's a little different from what we've imagined initially but I like it... It's definitely better than combining accountIDs and teamIDs in the same ConfigMap...

@zicongmei zicongmei marked this pull request as draft March 18, 2024 23:00
@ack-prow ack-prow bot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. ok-to-test Indicates a non-member PR verified by an org member that is safe to test.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants