Skip to main content

A simple CLI tool to assign AppRole to all members of a given Group in Microsoft Entra ID

Project description

app-role-assignment-cli

A simple CLI tool for the Unix shell to assign or remove an AppRole to all members of a given Group in Microsoft Entra ID. To interact with Microsoft Entra ID, you'll need to create an AppRegistration with the following API Permissions:

  • Application.Read.All
  • AppRoleAssignment.ReadWrite.All
  • Group.Read.All
  • GroupMember.Read.All
  • User.ReadWrite.All

Once the app is registered, you'll need to create a Client secret (created in the "Certificates & secrets" section of the registered Application).

The app-role command exposes two interfaces for granting and deleting an AppRoleAssignment to the users:

  • assign:

    Usage: app-role assign [OPTIONS] APP_ROLE_DISPLAY_NAME APPLICATION_DISPLAY_NAME GROUP_DISPLAY_NAME
    
  • remove:

    Usage: app-role remove [OPTIONS] APP_ROLE_DISPLAY_NAME APPLICATION_DISPLAY_NAME GROUP_DISPLAY_NAME
    

Installation

At the moment this package is not distributed. To install the package, poetry is required. After cloning the repository with git clone https://github.com/NewGlobe/app-role-assignment-cli.git run:

poetry install

Then to invoke the command, prepend them with poetry run e.g.:

poetry run app-role assign Viewer 'My App Defining Viewer Role' 'The Group'
poetry run app-role remove Viewer 'My App Defining Viewer Role' 'The Group'

Running The Commands

To authenticate the Microsoft Graph API requests the main interface MSGraphAPIWrapper class needs to be instantiated with tenant_id,client_id, and client_secret_value. At the moment, the secret holding these values is fetched from AWS Secrets Manager, and the SECRET_ID environment variable holds the secret name to fetch. At the moment this defaults to app-role-assignment-cli/dap/<environment>/azure_credentials, where <environment> is a placeholder for the lowercase version of the ENVIRONMENT environment variable.

The AWS Secrets Manager client is created via the boto3 library, which implicitly looks for AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY environment variables. Locally, the configuration is held in the local.env file and, as explained below, localstack is used to store and retrieve the secret.

Local Set Up

To run the commands locally, make sure localstack is up and running. This emulates the AWS cloud environment, and it can therefore be used to store the necessary secret that'll be retrieved at run time.

This project is equipped with the necessary docker-compose.yml to run localstack. Before that, populate the environment with the variables in local.env:

set -a && source local.env && set +a

Then start the container with:

docker compose -f docker-compose.yml up -d

To store the secret you can use the aws cli like:

aws secretsmanager create-secret --name "app-role-assignment-cli/dap/local/azure_credentials"   \
--secret-string '{"client_secret_value":"<client_secret_value>","client_id":"<client_id>","tenant_id":"<tenant_id>"}' \
--endpoint-url=http://localhost:4566 --region eu-west-1

once you've created the secret in the App Registration page in Azure portal.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

app_role_assignment_cli-0.1.1.tar.gz (22.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

app_role_assignment_cli-0.1.1-py3-none-any.whl (25.3 kB view details)

Uploaded Python 3

File details

Details for the file app_role_assignment_cli-0.1.1.tar.gz.

File metadata

  • Download URL: app_role_assignment_cli-0.1.1.tar.gz
  • Upload date:
  • Size: 22.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.3

File hashes

Hashes for app_role_assignment_cli-0.1.1.tar.gz
Algorithm Hash digest
SHA256 424aa3ee9a4f0feac5e47d7b0f4d87ae927d1a3cd97e3b7e2a6f085c4ad6295b
MD5 9e5399a545b48c05bd107ca7aeeac19c
BLAKE2b-256 5900aa2ee264bfdbb7d62c4ca6a47239175b3e99281d6cb3806c5f0f1ad17a2b

See more details on using hashes here.

File details

Details for the file app_role_assignment_cli-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for app_role_assignment_cli-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 c87e87afc176c9f9a7edcd4a33cee8d55652ce195f3d949ef227f45329820089
MD5 a4f9434a53265d65cc43bb5fb80762a2
BLAKE2b-256 842f57aeafce6a9ecf205295c877f94760058ebc6ad0be6d68b003b1b0e1ed06

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page