banner



How To Create Service Princiapls Of Ad In Linux

Document-based auth with Azure Service Principals from Linux command line

Generate Certificate

          openssl req -x509 -days 3650 -newkey rsa:2048 -keyout key.pem -out cert.pem        

  • cert.pem contains the public cardinal
  • central.pem contains the individual key

Document Thumbprint

          openssl x509 -in cert.pem -fingerprint -noout        

          echo $(openssl x509 -in cert.pem -fingerprint -noout) | sed 'due south/SHA1 Fingerprint=//thou' | sed 's/://g' | xxd -r -ps | base64        

Document Central Value

          tail -n+2 cert.pem | head -n-1        

Setup Azure CLI

  • Install Azure Control Line Interface (Azure CLI) on Linux
  • Connect to your Azure subscription from the Azure Command Line Interface (Azure CLI)

          azure config mode arm        

Create Application and its Service Principal

          azure ad app create — name "myapp20150918" — home-folio "http://myapp20150918/" — identifier-uris "http://myapp20150918/" — key-usage "Verify" — finish-date "2020–01–01" — fundamental-value "$(tail -north+two cert.pem | caput -n-1)"        

          azure ad sp create            <Copy and Paste Application Id GUID Here>                  

          azure role assignment create — objectId            <Copy and Paste Service Principal Object Id GUID Hither>            -o Contributor        

Install node.js package jsonwebtoken

          npm install jsonwebtoken        

Obtain Azure Active Directory Tenant Id

          azure account listing        

          azure account show "Arsen Subscription Proper name"        

Sign the JWT Token

  • "aud" (Audience) is set to https://login.microsoftonline.com/TENANT_ID _HERE/oauth2/token
  • "iss" (Issuer) and "sub" (Discipline) are all set up to the Awarding Id GUID
  • "jti" (JWT ID) is set to a unique identifier for the JWT (in this case I will set information technology to a random value)
  • "nbf" (Not Earlier) is set to the UNIX timestamp denoting the commencement of the token validity period
  • "exp" (Expiration Time) is set to the UNIX timestamp cogent the end of the token validity period
          var jwt = require('jsonwebtoken');
var fs = crave('fs');
var cert = fs.readFileSync('cardinal.pem');
var additionalHeaders = {
"x5t":"HuMOEZfePZctStPVCVWgmQc90Pc="
}
var myJwt = {
"aud": "https://login.microsoftonline.com/TENANT_ID/oauth2/token",
"iss": "APPLICATION_ID",
"sub": "APPLICATION_ID",
"jti": "" + Math.random(),
"nbf": "" + (Math.flooring(Engagement.now()/1000)-1000),
"exp": "" + (Math.flooring(Appointment.now()/1000)+7*8640000)
};
console.log(myJwt);
var token = jwt.sign(myJwt,cert,{algorithm:'RS256', header:additionalHeaders});
panel.log(token);
          node signjwt.js        

Validate Signed JWT Token

Become Access Token from Azure Active Directory

                      ringlet            
— data "grant_type=client_credentials&client_id=APPLICATION_ID&client_assertion_type=urn:ietf:params:oauth:customer-assertion-blazon:jwt-bearer&client_assertion=SIGNED_JWT&resource=https://direction.azure.com/" https://login.microsoftonline.com/TENTANT_ID/oauth2/token

Access Azure Resource Manager API

          curl -H "Say-so: Bearer ACCESS_TOKEN_HERE" https://management.azure.com/subscriptions/SUBSCRIPTION_ID/resourcegroups?api-version=2015-01-01        

Conclusion

How To Create Service Princiapls Of Ad In Linux,

Source: https://arsenvlad.medium.com/certificate-based-auth-with-azure-service-principals-from-linux-command-line-a440c4599cae

Posted by: cervantezglanking.blogspot.com

0 Response to "How To Create Service Princiapls Of Ad In Linux"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel