Skip to content

Support Managed Identity login for self-hosted runner#336

Closed
MoChilia wants to merge 9 commits intomasterfrom
shiying/managed-identity-cli-1
Closed

Support Managed Identity login for self-hosted runner#336
MoChilia wants to merge 9 commits intomasterfrom
shiying/managed-identity-cli-1

Conversation

@MoChilia
Copy link
Copy Markdown
Member

@MoChilia MoChilia commented Jun 8, 2023

Description

This PR is going to support both system- and user- assigned managed identity login for self-hosted runners on Azure VM.

What's new

  • The Action provides a parameter auth-type with value list [SERVICE_PRINCIPAL, IDENTITY] to identify the type of authentication.
    1. If auth-type: SERVICE_PRINCIPAL with clientId, tenantId and clientSecret detected in your input, we will attempt to login by using service principal with the secret.
    #login with secret
    - uses: azure/login@v1
          with:
            creds: ${{ secrets.AZURE_CREDENTIALS }}
            auth-type: SERVICE_PRINCIPAL
    1. If auth-type: SERVICE_PRINCIPAL with clientId and tenantId detected in your input, we will attempt to login by using OIDC.
    #login with OIDC
    - uses: azure/login@v1
        with:
            client-id: ${{ secrets.AZURE_CLIENT_ID }}
            tenant-id: ${{ secrets.AZURE_TENANT_ID }}
            subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
            auth-type: SERVICE_PRINCIPAL
    1. If auth-type: IDENTITY with clientId detected in your input, we will attempt to login by using user-assigned managed identity.
    #login with user-assigned managed identity
    - uses: azure/login@v1
       with:
           client-id: ${{ secrets.AZURE_CLIENT_ID }}
           auth-type: IDENTITY
    1. If auth-type: IDENTITY without clientId detected in your input, we will attempt to login by using system-assigned managed identity.
    #login with system-assigned managed identity
    - uses: azure/login@v1
     with:
           auth-type: IDENTITY

In order not to introduce breaking change, we set the default value of auth-type to be SERVICE_PRINCIPAL.

  • About the parameter subscription-id
    This parameter used to be mandatory if allow-no-subscriptions is not enabled in previous version:

    if (!this.subscriptionId && !this.allowNoSubscriptionsLogin) {
    throw new Error("Not all values are present in the credentials. Ensure subscriptionId is supplied.");
    }

    However, the two parameters are not relevant. allow-no-subscriptions is used to login tenant-level account and subscription-id is used to specify which subscription to work. Not specifying a subscription should be allowed, then the Action will use the current, active subscription. Hence the limitation is removed in this version with only warning being reported:
    if (!this.loginConfig.subscriptionId) {
    if (!this.loginConfig.allowNoSubscriptionsLogin) {
    core.warning(`No subscription-id is given. Skip setting subscription...
    If there are mutiple subscriptions under the tenant, please input subscription-id to specify which subscription to use.`);
    }
    return;
    }

  • About reading creds from Json
    The items in creds will not overwrite the individual parameters client-id, tenant-id and subscription-id, but as supplementary.
    In the previous code, creds is not compatible with individual parameters. We use creds for login using service principal with secret and individual parameters for OIDC login:

    login/src/main.ts

    Lines 78 to 93 in 990b22f

    if (servicePrincipalId || tenantId || subscriptionId) {
    //If few of the individual credentials (clent_id, tenat_id, subscription_id) are missing in action inputs.
    if (!(servicePrincipalId && tenantId && (subscriptionId || allowNoSubscriptionsLogin)))
    throw new Error("Few credentials are missing. ClientId, tenantId are mandatory. SubscriptionId is also mandatory if allow-no-subscriptions is not set.");
    }
    else {
    if (creds) {
    core.debug('using creds JSON...');
    enableOIDC = false;
    servicePrincipalId = secrets.getSecret("$.clientId", true);
    servicePrincipalKey = secrets.getSecret("$.clientSecret", true);
    tenantId = secrets.getSecret("$.tenantId", true);
    subscriptionId = secrets.getSecret("$.subscriptionId", true);
    resourceManagerEndpointUrl = secrets.getSecret("$.resourceManagerEndpointUrl", false);
    }

    In the new version, we aim to fetch the user's input credentials as much as possible:
    if (creds) {
    core.debug('Reading creds in JSON...');
    this.servicePrincipalId = this.servicePrincipalId ? this.servicePrincipalId : secrets.getSecret("$.clientId", false);
    this.servicePrincipalKey = secrets.getSecret("$.clientSecret", false);
    this.tenantId = this.tenantId ? this.tenantId : secrets.getSecret("$.tenantId", false);
    this.subscriptionId = this.subscriptionId ? this.subscriptionId : secrets.getSecret("$.subscriptionId", false);
    this.resourceManagerEndpointUrl = secrets.getSecret("$.resourceManagerEndpointUrl", false);
    }

  • The changes for README.md is in Update README.md for Managed identity #344.

@MoChilia MoChilia requested review from YanaXu and jiasli June 8, 2023 06:16
@MoChilia MoChilia temporarily deployed to Automation test June 8, 2023 06:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 8, 2023 06:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 8, 2023 06:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 8, 2023 06:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 8, 2023 06:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 8, 2023 06:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 8, 2023 06:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 8, 2023 06:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 8, 2023 06:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 8, 2023 06:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 8, 2023 06:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 8, 2023 06:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 8, 2023 06:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 8, 2023 06:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 9, 2023 09:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 9, 2023 09:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 9, 2023 09:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 9, 2023 09:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 9, 2023 09:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 9, 2023 09:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 9, 2023 09:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 9, 2023 09:37 — with GitHub Actions Inactive
@MoChilia MoChilia temporarily deployed to Automation test June 9, 2023 09:37 — with GitHub Actions Inactive
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:15 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:15 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:15 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:15 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:15 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:15 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:15 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:15 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:15 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:15 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:15 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:15 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:15 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:15 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:33 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:34 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:34 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:34 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:34 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:34 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:34 — with GitHub Actions Active
@MoChilia MoChilia deployed to Automation test June 29, 2023 02:34 — with GitHub Actions Active
@MoChilia MoChilia requested a review from evelyn-ys June 29, 2023 02:42
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