mirror of
https://github.com/azure/login.git
synced 2026-03-13 18:17:09 -04:00
Compare commits
5 Commits
releases-d
...
v1.4.6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
92a5484dfa | ||
|
|
24848bc889 | ||
|
|
ec3c14589b | ||
|
|
30a3a45036 | ||
|
|
1f63701bf3 |
15
README.md
15
README.md
@@ -23,11 +23,9 @@ With the [Azure Login](https://github.com/Azure/login/blob/master/action.yml) Ac
|
||||
|
||||
Note:
|
||||
- Ensure the CLI version is 2.30 or above to use OIDC support.
|
||||
- OIDC support in Azure is in Public Preview and is supported only for public clouds. Support for other clouds like Government clouds, Azure Stacks would be added soon.
|
||||
- GitHub runners will soon be updating the with the Az CLI and PowerShell versions that support with OIDC. Hence the below sample workflows include explicit instructions to download the same during workflow execution.
|
||||
- OIDC support in Azure is supported only for public clouds. Support for other clouds like Government clouds, Azure Stacks would be added soon.
|
||||
- By default, Azure access tokens issued during OIDC based login could have limited validity. This expiration time is configurable in Azure.
|
||||
|
||||
|
||||
## Sample workflow that uses Azure login action to run az cli
|
||||
|
||||
```yaml
|
||||
@@ -209,16 +207,23 @@ Follow the steps to configure Azure Service Principal with a secret:
|
||||
|
||||
# The command should output a JSON object similar to this:
|
||||
|
||||
|
||||
{
|
||||
"clientId": "<GUID>",
|
||||
"clientSecret": "<GUID>",
|
||||
"clientSecret": "<STRING>",
|
||||
"subscriptionId": "<GUID>",
|
||||
"tenantId": "<GUID>",
|
||||
"resourceManagerEndpointUrl": "<URL>"
|
||||
(...)
|
||||
}
|
||||
|
||||
```
|
||||
* Now in the workflow file in your branch: `.github/workflows/workflow.yml` replace the secret in Azure login action with your secret (Refer to the example above)
|
||||
* Note: The above `az ad sp create-for-rbac` command will give you the `--sdk-auth` deprecation warning. As we are working with CLI for this deprecation process, we strongly recommend users to use this `--sdk-auth` flag as the result dictionary output changes and not accepted by login action if `--sdk-auth` is not used.
|
||||
|
||||
### Manually creating the Credentials object
|
||||
|
||||
If you already created and assigned a Service Principal in Azure you can manually create the .json object above by finding the `clientId` and `clientSecret` on the Service Principal, and your `subscriptionId` and `tenantId` of the subscription and tenant respectively. The `resourceManagerEndpointUrl` will be `https://management.azure.com/` if you are using the public Azure cloud.
|
||||
|
||||
### Configure a service principal with a Federated Credential to use OIDC based authentication:
|
||||
|
||||
@@ -235,6 +240,7 @@ You can add federated credentials in the Azure portal or with the Microsoft Grap
|
||||
7. For **Entity type**, select **Environment**, **Branch**, **Pull request**, or **Tag** and specify the value, based on how you have configured the trigger for your GitHub workflow. For a more detailed overview, see [GitHub OIDC guidance]( https://docs.github.com/en/actions/deployment/security-hardening-your-deployments/about-security-hardening-with-openid-connect#defining-[…]dc-claims).
|
||||
8. Add a **Name** for the federated credential.
|
||||
9. Click **Add** to configure the federated credential.
|
||||
10. Make sure the above created application has the `contributor` access to the provided subscription. Visit [role-based-access-control](https://docs.microsoft.com/en-us/azure/role-based-access-control/role-assignments-portal?tabs=current#prerequisites) for more details.
|
||||
|
||||
For a more detailed overview, see more guidance around [Azure Federated Credentials](https://docs.microsoft.com/en-us/azure/active-directory/develop/workload-identity-federation-create-trust-github).
|
||||
|
||||
@@ -290,7 +296,6 @@ This action doesn't implement ```az logout``` by default at the end of execution
|
||||
- name: Azure CLI script
|
||||
uses: azure/CLI@v1
|
||||
with:
|
||||
azcliversion: 2.0.72
|
||||
inlineScript: |
|
||||
az logout
|
||||
az cache purge
|
||||
|
||||
@@ -34,5 +34,5 @@ branding:
|
||||
icon: 'login.svg'
|
||||
color: 'blue'
|
||||
runs:
|
||||
using: 'node12'
|
||||
using: 'node16'
|
||||
main: 'lib/main.js'
|
||||
|
||||
@@ -5,7 +5,7 @@ class Constants {
|
||||
exports.default = Constants;
|
||||
Constants.prefix = "az_";
|
||||
Constants.moduleName = "Az.Accounts";
|
||||
Constants.versionPattern = /[0-9]\.[0-9]\.[0-9]/;
|
||||
Constants.versionPattern = /[0-9]+\.[0-9]+\.[0-9]+/;
|
||||
Constants.AzureCloud = "AzureCloud";
|
||||
Constants.Subscription = "Subscription";
|
||||
Constants.ServicePrincipal = "ServicePrincipal";
|
||||
|
||||
47
lib/main.js
47
lib/main.js
@@ -40,22 +40,20 @@ function main() {
|
||||
return __awaiter(this, void 0, void 0, function* () {
|
||||
try {
|
||||
//Options for error handling
|
||||
let commandStdErr = false;
|
||||
const loginOptions = {
|
||||
silent: true,
|
||||
ignoreReturnCode: true,
|
||||
failOnStdErr: true,
|
||||
listeners: {
|
||||
stderr: (data) => {
|
||||
let error = data.toString();
|
||||
//removing the keyword 'ERROR' to avoid duplicates while throwing error
|
||||
if (error.toLowerCase().startsWith('error')) {
|
||||
error = error.slice(5);
|
||||
}
|
||||
// printing error
|
||||
if (error && error.trim().length !== 0) {
|
||||
commandStdErr = true;
|
||||
core.error(error);
|
||||
let startsWithWarning = error.toLowerCase().startsWith('warning');
|
||||
let startsWithError = error.toLowerCase().startsWith('error');
|
||||
// printing ERROR
|
||||
if (error && error.trim().length !== 0 && !startsWithWarning) {
|
||||
if (startsWithError) {
|
||||
//removing the keyword 'ERROR' to avoid duplicates while throwing error
|
||||
error = error.slice(5);
|
||||
}
|
||||
core.setFailed(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -134,17 +132,19 @@ function main() {
|
||||
// OIDC specific checks
|
||||
if (enableOIDC) {
|
||||
console.log('Using OIDC authentication...');
|
||||
//generating ID-token
|
||||
let audience = core.getInput('audience', { required: false });
|
||||
federatedToken = yield core.getIDToken(audience);
|
||||
if (!!federatedToken) {
|
||||
if (environment != "azurecloud")
|
||||
throw new Error(`Your current environment - "${environment}" is not supported for OIDC login.`);
|
||||
let [issuer, subjectClaim] = yield jwtParser(federatedToken);
|
||||
console.log("Federated token details: \n issuer - " + issuer + " \n subject claim - " + subjectClaim);
|
||||
try {
|
||||
//generating ID-token
|
||||
let audience = core.getInput('audience', { required: false });
|
||||
federatedToken = yield core.getIDToken(audience);
|
||||
if (!!federatedToken) {
|
||||
if (environment != "azurecloud")
|
||||
throw new Error(`Your current environment - "${environment}" is not supported for OIDC login.`);
|
||||
let [issuer, subjectClaim] = yield jwtParser(federatedToken);
|
||||
console.log("Federated token details: \n issuer - " + issuer + " \n subject claim - " + subjectClaim);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("Could not get ID token for authentication.");
|
||||
catch (error) {
|
||||
core.error(`${error.message.split(':')[1]}. Please make sure to give write permissions to id-token in the workflow.`);
|
||||
}
|
||||
}
|
||||
// Attempting Az cli login
|
||||
@@ -190,6 +190,7 @@ function main() {
|
||||
commonArgs = commonArgs.concat("--federated-token", federatedToken);
|
||||
}
|
||||
else {
|
||||
console.log("Note: Azure/login action also supports OIDC login mechanism. Refer https://github.com/azure/login#configure-a-service-principal-with-a-federated-credential-to-use-oidc-based-authentication for more details.");
|
||||
commonArgs = commonArgs.concat("-p", servicePrincipalKey);
|
||||
}
|
||||
yield executeAzCliCommand(`login`, true, loginOptions, commonArgs);
|
||||
@@ -213,10 +214,10 @@ function main() {
|
||||
}
|
||||
catch (error) {
|
||||
if (!isAzCLISuccess) {
|
||||
core.setFailed("Az CLI Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows");
|
||||
core.setFailed("Az CLI Login failed. Please check the credentials and make sure az is installed on the runner. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows");
|
||||
}
|
||||
else {
|
||||
core.setFailed(`Azure PowerShell Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"`);
|
||||
core.setFailed(`Azure PowerShell Login failed. Please check the credentials and make sure az is installed on the runner. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"`);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
export default class Constants {
|
||||
static readonly prefix: string = "az_";
|
||||
static readonly moduleName: string = "Az.Accounts";
|
||||
static readonly versionPattern = /[0-9]\.[0-9]\.[0-9]/;
|
||||
static readonly versionPattern = /[0-9]+\.[0-9]+\.[0-9]+/;
|
||||
|
||||
static readonly AzureCloud: string = "AzureCloud";
|
||||
static readonly Subscription: string = "Subscription";
|
||||
@@ -10,4 +10,4 @@ export default class Constants {
|
||||
static readonly Success: string = "Success";
|
||||
static readonly Error: string = "Error";
|
||||
static readonly AzVersion: string = "AzVersion";
|
||||
}
|
||||
}
|
||||
|
||||
47
src/main.ts
47
src/main.ts
@@ -12,22 +12,20 @@ var azPSHostEnv = !!process.env.AZUREPS_HOST_ENVIRONMENT ? `${process.env.AZUREP
|
||||
async function main() {
|
||||
try {
|
||||
//Options for error handling
|
||||
let commandStdErr = false;
|
||||
const loginOptions: ExecOptions = {
|
||||
silent: true,
|
||||
ignoreReturnCode: true,
|
||||
failOnStdErr: true,
|
||||
listeners: {
|
||||
stderr: (data: Buffer) => {
|
||||
let error = data.toString();
|
||||
//removing the keyword 'ERROR' to avoid duplicates while throwing error
|
||||
if (error.toLowerCase().startsWith('error')) {
|
||||
error = error.slice(5);
|
||||
}
|
||||
// printing error
|
||||
if (error && error.trim().length !== 0) {
|
||||
commandStdErr = true;
|
||||
core.error(error);
|
||||
let startsWithWarning = error.toLowerCase().startsWith('warning');
|
||||
let startsWithError = error.toLowerCase().startsWith('error');
|
||||
// printing ERROR
|
||||
if (error && error.trim().length !== 0 && !startsWithWarning) {
|
||||
if(startsWithError) {
|
||||
//removing the keyword 'ERROR' to avoid duplicates while throwing error
|
||||
error = error.slice(5);
|
||||
}
|
||||
core.setFailed(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -112,17 +110,19 @@ async function main() {
|
||||
// OIDC specific checks
|
||||
if (enableOIDC) {
|
||||
console.log('Using OIDC authentication...')
|
||||
//generating ID-token
|
||||
let audience = core.getInput('audience', { required: false });
|
||||
federatedToken = await core.getIDToken(audience);
|
||||
if (!!federatedToken) {
|
||||
if (environment != "azurecloud")
|
||||
throw new Error(`Your current environment - "${environment}" is not supported for OIDC login.`);
|
||||
let [issuer, subjectClaim] = await jwtParser(federatedToken);
|
||||
console.log("Federated token details: \n issuer - " + issuer + " \n subject claim - " + subjectClaim);
|
||||
try {
|
||||
//generating ID-token
|
||||
let audience = core.getInput('audience', { required: false });
|
||||
federatedToken = await core.getIDToken(audience);
|
||||
if (!!federatedToken) {
|
||||
if (environment != "azurecloud")
|
||||
throw new Error(`Your current environment - "${environment}" is not supported for OIDC login.`);
|
||||
let [issuer, subjectClaim] = await jwtParser(federatedToken);
|
||||
console.log("Federated token details: \n issuer - " + issuer + " \n subject claim - " + subjectClaim);
|
||||
}
|
||||
}
|
||||
else {
|
||||
throw new Error("Could not get ID token for authentication.");
|
||||
catch (error) {
|
||||
core.error(`${error.message.split(':')[1]}. Please make sure to give write permissions to id-token in the workflow.`);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -174,6 +174,7 @@ async function main() {
|
||||
commonArgs = commonArgs.concat("--federated-token", federatedToken);
|
||||
}
|
||||
else {
|
||||
console.log("Note: Azure/login action also supports OIDC login mechanism. Refer https://github.com/azure/login#configure-a-service-principal-with-a-federated-credential-to-use-oidc-based-authentication for more details.")
|
||||
commonArgs = commonArgs.concat("-p", servicePrincipalKey);
|
||||
}
|
||||
await executeAzCliCommand(`login`, true, loginOptions, commonArgs);
|
||||
@@ -208,10 +209,10 @@ async function main() {
|
||||
}
|
||||
catch (error) {
|
||||
if (!isAzCLISuccess) {
|
||||
core.setFailed("Az CLI Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows");
|
||||
core.setFailed("Az CLI Login failed. Please check the credentials and make sure az is installed on the runner. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows");
|
||||
}
|
||||
else {
|
||||
core.setFailed(`Azure PowerShell Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"`);
|
||||
core.setFailed(`Azure PowerShell Login failed. Please check the credentials and make sure az is installed on the runner. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"`);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
|
||||
Reference in New Issue
Block a user