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

az ad sp credential list --id xxxxx-xxxx-xxx customKeyIdentifier value is null #10234

Closed
paulpuvi06 opened this issue Aug 14, 2019 · 9 comments
Closed
Assignees
Labels

Comments

@paulpuvi06
Copy link

az feedback auto-generates most of the information requested below, as of CLI version 2.0.62

Describe the bug
Credential property customKeyIdentifier value is null for the secrets created using new improved app registration UI.

To Reproduce
-Add a client secret using new UI.
-execute az ad sp credential list --id xxxxx-xxxx-xxx

Expected behavior
it should return the "description" of the secrets which works for the secrets created using old UI.

Environment summary
az --version
azure-cli 2.0.69 *

OS version
sw_vers
ProductName: Mac OS X
ProductVersion: 10.14.5
BuildVersion: 18F132

Additional context
Add any other context about the problem here.

@jiasli jiasli self-assigned this Aug 14, 2019
@jiasli jiasli added the Graph az ad label Aug 14, 2019
@jiasli
Copy link
Member

jiasli commented Aug 14, 2019

I can reproduce. This doesn't seem like a CLI issue. When adding keys in Azure Portal using new UI, the corresponding items created in manifest have passwordCredentials.displayName. Meanwhile the public AAD REST only has PasswordCredential.customKeyIdentifier: https://github.com/Azure/azure-rest-api-specs/blob/ad6d5f6467aaab8cda44ceaa2863f84359c1e022/specification/graphrbac/data-plane/Microsoft.GraphRbac/stable/1.6/graphrbac.json#L2785.
@lmazuel @yugangw-msft @amarzavery

@paulpuvi06
Copy link
Author

@jiasli 👍, is there a plan to update to get the value of 'customKeyIdentifier' for the secrets created through portal?

@jiasli
Copy link
Member

jiasli commented Aug 14, 2019

Thank you for the feedback. We will work with REST specs team to fix this issue as soon as possible.

@paulpuvi06
Copy link
Author

@jiasli did you get an update from REST specs team ?

@haroldrandom haroldrandom added the Graph az ad label Oct 25, 2019
@jkewley
Copy link

jkewley commented Jan 6, 2020

Pinging this.

It looks like the graph API now returns displayName and a hint for a passwordCredential in the portal using https://graph.windows.net/myorganization/applicationsByAppId/<appId>?api-version=2.0 whereas az ad app list and az ad sp credential --id xxx return a subset of the credential properties. Would be nice to have access to hint, displayName, and createdOn properties for administrative tooling.

Portal:
image

CLI:
image

@yonzhan yonzhan added this to the S165 milestone Jan 7, 2020
@jiasli
Copy link
Member

jiasli commented Jan 22, 2020

The API you used is AD Graph API v2.0 which contains those fields. Without the REST spec for 2.0, we can't generate the Python SDK and build the CLI commands accordingly. We are still working with AAD team on this issue. Thanks for your patience.

Meanwhile, you may directly use az rest with Microsoft Graph API to get unblocked.

Using List applications, replacing {appId} with the application ID:

az rest --method get \
        --uri "https://graph.microsoft.com/v1.0/applications?$filter=appId eq '{appId}'"

Using Get application, replacing {objectId} with the object ID of the application:

az rest --method get \
        --uri https://graph.microsoft.com/v1.0/applications/{objectId}

Then you may use --query to query on the result and --output to configure the output format:

>az rest --method get \
         --uri https://graph.microsoft.com/v1.0/applications/{objectId} \
         --query passwordCredentials[].displayName \
         --output tsv
key2
key1

@yonzhan yonzhan modified the milestones: S165, S167 Feb 15, 2020
@yonzhan yonzhan modified the milestones: S167, S169 Mar 21, 2020
@jiasli
Copy link
Member

jiasli commented Apr 10, 2020

We will track MS Graph issues at #12946

@ernani
Copy link

ernani commented Jun 2, 2020

The API you used is AD Graph API v2.0 which contains those fields. Without the REST spec for 2.0, we can't generate the Python SDK and build the CLI commands accordingly. We are still working with AAD team on this issue. Thanks for your patience.

Meanwhile, you may directly use az rest with Microsoft Graph API to get unblocked.

Using List applications, replacing {appId} with the application ID:

az rest --method get \
        --uri "https://graph.microsoft.com/v1.0/applications?$filter=appId eq '{appId}'"

Using Get application, replacing {objectId} with the object ID of the application:

az rest --method get \
        --uri https://graph.microsoft.com/v1.0/applications/{objectId}

Then you may use --query to query on the result and --output to configure the output format:

>az rest --method get \
         --uri https://graph.microsoft.com/v1.0/applications/{objectId} \
         --query passwordCredentials[].displayName \
         --output tsv
key2
key1

This is not working for me, it returns an empty value. I am trying to get the password for an SP tied to this app...

This is because the following command:

az ad sp credential reset \
  --name myappid \
  --credential-description "my-rand-app-sp-pwd" \
  --query password -o tsv

Fails with the following error:

When present, application key identifier cannot be empty and can be at most 32 bytes.
Parameter name: applicationKeyIdentifierValue

$ az version
{
  "azure-cli": "2.6.0",
  "azure-cli-command-modules-nspkg": "2.0.3",
  "azure-cli-core": "2.6.0",
  "azure-cli-nspkg": "3.0.4",
  "azure-cli-telemetry": "1.0.4",
  "extensions": {
    "aro": "1.0.0",
    "azure-firewall": "0.3.1",
    "interactive": "0.4.4",
    "spring-cloud": "0.2.3"
  }
}

@jiasli
Copy link
Member

jiasli commented Jun 3, 2020

Hi @ernani,

Root cause and solution

As the error suggested,

When present, application key identifier cannot be empty and can be at most 32 bytes.
Parameter name: applicationKeyIdentifierValue

The --credential-description "my-rand-app-sp-pwd" you are using is too long. It will be encoded as "customKeyIdentifier": "//5tAHkALQByAGEAbgBkAC0AYQBwAHAALQBzAHAALQBwAHcAZAA=". Please shorten it and try again.

az ad sp credential reset is actually patching the application's credential

As you can see from the source code, az ad sp credential reset is actually patching the application's credential, instead of the service principal's:

client.applications.patch(app.object_id, app_patch_param)

We have an ongoing PR #11466 discussing this issue.

Using Microsoft Graph API

According to Microsoft Graph API passwordCredential resource type, customKeyIdentifier is deprecated.

We don't recommend using this legacy command az ad sp credential reset anymore. Please use Microsoft Graph API servicePrincipal: addPassword instead:

$ id="{service principal object ID}"
$ az rest -m POST -u https://graph.microsoft.com/v1.0/servicePrincipals/$id/addPassword -b '{
   "passwordCredential": {
     "displayName": "behold-my-very-long-password-description"
   }
 }'
{
  "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#microsoft.graph.passwordCredential",
  "customKeyIdentifier": null,
  "displayName": "behold-my-very-long-password-description",
  "endDateTime": "2022-06-03T02:30:42.0816985Z",
  "hint": null,
  "keyId": "592e77f1-10d6-49a5-9a2b-d9a79840bf68",
  "secretText": "LGO_9xxxxxxxxxxxxxxxxxxxx",
  "startDateTime": "2020-06-03T02:30:42.0816985Z"
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants