Giter Club home page Giter Club logo

service-auth-provider-app's Introduction

Service auth provider

Build Status Codacy Badge codecov

This microservice is used to authenticate services across HMCTS.

Getting Started

Prerequisites

Building

To build the project execute the following command:

$ ./gradlew build

Configuration

In order to setup Service Auth Provider to work with a client service, you need to do the following:

  • In the Azure Key Vault named s2s-{environment} add the service's secret used for generating OTPs (one-time passwords). This has to be done in each environment the service is going to be deployed to. Service Auth Provider will use that secret for validating OTPs. It has to be a BASE32-encoded sequence of ten random bytes (16 characters after encoding). By convention, the Azure Key Vault secret's name should follow this format: microservicekey-{service-name}. Here's how to generate it.
  • To make it work on AKS , Add the client service name (as in HTTP requests ) and Azure Key Vault secret created in the previous steps to values.yaml. A service TEST_SERVICE with secret key microservicekey-test-service needs to be configured as below :
java:
 keyVaults:
   "s2s":
     secrets:
       - name: microservicekey-test-service
         alias: microserviceKeys.test_service

Note: test_service is lower cased in alias mapping, though its not mandatory.

Generating the microservice secret

Here's a sample Java snippet to generate a microservice secret:

byte[] bytes = new byte[10];
SecureRandom.getInstanceStrong().nextBytes(bytes);
String secret = new Base32().encodeAsString(bytes);

Sample Python code to generate that secret:

import os
import base64
base64.b32encode(os.urandom(10))

Writing a secret into all the needed vaults

Please make sure realpath is installed as script uses it.

Ubuntu: sudo apt-get install coreutils
OS X  : brew install coreutils

On Debian or Ubuntu realpath should be installed by default

There's a script provided ./bin/set-secret-in-all-vaults <microservice-name> This will write the secret into all the vaults and then it will run the check script to check it can find the secret

You need to have the azure-cli installed and be logged in (az login) for it to work, also ensure you are in the dcd_reform_dev_logs group in AAD.

Getting the change to production

Create a pull request after you've set the secret in all vaults, once your build is green you can request a review by posting on the #platops-code-review Slack channel. If the build is green, and the PR template was filled out correctly showing that the secret has been entered in all vaults then the change will be merged and a build automatically triggered. Once the build is finished and passed it will be automatically deployed to the AAT and production environments. If you need it in demo you can merge the code to demo and git push.

Reading the secret in client service's infrastructure code

Once the service's secret is stored in Azure Key Vault, it can be retrieved from the S2S key vault with Terraform and written into your own vault.

data "azurerm_key_vault" "key_vault" {
  name                = "${var.product}-${var.env}" # update these values if required
  resource_group_name = "${var.product}-${var.env}" # update these values if required
}

data "azurerm_key_vault" "s2s_vault" {
  name                = "s2s-${var.env}"
  resource_group_name = "rpe-service-auth-provider-${var.env}"
}

data "azurerm_key_vault_secret" "key_from_vault" {
  name         = "microservicekey-ccd-data" # update key name e.g. microservicekey-your-name
  key_vault_id = data.azurerm_key_vault.s2s_vault.id
}

resource "azurerm_key_vault_secret" "s2s" {
  name         = "s2s-secret"
  value        = data.azurerm_key_vault_secret.key_from_vault.value
  key_vault_id = data.azurerm_key_vault.key_vault.id
}

Running

To run the app execute:

$ ./gradlew bootRun

You can also run the app on docker.
To build:

$ docker-compose build

And to run:

$ docker-compose up

Dockerized app comes with preconfigured sample service. See docker-compose.yml for details.

Documentation

API documentation is provided with Swagger.
Json spec is available under standard /v3/api-docs route.

Flow diagram can be found here

Developing

Unit tests

To run all unit tests execute the following command:

$ ./gradlew test

License

This project is licensed under the MIT License - see the LICENSE file for details.

service-auth-provider-app's People

Contributors

adusumillipraveen avatar alectronic0 avatar alexbaeza avatar alokdatta avatar attila-kiss-hmcts avatar davejones74 avatar dependabot-preview[bot] avatar dependabot[bot] avatar doncem avatar hannah38 avatar jasonpaige avatar karoljastrzebski avatar lgonczar avatar luigibk avatar msl8r avatar naikajah avatar nitinprabhu avatar nitishsingla1234 avatar padmajaruk avatar paul-pearson avatar pd-dudkiewicz avatar reespozzi avatar renovate[bot] avatar rkondratowicz avatar ruban72 avatar swalker125 avatar timja avatar tomxelliott avatar vijayrajagopalan-hmcts avatar yogesh-hullatti avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

service-auth-provider-app's Issues

Dependency Dashboard

This issue lists Renovate updates and detected dependencies. Read the Dependency Dashboard docs to learn more.

Awaiting Schedule

These updates are awaiting their schedule. Click on a checkbox to get an update now.

  • Update Helm release java to v5.2.1
  • Update Terraform azuread to v2.50.0
  • Update Terraform azurerm to ~> 3.104.0
  • Update plugin org.owasp.dependencycheck to v9.2.0

Open

These updates have all been created already. Click a checkbox below to force a retry/rebase of any.

Detected dependencies

docker-compose
docker-compose.yml
dockerfile
Dockerfile
  • hmctspublic.azurecr.io/base/java 21-distroless
gradle
gradle.properties
settings.gradle
build.gradle
  • se.patrikerdes.use-latest-versions 0.2.18
  • com.github.ben-manes.versions 0.51.0
  • org.owasp.dependencycheck 9.1.0
  • org.sonarqube 5.0.0.4638
  • io.spring.dependency-management 1.1.5
  • org.springframework.boot 3.2.0
  • au.com.dius.pact 4.6.9
  • org.yaml:snakeyaml 2.2
  • com.google.guava:guava 33.2.0-jre
  • io.jsonwebtoken:jjwt 0.9.1
  • org.apache.httpcomponents:httpclient 4.5.14
  • com.warrenstrange:googleauth 1.5.0
  • com.github.hmcts.java-logging:logging 6.1.4
  • org.apache.logging.log4j:log4j-api 2.22.0
  • org.apache.logging.log4j:log4j-to-slf4j 2.22.0
  • org.springdoc:springdoc-openapi-starter-webmvc-ui 2.5.0
  • jakarta.xml.bind:jakarta.xml.bind-api 2.3.3
  • net.sourceforge.findbugs:annotations 1.3.2
  • junit:junit 4.13.2
  • org.assertj:assertj-core 3.24.2
  • com.typesafe:config 1.4.3
  • junit:junit 4.13.2
  • au.com.dius.pact.provider:junit5 4.6.9
  • au.com.dius.pact.provider:spring6 4.6.9
  • com.warrenstrange:googleauth 1.5.0
  • org.junit.jupiter:junit-jupiter-api 5.10.2
  • org.junit.jupiter:junit-jupiter-engine 5.10.2
  • org.junit.platform:junit-platform-commons 1.10.2
gradle-wrapper
gradle/wrapper/gradle-wrapper.properties
  • gradle 8.7
helm-values
charts/rpe-service-auth-provider/values.yaml
helmv3
charts/rpe-service-auth-provider/Chart.yaml
  • java 5.2.0
regex
Dockerfile
  • microsoft/ApplicationInsights-Java 3.4.18
terraform
infrastructure/main.tf
infrastructure/state.tf
  • azuread 2.49.1
  • azurerm ~> 3.103.0
infrastructure/versions.tf
  • hashicorp/terraform >= 0.13
terraform-version
infrastructure/.terraform-version
  • hashicorp/terraform 1.8.3

  • Check this box to trigger a request for Renovate to run again on this repository

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.