-
Notifications
You must be signed in to change notification settings - Fork 1.5k
[AKS] identity binding commands #8724
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
Merged
Merged
Changes from all commits
Commits
Show all changes
40 commits
Select commit
Hold shift + click to select a range
15abf6a
feat: init
bcho f64669d
feat: poc
bcho 6368c5c
feat: create / delete commands
bcho 4f0d52c
Merge remote-tracking branch 'origin/main' into hbc/aks-ib
bcho f2fa91a
chore: remove workaround
bcho 7960d20
fix: drop debug line
bcho d3127b0
chore: correct imports
bcho e7325f6
fix: remove debug log
bcho 0a040d6
fix: remove workaround
bcho 91da004
fix: drop previous workaround
bcho 8719c00
chore: use dedicated test version
bcho 4bdbcfe
fix: correct version string format
bcho d33dbc6
fix: remove one more workaround
bcho e25f6fe
Merge remote-tracking branch 'origin/main' into hbc/aks-ib
bcho 662efe3
feat: add test
bcho e53454a
test: add unit tests
bcho be8944b
Merge remote-tracking branch 'upstream/main' into hbc/aks-ib
bcho ba6273f
fix: drop repeated client setup
bcho 0f2c12d
fix: exclude managed_identity_resource_id parameter
bcho f00f690
fix: lint
bcho 79240d3
doc: add help messages for identity binding commands
bcho c1364fa
Update src/aks-preview/azext_aks_preview/aks_identity_binding/command…
bcho 79d7a7d
fix: lint
bcho 2210c5c
fix: lint
bcho c4787c1
chore: update snapshots
bcho d5fd001
fix: revert old overrides
bcho 375fa5b
test: mark as live only
bcho 32f2d1d
fix: use custom_show_command
bcho 21a4182
fix: lint
bcho 578a056
test: update recording
bcho 25b4da8
fix: revert unnecessary changes
bcho 711aa7f
lint: exclude parameter
bcho dd73a2e
fix: update parameter order
bcho d197864
Revert "lint: exclude parameter"
bcho 1335e6f
fix: fix lint issue
bcho 0f74bbc
Apply suggestions from code review
bcho e22628f
Apply suggestions from code review
bcho a1601f3
Update src/aks-preview/azext_aks_preview/aks_identity_binding/command…
bcho 34fc03a
Update src/aks-preview/azext_aks_preview/aks_identity_binding/command…
bcho 85c49bb
doc: update history
bcho File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
84 changes: 84 additions & 0 deletions
84
src/aks-preview/azext_aks_preview/aks_identity_binding/commands.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| # `az aks identity-binding create` command | ||
bcho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| def aks_ib_cmd_create( | ||
| cmd, client, # pylint: disable=unused-argument | ||
| resource_group_name: str, | ||
| cluster_name: str, | ||
| name: str, | ||
| managed_identity_resource_id: str, | ||
| no_wait: bool = False, | ||
| ): | ||
| from azure.cli.core.util import sdk_no_wait | ||
| from azext_aks_preview.vendored_sdks.azure_mgmt_preview_aks.models import ( | ||
| IdentityBinding, | ||
| IdentityBindingProperties, | ||
| IdentityBindingManagedIdentityProfile, | ||
| ) | ||
|
|
||
| instance = IdentityBinding( | ||
| name=name, | ||
| properties=IdentityBindingProperties( | ||
| managed_identity=IdentityBindingManagedIdentityProfile( | ||
| resource_id=managed_identity_resource_id, | ||
| ) | ||
| ) | ||
| ) | ||
|
|
||
| return sdk_no_wait( | ||
| no_wait, | ||
| client.begin_create_or_update, | ||
| resource_group_name, | ||
| cluster_name, | ||
| name, | ||
| instance, | ||
| ) | ||
|
|
||
|
|
||
| # `az aks identity-binding delete` command | ||
| def aks_ib_cmd_delete( | ||
| cmd, client, # pylint: disable=unused-argument | ||
| resource_group_name: str, | ||
| cluster_name: str, | ||
| name: str, | ||
| no_wait: bool = False, | ||
| ): | ||
| from azure.cli.core.util import sdk_no_wait | ||
|
|
||
| return sdk_no_wait( | ||
| no_wait, | ||
| client.begin_delete, | ||
| resource_group_name=resource_group_name, | ||
| resource_name=cluster_name, | ||
| identity_binding_name=name, | ||
| ) | ||
|
|
||
|
|
||
| # `az aks identity-binding show` command | ||
| def aks_ib_cmd_show( | ||
| cmd, client, # pylint: disable=unused-argument | ||
| resource_group_name: str, | ||
| cluster_name: str, | ||
| name: str, | ||
| ): | ||
| return client.get( | ||
| resource_group_name=resource_group_name, | ||
| resource_name=cluster_name, | ||
| identity_binding_name=name, | ||
| ) | ||
|
|
||
|
|
||
| # `az aks identity-binding list` command | ||
| def aks_ib_cmd_list( | ||
| cmd, client, # pylint: disable=unused-argument | ||
| resource_group_name: str, | ||
| cluster_name: str, | ||
| ): | ||
| return client.list_by_managed_cluster( | ||
| resource_group_name=resource_group_name, | ||
| resource_name=cluster_name, | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1,536 changes: 1,536 additions & 0 deletions
1,536
src/aks-preview/azext_aks_preview/tests/latest/recordings/test_identity_binding_usages.yaml
Large diffs are not rendered by default.
Oops, something went wrong.
111 changes: 111 additions & 0 deletions
111
src/aks-preview/azext_aks_preview/tests/latest/test_identity_binding.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,111 @@ | ||
| # -------------------------------------------------------------------------------------------- | ||
| # Copyright (c) Microsoft Corporation. All rights reserved. | ||
| # Licensed under the MIT License. See License.txt in the project root for license information. | ||
| # -------------------------------------------------------------------------------------------- | ||
|
|
||
|
|
||
| from azure.cli.testsdk import ScenarioTest, live_only | ||
| from azure.cli.testsdk.scenario_tests import AllowLargeResponse | ||
|
|
||
| from azext_aks_preview.tests.latest.recording_processors import KeyReplacer | ||
| from azext_aks_preview.tests.latest.custom_preparers import ( | ||
| AKSCustomResourceGroupPreparer, | ||
| ) | ||
|
|
||
|
|
||
| class IdentityBindingTestCases(ScenarioTest): | ||
|
|
||
| def __init__(self, method_name): | ||
| super(IdentityBindingTestCases, self).__init__( | ||
| method_name, | ||
| recording_processors=[KeyReplacer()], | ||
| ) | ||
|
|
||
| @AllowLargeResponse() | ||
bcho marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| @live_only() | ||
| @AKSCustomResourceGroupPreparer( | ||
| random_name_length=17, | ||
| name_prefix="clitest", | ||
| location="eastus2", | ||
| ) | ||
| def test_identity_binding_usages(self, resource_group, resource_group_location): | ||
| aks_name = self.create_random_name("cliakstest", 16) | ||
| identity_name = self.create_random_name("cli", 16) | ||
| identity_binding_name = self.create_random_name("cliib", 16) | ||
| self.kwargs.update( | ||
| { | ||
| "resource_group": resource_group, | ||
| "aks_name": aks_name, | ||
| "identity_name": identity_name, | ||
| "identity_binding_name": identity_binding_name, | ||
| "location": resource_group_location, | ||
| } | ||
| ) | ||
|
|
||
| create_aks_cmd = ("aks create --resource-group={resource_group} --name={aks_name} " | ||
| "--location={location} --no-ssh-key -o json") | ||
| self.cmd(create_aks_cmd, checks=[ | ||
| self.check("provisioningState", "Succeeded")]) | ||
|
|
||
| list_identity_binding_cmd = ("aks identity-binding list --resource-group {resource_group} " | ||
| "--cluster-name {aks_name} -o json") | ||
| self.cmd( | ||
| list_identity_binding_cmd, | ||
| checks=[ | ||
| self.check("length(@)", 0) | ||
| ] | ||
| ) | ||
|
|
||
| create_identity_cmd = ("identity create --resource-group {resource_group} --name {identity_name} " | ||
| "--location {location} -o json") | ||
| identity = self.cmd(create_identity_cmd).get_output_in_json() | ||
| identity_resource_id = identity["id"] | ||
| identity_client_id = identity["clientId"] | ||
| identity_tenant_id = identity["tenantId"] | ||
|
|
||
| identity_binding_checks = [ | ||
| self.check("properties.provisioningState", "Succeeded"), | ||
| self.check( | ||
| "properties.managedIdentity.resourceId", | ||
| identity_resource_id | ||
| ), | ||
| self.check( | ||
| "properties.managedIdentity.clientId", | ||
| identity_client_id | ||
| ), | ||
| self.check( | ||
| "properties.managedIdentity.tenantId", | ||
| identity_tenant_id | ||
| ), | ||
| self.check( | ||
| f"ends_with(properties.oidcIssuer.oidcIssuerUrl, '/{identity_tenant_id}/{identity_client_id}')", | ||
| True, | ||
| ), | ||
| ] | ||
|
|
||
| create_identity_binding_cmd = ("aks identity-binding create --resource-group {resource_group} --cluster-name {aks_name} " | ||
| "-n {identity_binding_name} -o json" | ||
| f" --managed-identity-resource-id {identity_resource_id}") | ||
| self.cmd(create_identity_binding_cmd, checks=identity_binding_checks) | ||
|
|
||
| self.cmd( | ||
| list_identity_binding_cmd, | ||
| checks=[ | ||
| self.check("length(@)", 1) | ||
| ] | ||
| ) | ||
|
|
||
| show_identity_binding_cmd = ("aks identity-binding show --resource-group {resource_group} --cluster-name {aks_name} " | ||
| "-n {identity_binding_name} -o json") | ||
| self.cmd(show_identity_binding_cmd, checks=identity_binding_checks) | ||
|
|
||
| delete_identity_binding_cmd = ("aks identity-binding delete --resource-group {resource_group} --cluster-name {aks_name} " | ||
| "-n {identity_binding_name} -o json") | ||
| self.cmd(delete_identity_binding_cmd) | ||
|
|
||
| self.cmd( | ||
| list_identity_binding_cmd, | ||
| checks=[ | ||
| self.check("length(@)", 0) | ||
| ] | ||
| ) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.