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

pkg/destroy/azure: Delete app registrations during cluster destroy #2262

Merged

Conversation

joelddiaz
Copy link
Contributor

With cloud-cred-operator tagging Service Principals, we can now located the Service Principals by tag, and find their parent Application Registration and delete them as part of cluster destroy.

This should keep the App Registrations created by cloud-cred-operator from leaking out after cluster create/destroy.

dep ensure -v (with some code importing github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac)
@openshift-ci-robot openshift-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Aug 23, 2019
@wking wking changed the title delete app registrations during cluster destroy pkg/destroy/azure: Delete app registrations during cluster destroy Aug 23, 2019
@abhinavdahiya
Copy link
Contributor

dont' log errors with ERROR level, the destroy for azure returns them and prints them in DEBUG.

}

func (o *ClusterUninstaller) configureClients() {
o.resourceGroupsClient = resources.NewGroupsGroupClient(o.SubscriptionID)
o.resourceGroupsClient.Authorizer = o.Authorizer
o.resourceGroupsClient.Authorizer = o.ResourceManagerAuthorizer
Copy link
Contributor

Choose a reason for hiding this comment

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

hmm.. this should be Authorizer

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

for _, sp := range servicePrincipals {
logger = logger.WithField("appID", *sp.AppID)
appFilter := fmt.Sprintf("appId eq '%s'", *sp.AppID)
appResults, err := appClient.List(ctx, appFilter)
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 use https://godoc.org/github.com/Azure/azure-sdk-for-go/services/graphrbac/1.6/graphrbac#ApplicationsClient.Get vs listing for appID can there be more than one with same ID???

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 Get requires querying the objectID not the appID

[jdiaz@minigoomba ~]$ az ad app list --display-name jdiaz-app | jq -r ".[].appId , .[].objectId"
9ba357ad-0bf5-4a0c-8c3f-8e6eee8e6b36
10dbbb0c-29ae-4705-8bf9-95e99f0e8a3b

And all you get from the service principal is the appID of the app registration.

return matchedSPs, err
}

for {
Copy link
Contributor

Choose a reason for hiding this comment

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

use somethings like

for zonesPage, err := client.azureClient.List(ctx, to.Int32Ptr(100)); zonesPage.NotDone(); err = zonesPage.NextWithContext(ctx) {
if err != nil {
return nil, err
}
//TODO: filter out private zone and show only public zones.
//the property is present in the REST api response, but not mapped yet in the stable SDK (present in preview)
//https://github.com/Azure/azure-sdk-for-go/blob/07f918ba2d513bbc5b75bc4caac845e10f27449e/services/preview/dns/mgmt/2018-03-01-preview/dns/models.go#L857
for _, zone := range zonesPage.Values() {
allZones[to.String(zone.Name)] = to.String(zone.ID)
}
}
return allZones, nil

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 much prefer this. will change it

@abhinavdahiya
Copy link
Contributor

/test e2e-azure

LGTM

con you squash the commits 80ca614 and 96d22b6

@abhinavdahiya
Copy link
Contributor

/test e2e-azure

@joelddiaz
Copy link
Contributor Author

squashed

@joelddiaz
Copy link
Contributor Author

/retest

@joelddiaz
Copy link
Contributor Author

/test e2e-azure

1 similar comment
@joelddiaz
Copy link
Contributor Author

/test e2e-azure

@abhinavdahiya
Copy link
Contributor

https://storage.googleapis.com/origin-ci-test/pr-logs/pull/openshift_installer/2262/pull-ci-openshift-installer-master-e2e-azure/146/artifacts/e2e-azure/pods/openshift-cloud-credential-operator_cloud-credential-operator-65d96ddfdf-96fdd_manager.log

The cred operator created service principals.

https://storage.googleapis.com/origin-ci-test/pr-logs/pull/openshift_installer/2262/pull-ci-openshift-installer-master-e2e-azure/146/artifacts/e2e-azure/installer/.openshift_install.log
time="2019-08-26T15:03:06Z" level=debug msg="deleting public records"
time="2019-08-26T15:03:08Z" level=debug msg="removing matching private records from ci.azure.devcluster.openshift.com"
time="2019-08-26T15:03:10Z" level=info msg=deleted record=api.ci-op-1xw3yxn7-2dc90
time="2019-08-26T15:03:11Z" level=info msg=deleted record="*.apps.ci-op-1xw3yxn7-2dc90"
time="2019-08-26T15:03:11Z" level=debug msg="deleting resource group"
time="2019-08-26T15:17:01Z" level=info msg=deleted resource group=ci-op-1xw3yxn7-2dc90-7jkwd-rg
time="2019-08-26T15:17:01Z" level=debug msg="deleting application registrations
time="2019-08-26T15:17:02Z" level=debug msg="Purging asset "Terraform Variables" from disk"

Doesn't seem to have cleaned up any???

@joelddiaz
Copy link
Contributor Author

time="2019-08-26T15:17:01Z" level=debug msg="deleting application registrations
time="2019-08-26T15:17:02Z" level=debug msg="Purging asset "Terraform Variables" from disk"

Doesn't seem to have cleaned up any???

I think I see what's happening. The cloud-cred-operator clips the infra prefix to 20 characters (https://github.com/openshift/cloud-credential-operator/blob/master/pkg/azure/actuator.go#L497-L500), so when searching for Service Principals, this code should do the same.

@abhinavdahiya
Copy link
Contributor

time="2019-08-26T15:17:01Z" level=debug msg="deleting application registrations
time="2019-08-26T15:17:02Z" level=debug msg="Purging asset "Terraform Variables" from disk"

Doesn't seem to have cleaned up any???

I think I see what's happening. The cloud-cred-operator clips the infra prefix to 20 characters (https://github.com/openshift/cloud-credential-operator/blob/master/pkg/azure/actuator.go#L497-L500), so when searching for Service Principals, this code should do the same.

https://github.com/openshift/cloud-credential-operator/blob/14ea16f11aaf6b77d3bce0dcfb93546e12da6942/pkg/azure/actuator.go#L504-L506

make it unclip the credential name, why is it clipping the infra-id??

@joelddiaz
Copy link
Contributor Author

I think I see what's happening. The cloud-cred-operator clips the infra prefix to 20 characters (https://github.com/openshift/cloud-credential-operator/blob/master/pkg/azure/actuator.go#L497-L500), so when searching for Service Principals, this code should do the same.

https://github.com/openshift/cloud-credential-operator/blob/14ea16f11aaf6b77d3bce0dcfb93546e12da6942/pkg/azure/actuator.go#L504-L506

make it unclip the credential name, why is it clipping the infra-id??

I think it was done out of concern for the 93 character limit. @ingvagabund maybe you can give more context?

@ingvagabund
Copy link
Member

ingvagabund commented Aug 27, 2019

I think it was done out of concern for the 93 character limit. @ingvagabund maybe you can give more context?

Two things:

  1. aws actuator clips the infra name when generating a user name: https://github.com/openshift/cloud-credential-operator/blob/master/pkg/aws/actuator/actuator.go#L1119-L1121. I followed the same pattern
  2. Azure does not allow application (SP) names to be longer than 93 characters. It errors otherwise.

@joelddiaz
Copy link
Contributor Author

/test e2e-azure

@abhinavdahiya
Copy link
Contributor

I think it was done out of concern for the 93 character limit. @ingvagabund maybe you can give more context?

Two things:

1. aws actuator clips the infra name when generating a user name: https://github.com/openshift/cloud-credential-operator/blob/master/pkg/aws/actuator/actuator.go#L1119-L1121. I followed the same pattern

2. Azure does not allow application (SP) names to be longer than 93 characters. It errors otherwise.

But if depend on infra-id to filter the the service principals, I would rather truncate the credential name here.. the infra-id is max 32..

@joelddiaz
Copy link
Contributor Author

PR to raise infra field length to 32 here openshift/cloud-credential-operator#108

With cloud-cred-operator tagging Service Principals, we can now located the Service Principals by tag, and find their parent Application Registration and delete them as part of cluster destroy.
@joelddiaz
Copy link
Contributor Author

/test e2e-azure

@joelddiaz
Copy link
Contributor Author

looks like it's deleting the app registrations now

time="2019-08-27T18:08:30Z" level=debug msg="deleting application registrations"
time="2019-08-27T18:08:31Z" level=info msg=deleted appID=f18a9b1f-72ff-43db-8a73-abf73bc37ad9
time="2019-08-27T18:08:37Z" level=info msg=deleted appID=47c260de-9275-4db2-b889-c34334c33ee9
time="2019-08-27T18:08:43Z" level=info msg=deleted appID=2e39df42-0018-472c-b1b0-20c524eb2d3c

just need to get through CI now...

@abhinavdahiya
Copy link
Contributor

/approve

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 29, 2019
@joelddiaz
Copy link
Contributor Author

/retest

1 similar comment
@joelddiaz
Copy link
Contributor Author

/retest

@abhinavdahiya
Copy link
Contributor

/test e2e-azure

@joelddiaz
Copy link
Contributor Author

/retest

@joelddiaz
Copy link
Contributor Author

/test e2e-aws-scaleup-rhel7

@abhinavdahiya
Copy link
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Aug 30, 2019
@openshift-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: abhinavdahiya, joelddiaz

The full list of commands accepted by this bot can be found here.

The pull request process is described 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

@openshift-bot
Copy link
Contributor

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-ci-robot
Copy link
Contributor

openshift-ci-robot commented Aug 30, 2019

@joelddiaz: The following tests failed, say /retest to rerun them all:

Test name Commit Details Rerun command
ci/prow/e2e-aws-scaleup-rhel7 742e463 link /test e2e-aws-scaleup-rhel7
ci/prow/e2e-libvirt 742e463 link /test e2e-libvirt

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@openshift-merge-robot openshift-merge-robot merged commit cfcfd81 into openshift:master Aug 30, 2019
@joelddiaz joelddiaz deleted the delete-appregistration branch January 6, 2020 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. lgtm Indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants