Git Product home page Git Product logo

tf-aks-sql-aad's Introduction

tf-aks-sql-aad

Terraform

This Terraform template enables authentication to Azure SQL Database using AAD Pod Identity from an AKS Cluster. The template is loosely based on this document with the following differences;

CREATE USER [<identity-name>] WITH default_schema=[dbo], SID=[<identity-sid>], TYPE=E;

instead of

CREATE USER [<identity-name>] FROM EXTERNAL PROVIDER;

The later T-SQL statement requires [<identity-name>] to be a user principal and if a service principal/managed identity is specified, it will fail with the following error;

Principal 'abc' could not be found at this time. Please try again later.

Many thanks to my colleague Noel Bundick for pointing out to this solution based on the pseudo-documented SID hack.

Requirements

Note: This template performs Azure AD role assignments required by AAD Pod Identity. Therefore the Service Principal used for Terraform authentication must be created with Owner privileges.

Azure resources

  • Azure SQL Database
  • User-Assigned Managed Identity
  • AKS Cluster

Smoke Test

Once terraform apply has successfully completed, fill the following variables from the Terraform output;

export aad_pod_id_binding_selector="aad-pod-id-binding-selector"
export aks_cluster_name="aks-xxxxxx"
export rg_name="rg-xxxxxx"
export sql_db_name="sqldb-test"
export sql_server_fqdn="sql-xxxxxx"

Alternatively, you can execute the following;

eval $(terraform output | sed 's/^/export /; s/ = /="/g; s/$/"/')

Then;

./smoke_test.sh

The smoke test will create a test pod in the newly provisioned AKS cluster and will attempt to authenticate to the SQL DB from the pod using managed identity. Once authentication is successful it will perform DDL and CRUD operations to validate the database roles.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.