Service Principal added as unknown in keyvault access policy - azure-active-directory

I want to add Service Principal to Azure Keyvault access policies.
I tried with below command
Set-AzKeyVaultAccessPolicy -VaultName 'kvevalmock' -ObjectId '23erer-ed58-4ead-w34d-1ete23w3yofa' -PermissionsToSecrets #("get","list","set","delete","backup","restore","recover","purge") -PermissionsToKeys #("decrypt","encrypt","unwrapKey","wrapKey","verify","sign","get","list","update","create","import","delete","backup","restore","recover","purge") -BypassObjectIdValidation
Command gets executed but in keyvault access policies, Service principal is not listed in Application section. SP gets added as Unknown.
Due to this issue, keyvault secrets creation throw forbidden access error.

For the parameter -ObjectId, you should provide object id of the service principal(enterprise app) but not the object id of the registered app.
First go to your registered app, I guess you copy the object id in this page:
Click the "Managed application in local directory" which in red box in screenshot above to go to the service principal(enterprise app). And then copy the object of the app, use the object id in your command.

Related

Where does AzureAD store the "id" attribute returned by a SCIM endpoint?

I am integrating AzureAD with a SCIM endpoint. So far integration seems to work: AzureAD sends "POST" requests to create users, then later it queries/updates users using their 'id'.
Reminder from SCIM standard (RFC 7643): The 'id' is
A unique identifier for a SCIM resource as defined by the service provider
My SCIM endpoint generates this unique ID upon user first creation. It sends this ID to AzureAD in the reply, as required by the standard. I know that AzureAD stores the ID somewhere, because it uses it in subsequent requests.
My question: where is this ID stored in AzureAD? I need to read it, so I can forward it somewhere else. Using Graph Explorer I tried a lot of properties:
https://graph.microsoft.com/v1.0/me?$select=id,userPrincipalName,extensions,employeeId,externalUserState,identities,externalId
But none of them work. They are empty or do not contain the SCIM id.
Does anyone know if the property is publicly available?
Azure AD Provisioning has an internal data store that is not exposed via any external/customer-facing APIs where this is stored. If the service is evaluating an object that it does not know the SCIM ID value for it will try to locate that using a filtered GET such as GET /Users?filter=userName eq "user#domain.com", but once it has located that object the service will store internally a record stating that object X in Azure AD with objectId value of 123 is matched to object Y in with ID value of 456.
To specifically answer your end goal of "I need to find this value in Azure AD and forward it somewhere else" - this is not possible.
It is not like you think that AAD will save the user id from SCIM.
You can use Provision on demand to understand how it works.
Simple steps:
Click on "Provision on demand" in SCIM enterprise app.
Then select an AAD user and click on "Provision".
After it is executed successfully, you will be able to see the following:
Import user is retrieving User from Azure Active Directory.
Determine if user is in scope is determining if User in scope by evaluating against each scoping filter.
Match user between source and target system is retrieving User from SCIM and matching it with the AAD User in step 1. This is the point that you didn't know before. AAD will Get User by query in this step.
GET /Users?filter=userName eq "{userName}"
Then the user id from SCIM will be returned (As above screenshot shows).
Perform action updates User in SCIM using the id from step 3.
So AAD doesn't store the id from SCIM. It queries the user in SCIM firstly to get the id and then use this id to send update request to SCIM endpoint.

Azure powershell role assisgment using cloudshell and devops pipline

I am trying to remove the assigement for a particular object id.Below is the error I am getting.
I am attaching my service principal access level in AD.
When I am trying to exectute the same command using devops pipline I am getting different errror.
To remove the access what is the permission is required to my service prinicpal in API permission
section only read can work ? and why I am geeting the clould.execption errror. Any advice.
I can reproduce your issue, the command Remove-AzRoleAssignment will call the Azure AD Graph to validate the $objectid you passed, so you need give the Application permission Directory.Read.All of Azure AD Graph(not Microsoft Graph,not Delegated permission).
After adding the permission, there is some delay(30m - 1h), then test the command, it works. (I test in local, the same in cloud shell)
Note: Except the permission in Azure AD, your service principal also need to have the permission in the subscription/specific resource scope, e.g. the servcie principal is the Owner/User Access Admin role in the Access control (IAM) of the subscription/specific resource scope(in your case, the storage account). If the service principal does not have the role, please add it as below.
In Azure Devops, you don't need to login with Connect-AzAccount(Actually in cloud shell, you also don’t need to login, but if you want to do so, it's also ok), it will login automatically with the service principal related to the service connection(Task version >= 4.*).
So please make sure the secret of your service principal is correct and the connection was verified. To run Remove-AzRoleAssignment, also add the permission above for the App Registration related to the service connection.
Then test it, it works.
Joy Wang is correct, but I would like to add that, you shouldn't give a service principal owner to the entire subscription if its not absolutely needed. its a security consideration.
The better way would be to create a custom role in the subscription with only the permissions you need. in this case, some of the permissions you'll need to get it to work in the custom role are:
"Microsoft.Management/managementGroups/read"
"Microsoft.Authorization/roleAssignments/*"
"Microsoft.Authorization/roleDefinitions/*"
Also, I tried to run get-azroleassignment without directory.read.all with a service principal, and it works as long as you have the role permissions assigned in the subscription. that leads me to believe the powershell get-add-remove-azroleassignment does not use the graph api permissions at all.
Update
As joy stated, its possible that the custom role may be useless as it could technically give itself ownership, however, here is proof that you dont need api graph permissions for the service principal to do this:
Update2:
proof that removing the subscription rule, and only having api permissions does not work, it can only get the role assignments for itself, (the service principal itself) nothing else.

RBAC role for VM to manage resources with az

New to Azure.
I was trying to use az cli in 18.04.1-Ubuntu to manage a resource group [The VM is part of the resource group]. I enabled the system managed assigned identity for the VM and also gave RBAC access of owner to the VM from the resource group IAM.
But when I try to use the az resource list -g 'resource_group_name' I get
Please run 'az login' to setup account.
After some research I figured out that the identity has to be used for first time login to get the token for the cli. As per the docs
https://learn.microsoft.com/en-us/azure/active-directory/managed-identities-azure-resources/how-to-use-vm-sign-in
So basically the step is
Create an identity for the VM
Give a role to the identity from the resource that you intend the VM to manage.
Use the identity as an authenticator for the initial login using az login --identity to get the token which is valid till 90 days of inactivity.Since the identity is already related to the VM, the token is generated without passwords or usernames.
Then the VM can use the role to manage the resource.
Sharing it as this maybe useful to others

Service Account Name was not generated

I've created several GAE applications but failed to retrieve "Service Account Name" - there is no gserviceaccount mail on a 'Application Settings' page. My goal is to add service accounts of those applications to a list of members of the main application with edit permissions.I've tried to add account to a list of members of main project just by following pattern <appId>#appspot.gserviceaccount.com but it failed with following error "The email account you invited is not a valid Google account".My second idea was to create service account member on non-main project first following same pattern it didn't lead to an error but it has a following status "Invitation sent. Waiting for response".Have no idea how to fix it. I would greatly appreciate any help.Just for your notice: main application has billing enabled and has generated service account. Non-main applications have default version deployed and marked as "running".
Services account are always created by default when you create a new project in the Google Cloud Platform.
So there's no need for you to add them or re-create them in your project.
You may find them in the Permissions page under the main project section in the Developers' Console.
Or by using the URL https://console.developers.google.com/project/YOUR_PROJECT_NAME/permissions and using your real project name.
Older apps/projects didn't create service accounts.
Add the service account by
Going to https://console.developers.google.com/project/YOUR_PROJECT_NAME/permissions
Press Add Member
Add this email YOUR_PROJECT_NAME#appspot.gserviceaccount.com

Connecting to Prediction API from Google API Consol using service account

I am trying to use the Google Prediction API for the first time.
I am just following the steps given in the article https://developers.google.com/appengine/articles/prediction_service_accounts.
I am getting a strange problem while executing step 2.4 in the above mentioned article.
I have followed the steps as below.
1) I have an application created in say xyz.com domain, and I have service account name of my application as "myapp#appspot.gserviceaccount.com".
2) Then I went to "Team" tab on the Google API Console, and tried to add the service account name of my application, to the project in which I have activated Prediction API and Google Cloud Storage.
While adding the serivce account to the project it gives me an error saying that
"Only users in domain xyz.com may be added to the project".
The same kind of message is also displayed on the bottom of the "Team" tab.
xyz.com is the domain in wich my application is deployed.
Could any one please help me understand why this kind of message is comming?
Are there any domain level admin settings required to add the service account to the Google Console API project?
Regards,
Nirzari
Currently, if you created a project with your Apps account, you can only add members of that same domain.
What you'll have to do is create a new project from something like xxx#gmail.com account (NOT your Apps domain account). You can then add both #appspot.gserviceaccount.com and yourself#xyz.com.
I think you can even remove xxx#gmail.com later on, once you've added yourself#xyz.com. Even activate billing for yourself#xyz.com, not xxx#gmail.com, if you need to.
Take from https://developers.google.com/appengine/docs/python/googlestorage/overview
You can modify the ACL of the bucket manually:
An alternate way to grant app access to a bucket is manually edit and set the bucket ACL and the default object ACL, using the gsutil utility:
Get the ACL for the bucket and save it to a file for editing: gsutil getacl gs://mybucket > myAcl.txt
Add the following Entry to the ACL file you just retrieved:
<Entry>
<Scope type="UserByEmail">
<EmailAddress>
your-application-id#appspot.gserviceaccount.com
</EmailAddress>
</Scope>
<Permission>
WRITE
</Permission>
</Entry>
If you are adding multiple apps to the ACL, repeat the above entry
for each app, changing only the email address to reflect each app's
service name.
Set the modified ACL on your bucket: gsutil setacl myAcl.txt gs://mybucket

Resources