Skip to content

Commit 7a16955

Browse files
Merge pull request #138 from pagopa/PIDM-482-workload-identity
chore: [PIDM-482] Implement workload identity & new runner
2 parents aa5ab24 + 586da9c commit 7a16955

File tree

9 files changed

+54
-87
lines changed

9 files changed

+54
-87
lines changed

.github/maven_code_review/action.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,14 @@ runs:
5151
maven-version: ${{ inputs.maven_version }}
5252

5353
- name: Cache Maven packages
54-
uses: actions/cache@f5ce41475b483ad7581884324a6eca9f48f8dcc7 # v1
54+
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
5555
with:
5656
path: ~/.m2
5757
key: ${{ runner.os }}-m2-${{ hashFiles('**/pom.xml') }}
5858
restore-keys: ${{ runner.os }}-m2
5959

6060
- name: Cache SonarCloud packages
61-
uses: actions/cache@f5ce41475b483ad7581884324a6eca9f48f8dcc7 # v1
61+
uses: actions/cache@1bd1e32a3bdc45362d1e726936510720a7c30a57 # v4.2.0
6262
with:
6363
path: ~/.sonar-project.properties/cache
6464
key: ${{ runner.os }}-sonar-project.properties

.github/workflows/deploy_with_github_runner.yml

Lines changed: 8 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -7,78 +7,35 @@ on:
77
required: true
88
description: The name of the environment where to deploy
99
type: string
10-
target:
11-
required: true
12-
description: The environment target of the job
10+
branch:
11+
required: false
12+
default: ${{ github.ref_name }}
1313
type: string
1414

1515
env:
16-
NAMESPACE: receipts
1716
APP_NAME: pagopapagopareceiptpdfdatastore
1817

1918
permissions:
2019
id-token: write
2120
contents: read
2221

2322
jobs:
24-
create_runner:
25-
name: Create Runner
26-
runs-on: ubuntu-22.04
27-
environment:
28-
name: ${{ inputs.environment }}
29-
if: ${{ inputs.target == inputs.environment || inputs.target == 'all' }}
30-
outputs:
31-
runner_name: ${{ steps.create_github_runner.outputs.runner_name }}
32-
steps:
33-
- name: Create GitHub Runner
34-
id: create_github_runner
35-
# from https://github.com/pagopa/eng-github-actions-iac-template/tree/main/azure/github-self-hosted-runner-azure-create-action
36-
uses: pagopa/eng-github-actions-iac-template/azure/github-self-hosted-runner-azure-create-action@main
37-
with:
38-
client_id: ${{ secrets.CLIENT_ID }}
39-
tenant_id: ${{ secrets.TENANT_ID }}
40-
subscription_id: ${{ secrets.SUBSCRIPTION_ID }}
41-
container_app_environment_name: ${{ vars.CONTAINER_APP_ENVIRONMENT_NAME }}
42-
resource_group_name: ${{ vars.CONTAINER_APP_ENVIRONMENT_RESOURCE_GROUP_NAME }} # RG of the runner
43-
pat_token: ${{ secrets.BOT_TOKEN_GITHUB }}
44-
self_hosted_runner_image_tag: "latest"
45-
4623
deploy:
47-
needs: [ create_runner ]
48-
runs-on: [ self-hosted, "${{ needs.create_runner.outputs.runner_name }}" ]
49-
if: ${{ inputs.target == inputs.environment || inputs.target == 'all' }}
24+
runs-on: [ self-hosted-job, "${{ inputs.environment }}" ]
5025
name: Deploy on AKS
5126
environment: ${{ inputs.environment }}
5227
steps:
5328
- name: Deploy
5429
uses: pagopa/github-actions-template/aks-deploy@main
5530
with:
56-
branch: ${{ github.ref_name }}
31+
branch: ${{ inputs.branch }}
5732
client_id: ${{ secrets.CLIENT_ID }}
5833
subscription_id: ${{ secrets.SUBSCRIPTION_ID }}
5934
tenant_id: ${{ secrets.TENANT_ID }}
6035
env: ${{ inputs.environment }}
61-
namespace: ${{ env.NAMESPACE }}
36+
namespace: ${{ vars.NAMESPACE }}
6237
cluster_name: ${{ vars.CLUSTER_NAME }}
6338
resource_group: ${{ vars.CLUSTER_RESOURCE_GROUP }}
6439
app_name: ${{ env.APP_NAME }}
65-
helm_upgrade_options: "--debug"
66-
67-
cleanup_runner:
68-
name: Cleanup Runner
69-
needs: [ create_runner, deploy ]
70-
if: ${{ success() || failure() && inputs.target == inputs.environment || inputs.target == 'all' }}
71-
runs-on: ubuntu-22.04
72-
environment: ${{ inputs.environment }}
73-
steps:
74-
- name: Cleanup GitHub Runner
75-
id: cleanup_github_runner
76-
# from https://github.com/pagopa/eng-github-actions-iac-template/tree/main/azure/github-self-hosted-runner-azure-cleanup-action
77-
uses: pagopa/eng-github-actions-iac-template/azure/github-self-hosted-runner-azure-cleanup-action@0ee2f58fd46d10ac7f00bce4304b98db3dbdbe9a
78-
with:
79-
client_id: ${{ secrets.CLIENT_ID }}
80-
tenant_id: ${{ secrets.TENANT_ID }}
81-
subscription_id: ${{ secrets.SUBSCRIPTION_ID }}
82-
resource_group_name: ${{ vars.CONTAINER_APP_ENVIRONMENT_RESOURCE_GROUP_NAME }}
83-
runner_name: ${{ needs.create_runner.outputs.runner_name }}
84-
pat_token: ${{ secrets.BOT_TOKEN_GITHUB }}
40+
helm_upgrade_options: '--debug --set microservice-chart.azure.workloadIdentityClientId=${{vars.WORKLOAD_IDENTITY_ID}}'
41+
timeout: '15m0s'

.github/workflows/release-deploy.yml

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,16 @@ jobs:
101101
id: semver
102102
uses: pagopa/github-actions-template/ghcr-build-push@d91a1fd0b913c9830589be5d86cdb71c90813fae # v1.5.4
103103
with:
104-
branch: ${{ github.ref_name}}
105104
github_token: ${{ secrets.GITHUB_TOKEN }}
106105
tag: ${{ needs.release.outputs.version }}
107106

108107
deploy_aks:
109108
name: Deploy on AKS
110109
needs: [ setup, release, image ]
111110
if: ${{ always() && !contains(needs.*.result, 'failure') && !contains(needs.*.result, 'cancelled') }}
112-
strategy:
113-
matrix:
114-
environment: [ dev, uat, prod ]
115111
uses: ./.github/workflows/deploy_with_github_runner.yml
116112
with:
117-
environment: ${{ matrix.environment }}
118-
target: ${{ needs.setup.outputs.environment }}
113+
environment: ${{ needs.setup.outputs.environment }}
119114
secrets: inherit
120115

121116
notify:
@@ -126,7 +121,7 @@ jobs:
126121
steps:
127122
- name: Report Status
128123
if: always()
129-
uses: ravsamhq/notify-slack-action@be814b201e233b2dc673608aa46e5447c8ab13f2 # v2
124+
uses: ravsamhq/notify-slack-action@v2
130125
with:
131126
status: ${{ needs.deploy_aks.result }}
132127
token: ${{ secrets.GITHUB_TOKEN }}
@@ -135,4 +130,4 @@ jobs:
135130
message_format: '{emoji} <{workflow_url}|{workflow}> {status_message} in <{repo_url}|{repo}>'
136131
footer: 'Linked to Repo <{repo_url}|{repo}>'
137132
env:
138-
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}
133+
SLACK_WEBHOOK_URL: ${{ secrets.SLACK_WEBHOOK_URL }}

.identity/00_data.tf

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,12 @@ data "azurerm_storage_account" "receipts_sa" {
6262
resource_group_name = "pagopa-${var.env_short}-${local.location_short}-receipts-st-rg"
6363
}
6464

65+
data "azurerm_user_assigned_identity" "workload_identity_clientid" {
66+
name = "receipts-workload-identity"
67+
resource_group_name = "pagopa-${var.env_short}-${local.location_short}-${var.env}-aks-rg"
68+
}
6569

70+
data "azurerm_user_assigned_identity" "identity_cd_01" {
71+
resource_group_name = "${local.product}-identity-rg"
72+
name = "${local.product}-${local.domain}-job-01-github-cd-identity"
73+
}

.identity/03_github_environment.tf

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ resource "github_repository_environment" "github_repository_environment" {
2121

2222
locals {
2323
env_secrets = {
24-
"CLIENT_ID" : module.github_runner_app.application_id,
24+
"CLIENT_ID" : data.azurerm_user_assigned_identity.identity_cd_01.client_id,
2525
"TENANT_ID" : data.azurerm_client_config.current.tenant_id,
2626
"SUBSCRIPTION_ID" : data.azurerm_subscription.current.subscription_id,
2727
"RECEIPTS_COSMOS_CONN_STRING" : "AccountEndpoint=https://pagopa-${var.env_short}-${local.location_short}-${local.domain}-ds-cosmos-account.documents.azure.com:443/;AccountKey=${data.azurerm_cosmosdb_account.receipts_cosmos.primary_key};",
@@ -34,6 +34,7 @@ locals {
3434
"CLUSTER_RESOURCE_GROUP" : local.aks_cluster.resource_group_name,
3535
"DOMAIN" : local.domain,
3636
"NAMESPACE" : local.domain,
37+
"WORKLOAD_IDENTITY_ID": data.azurerm_user_assigned_identity.workload_identity_clientid.client_id
3738
}
3839
}
3940

helm/Chart.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ version: 0.121.0
66
appVersion: 1.13.4
77
dependencies:
88
- name: microservice-chart
9-
version: 2.4.0
9+
version: 7.5.0
1010
repository: "https://pagopa.github.io/aks-microservice-chart-blueprint"

helm/values-dev.yaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,43 @@ microservice-chart:
1010
livenessProbe:
1111
httpGet:
1212
path: /health
13-
port: 80
13+
port: 8080
1414
initialDelaySeconds: 60
1515
failureThreshold: 6
1616
periodSeconds: 10
1717
readinessProbe:
1818
httpGet:
1919
path: /health
20-
port: 80
20+
port: 8080
2121
initialDelaySeconds: 60
2222
failureThreshold: 6
2323
periodSeconds: 10
2424
deployment:
2525
create: true
26+
replicas: 1
2627
serviceMonitor:
2728
create: true
2829
endpoints:
2930
- interval: 10s #jmx-exporter
3031
targetPort: 12345
3132
path: /metrics
3233
ports:
33-
- 80 #http
34+
- 8080 #http
3435
- 12345 #jmx-exporter
3536
service:
3637
type: ClusterIP
3738
ports:
38-
- 80 #http
39+
- 8080 #http
3940
- 12345 #jmx-exporter
4041
ingress:
4142
create: true
4243
host: "weudev.receipts.internal.dev.platform.pagopa.it"
4344
path: /pagopa-receipt-pdf-datastore/(.*)
44-
servicePort: 80
45+
servicePort: 8080
4546
serviceAccount:
46-
create: false
47-
annotations: {}
48-
name: ""
47+
name: "receipts-workload-identity"
48+
azure:
49+
workloadIdentityClientId: <workload-identity-client-id-set-automatically-by-gha>
4950
podAnnotations: {}
5051
podSecurityContext:
5152
seccompProfile:
@@ -80,6 +81,7 @@ microservice-chart:
8081
envConfig:
8182
ENV: "dev"
8283
WEBSITE_SITE_NAME: "pagopareceiptpdfdatastore" # required to show cloud role name in application insights
84+
ASPNETCORE_URLS: "http://*:8080"
8385
FUNCTIONS_WORKER_RUNTIME: "java"
8486
RECEIPT_QUEUE_TOPIC: "pagopa-d-weu-receipts-queue-receipt-waiting-4-gen"
8587
COSMOS_RECEIPT_SERVICE_ENDPOINT: "https://pagopa-d-weu-receipts-ds-cosmos-account.documents.azure.com:443/"

helm/values-prod.yaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,43 @@ microservice-chart:
1010
livenessProbe:
1111
httpGet:
1212
path: /health
13-
port: 80
13+
port: 8080
1414
initialDelaySeconds: 60
1515
failureThreshold: 6
1616
periodSeconds: 10
1717
readinessProbe:
1818
httpGet:
1919
path: /health
20-
port: 80
20+
port: 8080
2121
initialDelaySeconds: 60
2222
failureThreshold: 6
2323
periodSeconds: 10
2424
deployment:
2525
create: true
26+
replicas: 2
2627
serviceMonitor:
2728
create: true
2829
endpoints:
2930
- interval: 10s #jmx-exporter
3031
targetPort: 12345
3132
path: /metrics
3233
ports:
33-
- 80 #http
34+
- 8080 #http
3435
- 12345 #jmx-exporter
3536
service:
3637
type: ClusterIP
3738
ports:
38-
- 80 #http
39+
- 8080 #http
3940
- 12345 #jmx-exporter
4041
ingress:
4142
create: true
4243
host: "weuprod.receipts.internal.platform.pagopa.it"
4344
path: /pagopa-receipt-pdf-datastore/(.*)
44-
servicePort: 80
45+
servicePort: 8080
4546
serviceAccount:
46-
create: false
47-
annotations: {}
48-
name: ""
47+
name: "receipts-workload-identity"
48+
azure:
49+
workloadIdentityClientId: <workload-identity-client-id-set-automatically-by-gha>
4950
podAnnotations: {}
5051
podSecurityContext:
5152
seccompProfile:
@@ -80,6 +81,7 @@ microservice-chart:
8081
envConfig:
8182
ENV: "prod"
8283
WEBSITE_SITE_NAME: "pagopareceiptpdfdatastore" # required to show cloud role name in application insights
84+
ASPNETCORE_URLS: "http://*:8080"
8385
FUNCTIONS_WORKER_RUNTIME: "java"
8486
RECEIPT_QUEUE_TOPIC: "pagopa-p-weu-receipts-queue-receipt-waiting-4-gen"
8587
COSMOS_RECEIPT_SERVICE_ENDPOINT: "https://pagopa-p-weu-receipts-ds-cosmos-account.documents.azure.com:443/"

helm/values-uat.yaml

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,42 +10,43 @@ microservice-chart:
1010
livenessProbe:
1111
httpGet:
1212
path: /health
13-
port: 80
13+
port: 8080
1414
initialDelaySeconds: 60
1515
failureThreshold: 6
1616
periodSeconds: 10
1717
readinessProbe:
1818
httpGet:
1919
path: /health
20-
port: 80
20+
port: 8080
2121
initialDelaySeconds: 60
2222
failureThreshold: 6
2323
periodSeconds: 10
2424
deployment:
2525
create: true
26+
replicas: 1
2627
serviceMonitor:
2728
create: true
2829
endpoints:
2930
- interval: 10s #jmx-exporter
3031
targetPort: 12345
3132
path: /metrics
3233
ports:
33-
- 80 #http
34+
- 8080 #http
3435
- 12345 #jmx-exporter
3536
service:
3637
type: ClusterIP
3738
ports:
38-
- 80 #http
39+
- 8080 #http
3940
- 12345 #jmx-exporter
4041
ingress:
4142
create: true
4243
host: "weuuat.receipts.internal.uat.platform.pagopa.it"
4344
path: /pagopa-receipt-pdf-datastore/(.*)
44-
servicePort: 80
45+
servicePort: 8080
4546
serviceAccount:
46-
create: false
47-
annotations: {}
48-
name: ""
47+
name: "receipts-workload-identity"
48+
azure:
49+
workloadIdentityClientId: <workload-identity-client-id-set-automatically-by-gha>
4950
podAnnotations: {}
5051
podSecurityContext:
5152
seccompProfile:
@@ -80,6 +81,7 @@ microservice-chart:
8081
envConfig:
8182
ENV: "uat"
8283
WEBSITE_SITE_NAME: "pagopareceiptpdfdatastore" # required to show cloud role name in application insights
84+
ASPNETCORE_URLS: "http://*:8080"
8385
FUNCTIONS_WORKER_RUNTIME: "java"
8486
RECEIPT_QUEUE_TOPIC: "pagopa-u-weu-receipts-queue-receipt-waiting-4-gen"
8587
COSMOS_RECEIPT_SERVICE_ENDPOINT: "https://pagopa-u-weu-receipts-ds-cosmos-account.documents.azure.com:443/"

0 commit comments

Comments
 (0)