Skip to content

Commit

Permalink
Merge pull request #290 from microsoft/user/elay/remove-client-secret
Browse files Browse the repository at this point in the history
Remove secret from cicd
  • Loading branch information
elayrocks committed May 7, 2024
2 parents 18915aa + 148e87e commit ceaad79
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 46 deletions.
38 changes: 19 additions & 19 deletions .github/workflows/cicd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@ env:
PCTASKS_COSMOSDB__URL: ${{ secrets.COSMOSDB_URL }}
PCTASKS_COSMOSDB__KEY: ${{ secrets.COSMOSDB_KEY }}
PCTASKS_COSMOSDB__TEST_CONTAINER_SUFFIX: ${{ github.run_id }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
AZURE_CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}

permissions:
id-token: write
Expand Down Expand Up @@ -72,23 +68,18 @@ jobs:
;;
esac

- name: Log into the ACR (test)
env:
CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
run: docker login pccomponentstest.azurecr.io --username ${CLIENT_ID} --password ${CLIENT_SECRET}
- name: Log in with Azure
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Publish images (test)
run: ./scripts/publish --acr pccomponentstest --tag ${{steps.get_image_tag.outputs.tag}} --no-login

- name: Log into the ACR
env:
CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
CLIENT_SECRET: ${{ secrets.AZURE_CLIENT_SECRET }}
run: docker login pccomponents.azurecr.io --username ${CLIENT_ID} --password ${CLIENT_SECRET}
run: ./scripts/publish --acr pccomponentstest --tag ${{steps.get_image_tag.outputs.tag}}

- name: Publish images
run: ./scripts/publish --acr pccomponents --tag ${{steps.get_image_tag.outputs.tag}} --no-login
run: ./scripts/publish --acr pccomponents --tag ${{steps.get_image_tag.outputs.tag}}

- name: Clean up CosmosDB test containers
run: ./scripts/setup --rm-test-containers
Expand All @@ -105,10 +96,19 @@ jobs:
steps:
- uses: actions/checkout@v2

- name: Log in with Azure
uses: azure/login@v1
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}

- name: Deploy
run: ./scripts/cideploy
env:
IMAGE_TAG: ${{needs.build_and_publish.outputs.image_tag}}
ENVIRONMENT: staging
AZURE_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
AZURE_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ secrets.AZURE_TENANT_ID }}
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
ARM_CLIENT_ID: ${{ secrets.AZURE_CLIENT_ID }}
ARM_USE_OIDC: true
4 changes: 2 additions & 2 deletions deployment/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ RUN echo "deb [arch=amd64] https://packages.microsoft.com/repos/microsoft-ubuntu

RUN apt-get update && apt-get install -y azure-functions-core-tools-4

# Install Terraform 0.14.4
# Install Terraform 1.8.2

RUN wget -O terraform.zip https://releases.hashicorp.com/terraform/1.1.2/terraform_1.1.2_linux_amd64.zip
RUN wget -O terraform.zip https://releases.hashicorp.com/terraform/1.8.2/terraform_1.8.2_linux_amd64.zip
RUN unzip terraform.zip
RUN mv terraform /usr/local/bin

Expand Down
7 changes: 1 addition & 6 deletions deployment/bin/deploy
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,8 @@ Options:
require_env "ARM_SUBSCRIPTION_ID"
require_env "ARM_TENANT_ID"
require_env "ARM_CLIENT_ID"
require_env "ARM_CLIENT_SECRET"
require_env "ARM_USE_OIDC"

require_env "AZURE_TENANT_ID"
require_env "AZURE_CLIENT_ID"
require_env "AZURE_CLIENT_SECRET"

###################
# Parse arguments #
Expand Down Expand Up @@ -112,8 +109,6 @@ if [ "${BASH_SOURCE[0]}" = "${0}" ]; then
# Gather environment variables from the terraform directory
source "${TERRAFORM_DIR}"/env.sh

bin/azlogin

require_env "DEPLOY_SECRETS_KV"
require_env "DEPLOY_SECRETS_KV_SECRET"
require_env "DEPLOY_SECRETS_KV_RG_NAME"
Expand Down
9 changes: 1 addition & 8 deletions deployment/bin/lib
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,6 @@ function cluster_login() {
CLUSTER_NAME=$2
fi

az login --service-principal \
--username ${ARM_CLIENT_ID} \
--password ${ARM_CLIENT_SECRET} \
--tenant ${ARM_TENANT_ID}

az aks get-credentials \
--resource-group ${RESOURCE_GROUP} \
--name ${CLUSTER_NAME} \
Expand All @@ -88,9 +83,7 @@ function cluster_login() {
# So we export to a kubeconfig file
echo "Converting kubeconfig..."
kubelogin convert-kubeconfig \
--login spn \
--client-id ${ARM_CLIENT_ID} \
--client-secret ${ARM_CLIENT_SECRET} \
-l azurecli \
--kubeconfig=kubeconfig
export KUBECONFIG=kubeconfig
}
Expand Down
19 changes: 10 additions & 9 deletions deployment/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ services:
dockerfile: deployment/Dockerfile
environment:
# For Terraform
- ARM_SUBSCRIPTION_ID=${AZURE_SUBSCRIPTION_ID}
- ARM_TENANT_ID=${AZURE_TENANT_ID}
- ARM_CLIENT_ID=${AZURE_CLIENT_ID}
- ARM_CLIENT_SECRET=${AZURE_CLIENT_SECRET}

# For Azure CLI
- AZURE_TENANT_ID=${AZURE_TENANT_ID}
- AZURE_CLIENT_ID=${AZURE_CLIENT_ID}
- AZURE_CLIENT_SECRET=${AZURE_CLIENT_SECRET}
- ARM_SUBSCRIPTION_ID
- ARM_TENANT_ID
- ARM_CLIENT_ID
- ARM_USE_OIDC
- ARM_OIDC_TOKEN
- ACTIONS_ID_TOKEN_REQUEST_URL
- ACTIONS_ID_TOKEN_REQUEST_TOKEN
- ARM_OIDC_REQUEST_TOKEN
- ARM_OIDC_REQUEST_URL

# Used in function deployment injected by GH Actions
- GITHUB_TOKEN
Expand All @@ -26,3 +26,4 @@ services:
- ../deployment:/opt/src/deployment
- ../pctasks:/opt/src/pctasks:ro
- ../pctasks_funcs:/opt/src/pctasks_funcs:ro
- ~/.azure:/root/.azure
3 changes: 2 additions & 1 deletion deployment/terraform/batch_pool/providers.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
provider azurerm {
features {}
skip_provider_registration = true
use_oidc = true
}

terraform {
Expand All @@ -9,7 +10,7 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.65.0"
version = "3.97.1"
}
}
}
3 changes: 2 additions & 1 deletion deployment/terraform/resources/providers.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
provider azurerm {
features {}
skip_provider_registration = true
use_oidc = true
}

terraform {
Expand All @@ -9,7 +10,7 @@ terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.65.0"
version = "3.97.1"
}
}
}
Expand Down
1 change: 1 addition & 0 deletions deployment/terraform/staging/backend.tf
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ terraform {
storage_account_name = "pctesttfstate"
container_name = "pctasks"
key = "staging.terraform.tfstate"
use_oidc = true
}
}

0 comments on commit ceaad79

Please sign in to comment.