Skip to content

Commit

Permalink
Add support for workload identity federation authentication.
Browse files Browse the repository at this point in the history
  • Loading branch information
frasdav committed May 30, 2024
1 parent 92bc956 commit f591a5b
Show file tree
Hide file tree
Showing 8 changed files with 46 additions and 10 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
# Sheriff Azure DevOps Extension Changelog

## 0.0.6

* `SheriffPlan` and `SheriffApply` tasks updated to support workload identity federation authentication.

## 0.0.5

* `InstallSheriffCLI` task updated to download Sheriff from Azure Storage.
Expand Down
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ About

This is an Azure DevOps extension that provides tasks for installing and running
`Sheriff <https://github.com/gofrontier-com/sheriff>`_, a command line tool to
manage Azure role-based access control (Azure RBAC) and Microsoft Entra
Privileged Identity Management (Microsoft Entra PIM) using desired state configuration.
manage Microsoft Entra Privileged Identity Management (Microsoft Entra PIM) using
desired state configuration.

------------
Installation
Expand Down
4 changes: 2 additions & 2 deletions tasks/SheriffApply/SheriffApplyV0/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tasks/SheriffApply/SheriffApplyV0/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sheriff-apply-task",
"version": "0.0.1",
"version": "0.0.2",
"description": "",
"scripts": {
"test": "run-p test:*",
Expand Down
18 changes: 17 additions & 1 deletion tasks/SheriffApply/SheriffApplyV0/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');

const tl = require('azure-pipelines-task-lib/task');

async function run() {
Expand All @@ -11,6 +14,8 @@ async function run() {

let subscriptionId = tl.getInput('subscriptionId', false);

const agentTempDirectory = tl.getVariable('Agent.TempDirectory');

const env = {};

const authScheme = tl.getEndpointAuthorizationScheme(connectedService, true);
Expand All @@ -22,7 +27,18 @@ async function run() {

if (authScheme.toLowerCase() === 'workloadidentityfederation') {
tl.debug('workload identity federation scheme');
throw new Error('Workload identity federation scheme not implemented');
const servicePrincipalId = tl.getEndpointAuthorizationParameter(connectedService, 'serviceprincipalid', false);
env.AZURE_CLIENT_ID = servicePrincipalId;

const tenantId = tl.getEndpointAuthorizationParameter(connectedService, 'tenantid', false);
env.AZURE_TENANT_ID = tenantId;

const federatedToken = await this.getIdToken(connectedService);
tl.setSecret(federatedToken);

const federatedTokenFilePath = path.join(agentTempDirectory, 'azure-identity-token');
fs.writeFileSync(federatedTokenFilePath, federatedToken);
env.AZURE_FEDERATED_TOKEN_FILE = federatedTokenFilePath;
} else if (authScheme.toLowerCase() === 'serviceprincipal') {
tl.debug('service principal scheme');
const authType = tl.getEndpointAuthorizationParameter(connectedService, 'authenticationType', false);
Expand Down
4 changes: 2 additions & 2 deletions tasks/SheriffPlan/SheriffPlanV0/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tasks/SheriffPlan/SheriffPlanV0/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "sheriff-plan-task",
"version": "0.0.1",
"version": "0.0.2",
"description": "",
"scripts": {
"test": "run-p test:*",
Expand Down
18 changes: 17 additions & 1 deletion tasks/SheriffPlan/SheriffPlanV0/src/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/usr/bin/env node

const fs = require('fs');
const path = require('path');

const tl = require('azure-pipelines-task-lib/task');

async function run() {
Expand All @@ -10,6 +13,8 @@ async function run() {

let subscriptionId = tl.getInput('subscriptionId', false);

const agentTempDirectory = tl.getVariable('Agent.TempDirectory');

const env = {};

const authScheme = tl.getEndpointAuthorizationScheme(connectedService, true);
Expand All @@ -21,7 +26,18 @@ async function run() {

if (authScheme.toLowerCase() === 'workloadidentityfederation') {
tl.debug('workload identity federation scheme');
throw new Error('Workload identity federation scheme not implemented');
const servicePrincipalId = tl.getEndpointAuthorizationParameter(connectedService, 'serviceprincipalid', false);
env.AZURE_CLIENT_ID = servicePrincipalId;

const tenantId = tl.getEndpointAuthorizationParameter(connectedService, 'tenantid', false);
env.AZURE_TENANT_ID = tenantId;

const federatedToken = await this.getIdToken(connectedService);
tl.setSecret(federatedToken);

const federatedTokenFilePath = path.join(agentTempDirectory, 'azure-identity-token');
fs.writeFileSync(federatedTokenFilePath, federatedToken);
env.AZURE_FEDERATED_TOKEN_FILE = federatedTokenFilePath;
} else if (authScheme.toLowerCase() === 'serviceprincipal') {
tl.debug('service principal scheme');
const authType = tl.getEndpointAuthorizationParameter(connectedService, 'authenticationType', false);
Expand Down

0 comments on commit f591a5b

Please sign in to comment.