Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use workload identity for sql server auth #39

Merged
merged 61 commits into from
Feb 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
a499329
handle errors in tests
Richard87 Feb 5, 2024
2e42a74
add ids
Richard87 Feb 5, 2024
03a689f
add ids
Richard87 Feb 5, 2024
de18661
test no subs
Richard87 Feb 6, 2024
37e7f12
test multiline connection string
Richard87 Feb 6, 2024
0c8ab8a
test multiline connection string
Richard87 Feb 6, 2024
4e3a8a1
test env variable
Richard87 Feb 6, 2024
39a91eb
test sql cmd
Richard87 Feb 6, 2024
e543fa4
test sql cmd
Richard87 Feb 6, 2024
c6b30f7
test sql cmd
Richard87 Feb 6, 2024
d613ee3
test sql cmd
Richard87 Feb 6, 2024
e8e7cc7
test odbc sqlcmd
Richard87 Feb 6, 2024
4c73fdd
run script file
Richard87 Feb 6, 2024
ca5c309
use default auth
Richard87 Feb 6, 2024
12fd2df
use sql action
Richard87 Feb 6, 2024
5df179d
spelling
Richard87 Feb 6, 2024
3e09f8e
change client-id
Richard87 Feb 6, 2024
1304d7f
test matrix
Richard87 Feb 6, 2024
3dd6d6c
test matrix
Richard87 Feb 6, 2024
7a01548
test acr task run
Richard87 Feb 6, 2024
647975b
test acr task run
Richard87 Feb 6, 2024
3f64a3e
test acr task run
Richard87 Feb 6, 2024
6a02106
test acr task run
Richard87 Feb 6, 2024
fd84e0a
test acr task run
Richard87 Feb 6, 2024
4873b1b
actually run
Richard87 Feb 6, 2024
88b5527
test
Richard87 Feb 6, 2024
83fbd1a
test
Richard87 Feb 6, 2024
ea4c223
test
Richard87 Feb 6, 2024
11be478
simplify workflows, use new managed identity for database interactions
Richard87 Feb 6, 2024
5a04006
remove permissions from pr
Richard87 Feb 7, 2024
1194435
add matrix if
Richard87 Feb 7, 2024
be947d3
test matrix in pr
Richard87 Feb 7, 2024
9e35fd2
test matrix in pr
Richard87 Feb 7, 2024
6720ca8
test matrix in pr
Richard87 Feb 7, 2024
7bf459c
test matrix in pr
Richard87 Feb 7, 2024
5ed2e31
test matrix in pr
Richard87 Feb 7, 2024
7d27668
test matrix in pr
Richard87 Feb 7, 2024
7f02291
test matrix in pr
Richard87 Feb 7, 2024
850c66a
test matrix in pr
Richard87 Feb 7, 2024
082f6d7
test matrix in pr
Richard87 Feb 7, 2024
2c6dcfb
test matrix in pr
Richard87 Feb 7, 2024
256e350
test matrix in pr
Richard87 Feb 7, 2024
8043079
test matrix in pr
Richard87 Feb 7, 2024
0259bd7
test matrix in pr
Richard87 Feb 7, 2024
b789d77
test matrix in pr
Richard87 Feb 7, 2024
0863067
test matrix in pr
Richard87 Feb 7, 2024
ede5fb1
test matrix in pr
Richard87 Feb 7, 2024
0fb2d76
test matrix in pr
Richard87 Feb 7, 2024
99f280a
test matrix in pr
Richard87 Feb 7, 2024
dcc9162
test matrix in pr
Richard87 Feb 7, 2024
0562fbf
test matrix in pr
Richard87 Feb 7, 2024
742bb49
test matrix in pr
Richard87 Feb 7, 2024
2d8c463
test matrix in pr
Richard87 Feb 7, 2024
8797e42
test matrix in pr
Richard87 Feb 7, 2024
c1fc51e
test matrix in pr
Richard87 Feb 7, 2024
f1ac92f
test matrix in pr
Richard87 Feb 7, 2024
1bcd99d
only run sql updates in prod/c2/playground on push to release
Richard87 Feb 7, 2024
c94cb54
use checkout v4
Richard87 Feb 7, 2024
4f042fd
add comment
Richard87 Feb 7, 2024
da7a997
fix ref
Richard87 Feb 9, 2024
7debf2b
fix ref and client-id
Richard87 Feb 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
114 changes: 69 additions & 45 deletions .github/workflows/build-push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,55 +5,79 @@ on:
branches: [ main, release ]

permissions:
actions: read
checks: read
contents: read
deployments: read
id-token: write
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
contents: read

jobs:
get-target-configs:
name: Get target configs for branch
outputs:
target_configs: ${{ steps.get-target-configs.outputs.target_configs }}
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Get target configs
id: get-target-configs
run: |
configs=$(ls $GITHUB_WORKSPACE/.github/workflows/config/${GITHUB_REF_NAME} | jq -Rsc '. / "\n" - [""]')
echo "target_configs=${configs}" >> $GITHUB_OUTPUT
build-deploy-image:
name: Build & push
build-deploy:
runs-on: ubuntu-20.04
needs:
- get-target-configs
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.get-target-configs.outputs.target_configs) }}
matrix:
target:
- name: "dev"
ref: "refs/heads/master"
acr-name: "radixdev"
client-id: "1a292b18-2960-49a5-b429-c8a50349b5eb"
subscription-id: "16ede44b-1f74-40a5-b428-46cca9a5741b"

- name: "playground"
ref: "refs/heads/release"
acr-name: "radixdev"
client-id: "1a292b18-2960-49a5-b429-c8a50349b5eb"
subscription-id: "16ede44b-1f74-40a5-b428-46cca9a5741b"

- name: "platform"
ref: "refs/heads/release"
acr-name: "radixprod"
client-id: "d1ee58e8-5896-48d9-a777-5418c3df9a58"
subscription-id: "ded7ca41-37c8-4085-862f-b11d21ab341a"

- name: "c2"
ref: "refs/heads/release"
acr-name: "radixc2prod"
client-id: "d1ee58e8-5896-48d9-a777-5418c3df9a58"
subscription-id: "ded7ca41-37c8-4085-862f-b11d21ab341a"

steps:
- uses: actions/checkout@v3
- name: Persist environment from ${{ matrix.config }} across steps
run: |
$GITHUB_WORKSPACE/.github/workflows/scripts/persist-env.sh ${{ matrix.config }}
- uses: azure/login@v1
with:
client-id: ${{ env.AZURE_CLIENT_ID }}
tenant-id: ${{ env.AZURE_TENANT_ID }}
subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}

- name: Build image
run: |
$GITHUB_WORKSPACE/.github/workflows/scripts/build-push.sh
- uses: actions/checkout@v4
if: matrix.target.ref == github.ref

- uses: azure/login@v1
if: matrix.target.ref == github.ref
with:
client-id: ${{matrix.target.client-id}}
tenant-id: "3aa4a235-b6e2-48d5-9195-7fcf05b459b0"
subscription-id: ${{matrix.target.subscription-id}}

- name: Generate image tag
if: matrix.target.ref == github.ref
id: tag
run: |
sha=${GITHUB_SHA::8}
ts=$(date +%s)
echo "tag=${GITHUB_REF_NAME}-${sha}-${ts}" >> $GITHUB_OUTPUT
- name: Build image
if: matrix.target.ref == github.ref
env:
AZURE_SUBSCRIPTION_ID: ${{matrix.target.subscription-id}}
ACR_NAME: ${{matrix.target.acr-name}}
IMAGE_NAME: radix-vulnerability-scanner
TAG: ${{steps.tag.outputs.tag}}
run: |
az acr task run \
--subscription ${AZURE_SUBSCRIPTION_ID} \
--name radix-image-builder-internal \
--registry ${ACR_NAME} \
--context ${GITHUB_WORKSPACE} \
--file ${GITHUB_WORKSPACE}/Dockerfile \
--set DOCKER_REGISTRY=${ACR_NAME} \
--set BRANCH=${GITHUB_REF_NAME} \
--set TAGS="--tag ${ACR_NAME}.azurecr.io/${IMAGE_NAME}:${TAG}" \
--set DOCKER_FILE_NAME=Dockerfile \
--set PUSH="--push" \
--set REPOSITORY_NAME=${IMAGE_NAME} \
--set CACHE="" \
--set CACHE_TO_OPTIONS="--cache-to=type=registry,ref=${ACR_NAME}.azurecr.io/${IMAGE_NAME}:radix-cache-${GITHUB_REF_NAME},mode=max"
7 changes: 0 additions & 7 deletions .github/workflows/config/common.cfg

This file was deleted.

12 changes: 0 additions & 12 deletions .github/workflows/config/main/dev.cfg

This file was deleted.

12 changes: 0 additions & 12 deletions .github/workflows/config/release/c2.cfg

This file was deleted.

12 changes: 0 additions & 12 deletions .github/workflows/config/release/playground.cfg

This file was deleted.

12 changes: 0 additions & 12 deletions .github/workflows/config/release/prod.cfg

This file was deleted.

140 changes: 73 additions & 67 deletions .github/workflows/deploy-database.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,85 +3,91 @@ name: Deploy Database
on:
push:
branches: [main, release]
workflow_dispatch:

permissions:
actions: read
checks: read
contents: read
deployments: read
id-token: write
issues: read
discussions: read
packages: read
pages: read
pull-requests: read
repository-projects: read
security-events: read
statuses: read
contents: read

jobs:
get-target-configs:
name: Get target configs for branch
outputs:
target_configs: ${{ steps.get-target-configs.outputs.target_configs }}
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Get target configs
id: get-target-configs
run: |
configs=$(ls $GITHUB_WORKSPACE/.github/workflows/config/${GITHUB_REF_NAME} | jq -Rsc '. / "\n" - [""]')
echo "target_configs=${configs}" >> $GITHUB_OUTPUT
deploy-sql-server:
deploy:
runs-on: ubuntu-20.04
needs:
- get-target-configs
strategy:
fail-fast: false
matrix:
config: ${{ fromJson(needs.get-target-configs.outputs.target_configs) }}
matrix:
target:
- name: "dev"
ref: "refs/heads/master"
client-id: "a23b30b8-3faa-42a1-817e-6cd097a620f1"
server: "sql-radix-vulnerability-scan-dev.database.windows.net"

- name: "playground"
ref: "refs/heads/release"
client-id: "453fb3de-daaa-43e6-93ef-a470849a2b6b"
server: "sql-radix-vulnerability-scan-playground.database.windows.net"

- name: "platform"
ref: "refs/heads/release"
client-id: "50e78187-ff60-49c5-bcbe-701bbbf4f5d7"
server: "sql-radix-vulnerability-scan-prod.database.windows.net"

- name: "c2"
ref: "refs/heads/release"
client-id: "f26240e2-3095-4273-8559-2ca9a121991e"
server: "sql-radix-vulnerability-scan-c2.database.windows.net"

env:
connection: >-
Server=${{matrix.target.server}};
Initial Catalog=radix-vulnerability-scan;
Authentication=Active Directory Default;
Encrypt=True;
TrustServerCertificate=False;
Connection Timeout=30;
steps:
- uses: actions/checkout@v3
- name: Persist environment from ${{ matrix.config }} across steps
run: |
$GITHUB_WORKSPACE/.github/workflows/scripts/persist-env.sh ${{ matrix.config }}
- uses: actions/checkout@v4
if: matrix.target.ref == github.ref

- uses: azure/login@v1
if: matrix.target.ref == github.ref
with:
client-id: ${{matrix.target.client-id}}
tenant-id: "3aa4a235-b6e2-48d5-9195-7fcf05b459b0"
allow-no-subscriptions: true

- uses: azure/login@v1
with:
client-id: ${{ env.AZURE_CLIENT_ID }}
tenant-id: ${{ env.AZURE_TENANT_ID }}
subscription-id: ${{ env.AZURE_SUBSCRIPTION_ID }}
- uses: azure/[email protected]
if: matrix.target.ref == github.ref
with:
connection-string: ${{env.connection}}
path: './azure-infrastructure/sql-scripts/predeploy.sql'

- name: Get DB password from KV
run: |
db_admin_pw=$(az keyvault secret show --id https://${KEY_VAULT_NAME}.vault.azure.net/secrets/${DB_ADMIN_SECRET_NAME} --query value --output tsv)
echo "::add-mask::$db_admin_pw"
echo "DB_ADMIN_PASSWORD=$db_admin_pw" >> $GITHUB_ENV
- uses: azure/[email protected]
if: matrix.target.ref == github.ref
with:
connection-string: ${{env.connection}}
path: './azure-infrastructure/sql-scripts/roles.sql'

- name: Generate random firewall rule name
run: |
fw_rule_name="github-runner-$(uuidgen)"
echo "FIREWALL_RULE_NAME=$fw_rule_name" >> $GITHUB_ENV
- name: Install SqlServer PS module
shell: pwsh
run: |
Set-PSRepository -Name "PSGallery" -InstallationPolicy Trusted
Install-Module -Name SqlServer
- uses: azure/[email protected]
if: matrix.target.ref == github.ref
with:
connection-string: ${{env.connection}}
path: './azure-infrastructure/sql-scripts/types.sql'

- name: Whitelist Runner IP in firewalls
shell: pwsh
run: |
./.github/workflows/scripts/whitelist-ip.ps1 -FirewallRuleName "${env:FIREWALL_RULE_NAME}"
- uses: azure/[email protected]
if: matrix.target.ref == github.ref
with:
connection-string: ${{env.connection}}
path: './azure-infrastructure/sql-scripts/tables.sql'

- name: Creating DB schema and tables
shell: pwsh
run: |
./.github/workflows/scripts/create-db.ps1
- uses: azure/[email protected]
if: matrix.target.ref == github.ref
with:
connection-string: ${{env.connection}}
path: './azure-infrastructure/sql-scripts/views.sql'

- name: Blacklist Runner IP in firewalls
shell: pwsh
if: ${{ always() }}
run: |
./.github/workflows/scripts/blacklist-ip.ps1 -FirewallRuleName "${env:FIREWALL_RULE_NAME}"
- uses: azure/[email protected]
if: matrix.target.ref == github.ref
with:
connection-string: ${{env.connection}}
path: './azure-infrastructure/sql-scripts/procedures.sql'
5 changes: 3 additions & 2 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@ on:
pull_request:
branches:
- main

jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- name: Build docker image
env:
REF: ${{ github. sha }}
Expand Down Expand Up @@ -36,7 +37,7 @@ jobs:
name: Unit Test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
with:
go-version: '1.21'
Expand Down
8 changes: 0 additions & 8 deletions .github/workflows/scripts/blacklist-ip.ps1

This file was deleted.

Loading
Loading