Skip to content

feat: Implement support for KMS arguments#288

Merged
lonegunmanb merged 10 commits intoAzure:masterfrom
swisspost:feature/secrets_kms_encryption
Jan 29, 2023
Merged

feat: Implement support for KMS arguments#288
lonegunmanb merged 10 commits intoAzure:masterfrom
swisspost:feature/secrets_kms_encryption

Conversation

@mkilchhofer
Copy link
Copy Markdown
Contributor

@mkilchhofer mkilchhofer commented Jan 6, 2023

Describe your changes

This implements Add Key Management Service (KMS) etcd encryption to an Azure Kubernetes Service (AKS) cluster.

Feature is not yet available in azurerm provider, but also opened a PR over there:

Issue number

-

Checklist before requesting a review

  • The pr title can be used to describe what this pr did in CHANGELOG.md file
  • I have executed pre-commit on my machine
  • I have passed pr-check on my machine

Thanks for your cooperation!

Copy link
Copy Markdown
Member

@lonegunmanb lonegunmanb left a comment

Choose a reason for hiding this comment

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

Thanks @mkilchhofer for opening this pr and submitting a new resource pr to terraform-azurerm-provider's repo, I've left some comments on provider's pr, once the pr has been merged into the provider, we can continue the code review for this pr.

Btw the review comments for your provider's pr are my personal suggestions, there's no guarantee that your pr would be accepted by HashiCorp if you accepted my suggestion.

Comment thread main.tf Outdated
}
}
dynamic "key_vault_kms" {
for_each = var.key_vault_kms_enabled ? ["key_vault_kms"] : []
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Since we could turn enabled to false meanwhile keeping this key_vault_kms, I would recommend the following toggle expression:

for_each = var.key_vault_kms_enabled != null ? ["key_vault_kms"] : []

Copy link
Copy Markdown
Contributor Author

@mkilchhofer mkilchhofer Jan 20, 2023

Choose a reason for hiding this comment

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

refactored this anyways (source was the upstream implementation)

@mkilchhofer mkilchhofer marked this pull request as ready for review January 20, 2023 09:53
@mkilchhofer
Copy link
Copy Markdown
Contributor Author

PR is now updated after the upstream provider PR got merged AND released ;-)

@lonegunmanb can you please review again?

Copy link
Copy Markdown
Member

@lonegunmanb lonegunmanb left a comment

Choose a reason for hiding this comment

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

Thanks @mkilchhofer for updating this pr, some issues need to be solved.

It would be nice if we could have an new example to demonstrate this new feature. We have already created a KeyValut in startup example, but for disk encryption key management for now, would you please estimate whether if we can make that KeyVault work for this new feature? We might need to update azurerm provider's restriction in providers.tf file in startup folder. Or we can just crate a new example folder to do so, your call.

Again, thanks for your contribution!

Comment thread variables.tf
Comment thread variables.tf Outdated
Comment thread main.tf
@mkilchhofer
Copy link
Copy Markdown
Contributor Author

I cannot test the examples as we @swisspost have no subscriptions which allows usage of public IPs.
Can someone test that for us?

@zioproto
Copy link
Copy Markdown
Contributor

@mkilchhofer I can do that ! thanks

@zioproto
Copy link
Copy Markdown
Contributor

@mkilchhofer could you please run the pre-commit step on your local machine ?:

docker run --rm -v $(pwd):/src -w /src mcr.microsoft.com/azterraform:latest make pre-commit

You patched the example and you have duplicated definitions for identity_type and identity_ids. See the error:

Error: Attribute redefined
│
│   on examples/named_cluster/main.tf line 88, in module "aks_cluster_name":
│   88:   identity_type         = "UserAssigned"
│
│ The argument "identity_type" was already set at
│ examples/named_cluster/main.tf:66,3-16. Each argument may be set only once.
╵

╷
│ Error: Attribute redefined
│
│   on examples/named_cluster/main.tf line 89, in module "aks_cluster_name":
│   89:   identity_ids          = [azurerm_user_assigned_identity.test.id]
│
│ The argument "identity_ids" was already set at
│ examples/named_cluster/main.tf:65,3-15. Each argument may be set only once.

- nullable=false on `kms_enabled`
- Validate kms_enabled and UserAssigned identity
Copy link
Copy Markdown
Contributor

@zioproto zioproto left a comment

Choose a reason for hiding this comment

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

Could you patch only the named_cluster example ?

We dont need to the KMS in the others, it would also require more work because the needed UserAssigned identity_type is not set in the others. Thanks

Comment thread examples/named_cluster/main.tf Outdated
Comment thread examples/named_cluster/main.tf Outdated
@mkilchhofer mkilchhofer requested review from lonegunmanb and zioproto and removed request for zioproto January 24, 2023 08:08
@zioproto
Copy link
Copy Markdown
Contributor

commit 7012178 is now passing both pre-commit and pr-check steps.

@lonegunmanb could you please review and run the e2e tests ? thanks

Comment thread .checkov_config.yaml
Comment thread variables.tf Outdated
Comment thread examples/named_cluster/kms.tf Outdated
@mkilchhofer
Copy link
Copy Markdown
Contributor Author

@lonegunmanb can you trigger E2E again? 😇

Copy link
Copy Markdown
Member

@lonegunmanb lonegunmanb left a comment

Choose a reason for hiding this comment

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

Thanks @mkilchhofer for this update, we've met some issues when we ran the test.

We've added network_acl on the KeyVault to restrict the source IP which can access this Key Vault, but the Aks's public IP is unpredictable so the original code would meet a 403 error.

We need config the aks to access the KeyVault via private network as this document described.

Comment thread examples/named_cluster/kms.tf
rbac_aad = true
rbac_aad_managed = true
role_based_access_control_enabled = true

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We need the following line below line 31:

service_endpoints                              = ["Microsoft.KeyVault"]

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Service endpoint is not needed (at least in our scenario). I think its only needed if some part inside the VNET wants to access the keyvault.

Comment thread examples/named_cluster/main.tf
Comment thread examples/named_cluster/main.tf Outdated
Comment thread examples/named_cluster/kms.tf
@mkilchhofer mkilchhofer temporarily deployed to acctests January 28, 2023 14:36 — with GitHub Actions Inactive
Copy link
Copy Markdown
Member

@lonegunmanb lonegunmanb left a comment

Choose a reason for hiding this comment

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

Thanks @mkilchhofer, LGTM! 🚀

@lonegunmanb lonegunmanb merged commit 5443398 into Azure:master Jan 29, 2023
@mkilchhofer
Copy link
Copy Markdown
Contributor Author

Thanks alot for your patience with me 👍

@mkilchhofer mkilchhofer deleted the feature/secrets_kms_encryption branch January 30, 2023 10:30
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