mirror of
https://github.com/azure/login.git
synced 2026-03-15 09:20:56 -04:00
Compare commits
1 Commits
releases/v
...
releasesv1
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac728af674 |
39
README.md
39
README.md
@@ -23,9 +23,11 @@ With the [Azure Login](https://github.com/Azure/login/blob/master/action.yml) Ac
|
|||||||
|
|
||||||
Note:
|
Note:
|
||||||
- Ensure the CLI version is 2.30 or above to use OIDC support.
|
- Ensure the CLI version is 2.30 or above to use OIDC support.
|
||||||
- OIDC support in Azure is supported only for public clouds. Support for other clouds like Government clouds, Azure Stacks would be added soon.
|
- 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.
|
||||||
- By default, Azure access tokens issued during OIDC based login could have limited validity. This expiration time is configurable in Azure.
|
- 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
|
## Sample workflow that uses Azure login action to run az cli
|
||||||
|
|
||||||
```yaml
|
```yaml
|
||||||
@@ -207,23 +209,16 @@ Follow the steps to configure Azure Service Principal with a secret:
|
|||||||
|
|
||||||
# The command should output a JSON object similar to this:
|
# The command should output a JSON object similar to this:
|
||||||
|
|
||||||
|
|
||||||
{
|
{
|
||||||
"clientId": "<GUID>",
|
"clientId": "<GUID>",
|
||||||
"clientSecret": "<STRING>",
|
"clientSecret": "<GUID>",
|
||||||
"subscriptionId": "<GUID>",
|
"subscriptionId": "<GUID>",
|
||||||
"tenantId": "<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)
|
* 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:
|
### Configure a service principal with a Federated Credential to use OIDC based authentication:
|
||||||
|
|
||||||
@@ -231,16 +226,13 @@ If you already created and assigned a Service Principal in Azure you can manuall
|
|||||||
You can add federated credentials in the Azure portal or with the Microsoft Graph REST API.
|
You can add federated credentials in the Azure portal or with the Microsoft Graph REST API.
|
||||||
|
|
||||||
#### Azure portal
|
#### Azure portal
|
||||||
1. [Register an application](https://docs.microsoft.com/en-us/azure/active-directory/develop/quickstart-register-app) in Azure Portal
|
1. Go to **Certificates and secrets**. In the **Federated credentials** tab, select **Add credential**.
|
||||||
2. Within the registered application, Go to **Certificates & secrets**.
|
1. The **Add a credential** blade opens.
|
||||||
3. In the **Federated credentials** tab, select **Add credential**.
|
1. In the **Federated credential scenario** box select **GitHub actions deploying Azure resources**.
|
||||||
4. The **Add a credential** blade opens.
|
1. Specify the **Organization** and **Repository** for your GitHub Actions workflow which needs to access the Azure resources scoped by this App (Service Principal)
|
||||||
5. In the **Federated credential scenario** box select **GitHub actions deploying Azure resources**.
|
1. 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).
|
||||||
6. Specify the **Organization** and **Repository** for your GitHub Actions workflow which needs to access the Azure resources scoped by this App (Service Principal)
|
1. Add a **Name** for the federated credential.
|
||||||
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).
|
1. Click **Add** to configure the federated credential.
|
||||||
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).
|
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).
|
||||||
|
|
||||||
@@ -252,19 +244,19 @@ For a more detailed overview, see more guidance around [Azure Federated Credenti
|
|||||||
Run the following command to [create a new federated identity credential](https://docs.microsoft.com/en-us/graph/api/application-post-federatedidentitycredentials?view=graph-rest-beta&preserve-view=true) on your app (specified by the object ID of the app). Substitute the values `APPLICATION-OBJECT-ID`, `CREDENTIAL-NAME`, `SUBJECT`. The options for subject refer to your request filter. These are the conditions that OpenID Connect uses to determine when to issue an authentication token.
|
Run the following command to [create a new federated identity credential](https://docs.microsoft.com/en-us/graph/api/application-post-federatedidentitycredentials?view=graph-rest-beta&preserve-view=true) on your app (specified by the object ID of the app). Substitute the values `APPLICATION-OBJECT-ID`, `CREDENTIAL-NAME`, `SUBJECT`. The options for subject refer to your request filter. These are the conditions that OpenID Connect uses to determine when to issue an authentication token.
|
||||||
* specific environment
|
* specific environment
|
||||||
```azurecli
|
```azurecli
|
||||||
az rest --method POST --uri 'https://graph.microsoft.com/beta/applications/<APPLICATION-OBJECT-ID>/federatedIdentityCredentials' --body '{"name":"<CREDENTIAL-NAME>","issuer":"https://token.actions.githubusercontent.com","subject":"repo:octo-org/octo-repo:environment:Production","description":"Testing","audiences":["api://AzureADTokenExchange"]}'
|
az rest --method POST --uri 'https://graph.microsoft.com/beta/applications/<APPLICATION-OBJECT-ID>/federatedIdentityCredentials' --body '{"name":"<CREDENTIAL-NAME>","issuer":"https://token.actions.githubusercontent.com/","subject":"repo:octo-org/octo-repo:environment:Production","description":"Testing","audiences":["api://AzureADTokenExchange"]}'
|
||||||
```
|
```
|
||||||
* pull_request events
|
* pull_request events
|
||||||
```azurecli
|
```azurecli
|
||||||
az rest --method POST --uri 'https://graph.microsoft.com/beta/applications/<APPLICATION-OBJECT-ID>/federatedIdentityCredentials' --body '{"name":"<CREDENTIAL-NAME>","issuer":"https://token.actions.githubusercontent.com","subject":"repo:octo-org/octo-repo:pull_request","description":"Testing","audiences":["api://AzureADTokenExchange"]}'
|
az rest --method POST --uri 'https://graph.microsoft.com/beta/applications/<APPLICATION-OBJECT-ID>/federatedIdentityCredentials' --body '{"name":"<CREDENTIAL-NAME>","issuer":"https://token.actions.githubusercontent.com/","subject":"repo:octo-org/octo-repo:pull-request","description":"Testing","audiences":["api://AzureADTokenExchange"]}'
|
||||||
```
|
```
|
||||||
* specific branch
|
* specific branch
|
||||||
```azurecli
|
```azurecli
|
||||||
az rest --method POST --uri 'https://graph.microsoft.com/beta/applications/<APPLICATION-OBJECT-ID>/federatedIdentityCredentials' --body '{"name":"<CREDENTIAL-NAME>","issuer":"https://token.actions.githubusercontent.com","subject":"repo:octo-org/octo-repo:ref:refs/heads/{Branch}","description":"Testing","audiences":["api://AzureADTokenExchange"]}'
|
az rest --method POST --uri 'https://graph.microsoft.com/beta/applications/<APPLICATION-OBJECT-ID>/federatedIdentityCredentials' --body '{"name":"<CREDENTIAL-NAME>","issuer":"https://token.actions.githubusercontent.com/","subject":"repo:octo-org/octo-repo:ref:refs/heads/{Branch}","description":"Testing","audiences":["api://AzureADTokenExchange"]}'
|
||||||
```
|
```
|
||||||
* specific tag
|
* specific tag
|
||||||
```azurecli
|
```azurecli
|
||||||
az rest --method POST --uri 'https://graph.microsoft.com/beta/applications/<APPLICATION-OBJECT-ID>/federatedIdentityCredentials' --body '{"name":"<CREDENTIAL-NAME>","issuer":"https://token.actions.githubusercontent.com","subject":"repo:octo-org/octo-repo:ref:refs/heads/{Tag}","description":"Testing","audiences":["api://AzureADTokenExchange"]}'
|
az rest --method POST --uri 'https://graph.microsoft.com/beta/applications/<APPLICATION-OBJECT-ID>/federatedIdentityCredentials' --body '{"name":"<CREDENTIAL-NAME>","issuer":"https://token.actions.githubusercontent.com/","subject":"repo:octo-org/octo-repo:ref:refs/heads/{Tag}","description":"Testing","audiences":["api://AzureADTokenExchange"]}'
|
||||||
```
|
```
|
||||||
|
|
||||||
## Support for using `allow-no-subscriptions` flag with az login
|
## Support for using `allow-no-subscriptions` flag with az login
|
||||||
@@ -296,6 +288,7 @@ This action doesn't implement ```az logout``` by default at the end of execution
|
|||||||
- name: Azure CLI script
|
- name: Azure CLI script
|
||||||
uses: azure/CLI@v1
|
uses: azure/CLI@v1
|
||||||
with:
|
with:
|
||||||
|
azcliversion: 2.0.72
|
||||||
inlineScript: |
|
inlineScript: |
|
||||||
az logout
|
az logout
|
||||||
az cache purge
|
az cache purge
|
||||||
|
|||||||
@@ -34,5 +34,5 @@ branding:
|
|||||||
icon: 'login.svg'
|
icon: 'login.svg'
|
||||||
color: 'blue'
|
color: 'blue'
|
||||||
runs:
|
runs:
|
||||||
using: 'node16'
|
using: 'node12'
|
||||||
main: 'lib/main.js'
|
main: 'lib/main.js'
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ class Constants {
|
|||||||
exports.default = Constants;
|
exports.default = Constants;
|
||||||
Constants.prefix = "az_";
|
Constants.prefix = "az_";
|
||||||
Constants.moduleName = "Az.Accounts";
|
Constants.moduleName = "Az.Accounts";
|
||||||
Constants.versionPattern = /[0-9]+\.[0-9]+\.[0-9]+/;
|
Constants.versionPattern = /[0-9]\.[0-9]\.[0-9]/;
|
||||||
Constants.AzureCloud = "AzureCloud";
|
Constants.AzureCloud = "AzureCloud";
|
||||||
Constants.Subscription = "Subscription";
|
Constants.Subscription = "Subscription";
|
||||||
Constants.ServicePrincipal = "ServicePrincipal";
|
Constants.ServicePrincipal = "ServicePrincipal";
|
||||||
|
|||||||
63
lib/main.js
63
lib/main.js
@@ -1,14 +1,14 @@
|
|||||||
"use strict";
|
"use strict";
|
||||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
var __createBinding = (this && this.__createBinding) || (Object.create ? (function (o, m, k, k2) {
|
||||||
if (k2 === undefined) k2 = k;
|
if (k2 === undefined) k2 = k;
|
||||||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
Object.defineProperty(o, k2, { enumerable: true, get: function () { return m[k]; } });
|
||||||
}) : (function(o, m, k, k2) {
|
}) : (function (o, m, k, k2) {
|
||||||
if (k2 === undefined) k2 = k;
|
if (k2 === undefined) k2 = k;
|
||||||
o[k2] = m[k];
|
o[k2] = m[k];
|
||||||
}));
|
}));
|
||||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function (o, v) {
|
||||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||||
}) : function(o, v) {
|
}) : function (o, v) {
|
||||||
o["default"] = v;
|
o["default"] = v;
|
||||||
});
|
});
|
||||||
var __importStar = (this && this.__importStar) || function (mod) {
|
var __importStar = (this && this.__importStar) || function (mod) {
|
||||||
@@ -40,20 +40,22 @@ function main() {
|
|||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
try {
|
try {
|
||||||
//Options for error handling
|
//Options for error handling
|
||||||
|
let commandStdErr = false;
|
||||||
const loginOptions = {
|
const loginOptions = {
|
||||||
silent: true,
|
silent: true,
|
||||||
|
ignoreReturnCode: true,
|
||||||
|
failOnStdErr: true,
|
||||||
listeners: {
|
listeners: {
|
||||||
stderr: (data) => {
|
stderr: (data) => {
|
||||||
let error = data.toString();
|
let error = data.toString();
|
||||||
let startsWithWarning = error.toLowerCase().startsWith('warning');
|
//removing the keyword 'ERROR' to avoid duplicates while throwing error
|
||||||
let startsWithError = error.toLowerCase().startsWith('error');
|
if (error.toLowerCase().startsWith('error')) {
|
||||||
// printing ERROR
|
error = error.slice(5);
|
||||||
if (error && error.trim().length !== 0 && !startsWithWarning) {
|
}
|
||||||
if (startsWithError) {
|
// printing error
|
||||||
//removing the keyword 'ERROR' to avoid duplicates while throwing error
|
if (error && error.trim().length !== 0) {
|
||||||
error = error.slice(5);
|
commandStdErr = true;
|
||||||
}
|
core.error(error);
|
||||||
core.setFailed(error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -132,19 +134,15 @@ function main() {
|
|||||||
// OIDC specific checks
|
// OIDC specific checks
|
||||||
if (enableOIDC) {
|
if (enableOIDC) {
|
||||||
console.log('Using OIDC authentication...');
|
console.log('Using OIDC authentication...');
|
||||||
try {
|
//generating ID-token
|
||||||
//generating ID-token
|
let audience = core.getInput('audience', { required: false });
|
||||||
let audience = core.getInput('audience', { required: false });
|
federatedToken = yield core.getIDToken(audience);
|
||||||
federatedToken = yield core.getIDToken(audience);
|
if (!!federatedToken) {
|
||||||
if (!!federatedToken) {
|
if (environment != "azurecloud")
|
||||||
if (environment != "azurecloud")
|
throw new Error(`Your current environment - "${environment}" is not supported for OIDC login.`);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
else {
|
||||||
core.error(`${error.message.split(':')[1]}. Please make sure to give write permissions to id-token in the workflow.`);
|
throw new Error("Could not get ID token for authentication.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Attempting Az cli login
|
// Attempting Az cli login
|
||||||
@@ -190,7 +188,6 @@ function main() {
|
|||||||
commonArgs = commonArgs.concat("--federated-token", federatedToken);
|
commonArgs = commonArgs.concat("--federated-token", federatedToken);
|
||||||
}
|
}
|
||||||
else {
|
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);
|
commonArgs = commonArgs.concat("-p", servicePrincipalKey);
|
||||||
}
|
}
|
||||||
yield executeAzCliCommand(`login`, true, loginOptions, commonArgs);
|
yield executeAzCliCommand(`login`, true, loginOptions, commonArgs);
|
||||||
@@ -214,10 +211,10 @@ function main() {
|
|||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
if (!isAzCLISuccess) {
|
if (!isAzCLISuccess) {
|
||||||
core.setFailed(`Az CLI Login failed with ${error}. 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`);
|
core.setFailed("Az CLI Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
core.setFailed(`Azure PowerShell Login failed with ${error}. 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"`);
|
core.setFailed(`Azure PowerShell Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -233,12 +230,4 @@ function executeAzCliCommand(command, silent, execOptions = {}, args = []) {
|
|||||||
yield exec.exec(`"${azPath}" ${command}`, args, execOptions);
|
yield exec.exec(`"${azPath}" ${command}`, args, execOptions);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
function jwtParser(federatedToken) {
|
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
|
||||||
let tokenPayload = federatedToken.split('.')[1];
|
|
||||||
let bufferObj = Buffer.from(tokenPayload, "base64");
|
|
||||||
let decodedPayload = JSON.parse(bufferObj.toString("utf8"));
|
|
||||||
return [decodedPayload['iss'], decodedPayload['sub']];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
main();
|
main();
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
export default class Constants {
|
export default class Constants {
|
||||||
static readonly prefix: string = "az_";
|
static readonly prefix: string = "az_";
|
||||||
static readonly moduleName: string = "Az.Accounts";
|
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 AzureCloud: string = "AzureCloud";
|
||||||
static readonly Subscription: string = "Subscription";
|
static readonly Subscription: string = "Subscription";
|
||||||
@@ -10,4 +10,4 @@ export default class Constants {
|
|||||||
static readonly Success: string = "Success";
|
static readonly Success: string = "Success";
|
||||||
static readonly Error: string = "Error";
|
static readonly Error: string = "Error";
|
||||||
static readonly AzVersion: string = "AzVersion";
|
static readonly AzVersion: string = "AzVersion";
|
||||||
}
|
}
|
||||||
51
src/main.ts
51
src/main.ts
@@ -12,20 +12,22 @@ var azPSHostEnv = !!process.env.AZUREPS_HOST_ENVIRONMENT ? `${process.env.AZUREP
|
|||||||
async function main() {
|
async function main() {
|
||||||
try {
|
try {
|
||||||
//Options for error handling
|
//Options for error handling
|
||||||
|
let commandStdErr = false;
|
||||||
const loginOptions: ExecOptions = {
|
const loginOptions: ExecOptions = {
|
||||||
silent: true,
|
silent: true,
|
||||||
|
ignoreReturnCode: true,
|
||||||
|
failOnStdErr: true,
|
||||||
listeners: {
|
listeners: {
|
||||||
stderr: (data: Buffer) => {
|
stderr: (data: Buffer) => {
|
||||||
let error = data.toString();
|
let error = data.toString();
|
||||||
let startsWithWarning = error.toLowerCase().startsWith('warning');
|
//removing the keyword 'ERROR' to avoid duplicates while throwing error
|
||||||
let startsWithError = error.toLowerCase().startsWith('error');
|
if (error.toLowerCase().startsWith('error')) {
|
||||||
// printing ERROR
|
error = error.slice(5);
|
||||||
if (error && error.trim().length !== 0 && !startsWithWarning) {
|
}
|
||||||
if(startsWithError) {
|
// printing error
|
||||||
//removing the keyword 'ERROR' to avoid duplicates while throwing error
|
if (error && error.trim().length !== 0) {
|
||||||
error = error.slice(5);
|
commandStdErr = true;
|
||||||
}
|
core.error(error);
|
||||||
core.setFailed(error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -110,19 +112,15 @@ async function main() {
|
|||||||
// OIDC specific checks
|
// OIDC specific checks
|
||||||
if (enableOIDC) {
|
if (enableOIDC) {
|
||||||
console.log('Using OIDC authentication...')
|
console.log('Using OIDC authentication...')
|
||||||
try {
|
//generating ID-token
|
||||||
//generating ID-token
|
let audience = core.getInput('audience', { required: false });
|
||||||
let audience = core.getInput('audience', { required: false });
|
federatedToken = await core.getIDToken(audience);
|
||||||
federatedToken = await core.getIDToken(audience);
|
if (!!federatedToken) {
|
||||||
if (!!federatedToken) {
|
if (environment != "azurecloud")
|
||||||
if (environment != "azurecloud")
|
throw new Error(`Your current environment - "${environment}" is not supported for OIDC login.`);
|
||||||
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);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
catch (error) {
|
else {
|
||||||
core.error(`${error.message.split(':')[1]}. Please make sure to give write permissions to id-token in the workflow.`);
|
throw new Error("Could not get ID token for authentication.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -174,7 +172,6 @@ async function main() {
|
|||||||
commonArgs = commonArgs.concat("--federated-token", federatedToken);
|
commonArgs = commonArgs.concat("--federated-token", federatedToken);
|
||||||
}
|
}
|
||||||
else {
|
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);
|
commonArgs = commonArgs.concat("-p", servicePrincipalKey);
|
||||||
}
|
}
|
||||||
await executeAzCliCommand(`login`, true, loginOptions, commonArgs);
|
await executeAzCliCommand(`login`, true, loginOptions, commonArgs);
|
||||||
@@ -209,10 +206,10 @@ async function main() {
|
|||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
if (!isAzCLISuccess) {
|
if (!isAzCLISuccess) {
|
||||||
core.setFailed(`Az CLI Login failed with ${error}. 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"`);
|
core.setFailed("Az CLI Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
core.setFailed(`Azure PowerShell Login failed with ${error}. 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"`);
|
core.setFailed(`Azure PowerShell Login failed. Please check the credentials. For more information refer https://aka.ms/create-secrets-for-GitHub-workflows"`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@@ -230,10 +227,4 @@ async function executeAzCliCommand(
|
|||||||
execOptions.silent = !!silent;
|
execOptions.silent = !!silent;
|
||||||
await exec.exec(`"${azPath}" ${command}`, args, execOptions);
|
await exec.exec(`"${azPath}" ${command}`, args, execOptions);
|
||||||
}
|
}
|
||||||
async function jwtParser(federatedToken: string) {
|
|
||||||
let tokenPayload = federatedToken.split('.')[1];
|
|
||||||
let bufferObj = Buffer.from(tokenPayload, "base64");
|
|
||||||
let decodedPayload = JSON.parse(bufferObj.toString("utf8"));
|
|
||||||
return [decodedPayload['iss'], decodedPayload['sub']];
|
|
||||||
}
|
|
||||||
main();
|
main();
|
||||||
|
|||||||
Reference in New Issue
Block a user