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 support for well known policies with IRSA #3045

Merged
merged 9 commits into from Jan 28, 2021

Conversation

michaelbeaumont
Copy link
Contributor

@michaelbeaumont michaelbeaumont commented Jan 7, 2021

Description

Fixes #2837
I've only added these 5 for now. I want to confirm the rest of the existing addonPolicies make sense with IRSA

Checklist

  • Added tests that cover your change (if possible)
  • Added/modified documentation as required (such as the README.md, or the userdocs directory)
  • Manually tested
  • Added labels for change area (e.g. area/nodegroup), target version (e.g. version/0.12.0) and kind (e.g. kind/improvement)
  • Make sure the title of the PR is a good description that can go into the release notes

@michaelbeaumont michaelbeaumont added the kind/feature New feature or request label Jan 7, 2021
@aclevername
Copy link
Contributor

can an example yaml be added please 😄

@michaelbeaumont michaelbeaumont force-pushed the irsa_addon_policies branch 2 times, most recently from 4e61994 to 58f186a Compare January 7, 2021 19:59
customPolicy{Name: "PolicyCertManagerGetChange", Statements: certManagerGetChangeStatements()},
)
if wellKnownPolicies.ExternalDNS {
policies = append(policies, customPolicy{Name: "PolicyCertManagerHostedZones", Statements: certManagerHostedZonesStatements("route53:ListHostedZones", "route53:ListTagsForResource")})
Copy link
Contributor

@TBBle TBBle Jan 8, 2021

Choose a reason for hiding this comment

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

This can't be hit, because we're in an else after if wellKnownPolicies.ExternalDNS above. (Which is a good reminder that I don't see any tests for this new feature yet...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, missed when going from handling elements of a list of policies to handling this struct.

Copy link
Contributor

Choose a reason for hiding this comment

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

I see this has been updated, but I think the logic has drifted slightly.

My understanding of the similar code in createRole is roughly:

  • If CertManager or ExternalDNS, changeSetStatements
  • If Certmanager, certManagerGetChangeStatements
  • If CertManager and ExternalDNS, certManagerHostedZonesStatements + a couple of things ExternalDNS needs that aren't in that
  • If CertManager but not ExternalDNS, certManagerHostedZonesStatements
  • If ExternalDNS but not CertManager, externalDNSHostedZonesStatements.

This logic is currently

  • If CertManager or ExternalDNS, changeSetStatements
  • If CertManager, certManagerGetChangeStatements
  • If CertManager and ExternalDNS, certManagerHostedZonesStatements + a couple of things ExternalDNS needs that aren't in that
  • If CertManager and not ExternalDNS, certManagerHostedZonesStatements
  • If ExternalDNS, externalDNSHostedZonesStatements <== Applied even if CertManager.

externalDNSHostedZonesStatements and certManagerHostedZonesStatements both contain route53:ListResourceRecordSets, and the "couple of things" above are the other two statements from externalDNSHostedZonesStatements. So externalDNSHostedZonesStatements is a strict subset of "certManagerHostedZonesStatements + a couple of things ExternalDNS needs that aren't in that", so the former should only if the latter has not been applied.

To be fair, I don't know why the effort is made to avoid the overlap, unless there's an actual failure on the AWS API when a policy contains multiple statements for the same Effect/Resource/Action tuple? It just makes it harder to read and reason about.

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've simplified that code now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@TBBle please do take a look over the changes if you get a chance

@@ -25,7 +25,7 @@ type IAMRole struct {
Path string `json:",omitempty"`

AssumeRolePolicyDocument MapOfInterfaces `json:",omitempty"`
ManagedPolicyArns []string `json:",omitempty"`
ManagedPolicyArns []interface{} `json:",omitempty"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not clear why this is changed. Is it just because we're smuggling the return value from makePolicyARN out of (rs *IAMServiceAccountResourceSet) AddAllResources() inside this slice? Would it make sense to just stringify the value before adding it to ManagedPolicyArns instead?

(I'm not clear on what this gfn business is all about, so maybe this comment doesn't make sense.)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it's kind of a less than ideal situation because we do some cloud formation using our own types and some using goformation. It's here that they're being mixed. makePolicyARN uses Cloudformation intrinsics, which aren't serialized as strings. Although in this case it's probably not strictly necessary to use the intrinsic.

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'm going to leave the intrinsics because we use them elsewhere (with makePolicyArns) (and interface{} is sort of how things are done in cfn/template right now)

- metadata:
name: aws-load-balancer-controller
namespace: kube-system
wellKnownPolicies:
Copy link
Contributor

Choose a reason for hiding this comment

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

would attachWellKnownPolicies be better? I'm still open for WellKnownPolicies to change, but I think having attach prefixed helps to describe the intent

Copy link
Contributor

Choose a reason for hiding this comment

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

I think it's a little odd that this is would be a verb, when the general idea of declarative config suggests using nouns instead, to describe the resulting state, not how you get there.

attachedWellKnownPolicies perhaps, but that's pretty verbose, and only subtly different, so likely to lead to muscle-memory mistakes.

I think the various uses of attach in eksctl config stand out as verbs in a sea of nouns, but I guess using attach specifically is consistent here, e.g., we also have securityGroups.attachIDs, not securityGroups.attachedIDs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, I was trying to avoid a verb but maybe withWellKnownPolicies?

Copy link
Contributor

Choose a reason for hiding this comment

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

Would I be at risk of ruining everything by saying I am not a fan of WellKnown? withCommonPolicies?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

the one problem with "common" is that it has two meanings, one "well known", the other "shared"...

Copy link
Contributor

Choose a reason for hiding this comment

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

yeh that's totally right. withNamedPolicies? although I suppose all policies have names.

Copy link
Contributor

Choose a reason for hiding this comment

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

Struggling to find a better alternative to WellKnownPolicies so I'm happy to stick with that. I'm still unsure about with vs attach. I know that using the word attach isn't technically correct, but IMO its worth using it to remain consistent with the other fields.

@michaelbeaumont michaelbeaumont force-pushed the irsa_addon_policies branch 2 times, most recently from f950aa9 to 4052080 Compare January 11, 2021 14:27
@michaelbeaumont michaelbeaumont requested a review from a team January 14, 2021 09:15
Copy link
Contributor

@aclevername aclevername left a comment

Choose a reason for hiding this comment

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

LGTM

pkg/cfn/builder/iam.go Outdated Show resolved Hide resolved
@michaelbeaumont michaelbeaumont merged commit 14097d1 into eksctl-io:master Jan 28, 2021
@michaelbeaumont michaelbeaumont deleted the irsa_addon_policies branch January 28, 2021 10:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/feature New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Addon Policy support for IRSA-enabled Service Accounts
4 participants