creating ServiceFabric-LabCluster in devtest lab using cicd pipeline - azure-devtest-labs

I am trying to create service fabric cluster in azure devtest lab for creating test environment of my service fabric application.
Can someone please provide information on creating ServiceFabric-LabCluster in devtest lab using cicd pipeline

Important link which helped
https://blogs.msdn.microsoft.com/devtestlab/2018/07/11/integrate-azure-devtest-labs-environments-into-your-vsts-continuous-integration-and-delivery-pipeline/
This is the link to Public Repo:
https://github.com/Azure/azure-devtestlab
which contains Artifacts and Envionments. Within Envronments contains ServiceFabric-LabCluster which contains azuredeploy.json from where we can get the entire information of the parameters which we need to send from VSTS Pipeline. It also contains Create-ClusterCertificate.ps1 which is used to create certificate for creating cluster.
So first we need to create self-signed certificate if we don't have
one by executing this powershell file.
In the VSTS in new release pipeline , we have to get a task Azure
DevTest Labs Create Environment.
There we have to provide some inputs(parameters)
Azure Rm subscription: Here we select azure subscription
LabName : where we select the labname we had created
Repository Name : Here we select Public Environment Repo
Template Name: Select ServiceFabric-LabCluster
Environment Name : Here we provide Environment Name to be created
Parameter : we can provide all parameters required eg
-adminUsername '$(userName)'
-adminPassword (ConvertTo-SecureString -String '$(password)' -AsPlainText -Force)
-certificate ''
-certificatePassword 'CertiicatePassword'
-certificateThumbprint ''
After creating the pipeline we deploy it and our cluster would be created in azure.

Related

Deployment failed case on Devtestlab

I am trying to add a claimable VM for my lab in Azure DevTest following this document Create and manage claimable VMs - Azure DevTest Labs | Microsoft Learn but whenever I try to add
Operating system = windows
base vm = windows server 2022 datacenter azure editon core
size = standard_B1s
I am getting failed yet each time I attempt to add
And the disk showing as No result
Any solution while using this particular data center it fails or am i doing something wrong and I want this particular data center to have a fix for the issue?
I tried to reproduce the same in my environment and got the same error like below:
I created Devtest lab like below:
To resolve this issue try to add Artifact to configure and add to the VM like below:
Select Artifact:
In Additionally try to set an expiration date that you might want to delete VMs automatically after a certain date so they don't keep incurring costs. To create more than one VM with this configuration select an instancelike below:
Now, Deployment is created with disk successfully like below:

Create tenant database programatically

I am having a multi-tenancy application developed with Spring boot. In the master table I hold information about the tenant databases. I am trying to create a service, that receives a row from the master table and creates the database for it. Is there a known way to do this in Spring boot? The only information I can find on internet is creating at start up of the application and this is not desired. The master-tenant table is in a master schema and has the following structure:
The method from the service is as follows:
public void createTenant(TenantDTO tenantDTO) {
tenantepository.save(new Tenant(tenantDTO));
MasterTenant masterTenant = new MasterTenant();
masterTenant.setDbName(tenantDTO.getTenantId());
masterTenant.setDriverClass("com.mysql.jdbc.Driver");
masterTenant.setTenantId(tenantDTO.getTenantId());
masterTenant.setPassword("password");
masterTenant.setStatus(EStatus.ACTIVE.name());
masterTenant.setUserName("root");
masterTenant.setUrl("jdbc:mysql://localhost:3306/"+tenantDTO.getTenantId());
DBContextHolder.setCurrentDb(masterTenant.getDbName());
masterTenantRepository.save(masterTenant);
multiTenantConnectionProvider.selectDataSource(masterTenant.getTenantId());
//create schema + create tables from existing entities or run a script of sql
}
I would need help figuring out the part with create schema and tables.
One Option that I can think of is having a back-end like Jenkins or AWS Lambda to which you can give the request to create the database in your server pool.
In case of choosing a Jenkins job, you have REST API exposed by Jenkins, which you can make use of to trigger the job. As it is more tied to the dev-ops you can use terraform like script in the jenkins job that accepts the tenant id as a parameter to set that as the database name etc.
Some advantages of using a Jenkins job are
The job can be long running
Supports queueing
Can easily integrate with devops and remove those dependencies with the application
API based access to trigger a job, view status and logs etc.

How to validate and configure existing VNet/subnet for Azure SQL Managed Instance

Azure SQL database - Managed Instance must be placed in Azure VNet in dedicated subnet within the VNet. There are some special requirements that VNet and subnet must satisfy that are described here: https://medium.com/azure-sqldb-managed-instance/the-ultimate-guide-for-creating-and-configuring-azure-sql-managed-instance-environment-91ff58c0be01
What is the easiest way to check is the existing Azure VNet/subnet configured according the requirements and to fix issues/configure VNet/subnet in order to deploy Managed Instance in the existing VNet/subnet?
In Azure docs is described how to configure existing VNet/subnet to deploy Managed Instances in them - see https://learn.microsoft.com/en-us/azure/sql-database/sql-database-managed-instance-configure-vnet-subnet
You should use the following script and put subscription id, VNet and subnet names:
scriptUrlBase = 'https://raw.githubusercontent.com/Microsoft/sql-server-samples/master/samples/manage/azure-sql-db-managed-instance/prepare-subnet'
$parameters = #{
subscriptionId = '<subscriptionId>'
resourceGroupName = '<resourceGroupName>'
virtualNetworkName = '<virtualNetworkName>'
subnetName = '<subnetName>'
}
Invoke-Command -ScriptBlock ([Scriptblock]::Create((iwr ($scriptUrlBase+'/prepareSubnet.ps1?t='+ [DateTime]::Now.Ticks)).Content)) -ArgumentList $parameters
Script has the following steps:
Validate - Selected virtual network and subnet are validated for Managed Instance networking requirements
Reports & confirm - Script shows a set of changes that need to be made to prepare subnet for Managed Instance deployment and asked for consent
Prepare - Virtual network and subnet are modified by the script and configured properly.

Identityserver4 - Hosting in IIS

How to host ASPNET CORE APP with IdentityServer4 in IIS. The app is running fine from localhost but not as a web application setup in IIS.
For Example,
http://localhost:5000/connect/token is working but http://example.com/myauthapp/connect/token is not reachable - returning 500 - internal server error when tried from a console app using identity model or via postman. I am able to login to the app using web browser but not thru a console app or postman.
Further Troubleshoot and I find the below.
An unhandled exception has occurred: IDX10638: Cannot created the SignatureProvider, 'key.HasPrivateKey' is false, cannot create signatures. Key: Microsoft.IdentityModel.Tokens.RsaSecurityKey.
System.InvalidOperationException: IDX10638: Cannot created the SignatureProvider, 'key.HasPrivateKey' is false, cannot create signatures. Key: Microsoft.IdentityModel.Tokens.RsaSecurityKey.
at Microsoft.IdentityModel.Tokens.AsymmetricSignatureProvider..ctor(SecurityKey key, String algorithm, Boolean willCreateSignatures)
at Microsoft.IdentityModel.Tokens.CryptoProviderFactory.CreateSignatureProvider(SecurityKey key, String algorithm, Boolean willCreateSignatures)
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.CreateEncodedSignature(String input, SigningCredentials signingCredentials)
at System.IdentityModel.Tokens.Jwt.JwtSecurityTokenHandler.WriteToken(SecurityToken token)
at IdentityServer4.Services.DefaultTokenCreationService.CreateJwtAsync(JwtSecurityToken jwt)
at IdentityServer4.Services.DefaultTokenCreationService.<CreateTokenAsync>d__3.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
How can I solve this issue?
As Arun noted in his comment, the certificate has to be installed on the server.
1 . To test this on localhost first, make sure you are using "AddSigningCredential" not "AddTemporarySigningCredential".
services.AddIdentityServer()
.AddSigningCredential(new X509Certificate2(Path.Combine(_environment.ContentRootPath, "certs", "IdentityServer4Auth.pfx")));
//.AddTemporarySigningCredential()
;
Create the certificate in your project (create certs folder), running this in visual studio command:
"C:\Program Files (x86)\Windows Kits\8.1\bin\x64\makecert" -n
"CN=IdentityServer4Auth" -a sha256 -sv IdentityServer4Auth.pvk -r
IdentityServer4Auth.cer -b 01/01/2017 -e 01/01/2025
"C:\Program Files (x86)\Windows Kits\8.1\bin\x64\pvk2pfx" -pvk IdentityServer4Auth.pvk
-spc IdentityServer4Auth.cer -pfx IdentityServer4Auth.pfx
Test on localhost
If successful, deploy to iis server , install the certificate on the server by double clicking on it, and test.
Make sure the application pool "load user profile" is set to true :
Go to IIS Manager
Go to the application pool instance
Click advanced settings
Under Process model, set Load User Profile to true
Restart IIS
If this fails with a 500, like with me (and there is no logs to help you out), try this. To fix this recreate the certificate on the server the same way as in step 2 in the certs folder . double click the cert to install.
You might have to install the developer kit if you dont have visual studio installed:
https://developer.microsoft.com/en-us/windows/downloads/windows-8-1-sdk
A little background first, on why it is working on your Local Development computer and not running under IIS on a QA or Production Environment. If you are using Temporary Signing Credential when adding the service Identity Server 4 like so,
services.AddIdentityServer().AddTemporarySigningCredential();
Then you have to make sure the "User" that the "Process" is running as has a Private Key available for ID4 to create a Temporary Certificate. This is why the error message is
SignatureProvider, 'key.HasPrivateKey' is false, cannot create
signatures. Key: Microsoft.IdentityModel.Tokens.RsaSecurityKey.
In the case of Windows, this private key is generated by Windows automatically and can be found at the folder %APPDATA%\Microsoft\Crypto\RSA of the User or C:\Users\Username\AppData\Roaming\Microsoft\Crypto\RSA. The reason why this Private Key is missing is perhaps because the User that your Process is running as has never logged onto that Computer.
The likely SOLUTION in that case is to log in once as the User that will be running the Process on that Server. It is quite common for the Private Key directory to be missing if your Application Pool within IIS runs as a "non-service" user with very High Privileges and that user has never interactively logged onto the Server itself. This also explains why "localhost" works on your development computer, while running on a Production or QA Server may not.
More information on how and where Windows creates the Private Key for a User can be found here in this link Microsoft Key Storage and Retrieval. Also, it is recommended as mentioned by David Smit to explicitly specify a Private Key file, instead of using Temporary Signing Credentials. That is the cleaner solution if you are allowed to make code changes.
services.AddIdentityServer()
.AddSigningCredential(new X509Certificate2("C:\Certs\IdentityServer4PrivateKeyFile.pfx")));

Accessing existing cloud SQL instance from another project ID

I have created a cloud sql instance in a PHP project and have made the billing procedure successfully. The project works.
Now, I want to access my database from another project but this time in Java SDK project with servlets.
Using the example in https://developers.google.com/appengine/
docs/java/cloud-sql/
In Java project I have:
project id: javaProjectID
In php project id I have:
project id: phptestID
instance name: phpinstanceName
database: dbname
In my code in Servlet i do the below connection:
String url = "jdbc:google:mysql://phptestID:phpinstanceName/dbname?user=root";
Connection conn = (Connection) DriverManager.getConnection(url);
(...>> The connection fails in this point and doesn't access the database to make the below query )
String sqlStmt = "SELECT * FROM sometable";
PreparedStatement stmt = conn.prepareStatement(sqlStmt);
ResultSetres = stmt.executeQuery(sqlStmt);
How can I access my database in another project?? Is there any other way except
your-project-id:your-instance-name???
You will need to give the new app engine app access to your CloudSQL instance. To do this go to the Cloud SQL instance in the console, edit it, go down to Authorized App Engine Applications and then add the app id of the new App Engine app.
UPDATE:
The most recent steps look like in the attached screenshot below

Resources