Home
%3CLINGO-SUB%20id%3D%22lingo-sub-783076%22%20slang%3D%22en-US%22%3ESecuring%20Connectivity%20to%20Azure%20Database%20for%20MySQL%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-783076%22%20slang%3D%22en-US%22%3E%3CH1%20id%3D%22toc-hId-1991718174%22%20id%3D%22toc-hId-1991751870%22%3E%3CSTRONG%3ESecuring%20Connectivity%20to%20Azure%20Database%20for%20MySQL%3C%2FSTRONG%3E%3C%2FH1%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EEnsuring%20secure%20connectivity%20to%20database%20resource%20is%20an%20important%20requirement%20and%20consideration%20for%20customers%20running%20in%20cloud%20environment.%20Today%20customers%20want%20to%20connect%20to%20their%20Azure%20Database%20for%20MySQL%20from%20both%20inside%2Foutside%20of%20Azure%2C%20and%20based%20on%20the%20security%20and%20compliance%20requirements%2C%20organizations%20can%20choose%20one%20of%20the%20options%20provided%20by%20Azure%20Database%20for%20MySQL.%20In%20this%20blog%20post%2C%20we%20share%20the%20different%20connectivity%20options%20that%20can%20be%20used%20to%20connect%20to%20your%20Azure%20Database%20for%20MySQL%20and%20reap%20the%20benefits%20of%20the%20Azure%20platform.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--756952292%22%20id%3D%22toc-hId--756918596%22%3E%3CFONT%20color%3D%22%23000000%22%3E%3CSTRONG%3EUsing%20Service%20endpoints%20supported%20by%20Azure%20Database%20for%20MySQL%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EIf%20the%20resources%20accessing%20the%20Azure%20Database%20for%20MySQL%20are%20all%20within%20Azure%2C%20you%20can%20leverage%20Virtual%20Network%20Service%20Endpoints%20to%20connect%20to%20the%20server.%26nbsp%3B%20VNet%20service%20endpoints%20enable%20you%20to%20isolate%20connectivity%20to%20your%20logical%20server%20from%20only%20a%20given%20subnet%20or%20set%20of%20subnets%20within%20your%20virtual%20network.%20The%20traffic%20to%20Azure%20Database%20for%20MySQL%20from%20your%20VNet%20always%20stays%20within%20the%20Azure%20backbone%20network.%20Preference%20for%20this%20direct%20route%20is%20over%20any%20specific%20ones%20that%20route%20Internet%20traffic%20through%20virtual%20appliances%20or%20on-premises.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20418px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F125238i2E49C3F0F4C46733%2Fimage-dimensions%2F418x356%3Fv%3D1.0%22%20width%3D%22418%22%20height%3D%22356%22%20alt%3D%22clipboard_image_0.png%22%20title%3D%22clipboard_image_0.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETurning%20on%20VNet%20service%20endpoints%20does%20not%20override%20firewall%20rules%20that%20you%20have%20provisioned%20on%20your%20Azure%20Database%20for%20MySQL%20or%20PostgreSQL.%20Both%20continue%20to%20be%20applicable.%26nbsp%3BVNet%20service%20endpoints%20don%E2%80%99t%20extend%20to%20on-premises.%20To%20allow%20access%20from%20on-premises%2C%20firewall%20rules%20can%20be%20used%20to%20limit%26nbsp%3B%20connectivity%20only%20to%20your%20public%20(NAT)%20IPs.%26nbsp%3BYou%20can%20refer%20to%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fmysql%2Fhowto-manage-vnet-using-portal%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Edocumentation%3C%2FA%3Efor%20Azure%20Database%20for%20MySQL%20on%20how%20to%20setup%20service%20endpoints.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAdditionally%2C%20the%20Connection%20security%20pane%20has%20an%20ON%2FOFF%20button%20that%20is%20labeled%20%3CSTRONG%3E%3CEM%3E%E2%80%9CAllow%20Access%20to%20Azure%20services%E2%80%9D%3C%2FEM%3E%3C%2FSTRONG%3E.%20The%20ON%20setting%20allows%20communications%20from%20all%20Azure%20IP%20addresses%20and%20all%20Azure%20subnets.%20These%20Azure%20IPs%20or%20subnets%20might%20not%20be%20owned%20by%20you.%20This%20ON%20setting%20is%20probably%20more%20open%20than%20you%20want%20your%20Azure%20Database%20for%20MySQL%20Database%20to%20be.%20The%20virtual%20network%20rule%20feature%20offers%20much%20finer%20granular%20control%20and%20therefore%20a%20preferred%20way%20to%20establish%20connectivity%20for%20product%20environments.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-789344538%22%20id%3D%22toc-hId-789378234%22%3E%3CSTRONG%3ELimitations%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20pre-requisite%20for%20VNet%20service%20endpoint%20is%20%E2%80%9C%3CSTRONG%3Esame%20Azure%20region%20and%20same%20Azure%20AD%20tenant%E2%80%9D.%20%3C%2FSTRONG%3E%3CBR%20%2F%3EIf%20the%20resource%20requesting%20access%20to%20the%20MySQL%20resource%20are%20in%20two%20Active%20directory%20tenant%2C%20the%20recommended%20and%20preferred%20option%20is%20to%20use%20the%20single%20AD%20tenant%20with%20multiple%20subscription%20and%20but%20at%20the%20same%20time%20limit%20the%20access%20to%20database%20subscription%20using%20RBAC.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId--1566298918%22%20id%3D%22toc-hId--1566265222%22%3E%3CFONT%20color%3D%22%23000000%22%3E%3CSTRONG%3EUse%20Public%20Endpoints%20to%20connect%20to%20Azure%20DB%20for%20MySQL%20service%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20Azure%20DB%20for%20MySQL%20service%20is%20architected%20such%20that%20it%20sits%20behind%20Azure%20network%20protection%20and%20has%20its%20own%20gateway%20that%20securely%20establishes%20connections%20with%20your%20server.%20Connections%20to%20the%20database%20services%20are%20protected%20further%20by%20configuring%20MySQL%20native%20database%20firewalls%20which%20will%20ensure%20only%20traffic%20from%20whitelisted%20IP%20can%20enter%20and%20try%20to%20connect%20to%20the%20database.%20Additionally%2C%20Azure%20Database%20for%20MySQL%20support%20SSL%20connections%20and%20it%20is%20recommended%20to%20keep%20it%20%E2%80%9CON%E2%80%9D%20for%20any%20public%20incoming%20traffic.%3C%2FP%3E%0A%3CP%3EVisit%20these%20articles%20to%20learn%20how%20to%20configure%20SSL%20for%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fmysql%2Fhowto-configure-ssl%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20DB%20for%20MySQL%20service%3C%2FA%3E.%20Native%20database%20authentication%20methods%20for%20MySQL%20are%20supported%20out%20of%20the%20box.%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EYou%20can%20refer%20to%20the%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fen-us%2Fazure%2Fmysql%2Fhowto-manage-firewall-using-portal%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Edocumentation%3C%2FA%3Efor%20Azure%20Database%20for%20MySQL%20on%20how%20to%20setup%20firewall%20rules.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH2%20id%3D%22toc-hId-176511417%22%20id%3D%22toc-hId-176545113%22%3E%3CFONT%20color%3D%22%23000000%22%3E%3CSTRONG%3EUsing%20a%20TCP%20proxy%20along%20with%20VNet%20Peering%20to%20connect%20to%20Azure%20Database%20of%20MySQL%3C%2FSTRONG%3E%3C%2FFONT%3E%3C%2FH2%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ECustomer%20also%20want%20to%20connect%20to%20Azure%20Database%20for%20MySQL%20from%20on-premises%20by%20allowing%20outbound%20traffic%20to%20well-known%20IP%20addresses%20for%20Azure%20database%20for%20MySQL%20gateway%20for%20your%20Azure%20region%20that%20are%20documented%20%3CA%20href%3D%22https%3A%2F%2Fdocs.microsoft.com%2Fazure%2Fmysql%2Fconcepts-connectivity-architecture%22%20target%3D%22_blank%22%20rel%3D%22noopener%20noopener%20noreferrer%20noopener%20noreferrer%22%3Ehere%3C%2FA%3E.%20With%20the%20firewall%20rules%20and%20public%20endpoints%20explained%20in%20the%20previous%20section%2C%20the%20traffic%20goes%20over%20the%20Internet%20which%20introduces%20with%20it%20some%20inherent%20security%20and%20reliability%20challenges.%20A%20common%20example%20is%20having%20to%20manage%20firewall%20rules%20for%20mobile%20clients%20whose%20SNAT%20addresses%20change%20frequently.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EAn%20alternative%20is%20to%20setup%20a%20private%20connection%20to%20Azure%20%E2%80%93%20via%20P2S%20VPN%2C%20S2S%20VPN%20or%20Express%20Route%20%E2%80%93%20and%20then%20use%20a%20TCP%20proxy%20server%20to%20forward%20traffic%20to%20public%20IP%20address%20for%20Azure%20Database%20for%20MySQL.%20We%20can%20achieve%20this%20using%20P2S%20VPN%20and%20NGINX%20server.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20used%20P2S%20VPN%20as%20easy%20way%20to%20get%20traffic%20to%20flow%20from%20on-premises%20to%20Azure.%20In%20real-world%20scenarios%20customers%20should%20rely%20on%20more%20robust%20peering%20solutions%20like%20S2S%20VPN%20or%20Express%20Route%20for%20their%20production%20workloads.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EHere%20is%20the%20high-level%20architecture%20diagram%20of%20how%20this%20solution%20works%20in%20practice%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20539px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F125239i03B135CF562D3248%2Fimage-dimensions%2F539x159%3Fv%3D1.0%22%20width%3D%22539%22%20height%3D%22159%22%20alt%3D%22clipboard_image_1.png%22%20title%3D%22clipboard_image_1.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep1%3C%2FSTRONG%3E-%20User%20connects%20from%20on-premises%20(over%20VPN)%20by%20specifying%20Private%20IP%20address%20for%20Azure%20VM%20%26amp%3B%20port%203306.%20Alternately%2C%20hostname%20can%20be%20used%20with%20custom%20DNS%20that%20then%20maps%20it%20to%20Private%20IP%20address.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%202%3C%2FSTRONG%3E-%20NGINX%20is%20running%20on%20Azure%20VM%20and%20listening%20for%20traffic%20on%20port%203306%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSTRONG%3EStep%203%3C%2FSTRONG%3E-%20Traffic%20is%20forwarded%20by%20NGINX%20to%20the%20Azure%20Database%20for%20MySQL%20Gateway%20(for%20the%20region%20hosting%20your%20MySQL%20server)%20as%20part%20of%20normal%20login%20flow.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CH3%20id%3D%22toc-hId-1722808247%22%20id%3D%22toc-hId-1722841943%22%3E%3CSTRONG%3EHere%20is%20a%20step%20by%20step%20guide%20to%20implementing%20this%20architecture%3C%2FSTRONG%3E%3C%2FH3%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EStart%20by%20adding%20Azure%20VM%20vnet%26amp%3Bsubnet%20to%20virtual%20network%20rule%20on%20Azure%20Database%20for%20MySQ%20as%20described%20here.%20This%20will%20ensure%20that%20the%20subnet%20hosting%20Azure%20VM%20can%20communicate%20to%20MySQL%20server.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThe%20result%20should%20be%20a%20firewall%20rule%20that%20looks%20like%20this.%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20671px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F125243i4C240D097CCFDD54%2Fimage-dimensions%2F671x114%3Fv%3D1.0%22%20width%3D%22671%22%20height%3D%22114%22%20alt%3D%226.png%22%20title%3D%226.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENext%2C%20assign%20a%20Private%20IP%20address%20to%20your%20via%20VM%20Blade%20%C3%A0%20Networking%20%C3%A0%20IP%20Configurations.%20For%20this%20demo%20I%20typed%20in%2010.1.1.5%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%3CSPAN%20class%3D%22lia-inline-image-display-wrapper%20lia-image-align-inline%22%20style%3D%22width%3A%20504px%3B%22%3E%3CIMG%20src%3D%22https%3A%2F%2Fgxcuf89792.i.lithium.com%2Ft5%2Fimage%2Fserverpage%2Fimage-id%2F125439iE74CDEC8F19ED61D%2Fimage-dimensions%2F504x312%3Fv%3D1.0%22%20width%3D%22504%22%20height%3D%22312%22%20alt%3D%228.png%22%20title%3D%228.png%22%20%2F%3E%3C%2FSPAN%3E%3C%2FP%3E%0A%3CDIV%20id%3D%22tinyMceEditorclipboard_image_4%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%20id%3D%22tinyMceEditorclipboard_image_5%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CDIV%20id%3D%22tinyMceEditorclipboard_image_6%22%20class%3D%22mceNonEditable%20lia-copypaste-placeholder%22%3E%26nbsp%3B%3C%2FDIV%3E%0A%3CP%3E%3CA%20href%3D%22http%3A%2F%2Fnginx.org%2Fen%2Fdownload.html%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EDownload%3C%2FA%3ENginx%20and%20append%20the%20below%20snippet%20the%20bottom%20of%20the%20nginx.conf%26nbsp%3Bfile%26nbsp%3Bas%20follows%26nbsp%3Bwithout%20modifying%20headers%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CPRE%20class%3D%22lia-code-sample%20language-markup%22%3E%3CCODE%3Estream%20%7B%0A%20%20%20upstream%20sqlvm%20%7B%0A%20%20%20%20%20%20%20%20%20server%20mymysqlserver.mysql.database.azure.com%3A3306%3B%0A%20%20%20%7D%0A%20%20%20server%20%7B%0A%20%20%20%20%20%20%20%20%20listen%203306%3B%0A%20%20%20%20%20%20%20%20%20proxy_pass%20sqlvm%3B%0A%20%20%20%7D%0A%7D%3C%2FCODE%3E%3C%2FPRE%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EThis%20tells%20NGINX%20to%20forward%20any%20traffic%20received%20on%20port%203306%20to%20your%20Azure%20Database%20for%20MySQL%20server%20mymysqlserver.mysql.database.azure.com%3A3306.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ENow%20connect%20via%20%3CSTRONG%3E%3CEM%3E%E2%80%9CMySQL%20Workbench%E2%80%9D%3C%2FEM%3E%3C%2FSTRONG%3Especifying%20the%20Private%20IP%20address%20of%20VM%20and%20port%203306%20(which%20Nginx%20is%20listening%20on)%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3EWe%20showed%20you%20a%20proof-of-concept%20for%20how%20you%20can%20connect%20to%20Azure%20Database%20for%20MySQL%20from%20on-premises%20by%20using%20a%20TCP%20proxy%20server%20to%20forward%20traffic.%20Please%20note%2C%20the%20same%20steps%20will%20work%20for%20Azure%20Database%20for%20MariaDB%20on%20port%203306%20and%20for%20Azure%20Database%20for%20PostgreSQL%20on%20port%205432.%3C%2FP%3E%0A%3CP%3E%26nbsp%3B%3C%2FP%3E%0A%3CP%3ETo%20conclude%2C%20for%20ensuring%20secure%20connectivity%20to%20your%20Azure%20Database%20for%20MySQL%2C%20the%20different%20options%20gives%20you%20the%20flexibility%20and%20control%20of%20how%20data%20is%20transmitted.%20We%20are%20continuously%20working%20on%20making%20it%20easy%20for%20the%20customers%20to%20manage%20their%20database%20resource.%20You%20can%20engage%20with%20us%20on%20the%20Azure%20feedback%20forums%20for%20%3CA%20href%3D%22https%3A%2F%2Ffeedback.azure.com%2Fforums%2F597982-azure-database-for-mysql%22%20target%3D%22_blank%22%20rel%3D%22noopener%20nofollow%20noopener%20noreferrer%20noopener%20noreferrer%22%3EAzure%20Database%20for%20MySQL%3C%2FA%3E.%3C%2FP%3E%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-783076%22%20slang%3D%22en-US%22%3E%3CP%3E%3CSTRONG%3ESecuring%20Connectivity%20to%20Azure%20Database%20for%20MySQL%20%3C%2FSTRONG%3E%3C%2FP%3E%0A%3CP%3EEnsuring%20secure%20connectivity%20to%20database%20resource%20is%20an%20important%20requirement%20and%20consideration%20for%20customers%20running%20in%20cloud%20environment.%20Today%20customers%20want%20to%20connect%20to%20their%20Azure%20Database%20for%20MySQL%20from%20both%20inside%2Foutside%20of%20Azure%2C%20and%20based%20on%20the%20security%20and%20compliance%20requirements%2C%20organizations%20can%20choose%20one%20of%20the%20options%20provided%20by%20Azure%20Database%20for%20MySQL.%20In%20this%20blog%20post%2C%20we%20share%20the%20different%20connectivity%20options%20that%20can%20be%20used%20to%20connect%20to%20your%20Azure%20Database%20for%20MySQL%20and%20reap%20the%20benefits%20of%20the%20Azure%20platform.%3C%2FP%3E%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-783076%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESecuring%20Connectivity%20to%20Azure%20Database%20for%20MySQL%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Microsoft

Securing Connectivity to Azure Database for MySQL

 

Ensuring secure connectivity to database resource is an important requirement and consideration for customers running in cloud environment. Today customers want to connect to their Azure Database for MySQL from both inside/outside of Azure, and based on the security and compliance requirements, organizations can choose one of the options provided by Azure Database for MySQL. In this blog post, we share the different connectivity options that can be used to connect to your Azure Database for MySQL and reap the benefits of the Azure platform.

 

Using Service endpoints supported by Azure Database for MySQL

 

If the resources accessing the Azure Database for MySQL are all within Azure, you can leverage Virtual Network Service Endpoints to connect to the server.  VNet service endpoints enable you to isolate connectivity to your logical server from only a given subnet or set of subnets within your virtual network. The traffic to Azure Database for MySQL from your VNet always stays within the Azure backbone network. Preference for this direct route is over any specific ones that route Internet traffic through virtual appliances or on-premises.

clipboard_image_0.png

 

Turning on VNet service endpoints does not override firewall rules that you have provisioned on your Azure Database for MySQL or PostgreSQL. Both continue to be applicable. VNet service endpoints don’t extend to on-premises. To allow access from on-premises, firewall rules can be used to limit  connectivity only to your public (NAT) IPs. You can refer to the documentation for Azure Database for MySQL on how to setup service endpoints.

 

Additionally, the Connection security pane has an ON/OFF button that is labeled “Allow Access to Azure services”. The ON setting allows communications from all Azure IP addresses and all Azure subnets. These Azure IPs or subnets might not be owned by you. This ON setting is probably more open than you want your Azure Database for MySQL Database to be. The virtual network rule feature offers much finer granular control and therefore a preferred way to establish connectivity for product environments.

 

Limitations

 

The pre-requisite for VNet service endpoint is “same Azure region and same Azure AD tenant”.
If the resource requesting access to the MySQL resource are in two Active directory tenant, the recommended and preferred option is to use the single AD tenant with multiple subscription and but at the same time limit the access to database subscription using RBAC.

 

Use Public Endpoints to connect to Azure DB for MySQL service

 

The Azure DB for MySQL service is architected such that it sits behind Azure network protection and has its own gateway that securely establishes connections with your server. Connections to the database services are protected further by configuring MySQL native database firewalls which will ensure only traffic from whitelisted IP can enter and try to connect to the database. Additionally, Azure Database for MySQL support SSL connections and it is recommended to keep it “ON” for any public incoming traffic.

Visit these articles to learn how to configure SSL for Azure DB for MySQL service. Native database authentication methods for MySQL are supported out of the box. 

 

You can refer to the documentation for Azure Database for MySQL on how to setup firewall rules.

 

Using a TCP proxy along with VNet Peering to connect to Azure Database of MySQL

 

Customer also want to connect to Azure Database for MySQL from on-premises by allowing outbound traffic to well-known IP addresses for Azure database for MySQL gateway for your Azure region that are documented here. With the firewall rules and public endpoints explained in the previous section, the traffic goes over the Internet which introduces with it some inherent security and reliability challenges. A common example is having to manage firewall rules for mobile clients whose SNAT addresses change frequently.

 

An alternative is to setup a private connection to Azure – via P2S VPN, S2S VPN or Express Route – and then use a TCP proxy server to forward traffic to public IP address for Azure Database for MySQL. We can achieve this using P2S VPN and NGINX server.

 

We used P2S VPN as easy way to get traffic to flow from on-premises to Azure. In real-world scenarios customers should rely on more robust peering solutions like S2S VPN or Express Route for their production workloads.

 

Here is the high-level architecture diagram of how this solution works in practice

 

clipboard_image_1.png

 

Step1 - User connects from on-premises (over VPN) by specifying Private IP address for Azure VM & port 3306. Alternately, hostname can be used with custom DNS that then maps it to Private IP address.

 

Step 2 - NGINX is running on Azure VM and listening for traffic on port 3306

 

Step 3 - Traffic is forwarded by NGINX to the Azure Database for MySQL Gateway (for the region hosting your MySQL server) as part of normal login flow.

 

Here is a step by step guide to implementing this architecture

 

Start by adding Azure VM vnet&subnet to virtual network rule on Azure Database for MySQ as described here. This will ensure that the subnet hosting Azure VM can communicate to MySQL server.

 

The result should be a firewall rule that looks like this.

6.png

 

Next, assign a Private IP address to your via VM Blade à Networking à IP Configurations. For this demo I typed in 10.1.1.5

 

8.png

 
 
 

Download Nginx and append the below snippet the bottom of the nginx.conf file as follows without modifying headers

 

 

stream {
   upstream sqlvm {
         server mymysqlserver.mysql.database.azure.com:3306;
   }
   server {
         listen 3306;
         proxy_pass sqlvm;
   }
}

 

 

This tells NGINX to forward any traffic received on port 3306 to your Azure Database for MySQL server mymysqlserver.mysql.database.azure.com:3306.

 

Now connect via “MySQL Workbench” specifying the Private IP address of VM and port 3306 (which Nginx is listening on)

 

We showed you a proof-of-concept for how you can connect to Azure Database for MySQL from on-premises by using a TCP proxy server to forward traffic. Please note, the same steps will work for Azure Database for MariaDB on port 3306 and for Azure Database for PostgreSQL on port 5432.

 

To conclude, for ensuring secure connectivity to your Azure Database for MySQL, the different options gives you the flexibility and control of how data is transmitted. We are continuously working on making it easy for the customers to manage their database resource. You can engage with us on the Azure feedback forums for Azure Database for MySQL.