Skip to content

Instantly share code, notes, and snippets.

View paolosalvatori's full-sized avatar
🏠
Working from home

Paolo Salvatori paolosalvatori

🏠
Working from home
View GitHub Profile
@paolosalvatori
paolosalvatori / login-via-pim.sh
Created February 25, 2025 08:25
This Bash script allows to login to a given Azure Subscription using Microsoft Entra Privileged Identity Management (PIM)
#!/bin/bash
# Variables
SUBSCRIPTION_ID=$(az account show --query id --output tsv) # Subscription ID
ROLE_NAME="8e3af657-a8ff-443c-a75c-2fe8c4bcb635" # Owner role
ROLE_DEFINITION_ID="/subscriptions/${SUBSCRIPTION_ID}/providers/Microsoft.Authorization/roleDefinitions/${ROLE_NAME}" # Role definition resource ID
PRINCIPAL_ID=$(az ad user show --id $(az account show --query user.name -o tsv) --query id -o tsv) # Your account object ID
ROLE_ASSIGNMENT_ID=$(uuidgen) # Generate a unique GUID for the role assignment
JUSTIFICATION="I need access to [$(az account show --query name --output tsv)] Azure subscription" # Justification for the role assignment
API_VERSION="2020-10-01" # API version
Environment variable Description
AZURE_AUTHORITY_HOST The Microsoft Entra ID endpoint (https://login.microsoftonline.com/).
AZURE_CLIENT_ID The client ID of the Microsoft Entra ID registered application or user-assigned managed identity.
AZURE_TENANT_ID The tenant ID of the Microsoft Entra ID registered application or user-assigned managed identity.
AZURE_FEDERATED_TOKEN_FILE The path of the projected service account token file.
@paolosalvatori
paolosalvatori / app.py
Last active August 27, 2024 09:01
A Streamlit chat written in Python and based on Azure OpenAI. The application was successfully tested on Azure Kubernetes Service (AKS)
"""
MIT License
Copyright (c) 2023 Paolo Salvatori
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is