Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: Add Identity service #218

Merged
merged 43 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 41 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
cad6210
Feat: Add Credential, Credential Schema and Identity services from Sa…
techsavvyash Apr 17, 2023
6265de0
Feat: Add identity service
techsavvyash Apr 18, 2023
d5a8b69
Feat: add sample env
techsavvyash Apr 18, 2023
af2000b
feat: Add targets for identity-service
tushar5526 Jun 20, 2023
6ae6a53
feat: Add containerized tests
tushar5526 Jun 20, 2023
de7798b
feat: Update makefile
tushar5526 Jun 20, 2023
7cd8731
Merge pull request #1 from tushar5526/identity
techsavvyash Jun 21, 2023
6af1cd1
fix: remove `.gitmodules`, make did method dynamic
techsavvyash Jun 21, 2023
4b1abd7
feat: Fix dockerfile and add vault config
tushar5526 Jun 26, 2023
4ca48af
feat: Automate vault
tushar5526 Jun 26, 2023
5ed5da8
fix: fix makefile to tag release
tushar5526 Jun 27, 2023
472c7ca
fix: Fix setup_vault.sh
tushar5526 Jun 27, 2023
38ddc7a
fix: fixes part 1
techsavvyash Jun 27, 2023
feab152
fix: remove ulp specific jenkins file
techsavvyash Jun 27, 2023
7b08768
feat: Dockerized tests
tushar5526 Jun 27, 2023
a21b2fa
delete gitpod.yml
tushar5526 Jun 27, 2023
6bf139c
fix: remove test containers before starting tests
tushar5526 Jun 27, 2023
3d8cf31
fix: add compose-init target and readme update
tushar5526 Jun 27, 2023
bc7c9a2
fix: update env vars in compose
tushar5526 Jun 27, 2023
4f5f5a5
Merge pull request #4 from tushar5526/identity-dockerfile
techsavvyash Jun 27, 2023
d01d3ef
Update setup_vault.sh
tushar5526 Jun 27, 2023
97a2eee
Merge pull request #5 from tushar5526/patch-1
techsavvyash Jun 27, 2023
428123c
feat: add verify endpoint
techsavvyash Jun 27, 2023
193bf06
Merge branch 'identity' of github.com:techsavvyash/sunbird-rc-core in…
techsavvyash Jun 27, 2023
2de0ddf
fix and enable auth guard
techsavvyash Jun 27, 2023
a6e2e4e
fix: error handling logging and touchups
techsavvyash Jun 27, 2023
b399774
feat: tests
techsavvyash Jun 27, 2023
f1bcc31
Update setup_vault.sh
tushar5526 Jun 28, 2023
9a366f7
Merge pull request #7 from tushar5526/patch-2
techsavvyash Jun 28, 2023
b994fde
fix: Fix tests, docker-compose-test, and setup_vault.sh
tushar5526 Jun 28, 2023
3421b72
Merge pull request #8 from tushar5526/test-fix
techsavvyash Jun 28, 2023
7dd2719
feat: add health checks for DB container
tushar5526 Jun 28, 2023
b99a439
fix: make tests working
techsavvyash Jun 28, 2023
580a640
Merge pull request #9 from tushar5526/compose-fix
techsavvyash Jun 28, 2023
8e5a1b3
update tests
techsavvyash Jun 28, 2023
8811c86
Update .env
tejash-jl Jul 1, 2023
c9ead04
feat: add health check
techsavvyash Jul 3, 2023
31bd2fa
fix: vault health check
techsavvyash Jul 3, 2023
6195bcd
fix
techsavvyash Jul 3, 2023
884f9d1
feat: add health checks to vault and use test network for test contai…
tushar5526 Jul 3, 2023
97da68c
Merge branch 'main' into identity
tushar5526 Jul 3, 2023
ce6ac5e
fix: improvements
techsavvyash Jul 4, 2023
f2d1bfd
Merge branch 'identity' of https://github.com/techsavvyash/sunbird-rc…
techsavvyash Jul 4, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
RELEASE_VERSION=v0.0.14
VIEW_DIR=java/apitest/src/test/resources/views
SCHEMA_DIR=java/apitest/src/test/resources/schemas
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ RELEASE_VERSION = v0.0.14
IMAGES := dockerhub/sunbird-rc-core dockerhub/sunbird-rc-nginx dockerhub/sunbird-rc-context-proxy-service \
dockerhub/sunbird-rc-public-key-service dockerhub/sunbird-rc-keycloak dockerhub/sunbird-rc-certificate-api \
dockerhub/sunbird-rc-certificate-signer dockerhub/sunbird-rc-notification-service dockerhub/sunbird-rc-claim-ms \
dockerhub/sunbird-rc-digilocker-certificate-api dockerhub/sunbird-rc-bulk-issuance dockerhub/sunbird-rc-metrics
dockerhub/sunbird-rc-digilocker-certificate-api dockerhub/sunbird-rc-bulk-issuance dockerhub/sunbird-rc-metrics \
dockerhub/sunbird-rc-identity-service

build: java/registry/target/registry.jar
echo ${SOURCES}
rm -rf java/claim/target/*.jar
Expand All @@ -21,6 +23,7 @@ build: java/registry/target/registry.jar
make -C services/digilocker-certificate-api docker
make -C services/bulk_issuance docker
docker build -t dockerhub/sunbird-rc-nginx .
make -C services/identity-service/ docker

java/registry/target/registry.jar: $(SOURCES)
echo $(SOURCES)
Expand Down Expand Up @@ -54,7 +57,8 @@ test: build
make -C services/public-key-service test
make -C services/context-proxy-service test
make -C services/bulk_issuance test

make -C services/identity-service test

clean:
@rm -rf target || true
@rm java/registry/target/registry.jar || true
Expand Down
25 changes: 25 additions & 0 deletions services/identity-service/.env.sample
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# JWKS_URI=""
# VAULT_ADDR=""
# VAULT_TOKEN=""
# APPLICATION_ID=""
# DATABASE_URL=""
# EMAIL_HOST=""
# EMAIL_PASSWORD=""
# EMAIL_SENDER=""
# FUSION_API_KEY=""


DATABASE_URL=""
JWKS_URI=""

# key generation configs
SIGNING_ALGORITHM="RS256"

# vault configs
VAULT_ADDR=""
VAULT_TOKEN=""
VAULT_BASE_URL=""
VAULT_ROOT_PATH=""
VAULT_TIMEOUT=5000
VAULT_PROXY='' #this is supposed to be a boolean flag given as a string
ENABLE_AUTH=false
21 changes: 21 additions & 0 deletions services/identity-service/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
FROM node:16 AS install
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn

FROM node:16 as build
WORKDIR /app
COPY prisma ./prisma/
COPY --from=install /app/node_modules ./node_modules
RUN npx prisma generate
COPY . .
RUN yarn build

FROM node:16
WORKDIR /app
COPY --from=build /app/dist ./dist
COPY --from=build /app/package*.json ./
COPY --from=build /app/prisma ./prisma
COPY --from=build /app/node_modules ./node_modules
EXPOSE 3332
CMD [ "npm", "run", "start:migrate:prod" ]
13 changes: 13 additions & 0 deletions services/identity-service/Dockerfile.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM node:16 AS install
WORKDIR /app
COPY package.json yarn.lock ./
RUN yarn

FROM node:16 as test
WORKDIR /app
COPY prisma ./prisma/
COPY --from=install /app/node_modules ./node_modules
RUN npx prisma generate
COPY . .
EXPOSE 3332
CMD [ "yarn", "test:migrate" ]
21 changes: 21 additions & 0 deletions services/identity-service/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 Sunbird RC

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
15 changes: 15 additions & 0 deletions services/identity-service/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
IMAGE:=dockerhub/sunbird-rc-identity-service

.PHONY: docker publish test run unseal

docker:
@docker build -t $(IMAGE) .
publish:
@docker push $(IMAGE)
test:
@docker-compose -f docker-compose-test.yml down
bash build/setup_vault.sh docker-compose-test.yml vault-test
@docker-compose -f docker-compose-test.yml up --build --abort-on-container-exit
compose-init:
bash build/setup_vault.sh
@docker-compose up -d --build
52 changes: 52 additions & 0 deletions services/identity-service/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
## Description

[Nest](https://github.com/nestjs/nest) framework TypeScript starter repository.

## Installation

```bash
$ npm install
```

## Running the app

```bash
# development env
$ npm run start

# watch mode
$ npm run start:dev

# production mode
$ npm run start:prod
```

## Test

```bash
# unit tests
$ npm run test

# In independent docker containers
$ make test

# e2e tests
$ npm run test:e2e

# test coverage
$ npm run test:cov
```

## Support

Nest is an MIT-licensed open source project. It can grow thanks to the sponsors and support by the amazing backers. If you'd like to join them, please [read more here](https://docs.nestjs.com/support).

## Stay in touch

- Author - [Kamil Myśliwiec](https://kamilmysliwiec.com)
- Website - [https://nestjs.com](https://nestjs.com/)
- Twitter - [@nestframework](https://twitter.com/nestframework)

## License

Nest is [MIT licensed](LICENSE).
63 changes: 63 additions & 0 deletions services/identity-service/build/setup_vault.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/bin/bash

# This script does the following things
# * Start a vault instance with vault/vault.json configuration
# * Unseal the vault
# * Create a v2 kv engine
# * Prints the unseal keys and root token
# * This script does not automatically unseal vault on restarts, it only works with fresh installations

COMPOSE_FILE="${1:-docker-compose.yml}"
SERVICE_NAME="${2:-vault}"

echo "Setting up $SERVICE_NAME in $COMPOSE_FILE"

docker-compose -f "$COMPOSE_FILE" up -d "$SERVICE_NAME"

# Function to check if Vault is ready
check_vault_status() {
vault_status=$(docker-compose -f "$COMPOSE_FILE" exec "$SERVICE_NAME" vault status 2>&1)
if [[ $vault_status == *"connection refused"* ]]; then
echo "Unable to connect to Vault. Waiting for Vault to start..."
return 1
elif [[ $vault_status == *"Sealed true"* ]]; then
echo "Vault is sealed. Waiting for unsealing..."
return 0
else
echo "Unsealed and up. Moving to next steps."
return 0
fi
}


# Wait for Vault service to become available
until check_vault_status; do
echo "Waiting for Vault service to start..."
sleep 1;
done

# keys contains ansi escape sequences, remove them if any
docker-compose -f "$COMPOSE_FILE" exec "$SERVICE_NAME" vault operator init > ansi-keys.txt
sed 's/\x1B\[[0-9;]*[JKmsu]//g' < ansi-keys.txt > keys.txt
sed -n 's/Unseal Key [1-1]\+: \(.*\)/\1/p' keys.txt > parsed-key.txt
key=$(cat parsed-key.txt)
docker-compose -f "$COMPOSE_FILE" exec -T "$SERVICE_NAME" vault operator unseal "$key"

sed -n 's/Unseal Key [2-2]\+: \(.*\)/\1/p' keys.txt > parsed-key.txt
key=$(cat parsed-key.txt)
docker-compose -f "$COMPOSE_FILE" exec -T "$SERVICE_NAME" vault operator unseal "$key"

sed -n 's/Unseal Key [3-3]\+: \(.*\)/\1/p' keys.txt > parsed-key.txt
key=$(cat parsed-key.txt)
docker-compose -f "$COMPOSE_FILE" exec -T "$SERVICE_NAME" vault operator unseal "$key"

root_token=$(sed -n 's/Initial Root Token: \(.*\)/\1/p' keys.txt | tr -dc '[:print:]')

sed -i "s/VAULT_TOKEN:.*/VAULT_TOKEN: $root_token/" "$COMPOSE_FILE"

docker-compose -f "$COMPOSE_FILE" exec -e VAULT_TOKEN=$root_token -T "$SERVICE_NAME" vault secrets enable -path=kv kv-v2

echo -e "\nNOTE: STORE THE FOLLOWING KEYS SOMEWHERE SAFELY. THESE ARE USED TO UNSEAL VAULT ON RESTARTS"

cat keys.txt
rm parsed-key.txt ansi-keys.txt keys.txt
70 changes: 70 additions & 0 deletions services/identity-service/docker-compose-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
version: '3'
services:
vault-test:
image: vault:1.13.3
restart: always
volumes:
- ./vault/vault.json:/vault/config/vault.json
environment:
- VAULT_ADDR=http://0.0.0.0:8200
- VAULT_API_ADDR=http://0.0.0.0:8200
- VAULT_ADDRESS=http://0.0.0.0:8200
cap_add:
- IPC_LOCK
command: vault server -config=/vault/config/vault.json
healthcheck:
test: ["CMD-SHELL", "wget --spider http://127.0.0.1:8200/v1/sys/health || exit 1"]
interval: 10s
timeout: 5s
retries: 3
networks:
test:

db-test:
image: postgres:latest
restart: always
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 10s
timeout: 5s
retries: 5
networks:
test:

identity-service-test:
image: identity-test
build:
context: .
dockerfile: Dockerfile.test
depends_on:
db-test:
condition: service_healthy
vault-test:
condition: service_healthy
environment:
DATABASE_URL: "postgres://postgres:postgres@db-test:5432/postgres"
VAULT_ADDR: "http://vault-test:8200"
# This will be replaced automatically on initialisation
# make compose-init will call setup_vault.sh
VAULT_TOKEN: hvs.dOLOfZJe5HJW1LBgQLCnW3YU
VAULT_BASE_URL: "http://vault-test:8200/v1"
VAULT_ROOT_PATH: "http://vault-test:8200/v1/kv"
VAULT_TIMEOUT: 5000
VAULT_PROXY: 'false'
SIGNING_ALGORITHM: "RS256"
JWKS_URI: ""
ENABLE_AUTH: "false"
networks:
test:
healthcheck:
test:
[ "CMD-SHELL", "curl -f http://localhost:3332/health || exit 1" ]
interval: 10s
timeout: 5s
retries: 5

networks:
test:
71 changes: 71 additions & 0 deletions services/identity-service/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
version: '3'
services:
vault:
image: vault:1.13.3
restart: always
volumes:
- ./vault/vault.json:/vault/config/vault.json
- vault-data:/vault/file
environment:
- VAULT_ADDR=http://0.0.0.0:8200
- VAULT_API_ADDR=http://0.0.0.0:8200
- VAULT_ADDRESS=http://0.0.0.0:8200
cap_add:
- IPC_LOCK
command: vault server -config=/vault/config/vault.json
ports:
- 8200:8200
healthcheck:
test: ["CMD-SHELL", "wget --spider http://127.0.0.1:8200/v1/sys/health || exit 1"]
interval: 10s
timeout: 5s
retries: 3
db:
image: postgres:latest
restart: always
ports:
- 5432:5432
environment:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
volumes:
- data:/var/lib/postgresql/data
healthcheck:
test: [ "CMD-SHELL", "pg_isready -U postgres" ]
interval: 10s
timeout: 5s
retries: 5
identity-service:
image: identity
build:
context: .
dockerfile: Dockerfile
depends_on:
db:
condition: service_healthy
vault:
condition: service_healthy
ports:
- 3332:3332
environment:
DATABASE_URL: "postgres://postgres:postgres@db:5432/postgres"
VAULT_ADDR: "http://vault:8200"
# This will be replaced automatically on initialisation
# make compose-init will call setup_vault.sh
VAULT_TOKEN: hvs.jwNIOFLgGBQhHRFuRL3y9Obl
VAULT_BASE_URL: "http://vault:8200/v1"
VAULT_ROOT_PATH: "http://vault:8200/v1/kv"
VAULT_TIMEOUT: 5000
VAULT_PROXY: 'false'
SIGNING_ALGORITHM: "RS256"
JWKS_URI:
ENABLE_AUTH: "false"
healthcheck:
test:
[ "CMD-SHELL", "curl -f http://localhost:3332/health || exit 1" ]
interval: 10s
timeout: 5s
retries: 5
volumes:
data:
vault-data:
Loading