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

feat(eks): improve security using IRSA conditions #8084

Merged
merged 12 commits into from
May 21, 2020

Conversation

vlesierse
Copy link
Contributor

@vlesierse vlesierse commented May 19, 2020

Currently the ServiceAccountconstruct creates a role with no conditions to the trust relationship or assume role policy. Without this it is possible for other pods in the same namespace to assume the role. To tighten this security the conditions needs to be set.

Documentation: https://docs.aws.amazon.com/eks/latest/userguide/create-service-account-iam-policy-and-role.html#create-service-account-iam-role

  • Add condition to the policy document using a custom resource
  • Add unit tests
  • Add integration tests
  • Adjust README and remove warning

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

@vlesierse
Copy link
Contributor Author

@eladb I've chosen to put the custom resource in the aws-eks module as it is currently specific for this use case. Having a patching construct in the aws-iam module didn't feel right. I've tried it in this branch: https://github.com/vlesierse/aws-cdk/tree/iam/policytemplate

@SomayaB SomayaB assigned rix0rrr and eladb and unassigned rix0rrr May 19, 2020
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 60ab001
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 1f147cd
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

eladb pushed a commit that referenced this pull request May 20, 2020
Rarely there is a need to use a CloudFormation intrinsic in a JSON hash key. This is impossible since intrinsics are not strings. To circumvent that, CfnJson can be used to "delay" the rendition of the object using a simple custom resource
which simply parses and reflects the input value as an attribute.

Required in order to implement EKS IRSA (#8084) and other federated identity use cases.
eladb
eladb previously requested changes May 20, 2020
Copy link
Contributor

@eladb eladb 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 what I meant when I proposed a more generic solution:
#8099

Let's wait for this to be merged and then this one is going to be easy...

@vlesierse
Copy link
Contributor Author

Yep, this looks lot better. Probably the lack of knowledge on how the tokenisation works within CDK. I'll dive a bit deep to understand it. Meanwhile I'll do my adjustments when this lands on the master branch.

mergify bot pushed a commit that referenced this pull request May 21, 2020
Rarely there is a need to use a CloudFormation intrinsic in a JSON hash key. This is impossible since intrinsics are not strings. To circumvent that, CfnJson can be used to "delay" the rendition of the object using a simple custom resource
which simply parses and reflects the input value as an attribute.

Required in order to implement EKS IRSA (#8084) and other federated identity use cases.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@mergify mergify bot dismissed eladb’s stale review May 21, 2020 09:19

Pull request has been modified.

@vlesierse vlesierse changed the title feat(iam): improve security using IRSA conditions feat(aws-eks): improve security using IRSA conditions May 21, 2020
@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: ab744f1
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: b076d70
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

eladb
eladb previously requested changes May 21, 2020
packages/@aws-cdk/aws-eks/lib/cluster.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-eks/lib/irsa-conditions/external.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-eks/lib/irsa-conditions/index.ts Outdated Show resolved Hide resolved
packages/@aws-cdk/aws-eks/lib/service-account.ts Outdated Show resolved Hide resolved
@mergify mergify bot dismissed eladb’s stale review May 21, 2020 18:51

Pull request has been modified.

Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

Minor comment. I think you can convert to a non-draft PR.

@eladb eladb changed the title feat(aws-eks): improve security using IRSA conditions feat(eks): improve security using IRSA conditions May 21, 2020
@vlesierse vlesierse marked this pull request as ready for review May 21, 2020 19:05
eladb
eladb previously requested changes May 21, 2020
Copy link
Contributor

@eladb eladb left a comment

Choose a reason for hiding this comment

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

sorry one more comment

@@ -198,7 +198,7 @@ export class ClusterResourceHandler extends ResourceHandler {
Endpoint: cluster.endpoint,
Arn: cluster.arn,
CertificateAuthorityData: cluster.certificateAuthority?.data,
OpenIdConnectIssuerUrl: cluster.identity?.oidc?.issuer,
OpenIdConnectIssuerUrl: cluster.identity?.oidc?.issuer?.substring(8), // Strips off https:// from the issuer url
Copy link
Contributor

Choose a reason for hiding this comment

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

This is technically a breaking change. Perhaps the correct approach is to add another attribute OpenIdConnectIssuer which will return the value without the https:// prefix.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah yeah. Good one. I'll make the change.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should I create the additional property on the Cluster construct as well?

Copy link
Contributor

Choose a reason for hiding this comment

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

Sure

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: d71c897
  • Result: FAILED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 5e9e726
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 69a82b8
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot dismissed eladb’s stale review May 21, 2020 20:45

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 1b249bf
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented May 21, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildProject6AEA49D1-qxepHUsryhcu
  • Commit ID: 9315fba
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify
Copy link
Contributor

mergify bot commented May 21, 2020

Thank you for contributing! Your pull request will be updated from master and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@mergify mergify bot merged commit 35a01a0 into aws:master May 21, 2020
karupanerura pushed a commit to karupanerura/aws-cdk that referenced this pull request May 22, 2020
Rarely there is a need to use a CloudFormation intrinsic in a JSON hash key. This is impossible since intrinsics are not strings. To circumvent that, CfnJson can be used to "delay" the rendition of the object using a simple custom resource
which simply parses and reflects the input value as an attribute.

Required in order to implement EKS IRSA (aws#8084) and other federated identity use cases.


----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
@@ -708,7 +723,7 @@ export class Cluster extends Resource implements ICluster {
* @param id the id of this service account
* @param options service account options
*/
public addServiceAccount(id: string, options: ServiceAccountOptions) {
public addServiceAccount(id: string, options: ServiceAccountOptions = { }) {
Copy link
Contributor

@pahud pahud May 27, 2020

Choose a reason for hiding this comment

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

the options is still mandatory here and user will still need to run addServiceAccont(id, {}) if no options.

Maybe this?

   public addServiceAccount(id: string, options?: ServiceAccountOptions = { }) { 

Copy link
Contributor

Choose a reason for hiding this comment

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

The default value turns it into optional. The “?” Is not needed

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.

5 participants