Support SqlPackage Access Token Authentication

Open
#262 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
3/5
Estimated time
1-2 days
Newbie friendliness
45/100
Issue type
Feature
Clarity
Mostly clear
Activity status
Stale
Tech stack
azure, github-actions, sql, typescript
Domain
ci-cd, cloud, database

Research direction

Start by tracing the action's connection-string validation and argument handling, then reproduce the workflow using the shown connection string and /at token argument. Compare its behavior with the direct sqlpackage command. Done means the action can deploy with SqlPackage access-token authentication when no Authentication, User, or User Id value is present.

Written by the indexing model from the issue text.

Description

need-to-triage

SqlPackage supports the passing in of an access token as an authentication method, with no Authentication key/value pair present in the connection string. When this key is omitted from the action, an error is returned requiring that User or User Id keys are provided. Below is the example workflow yaml:

      - name: 'Az CLI login'
        uses: azure/login@v1
        with:
          client-id: ${{ vars.AZURE_CLIENT_ID }}
          tenant-id: ${{ vars.AZURE_TENANT_ID }}
          subscription-id: ${{ vars.AZURE_SUBSCRIPTION_ID }}
      
      - name: Get Access Token
        run: |
          ACCESS_TOKEN=$(az account get-access-token \
            --resource https://database.windows.net/ \
            --query accessToken \
            --output tsv)
          echo "AZ_ACCESS_TOKEN=$ACCESS_TOKEN" >> "$GITHUB_ENV"

      - name: build
        run: # build db project
      
      - name: Deploy to Azure SQL Database
        uses: Azure/sql-action@v2.3
        with:
          connection-string: 'Server=<server>;Initial Catalog=<database>;Connection timeout=60;Encrypt=True'
          path: # dacpac file
          action: 'publish'
          skip-firewall-check: true
          arguments: /at:$AZ_ACCESS_TOKEN

The above fails with the error: Invalid connection string. Please ensure 'User' or 'User ID' is provided in the connection string.

Replacing the final deployment step with a direct call to sqlpackage and passing in the same arguments successfully deploys the dacpac, like so:

sqlpackage /Action:Publish /TargetConnectionString:"Server=<server>;Initial Catalog=<database>;Connection timeout=60;Encrypt=True;" /SourceFile:<dacpac> /at:$AZ_ACCESS_TOKEN

The use case for this is that I am deploying to an Azure SQL instance using a user assigned managed identity with federated credentials, running on a self hosted runner which has not been assigned the managed identity. Using Authentication=Active Directory Managed Identity requires that the MI has been assigned to the runner machine.

Dominant language
TypeScript
Stars
142
Forks
73
Avg merge
9d 18h
Merged PRs (30d)
2

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Azure/sql-action

All issues in Azure/sql-action

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.