Skip to content

Conversation

@rolandmkunkel
Copy link
Contributor

@rolandmkunkel rolandmkunkel commented Aug 16, 2021

Which issue this PR addresses:

  • extends e2e tests to create cluster with disk encryption enabled with customer managed keys.

  • adds e2e test to confirm following:
    All vms has disk encryption set
    Storage class is set to provision encrypted disk

Fixes https://msazure.visualstudio.com/AzureRedHatOpenShift/_workitems/edit/7404076

What this PR does / why we need it:

Helps us testing the e2e disk encryption feature and gives us more confidence to ship it.

@rolandmkunkel rolandmkunkel requested a review from m1kola August 16, 2021 16:38
@rolandmkunkel rolandmkunkel force-pushed the disc-encryption-e2e-tests branch from 57560c9 to 32a46fa Compare August 16, 2021 16:42
@github-actions github-actions bot added the needs-rebase branch needs a rebase label Aug 16, 2021
@github-actions
Copy link

Please rebase pull request.

@rolandmkunkel rolandmkunkel force-pushed the disc-encryption-e2e-tests branch from 32a46fa to 85d81d1 Compare September 9, 2021 10:13
Copy link
Contributor

@mjudeikis mjudeikis left a comment

Choose a reason for hiding this comment

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

Few nits but getting close

Copy link
Contributor

Choose a reason for hiding this comment

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

So if this is not available? Maybe try again and not fail?

Copy link
Contributor

@m1kola m1kola left a comment

Choose a reason for hiding this comment

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

Few questions/suggestions, but in general looks good so far.

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 at this point we should probably rename vnetResourceGroup to something more generic as it now hold not only vnet, but key vault as well. I however don't have ideas apart from something stupid like "bring your own resource resource group" :)

Copy link
Contributor

Choose a reason for hiding this comment

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

Also specificly for this line:

You do c.diskEncryptionSets.Get(...) here but you only use it to retreive diskEncryptionSet.ID. At the same time, few lines below you construct this ID (line 235):

{"/subscriptions/" + c.env.SubscriptionID() + "/resourceGroups/" + vnetResourceGroup + "/providers/Microsoft.Compute/diskEncryptionSets/" + diskEncryptionSetName, rbac.RoleReader},

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 is fine to check via VMs. But I'm wondering why you can't list disks by resoruce group?

Copy link
Contributor

Choose a reason for hiding this comment

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

@rolandmkunkel we previously discussed that we need to add a code comment explaining why becasue it is not obvious.

@rolandmkunkel rolandmkunkel force-pushed the disc-encryption-e2e-tests branch 2 times, most recently from ae46a5e to a46840b Compare September 23, 2021 08:36
@rolandmkunkel rolandmkunkel force-pushed the disc-encryption-e2e-tests branch from a46840b to 0847e8a Compare September 30, 2021 10:13
@github-actions github-actions bot removed the needs-rebase branch needs a rebase label Sep 30, 2021
Copy link
Contributor Author

Choose a reason for hiding this comment

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

renamed version of deploy/cluster-predeploy.json

@rolandmkunkel rolandmkunkel force-pushed the disc-encryption-e2e-tests branch 7 times, most recently from b42758a to 792e4a8 Compare October 1, 2021 14:45
@rolandmkunkel rolandmkunkel changed the title WIP e2e disk encryption tests e2e disk encryption tests Oct 4, 2021
@github-actions
Copy link

github-actions bot commented Oct 4, 2021

Please rebase pull request.

@github-actions github-actions bot added the needs-rebase branch needs a rebase label Oct 4, 2021
Copy link
Contributor

@m1kola m1kola left a comment

Choose a reason for hiding this comment

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

I didn't finish reviewing this PR. Just positng early feedback.

Copy link
Contributor

Choose a reason for hiding this comment

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

@rolandmkunkel we previously discussed that we need to add a code comment explaining why becasue it is not obvious.

Comment on lines +63 to +98
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this is how we check that PVCs with default storage class provision encrypted disks. Is it right? If so, then we should add a comment. Or even better add two separate By("...") (we might end up with two for loops for the same vms because of that, but that's fine IMO).

Anyway - I think we need some form of clarification here as it is not obvious.

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 looking at GetSecret and it looks like we are simplifying the interface even further by ommiting keyVersion.

Suggested change
func (m *manager) GetKey(ctx context.Context, keyName string, keyVersion string) (azkeyvault.KeyBundle, error) {
return m.kv.GetKey(ctx, m.keyvaultURI, keyName, keyVersion)
}
func (m *manager) GetKey(ctx context.Context, keyName string) (azkeyvault.KeyBundle, error) {
return m.kv.GetKey(ctx, m.keyvaultURI, keyName, "")
}

This way can probably get rid of LatestKeyVersion constant.

Copy link
Contributor

@m1kola m1kola left a comment

Choose a reason for hiding this comment

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

Still need to review pkg/util/cluster/cluster.go.

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 we no longer use this. Everything is in BaseClient now.

@rolandmkunkel rolandmkunkel force-pushed the disc-encryption-e2e-tests branch from 792e4a8 to 32261e4 Compare October 7, 2021 11:32
@rolandmkunkel rolandmkunkel force-pushed the disc-encryption-e2e-tests branch from 32261e4 to 04eb293 Compare October 7, 2021 12:22
@github-actions github-actions bot removed the needs-rebase branch needs a rebase label Oct 7, 2021
@rolandmkunkel rolandmkunkel force-pushed the disc-encryption-e2e-tests branch 2 times, most recently from ba8eca9 to e91acfc Compare October 7, 2021 13:27
@rolandmkunkel rolandmkunkel force-pushed the disc-encryption-e2e-tests branch from e91acfc to 6a907bf Compare October 8, 2021 11:04
@github-actions github-actions bot added the needs-rebase branch needs a rebase label Oct 8, 2021
@github-actions
Copy link

github-actions bot commented Oct 8, 2021

Please rebase pull request.

Copy link
Contributor

@m1kola m1kola left a comment

Choose a reason for hiding this comment

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

I have a lot of questions.

Also I think this PR now has too many things in the scope:

  • Updating shared environemt
  • Dealing with deployments in a non-shared resoruce group.
  • Dealing with setting up e2e clusters
  • E2Es tests on their own

I think part of this is my fault: I didn't realise it is earlier. Let's talk tomorrow on what to do with this.

Copy link
Contributor

Choose a reason for hiding this comment

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

Is it going to stay? If so, we might want to give it better message and use infof.

Comment on lines +206 to +218
res, err := serviceKeyvault.GetKey(ctx, keyName)
if err == nil && res.Key != nil {
c.log.Infoln("using existing key")
shouldCreateKey = false
} else {
err = serviceKeyvault.RecoverDeletedKey(ctx, keyName)
if err != nil {
c.log.Infoln("could not recover any existing key")
} else {
c.log.Infoln("recovered key")
shouldCreateKey = false
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What is the reason why we should reuse keys? Can we create a new key each time for both CI and dev runs?

I would like to get rid of this logic, if possible.

{
ObjectID: to.StringPtr("[parameters('azureServicePrincipalId')]"),
Permissions: &mgmtkeyvault.Permissions{
Keys: &[]mgmtkeyvault.KeyPermissions{mgmtkeyvault.KeyPermissionsCreate, mgmtkeyvault.KeyPermissionsGet, mgmtkeyvault.KeyPermissionsDelete, mgmtkeyvault.KeyPermissionsRecover},
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: on formatting.

Suggested change
Keys: &[]mgmtkeyvault.KeyPermissions{mgmtkeyvault.KeyPermissionsCreate, mgmtkeyvault.KeyPermissionsGet, mgmtkeyvault.KeyPermissionsDelete, mgmtkeyvault.KeyPermissionsRecover},
Keys: &[]mgmtkeyvault.KeyPermissions{
mgmtkeyvault.KeyPermissionsCreate,
mgmtkeyvault.KeyPermissionsGet,
mgmtkeyvault.KeyPermissionsDelete,
mgmtkeyvault.KeyPermissionsRecover,
},

)

var _ = Describe("Encryption at host should be enabled", func() {
BeforeEach(skipIfNotInDevelopmentEnv)
Copy link
Contributor

Choose a reason for hiding this comment

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

Why?

Comment on lines +65 to +76
for _, vm := range vms {
vm.StorageProfile.DataDisks = &[]mgmtcompute.DataDisk{{
Lun: to.Int32Ptr(0),
CreateOption: mgmtcompute.DiskCreateOptionTypesEmpty,
DiskSizeGB: to.Int32Ptr(1),
ManagedDisk: &mgmtcompute.ManagedDiskParameters{
DiskEncryptionSet: &mgmtcompute.DiskEncryptionSetParameters{ID: to.StringPtr(diskEncryptionSetId)},
},
}}
err = clients.VirtualMachines.CreateOrUpdateAndWait(ctx, clusterResourceGroup, *vm.Name, vm)
Expect(err).NotTo(HaveOccurred())
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Why are we creating VM here?

},
})

vaultResource.APIVersion = azureclient.APIVersion("Microsoft.KeyVault")
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not have it in g.keyVault(...)?

Same question for devDiskEncryptionKeyvault() in pkg/deploy/generator/resources_dev.go.


Also take a look at virtualNetwork: we accept condition and dependsOn as params. Should we do something similar for g.keyVault(...)?

func (g *generator) virtualNetwork(name, addressPrefix string, subnets *[]mgmtnetwork.Subnet, condition interface{}, dependsOn []string) *arm.Resource {

})

vaultResource.APIVersion = azureclient.APIVersion("Microsoft.KeyVault")
vaultResource.Condition = to.StringPtr("[equals(parameters('shouldCreateKeyVault'), 'true')]")
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't we just use [parameters('ci')] as a condition?

}
}

diskEncryptionSetName := clusterName + "-des"
Copy link
Contributor

Choose a reason for hiding this comment

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

Should we have a constant for "-des"?

Comment on lines +93 to +102
{
TenantID: &tenantUUIDHack,
ObjectID: to.StringPtr("[parameters('rpServicePrincipalId')]"),
Permissions: &mgmtkeyvault.Permissions{
Keys: &[]mgmtkeyvault.KeyPermissions{
mgmtkeyvault.KeyPermissions(mgmtkeyvault.Create),
mgmtkeyvault.KeyPermissions(mgmtkeyvault.Delete),
},
},
},
Copy link
Contributor

Choose a reason for hiding this comment

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

Giving these permissions to RP service principal doesn't sound right. RP SP is for RP resources, not cluster/customer resoruces.

Expect(osDisk.Encryption.Type).To(Equal(mgmtcompute.EncryptionAtRestWithCustomerKey))
}

By("checking the encryption property on each data disk of each VM")
Copy link
Contributor

Choose a reason for hiding this comment

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

This should be about validating that default storrage class creates disks with disk encryption enabled.

See "How to test that default PV is encrypted" in for manual steps: #1627

But I think this PR is too big already: it is very hard to follow. Let's deal wtih it once we merge this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants