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

[Containerapp] az containerapp create/up: --registry-server and --source use managed identity for image pull by default #7972

Conversation

Greedygre
Copy link
Contributor

@Greedygre Greedygre commented Sep 12, 2024


This checklist is used to make sure that common guidelines for a pull request are followed.

Related command

  • 'az containerapp containerapp create/up': --registry-server use managed identity for image pull by default
  • 'az containerapp containerapp create': --registry-server use managed identity for image pull by default. --no-wait will not take effect with system registry identity.
  • 'az containerapp up': Support --registry-identity, --system-assigned, --user-assigned

General Guidelines

  • Have you run azdev style <YOUR_EXT> locally? (pip install azdev required)
  • Have you run python scripts/ci/test_index.py -q locally? (pip install wheel==0.30.0 required)
  • My extension version conforms to the Extension version schema

For new extensions:

About Extension Publish

There is a pipeline to automatically build, upload and publish extension wheels.
Once your pull request is merged into main branch, a new pull request will be created to update src/index.json automatically.
You only need to update the version information in file setup.py and historical information in file HISTORY.rst in your PR but do not modify src/index.json.

Copy link

azure-client-tools-bot-prd bot commented Sep 12, 2024

⚠️Azure CLI Extensions Breaking Change Test
⚠️containerapp
rule cmd_name rule_message suggest_message
⚠️ 1006 - ParaAdd containerapp up cmd containerapp up added parameter registry_identity
⚠️ 1006 - ParaAdd containerapp up cmd containerapp up added parameter system_assigned
⚠️ 1006 - ParaAdd containerapp up cmd containerapp up added parameter user_assigned

Copy link

Hi @Greedygre,
Please write the description of changes which can be perceived by customers into HISTORY.rst.
If you want to release a new extension version, please update the version in setup.py as well.

@yonzhan
Copy link
Collaborator

yonzhan commented Sep 12, 2024

Containerapp

Copy link

CodeGen Tools Feedback Collection

Thank you for using our CodeGen tool. We value your feedback, and we would like to know how we can improve our product. Please take a few minutes to fill our codegen survey

Copy link

github-actions bot commented Sep 12, 2024

Hi @Greedygre

Release Suggestions

Module: containerapp

  • Update VERSION to 1.0.0b4 in src/containerapp/setup.py

Notes

@Greedygre
Copy link
Contributor Author

About src/containerapp/azext_containerapp/_utils.py, I will revert it from this PR after PR Fix create containerapp/containerappjob with msi issue merge:

@@ -1247,9 +1256,13 @@ def _get_acr_from_image(cmd, app):
app.registry_server = app.image.split("/")[
0
] # TODO what if this conflicts with registry_server param?

# If --registry-server is ACR, use system-assigned managed identity for image pull by default
if app.registry_identity is None and app.registry_user is None and app.registry_pass is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

What if a public registry? Do we need system?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This logic is for command az containerapp up, if the image is from ACR, it will always look up credential and add ACR to properties.configuration.registries.
For properties.configuration.registries, it require (username and password) or identity, otherwise it throw error from DP:
(ContainerAppRegistriesPasswordSecretRefNotFound) PasswordSecretRef '' defined for registry server 'acaxinyulogtest.azurecr.io' not found.

So we need system.

For az containerapp create, if it is a public registry, without argument --registry-server the CLI will not add registry to properties.configuration.registries, then it will treat as a public image.

@Greedygre
Copy link
Contributor Author

The CI failed with following error, which is not relate to our containerapp extension.

=========================== short test summary info ============================
FAILED src/standbypool/azext_standbypool/tests/latest/test_standbypool.py::StandbypoolScenario::test_standby_container_group_pool_scenarios
FAILED src/standbypool/azext_standbypool/tests/latest/test_standbypool.py::StandbypoolScenario::test_standby_virtual_machine_pool_scenarios

@Greedygre Greedygre force-pushed the xinyu/20240829_registry_server_default_system_assign branch from 680f092 to c459d1e Compare September 18, 2024 03:09
@github-actions github-actions bot added the release-version-block Updates do not qualify release version rules. NOTE: please do not edit it manually. label Sep 18, 2024
@FumingZhang
Copy link
Member

It looks like some unrelated changes (about aks-preview) were merged into your branch?

@Greedygre Greedygre force-pushed the xinyu/20240829_registry_server_default_system_assign branch from c459d1e to de7d0bf Compare September 18, 2024 04:01
@Greedygre
Copy link
Contributor Author

It looks like some unrelated changes (about aks-preview) were merged into your branch?

Fixed.

@github-actions github-actions bot removed the release-version-block Updates do not qualify release version rules. NOTE: please do not edit it manually. label Sep 18, 2024
@Greedygre Greedygre changed the title [Containerapp] az containerapp create/up: --registry-server use managed identity for image pull by default [Containerapp] az containerapp create/up: --registry-server and --source use managed identity for image pull by default Sep 25, 2024
@@ -409,7 +409,10 @@ def __init__(
env_vars=None,
workload_profile_name=None,
ingress=None,
force_single_container_updates=None
force_single_container_updates=None,
registry_identity=None,
Copy link
Contributor

Choose a reason for hiding this comment

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

should this parameter be exposed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

For az containerapp up, we expose new arguments --registry-identity, --system-assigned, --user-assigned

Copy link
Contributor

Choose a reason for hiding this comment

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

I do not see --registry-identity added in params.py

Copy link
Contributor Author

@Greedygre Greedygre Sep 26, 2024

Choose a reason for hiding this comment

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

For --registry-identity, it is Inherited from azure-cli az containerapp:
image

parsed = urlparse(app.image)
registry_name = (parsed.netloc if parsed.scheme else parsed.path).split(".")[0]
if app.registry_user is None or app.registry_pass is None:
Copy link
Contributor

Choose a reason for hiding this comment

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

what if only app.registry_user provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It will be handled in create_containerapp or update_containerapp, we will look up creds for it, also I has test case cover it: test_containerapp_registry_acr_look_up_credentical

@@ -849,6 +880,7 @@ def parent_construct_payload(self):
self.set_up_registry_identity()

def construct_payload(self):
self.set_up_system_assigned_identity_as_default_if_using_acr()
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 put after parent_construct_payload()?

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 set_up_system_assigned_identity_as_default_if_using_acr will set --identity to system as default, it should be execute before parent_construct_payload()

Comment on lines +1035 to +1037
if self.get_argument_source():
_get_registry_details_without_get_creds(self.cmd, app, self.get_argument_source())
if self.get_argument_repo():
Copy link
Contributor

Choose a reason for hiding this comment

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

what about both --source and --repo provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't allowed input --source and --repo together:
When input --source --repo together, throw:
Cannot use --source and --repo together. Can either deploy from a local directory or a Github repo

For --repo, it will create github action with sourcecontrols, it use the ACR registry to create github action.
registry_username=app.registry_user,

The sourcecontrols doesn't support registry with registry identity. It only support registry username and password.

system_sp = safe_get(self.containerapp_def, "identity", "principalId")

# create system service principalId
if system_sp is None and is_registry_msi_system(identity):
Copy link
Contributor

Choose a reason for hiding this comment

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

in this condition, only when customer specify system as identity, we will create the system principalId? should we also create in default scenario?

Copy link
Contributor Author

@Greedygre Greedygre Sep 25, 2024

Choose a reason for hiding this comment

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

Yes, we did.
For the default behavior, in the set_up_system_assigned_identity_as_default_if_using_acr, it will set identity to system, then in here it will create the system principalId too.
I have test to cover it: test_containerapp_registry_identity_system

return
registry_exists = False
for r in registries_def:
if r['server'].lower() == self.get_argument_registry_server().lower():
Copy link
Contributor

Choose a reason for hiding this comment

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

what if no 'server' in r?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there such a scenario? Is it a legal scenario?

Comment on lines +1283 to +1285
if source:
_get_registry_details_without_get_creds(cmd, app, source)
if repo:
Copy link
Contributor

Choose a reason for hiding this comment

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

what if both source and repo provided?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is not allowed:
When input --source --repo together, throw:
Cannot use --source and --repo together. Can either deploy from a local directory or a Github repo

code in _validate_up_args


force_single_container_updates = False
if source:
app.get_acr_creds = False
Copy link
Contributor

Choose a reason for hiding this comment

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

once source is provided, you will never try to get acr creds?

Copy link
Contributor Author

@Greedygre Greedygre Sep 25, 2024

Choose a reason for hiding this comment

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

with --source,
If customer not provider --registry-username, we will never try to get acr creds.
If customer provider --registry-username or --registry-password, we will try to get acr creds in the next stepscreate_containerapp or update_containerapp.

self.cmd.cli_ctx, registry_name
)
if self.get_acr_creds:
self.registry_user, self.registry_pass, _ = _get_acr_cred(
Copy link
Contributor

Choose a reason for hiding this comment

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

the format looks strange

Comment on lines +261 to +262
c.argument('user_assigned', nargs='+', help="Space-separated user identities to be assigned.")
c.argument('system_assigned', help="Boolean indicating whether to assign system-assigned identity.", action='store_true')
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you refer to the guideline https://github.com/Azure/azure-cli/blob/dev/doc/managed_identity_command_guideline.md to design these managed identity related parameters?

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 new user_assigned and system_assigned parameters for the az containerapp up command are consistent with those for az containerapp create. We need to change them together, otherwise the user experience will be inconsistent.

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, sounds good

@zhoxing-ms zhoxing-ms merged commit 3005636 into Azure:main Oct 8, 2024
20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Auto-Assign Auto assign by bot ContainerApp
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants