Skip to content

Commit

Permalink
SFDP-148 - Migrate to Workload Identity (#7)
Browse files Browse the repository at this point in the history
* Migrate to workload identity

* Bump package version

* Add cluster ip to helm
  • Loading branch information
sfitz42 authored Jan 17, 2025
1 parent 75d33a4 commit 5e5e441
Show file tree
Hide file tree
Showing 18 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
@Library('defra-library@v-9') _
@Library('defra-library@v-10') _

buildNodeJs()
4 changes: 2 additions & 2 deletions app/utils/storage.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { StorageSharedKeyCredential } from '@azure/storage-blob'
import { ManagedIdentityCredential } from '@azure/identity'
import { WorkloadIdentityCredential } from '@azure/identity'

import { storageConfig } from '../config/index.js'

Expand All @@ -19,7 +19,7 @@ const getStorageCredential = (accountName, accessKey) => {

console.log('Using Azure Identity Credential for account:', accountName)

return new ManagedIdentityCredential({ clientId: storageConfig.get('managedIdentityClientId') })
return new WorkloadIdentityCredential({ clientId: storageConfig.get('managedIdentityClientId') })
}

export {
Expand Down
Empty file added appconfig/common.yaml
Empty file.
Empty file added appconfig/dev.yaml
Empty file.
Empty file.
Empty file added appconfig/prd.yaml
Empty file.
Empty file added appconfig/pre.yaml
Empty file.
Empty file added appconfig/snd2.yaml
Empty file.
Empty file added appconfig/test.yaml
Empty file.
2 changes: 1 addition & 1 deletion helm/fcp-fd-file-retriever/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ name: fcp-fd-file-retriever
version: 1.0.0
dependencies:
- name: ffc-helm-library
version: 4.6.0
version: 4.7.2
repository: https://raw.githubusercontent.com/defra/ffc-helm-repository/master/

This file was deleted.

5 changes: 0 additions & 5 deletions helm/fcp-fd-file-retriever/templates/azure-identity.yaml

This file was deleted.

3 changes: 3 additions & 0 deletions helm/fcp-fd-file-retriever/templates/service-account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{{- include "ffc-helm-library.service-account" (list . "fcp-fd-file-processor.service-account") -}}
{{- define "fcp-fd-file-processor.service-account" -}}
{{- end -}}
6 changes: 5 additions & 1 deletion helm/fcp-fd-file-retriever/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,16 @@ readinessProbe:
failureThreshold: 3
timeoutSeconds: 5

usePodIdentity: true
workloadIdentity: true

azureIdentity:
clientID: not-a-real-clientID
resourceID: not-a-real-resourceID

service:
port: 80
type: ClusterIP

ingress:
class: nginx
endpoint: fcp-fd-file-retriever
Expand Down
6 changes: 3 additions & 3 deletions 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 package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fcp-fd-file-retriever",
"version": "0.3.1",
"version": "0.3.2",
"description": "File retrieval service for Single Front Door",
"homepage": "https://github.com/DEFRA/fcp-fd-file-retriever",
"main": "app/index.js",
Expand Down
2 changes: 2 additions & 0 deletions provision.azure.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
resources:
identity: fd-file-retriever
8 changes: 4 additions & 4 deletions test/unit/storage/blob/clean.test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { beforeEach, describe, expect, jest, test } from '@jest/globals'

const mockSharedKeyCredential = jest.fn()
const mockManagedIdentityCredential = jest.fn()
const mockWorkloadIdentityCredential = jest.fn()

const mockCreateIfNotExists = jest.fn()

Expand All @@ -17,7 +17,7 @@ jest.unstable_mockModule('@azure/storage-blob', () => ({
}))

jest.unstable_mockModule('@azure/identity', () => ({
ManagedIdentityCredential: mockManagedIdentityCredential
WorkloadIdentityCredential: mockWorkloadIdentityCredential
}))

describe('Clean Blob Storage Client', () => {
Expand Down Expand Up @@ -53,7 +53,7 @@ describe('Clean Blob Storage Client', () => {

expect(client).toBeDefined()
expect(mockSharedKeyCredential).toHaveBeenCalled()
expect(mockManagedIdentityCredential).not.toHaveBeenCalled()
expect(mockWorkloadIdentityCredential).not.toHaveBeenCalled()

process.env = orginalEnv
})
Expand All @@ -70,7 +70,7 @@ describe('Clean Blob Storage Client', () => {
const { client } = await import('../../../../app/storage/blob/clean')

expect(client).toBeDefined()
expect(mockManagedIdentityCredential).toHaveBeenCalled()
expect(mockWorkloadIdentityCredential).toHaveBeenCalled()
expect(mockSharedKeyCredential).not.toHaveBeenCalled()

process.env = orginalEnv
Expand Down

0 comments on commit 5e5e441

Please sign in to comment.