Skip to content
This repository was archived by the owner on Feb 3, 2021. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 20 additions & 5 deletions account_setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import yaml
from azure.common import credentials
from azure.graphrbac import GraphRbacManagementClient
from azure.graphrbac.models import ApplicationCreateParameters, PasswordCredential, ServicePrincipalCreateParameters
from azure.graphrbac.models import ApplicationCreateParameters, ApplicationUpdateParameters, PasswordCredential, ServicePrincipalCreateParameters
from azure.graphrbac.models.graph_error import GraphErrorException
from azure.mgmt.authorization import AuthorizationManagementClient
from azure.mgmt.batch import BatchManagementClient
Expand Down Expand Up @@ -189,6 +189,7 @@ def create_aad_user(credentials, tenant_id, **kwargs):
display_name=display_name,
password_credentials=[
PasswordCredential(
start_date=datetime(2000, 1, 1, 0, 0, 0, 0, tzinfo=timezone.utc),
Copy link
Member

Choose a reason for hiding this comment

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

shoudn't that be current time?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't think it should matter, It will have the same effect.

We shouldn't have to include this line at all, this is only necessary because there is a bug in the graphrbac client if start_date isn't specified.

end_date=datetime(2299, 12, 31, 0, 0, 0, 0, tzinfo=timezone.utc),
value=application_credential,
key_id=uuid.uuid4()
Expand All @@ -210,7 +211,21 @@ def create_aad_user(credentials, tenant_id, **kwargs):
confirmation_prompt = "Previously created application with name {} found. "\
"Would you like to use it? (y/n): ".format(application.display_name)
prompt_for_confirmation(confirmation_prompt, e, ValueError("Response not recognized. Please try again."))

password_credentials = list(graph_rbac_client.applications.list_password_credentials(application_object_id=application.object_id))
password_credentials.append(
PasswordCredential(
start_date=datetime(2000, 1, 1, 0, 0, 0, 0, tzinfo=timezone.utc),
end_date=datetime(2299, 12, 31, 0, 0, 0, 0, tzinfo=timezone.utc),
value=application_credential,
key_id=uuid.uuid4()
)
)
graph_rbac_client.applications.patch(
application_object_id=application.object_id,
parameters=ApplicationUpdateParameters(
password_credentials=password_credentials
)
)
service_principal = next(graph_rbac_client.service_principals.list(
filter="appId eq '{}'".format(application.app_id)))
else:
Expand Down Expand Up @@ -254,7 +269,7 @@ def create_role_assignment(credentials, subscription_id, scope, principal_id):

def format_secrets(**kwargs):
'''
Retuns the secrets for the created resources to be placed in secrets.yaml
Returns the secrets for the created resources to be placed in secrets.yaml
The following form is returned:

service_principal:
Expand Down Expand Up @@ -381,7 +396,7 @@ def stop(self):
with Spinner():
storage_account_id = create_storage_account(creds, subscription_id, **kwargs)
kwargs["storage_account_id"] = storage_account_id
print("Created Storage group.")
print("Created Storage account.")

# create batch account
with Spinner():
Expand All @@ -397,8 +412,8 @@ def stop(self):
aad_cred, subscirption_id, tenant_id = profile.get_login_credentials(
resource=AZURE_PUBLIC_CLOUD.endpoints.active_directory_graph_resource_id
)

application_id, service_principal_object_id, application_credential = create_aad_user(aad_cred, tenant_id, **kwargs)

print("Created Azure Active Directory service principal.")

with Spinner():
Expand Down
4 changes: 2 additions & 2 deletions account_setup.sh
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
#!/bin/bash

echo "Installing depdendencies..." &&
echo "Installing dependencies..." &&
pip install --force-reinstall --upgrade --user pyyaml==3.12 azure==3.0.0 azure-cli-core==2.0.30 msrestazure==0.4.25 > /dev/null 2>&1 &&
echo "Finished installing depdencies." &&
echo "Finished installing dependencies." &&
echo "Getting account setup script..." &&
wget -q https://raw.githubusercontent.com/Azure/aztk/v0.7.0/account_setup.py -O account_setup.py &&
chmod 755 account_setup.py &&
Expand Down